<?php
$acedemic_session=$this->session->userdata('acedemic_session');
?>
<style>
    .pegination{text-align:center;height:40px;}
 .pegination a{
    font-size: 15px;
    color: green;border-radius:5px;width: 34px;height:34px;
    border:1px solid green;margin-left:10px;padding:5px;text-decoration:none;
}
.pegination a:hover{
   background:green;color:#fff;text-decoration:none;
}
.pegination strong{
    font-size: 15px;
    color: brown;
    border:1px solid green;margin-left:10px;padding:5px;
    background:green;color:#fff;text-decoration:none;
    border-radius:5px;width: 34px;
}
</style>
<div class="container-fluid bg-white mt-3 mb-3 ">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Fee/all_students">Fee</a></li>
                <li class="breadcrumb-item"><a href="#"></a>Invoices</li>
            </ul>
            
            <table class="table table-bordered">
                <tr>
                    <td><a href="<?php echo base_url();?>Enquiry/invoices">Enquiry and Admission Fee</a></td>
                    <td><a href="<?php echo base_url();?>Fee/invoices">Monthly Fee Invoices</a></td>
                </tr>
            </table>
            
            <div class="table-responsive">
                <table class="table table-bordered" id="">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Fee No.</th>
                            <th>S. Id.</th>
                            
                            <th>Name</th>
                            <th>Father's Name</th>
                            <th>Est Amount</th>
                            <th>Received Amount</th>
                            <th>Discount</th>
                            <!--<th>Fee Months</th>-->
                            <!--<th>Fee Type</th>-->
                            <th>Bill Book No.</th>
                            <th>Course</th>
                            <th>Date</th>
                            <th>Invoices</th>
                            <th>Edit</th>
                            
                            <?php 
                            if($this->session->userdata('all_permission') ==1){
                                ?>
                                <th class="text-danger">
                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill" viewBox="0 0 16 16">
                                    <path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"/>
                                </svg>
                                </th>
                                <?php
                            }
                            ?>
                            
                        </tr>
                    </thead>
                    <tbody>
                       <?php ?>
                        <?php 
                        $fee_table='student_fee';
                        $count=0;
                        foreach ($all_invoices as $fee_invoices):
                        // $get_all_fee_invoices=$this->NewFeeModel->get_fee_data_by_desc($fee_table);
                        // if($get_all_fee_invoices){
                        //     foreach($get_all_fee_invoices as $fee_invoices){
                                $count=$count + 1;
                                $student_table='student';
                                ?>
                                <tr>
                                    <td><?php echo $count;?></td>
                                    
                                    <td><?php echo $fee_invoices->fee_no;?></td>
                                    <td><?php echo $fee_invoices->sid;?></td>
                                <?php
                                $get_student_data=$this->NewFeeModel->get_item_data($fee_invoices->sid,$student_table);
                                if($get_student_data){
                                    foreach($get_student_data as $student_data){
                                ?>
                                
                                    
                                    
                                    <td><?php echo $student_data['student_name'];?></td>
                                    <td><?php echo $student_data['father_name'];?></td>
                                          
                                <?php
                                    }
                                }else{
                                    ?>
                                    
                                    <td></td>
                                    <td></td>
                                    <?php
                                }
                                ?>
                                    <td><?php echo $fee_invoices->estimate_amount;?></td>
                                    <td><?php echo $fee_invoices->received_amount;?></td>
                                    <td><?php echo $fee_invoices->discount;?></td>
                                    <!--<td><?php echo $fee_invoices->fee_type;?></td>-->
                                    <td><?php echo $fee_invoices->bill_book_no;?></td>
                                    <td>
                                    <?php
                                    $course_id=$fee_invoices->course_id;
                                    $courses_table_1='courses';
                                    $get_course_data=$this->NewFeeModel->get_item_data($course_id,$courses_table_1);
                                    if($get_course_data){
                                        foreach($get_course_data as $course_data){
                                    
                                     echo $course_data['course']; echo " "; echo $course_data['subject_stream'];
                                         
                                        }
                                    }
                                    ?>
                                    </td>
                                    <td><?php echo date('M-d-Y',strtotime($fee_invoices->fee_date));?></td>
                                    <td>
                                        <a href="<?php echo base_url();?>Fee/invoice/<?php echo $fee_invoices->fee_no;?>" class="btn btn-sm btn-info" style="color:#fff;" target="_blank">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-printer-fill" viewBox="0 0 16 16">
                                                <path d="M5 1a2 2 0 0 0-2 2v1h10V3a2 2 0 0 0-2-2H5zm6 8H5a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1z"/>
                                                <path d="M0 7a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2h-1v-2a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2H2a2 2 0 0 1-2-2V7zm2.5 1a.5.5 0 1 0 0-1 .5.5 0 0 0 0 1z"/>
                                            </svg>
                                        </a>
                                    </td>
                                    <td>
                                        <a href="<?php echo base_url();?>Fee/edit_fee_data/<?php echo $fee_invoices->fee_no;?>" class="btn btn-sm btn-warning" target="_blank">
                                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
                                                <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
                                                <path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
                                            </svg>
                                        </a>
                                    </td>
                            <?php 
                            if($this->session->userdata('all_permission') ==1){
                                ?>
                                    <td><button class="text-danger btn btn-sm" id="item_to_trash" item_id="<?php echo $fee_invoices->fee_no;?>"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash-fill" viewBox="0 0 16 16"><path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"/></svg></button></td>
                                
                            <?php
                            }
                            ?>
                                  
                                </tr>
                                <?php
                        //     }
                        // }
                        ?>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            <div id="dump_data"></div>
            
            <p class="mt-2 pegination"><?php echo $links; ?></p>
        </div>

    </div>
</div>


<script>
    $(document).ready(function(){
    
    
        $(document).on("click","#item_to_trash",function(){
            // alert("Hi");     
            //   var item_id=$(this).
            var item_id = $(this).attr("item_id");
            // alert(item_id);
            $.ajax({
                url: '<?php echo base_url(); ?>Fee/delete_invoice',
                type: 'POST',
                data: {item_id:item_id},
                success: function(data){
                    // location.reload();
                    alert(data);
                    // $("#dump_data").html(data);
                }
        });
        
        
    });
    });
</script>