<div class="container bg-white mt-3 mb-3 pt-3 pb-3">
    <div class="row">
        <div class="col-sm-12">
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>S. Id.</th>
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>Course</th>
                            <th>Extra Amount</th>
                            <th>Extra Ref Status</th>
                            <th>Extra Ref Used Status </th>
                            <th>Update</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $count=0;
                    $acedemic_session=$this->session->userdata('acedemic_session');
                    $all_students=$this->WelcomeModel->get_students_ac_session($acedemic_session);
        if($all_students){
            foreach($all_students as $students){
                $student_table='student';
                $sid=$students['sid'];
                $get_students_info=$this->DeveloperModel->get_item_data($sid,$student_table);
                
                $get_students_fee_data=$this->DeveloperModel->get_student_fee_data($sid,$acedemic_session);
                if($get_students_fee_data){
                    foreach($get_students_fee_data as $students_fee_data){
                        if($students_fee_data['extra_amount'] !=0 && $students_fee_data['extra_amount_status'] ==0){
                            $count = $count + 1;
                            $fee_no=$students_fee_data['fee_no'];
                            ?>
                            <tr>
                                <td><?php echo $count;?></td>
                                <td><?php echo $sid;?></td>
                                <?php 
                                if($get_students_info){
                                    foreach($get_students_info as $students_info){
                                        ?>
                                        <td><?php echo $students_info['student_name'];?></td>
                                        <td><?php echo $students_info['father_name'];?></td>
                                        
                                        <?php
                                    }
                                }else{
                                    ?>
                                    
                                    <td></td>
                                    <td></td>
                                    <?php
                                }
                                ?>
                                
                                <?php
                                $courses_table='courses';
                                $course_id=$students_fee_data['course_id'];
                                $get_course_info=$this->DeveloperModel->get_item_data($course_id,$courses_table);
                                if($get_course_info){
                                    foreach($get_course_info as $course_info){
                                ?>
                                <td><?php echo $course_info['course']; echo " "; echo $course_info['subject_stream'];?></td>
                                <?php
                                    }
                                }
                                ?>
                                <td><?php echo $students_fee_data['extra_amount'];?></td>
                                <td><?php echo $students_fee_data['extra_amount_status'];?></td>
                                <?php
                                $added_status=0;
                                $get_bal_fee_invoices_status=$this->NewFeeModel->get_extra_fee_invoices_for_fee_no($fee_no,$sid);
                                if($get_bal_fee_invoices_status){
                                    foreach($get_bal_fee_invoices_status as $bal_fee_invoices_status){
                                        $added_status=$added_status + 1;
                                    }
                                }
                                
                                // $bal_fee_ref_no=$students_fee_data['balance_amount_added_refrence'];
                                // $check_bal_added_ref_no_closed_status=$this->NewFeeModel->get_invoice_data($bal_fee_ref_no);
                                // if($check_bal_added_ref_no_closed_status){
                                //     foreach($check_bal_added_ref_no_closed_status as $ref_no_closed_status){
                                //         $ref_status=$ref_no_closed_status['balance_amount_status'];
                                //         // if($ref_status == ){}
                                //     }
                                // }
                                
                                if($added_status == 0){echo "<td class='bg-danger text-white'>";}else{echo "<td>";}
                                ?>
                                
                                <?php
                                echo $added_status;
                                echo "</td>";
                                ?>
                                <td>
                                    <?php 
                                    if($added_status == 0){
                                    ?>
                                    <a href="<?php echo base_url();?>Developer/inv_extra_calibration/<?php echo $fee_no; ?>" class="btn btn-sm btn-warning text-white">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hammer" viewBox="0 0 16 16">
                                            <path d="M9.972 2.508a.5.5 0 0 0-.16-.556l-.178-.129a5.009 5.009 0 0 0-2.076-.783C6.215.862 4.504 1.229 2.84 3.133H1.786a.5.5 0 0 0-.354.147L.146 4.567a.5.5 0 0 0 0 .706l2.571 2.579a.5.5 0 0 0 .708 0l1.286-1.29a.5.5 0 0 0 .146-.353V5.57l8.387 8.873A.5.5 0 0 0 14 14.5l1.5-1.5a.5.5 0 0 0 .017-.689l-9.129-8.63c.747-.456 1.772-.839 3.112-.839a.5.5 0 0 0 .472-.334z"/>
                                        </svg>
                                    </a>
                                    <?php
                                    }
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                    }
                }
                
                if($get_students_info){
                    foreach($get_students_info as $students_info){
                        
                    }
                }
                
                
            }
        }
        ?>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>