<?php
$course_id=$this->uri->segment('3');
$course_table='courses';
$course='';
$subject_stream='';
$acedemic_session=$this->session->userdata('acedemic_session');
$get_course_info=$this->WelcomeModel->get_item_data($course_id,$course_table);
if($get_course_info){
    foreach($get_course_info as $course_info){
        $course=$course_info['course'];
        $subject_stream=$course_info['subject_stream'];
    }
}
?>
<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">Opening Balance</li>
                <li class="breadcrumb-item"><?php echo $course;
                if($subject_stream !=''){ echo " ("; echo $subject_stream; echo ")";}
                ?></li>
            </ul>
        <!--</div>-->
        <!--<div class="col-sm-12">-->
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Father's Name</th>
                            <th>Contact No</th>
                            <th>Opening Baalance</th>
                            <th>Fee Note</th>
                            <th>Paid Amount</th>
                            <th>Balance Opening Fee</th>
                            <th>Pay Fee</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                        
<?php
$get_student_courses_data=$this->OpeningBalanceModel->get_student_courses_data($course_id,$acedemic_session);


$s_count=0;
                            
if($get_student_courses_data){
    foreach($get_student_courses_data as $courses_data){
        $expected_course_fee=0;
        $received_fee=0;
        $discount=0;
        $s_count=$s_count + 1;
        $sid=$courses_data['sid'];
        $opening_fee_table='opening_balance';
        $get_opening_expected_balance=$this->OpeningBalanceModel->get_student_opening_fee($sid,$opening_fee_table);
        if($get_opening_expected_balance){
            foreach($get_opening_expected_balance as $expected_balance){
                    // $d_count=$d_count + 1;
                    $expected_course_fee=$expected_course_fee + $expected_balance['opening_fee_amount'];
        $get_received_fee=$this->OpeningBalanceModel->get_received_opening_fee_for_student($sid);
            if($get_received_fee){
                foreach($get_received_fee as $fee){
                    $received_fee=$received_fee + $fee['received_amount'];
                    $discount=$discount + $fee['discount'];
                    
                    
                }
            }         
            $student_table='student';
            $get_student_profile=$this->WelcomeModel->get_item_data($sid,$student_table);
            if($get_student_profile){
                foreach($get_student_profile as $profile){
                    ?>
                        <tr>
                            <td><?php echo $s_count;?></td>
                            <td><?php echo $profile['student_name'];?></td>
                            <td><?php echo $profile['father_name'];?></td>
                            <td><?php echo $profile['contact_no'];?></td>
                            <td><?php echo $expected_course_fee;?></td>
                            <td style="text-transform:uppercase;"><?php echo $expected_balance['fee_note'];?></td>
                            <td><?php echo $received_fee;?></td>
                            <td><?php echo $balance=$expected_course_fee - $received_fee; ?></td>
                            <td><a href="<?php echo base_url();?>Fee/pay_opening_balance/<?php echo $sid;?>" class="btn btn-sm btn-info">Pay</a></td>
                        </tr>
                    <?php
                }
            }
                    ?>
                        
                    
                    <?php
            }
        }
                                
                            
                            
        
    }
}
$course_due_fee=($expected_course_fee - $received_fee - $discount);
?>

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