<?php
$day=$this->uri->segment('3');
$month=$this->uri->segment('4');
$year=$this->uri->segment('5');

$acedemic_session=$this->session->userdata('acedemic_session');
$dateObj=DateTime::createFromFormat('!m',$month);
$monthName = $dateObj->format('F');


$date = new DateTime();
$date->setDate($year, $month, $day);
$fee_date=date('Y-m-d',strtotime($date->format('Y-m-d')));
?>
<style>

#student {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#student td, #student th {
  border: 1px solid #ddd;
  padding: 5px;
  
}

#student td{
    font-size:12px;
}

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

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

#student th {
  padding-top: 5px;
  padding-bottom: 5px;
  text-align: left;
  /*background-color: #04AA6D;*/
  background:#17A2B8;
  color: white;
  font-size:14px;
  
}
</style>
<div class="container mt-3 mb-3 pt-3 pb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">
            
            <!--<ul class="breadcrumb">-->
            <!--    <li class="breadcrumb-item">Home</li>-->
            <!--    <li class="breadcrumb-item"><a href="<?php echo base_url();?>FeeManagement">Fee Collection</a></li>-->
            <!--    <li class="breadcrumb-item"><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; echo "/"; echo $month;?>"><?php echo $monthName; echo "-"; echo $year;?></a></li>-->
            <!--    <li class="breadcrumb-item"><?php echo $day;?></li>-->
            <!--</ul>-->
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="student">
                    <thead>
                        <tr>
                            <th style="text-align:center;" colspan="7">S. J. Education Center</th>
                        </tr>
                        <tr>
                            <th colspan="7" style="text-align:center;">Date : <?php echo date('d-M-Y',strtotime($fee_date));?></th>
                        </tr>
                        <tr>
                            <th>#</th>
                            <th>Student Name</th>
                            <th>Father's Name</th>
                            <th>Class</th>
                            <th>Con. No.</th>
                            <th>P. Mode</th>
                            <th>Received </th>
                            <!--<th></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;
                        // $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);
                        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 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 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:right;"><?php echo $collention_total; ?></th>
                            
                        </tr>
                    </tbody>
                </table>
            </div>
            
        </div>
    </div>
</div>