<?php 
$from_date=$this->uri->segment("3");
$to_date=$this->uri->segment("4");

?>
<!DOCTYPE html>
<html>
    <head>
        <title>Fee Collection Report</title>
         <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@200;300;400;500;600;700&display=swap" rel="stylesheet"> 

        <style>
            .w-100{width:100%;}
            .w-50-1{width:50%;float:left;height:100%;border-right:1px dotted red;}
            .w-50-2{width:50%;float:left;height:100%;}
            .w-2{width:0%;float:left;}
            img{height:50px;width:auto;}
            html{padding:0px;margin:0px;}
            body{padding:25px;margin:0px;font-size:12px;font-family: 'Inconsolata', monospace; }
            #student {
                /*font-family: Arial, Helvetica, sans-serif;*/
                border-collapse: collapse;
                width: 100%;
            }
            #student tr th{
                border: 1px solid #ddd;
                padding: 5px;
            }
            #student tr td,  {
                border: 1px solid #ddd;
                padding: 5px;
                font-size:14px;
            }

            #student tr:nth-child(even){background-color: #f2f2f2;}

            #student tr:hover {background-color: #ddd;}

            #student tr th {
                padding-top: 8px;
                padding-bottom: 8px;
                text-align: left;
            }
        </style>
    </head>
    <body>
        <div style="border:1px solid;width:100%;">
            <table style="width:100%;margin:0px;padding:0px;background:#fff;color:#4F3F85;">
            <thead>
                <tr style="width:100% !important;padding:0px !important;">
                    <th colspan="3" style="text-align:right;padding-top:0px;padding-bottom:0px;padding-left:0px;padding-right:40px !important;">
                        <img src="<?php echo school_logo_full; ?>" style="">
                    </th>
                            
                    <td colspan="3" style="width:100%;background:;margin:0px;text-align:left;padding:0px;">
                        <p style="padding:0px;margin:0px;font-size:22px;font-weight:700;"><?php echo school_full_name; ?></p>
                    </td>
                </tr>
                <tr style="width:100% !important;padding:0px !important;">
                    <th colspan="3" style="background:;text-align:center;">Date : <?php if($from_date == $to_date){ echo date('d-m-Y',strtotime($from_date)); }else{ echo date('d-m-Y',strtotime($from_date))." to ".date("d-M-Y",strtotime($to_date));  } ?></th>
                    <th colspan="3" style="background:;text-align:center;">
                    <?php
                    $acedemic_session=$this->session->userdata('acedemic_session');
                    $acedemic_session_table='academic_session_details';
                    $get_ac_sess_data=$this->NewFeeModel->get_item_data($acedemic_session,$acedemic_session_table);
                    if($get_ac_sess_data){
                        foreach($get_ac_sess_data as $ac_sess_data){
                    ?>
                        <p style="text-align:center;padding:0px;margin:0px;font-size:16px;font-weight:500;">Academic Year : <?php echo $ac_sess_data['year_long'];?></p>
                    
                    <?php
                        }
                    }
                    ?>
                    </th>
                    
                </tr>
            </thead>
            </table>
            
            <table class="table table-bordered table-striped" id="student">
                    <thead>
                        
                        <tr>
                            <th>#</th>
                            <th>Student Name</th>
                            <th>Father's Name</th>
                            <th>Class</th>
                            <th>Con. No.</th>
                            <th>Fee Type</th>
                            <th style="width:80px;">Date</th>
                            <th>P. Mode</th>
                            <th>Received </th>
                            
                            <!--<th>View</th>-->
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $count=0;
                        $fee_table='student_fee';
                        $collention_total=0;
                        $cash_collection=0;
                        $other_then_cash_collection=0;
                        
                        
                        $tfc_collention_total=0;
                        $tfc_cash_collection=0;
                        $tfc_other_then_cash_collection=0;
                        
                        // $today_collection=$this->NewFeeModel->get_date_fee_collection($day,$month,$year,$acedemic_session);
                        // $today_collection=$this->NewFeeModel->day_fee_collection($fee_date,$acedemic_session,$fee_table);
                        
                        $today_collection=$this->NewFeeModel->get_date_range_fee_collection($from_date,$to_date,$acedemic_session);
                        if($today_collection){
                            foreach($today_collection as $collection){
                                $sid=$collection['sid'];
                                $student_table='student';
                                $course_id=$collection['course_id'];
                                $courses_table='courses';
                                $course_stream='';
                                $course='';
                                $get_course_info=$this->NewFeeModel->get_item_data($course_id,$courses_table);
                                if($get_course_info){
                                    foreach($get_course_info as $course_info){
                                        $course_stream=$course_info['subject_stream'];
                                        $course=$course_info['course'];
                                    }
                                }
                                
                                $get_student_profile=$this->NewFeeModel->get_item_data($sid,$student_table);
                                if($get_student_profile){
                                    foreach($get_student_profile as $student){
                                        $count=$count + 1;
                                        if($collection['payment_mode'] == 'cash'){
                                            $cash_collection=$cash_collection + $collection['received_amount'];
                                        }else{
                                            $other_then_cash_collection= $other_then_cash_collection + $collection['received_amount'];
                                        }
                                        
                                        $collention_total=$collention_total + $collection['received_amount'];
?>
                        <tr>
                            <td><?php echo $count;?></td>
                            <td><?php echo $student['student_name'];?></td>
                            <td><?php echo $student['father_name'];?></td>
                            <td><?php echo $course; echo " "; echo $course_stream; ?></td>
                            <td><?php echo $student['contact_no'];?></td>
                            <td><?php echo $collection['fee_type']; ?></td>
                            <td><?php echo date("d-m-Y",strtotime($collection['fee_date']));?></td>
                            <td style="text-transform:uppercase;text-align:center;"><?php echo $collection['payment_mode'];?></td>
                            <td class="text-success font-weight-bold" style="text-align:center;"><?php echo $collection['received_amount'];?></td>
                            
                        </tr>                                
                                <?php
                                    }
                                }
                            }
                        }
                        ?>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th style="text-align:right;">Cash</th>
                            <th style="text-align:right;"><?php echo $cash_collection;?></th>
                            <th style="text-align:right;">Other</th>
                            <th style="text-align:right;"><?php echo $other_then_cash_collection;?></th>
                            <th style="text-align:right;">Total</th>
                            <th style="text-align:center;"><?php echo $collention_total; ?></th>
                        </tr>
                        <?php
                        $transport_count=0;
                        $transport_fee_collection=$this->NewFeeModel->get_date_range_transport_fee_collection($from_date,$to_date,$acedemic_session);
                        if($transport_fee_collection){
                            foreach($transport_fee_collection as $tfc){
                                $transport_count=$transport_count + 1;
                                $count=$count + 1;
                                
                                
                                if($tfc['fee_mode'] == "CASH"){
                                $tfc_cash_collection=$tfc_cash_collection + $tfc['received_fee'];    
                                }else{
                                    $tfc_other_then_cash_collection=$tfc_other_then_cash_collection + $tfc['received_fee'];        
                                }
                                $tfc_collention_total=$tfc_collention_total + $tfc['received_fee'];
                                
                        ?>
                        <tr>
                            <td><?php echo $count;?></td>
                            <td><?php echo $tfc['student_name'];?></td>
                            <td><?php echo $tfc['father_name'];?></td>
                            <td><?php echo $tfc['course']; echo " "; echo $tfc['course_stream']; ?></td>
                            <td><?php echo $tfc['contact_no'];?></td>
                            <td><?php echo $tfc['fee_type']; ?></td>
                            <td><?php echo date("d-m-Y",strtotime($tfc['fee_date']));?></td>
                            <td style="text-transform:uppercase;text-align:center;"><?php echo $tfc['fee_mode'];?></td>
                            <td class="text-success font-weight-bold" style="text-align:center;"><?php echo $tfc['received_fee'];?></td>
                        </tr>
                        <?php
                            }
                        }
                        if($transport_count >0){
                        ?>
                        <tr>
                            <th colspan="3">Transport Total</th>
                            <th style="text-align:right;">Cash</th>
                            <th style="text-align:right;"><?php echo $tfc_cash_collection;?></th>
                            <th style="text-align:right;">Other</th>
                            <th style="text-align:right;"><?php echo $tfc_other_then_cash_collection;?></th>
                            <th style="text-align:right;">Total</th>
                            <th style="text-align:center;"><?php echo $tfc_collention_total; ?></th>
                        </tr>
                        
                        
                        <tr>
                            <th colspan="3">Grand Total</th>
                            <th style="text-align:right;">Cash</th>
                            <th style="text-align:right;"><?php echo $cash_collection + $tfc_cash_collection;?></th>
                            <th style="text-align:right;">Other</th>
                            <th style="text-align:right;"><?php echo $other_then_cash_collection; + $tfc_other_then_cash_collection?></th>
                            <th style="text-align:right;">Total</th>
                            <th style="text-align:center;"><?php echo $collention_total + $tfc_collention_total; ?></th>
                        </tr>
                        <?php 
                        }
                        ?>
                    </tbody>
                </table>
        </div>
        
    </body>
</html>         