<div class="container-fluid mt-3 mb-3 bg-white">
    <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="#">Opening Fee</a></li>
                <li class="breadcrumb-item">Invoices</li>
                <?php 
                if($this->session->userdata('all_permission') ==1){
                ?>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>OpeningFee/deleted_invoices">Deleted Invoices</a></li>
                <?php
                }
                ?>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Student Name</th>
                            <th>Father's Name</th>
                            <th>Contact No.</th>
                            <th>Est. Fee</th>
                            <th>Discount</th>
                            <th>Received</th>
                            <th>Bal. Fee</th>
                            <th>Fee Note</th>
                            <th>Date</th>
                            <th>Invoice</th>
                            <?php 
                            if($this->session->userdata('all_permission') ==1){
                            ?>
                                <th>Delete</th>    
                            <?php
                            }
                            ?>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $table='opening_balance_fee';
                        $all_invoices_data=$this->WelcomeModel->get_data($table);
                        if($all_invoices_data){
                            foreach($all_invoices_data as $data){
                                ?>
                                <tr>
                                <?php
                                $sid=$data['sid'];
                                $student_table='student';
                                $get_student_info=$this->WelcomeModel->get_item_data($sid,$student_table);
                                if($get_student_info){
                                    foreach($get_student_info as $info){
                                        
                                        ?>
                                        <td><?php echo $data['id'];?></td>
                                        <td><?php echo $info['student_name'];?></td>
                                        <td><?php echo $info['father_name'];?></td>
                                        <td><?php echo $info['contact_no'];?></td>
                                <?php
                                    }
                                }else{
                                ?>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <?php
                                }
                                ?>
                                    
                                        <td><?php echo $data['estimate_amount']?></td>
                                        <td><?php echo $data['discount']?></td>
                                        <td><?php echo $data['received_amount']?></td>
                                        <td><?php echo $data['balance_amount'];?></td>
                                        <td></td>
                                        <td><?php echo date('d-M-Y',strtotime($data['fee_date']));?></td>
                                        <td class="text-center">
                                            <a href="<?php echo base_url();?>OpeningFee/invoice/<?php echo $data['id']; ?>">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-eye-fill text-danger" viewBox="0 0 16 16">
                                                    <path d="M10.5 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0z"/>
                                                    <path d="M0 8s3-5.5 8-5.5S16 8 16 8s-3 5.5-8 5.5S0 8 0 8zm8 3.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z"/>
                                                </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 $data['id'];?>"><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
                            }
                        }
                        ?>
                    </tbody>
                    
                </table>
                
            </div>
            
        </div>
    </div>
</div>


<?php
$table='opening_balance_fee';
$all_invoices=$this->WelcomeModel->get_data($table);
if($all_invoices){
    foreach($all_invoices as $invoices){
?>    
        
<?php        
    }
}
?>

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