<?php 
    $acedemic_session=$this->uri->segment('3');
    $month=$this->uri->segment('4');
    $y1='';
    $y2='';
    $ac_table='academic_session_details';
    $get_session_info=$this->NewFeeModel->get_item_data($acedemic_session,$ac_table);
    if($get_session_info){
        foreach($get_session_info as $info){
            $y1=$info['y1'];
            $y2=$info['y2'];
        }
    }
                        
    $year='';
    if($month == 1 || $month ==2 || $month ==3){
    $year=$y2;
    }else{
    $year=$y1;
    }
    $d=cal_days_in_month(CAL_GREGORIAN,$month,$year);
    $dateObj = DateTime::createFromFormat('!m', $month);
                        // Store the month name to variable
    $monthName = $dateObj->format('F');
    
    

?>
<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">Home</li>
                <li class="breadcrumb-item">Fee</li>
                <li class="breadcrumb-item"><? echo $monthName;?></li>
                <li class="breadcrumb-item"><?php echo $year;?></li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Day</th>
                            <th>Invoices</th>
                            <th>Amount Received</th>
                            <th>View</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        
                        
                        for($i=1;$i<=$d;$i++){
                            $day_invoices=0;
                            $day_collection=0;
                            $date = new DateTime();
                            $date->setDate($year, $month, $i);
                            $fee_date=date('Y-m-d',strtotime($date->format('Y-m-d')));
                            
                            $fee_table='student_fee';
                            
                            $get_invoices_for_day=$this->NewFeeModel->day_fee_collection($fee_date,$acedemic_session,$fee_table);
                            
                            
                            // $get_invoices_for_day=$this->NewFeeModel->get_date_fee_collection($i,$month,$year,$acedemic_session);
                            if($get_invoices_for_day){
                                foreach($get_invoices_for_day as $get_invoices_for_day){
                                $day_invoices=$day_invoices + 1;
                                $day_collection=$day_collection + $get_invoices_for_day['received_amount'];
                                }
                            }
                            
                            
                            ?>
                        <tr>
                            <td><?php echo $i;?></td>
                            <td><?php echo $day_invoices;?></td>
                            <td><?php echo $day_collection;?></td>
                            <td><a href="<?php echo base_url();?>FeeManagement/day_collection/<?php echo $i; echo "/"; echo $month; echo "/"; echo $year;?>" class="btn btn-sm btn-success">View</a></td>
                        </tr>                            
                            <?php
                        }
                        
                        ?>

                        
                    </tbody>
                </table>
            </div>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <tr>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/4">Apr</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/5">May</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/6">Jun</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/7">Jul</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/8">Aug</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/9">Sep</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/10">Oct</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/11">Nov</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/12">Dec</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/1">Jan</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/2">Feb</a></td>
                        <td><a href="<?php echo base_url();?>FeeManagement/month_data/<?php echo $acedemic_session; ?>/3">Mar</a></td>
                    </tr>
                </table>
            </div>
            
        </div>
    </div>
</div>