<style>
.item{
padding:15px;    
height:auto;
width:90%;
float:left;
margin: 20px;
border-radius:2px;
background:#DFF0D8 !important;
}
.item .total-student{
text-align:left;font-weight:600;padding:15px;    
}
.item .total-fee-recieved{text-align:left;font-weight:600;padding:15px;}
.dashboard{background:#F9F9F9 !important;margin-bottom:10px; padding:20px;}

@media only screen and (max-width:767px){
.item{
height:auto;
width:100% !important;
border:none;
float:left;
margin-top:10px !important;
margin: auto;
margin-left:0px;
border-radius:5px;
background:#DFF0D8;
color:#468847;
text-align:left;    
padding:15px;
}    
.item .form-group #student_class{
height:40px !important;
width:70%;
}
.item .form-group .btn{
height:42px !important;
}
.margin-header{height:70px;
}
}
tr{
background:#fff;    
padding:15px;
margin:5px !important;
}
tr td a{
text-decoration:none;    
color:black;
}
tr td i{
font-size:18px;
padding:10px;
color:black;
}
</style>
<?php
$month = ltrim(date('m'),"0"); 
$year = date('y');
$month_name1 = date("F", mktime(0, 0, 0, $month, 10));
$month_name = strtolower(date("F", mktime(0, 0, 0, $month, 10)));


$table="student";
$data1 = $this->FeeModel->fetch_all_student($table);
if($data1){
$count =0;
$pg_count =0;
$lkg_count =0;
$ukg_count =0;
$count1 =0;
$count2 =0;
$count3 =0;
$count4 =0;
$count5 =0;
$count6 =0;
$count7 =0;
$count8 =0;
$count9=0;
$count10=0;

foreach($data1 as $records1){
$count++;
if($records1['class'] == 'PG'){
$pg_count ++;    
}else if($records1['class'] == 'LKG'){
$lkg_count ++;    
}else if($records1['class'] == 'UKG'){
$ukg_count ++;    
}else if($records1['class'] == 1){
$count1 ++;    
}else if($records1['class'] == 2){
$count2 ++;    
}else if($records1['class'] == 3){
$count3 ++;    
}else if($records1['class'] == 4){
$count4 ++;    
}else if($records1['class'] == 5){
$count5 ++;    
}else if($records1['class'] == 6){
$count6 ++;    
}else if($records1['class'] == 7){
$count7 ++;    
}else if($records1['class'] == 8){
$count8 ++;    
}else if($records1['class'] == 9){
$count9 ++;    
}else if($records1['class'] == 10){
$count10 ++;    
}

}
}




$table="school_fee_structure";
$data = $this->FeeModel->fetch_fee_structure($table);
$pg_fee=0;$lkg_fee=0;$ukg_fee=0;
if($data){

foreach($data as $records){ 
if($records['class'] == 'PG'){
$pg_fee =$records['april'];    

}else if($records['class'] == 'LKG'){
$lkg_fee =$records['april'];     
}else if($records['class'] == 'UKG'){
$ukg_fee =$records['april'];     
}else if($records['class'] == 1){
$fee1 =$records['april'];     
}else if($records['class'] == 2){
$fee2 =$records['april'];     
}else if($records['class'] == 3){
$fee3 =$records['april'];     
}else if($records['class'] == 4){
$fee4 =$records['april'];     
}else if($records['class'] == 5){
$fee5 =$records['april'];     
}else if($records['class'] == 6){
$fee6 =$records['april'];     
}else if($records['class'] == 7){
$fee7 =$records['april'];     
}else if($records['class'] == 8){
$fee8 =$records['april'];     
}else if($records['class'] == 9){
$fee9 =$records['april'];     
}else if($records['class'] == 10){
$fee10 =$records['april'];     
}

}
}

$pg_fee_exp= $pg_fee*$pg_count;
$lkg_fee_exp= $lkg_fee*$lkg_count;
$ukg_fee_exp= $ukg_fee*$ukg_count;
$class1_fee_exp= $fee1*$count1;
$class2_fee_exp= $fee2*$count2;
$class3_fee_exp= $fee3*$count3;
$class4_fee_exp= $fee4*$count4;
$class5_fee_exp= $fee5*$count5;
$class6_fee_exp= $fee6*$count6;
$class7_fee_exp= $fee7*$count7;
$class8_fee_exp= $fee8*$count8;
$class9_fee_exp=$fee9*$count9;
$class10_fee_exp=$fee10*$count10;
$current_month_total_expected = $pg_fee_exp + $lkg_fee_exp +$ukg_fee_exp + $class1_fee_exp + $class2_fee_exp +$class3_fee_exp + $class4_fee_exp + $class5_fee_exp + $class6_fee_exp + $class7_fee_exp + $class8_fee_exp +$class9_fee_exp + $class10_fee_exp;
 










$current_month_total=0;
$current_month_paid_student_no=0;
$grand_total =0;
$table="student_fee";
$count_rows=0;
$fee_collection = $this->FeeModel->fetch_fee_collection($table);
if($fee_collection){

foreach($fee_collection as $feec){
$count_rows++;    
$student_class=$feec['student_class'];    
if($feec[$month_name] == 1){
$current_month_paid_student_no=$current_month_paid_student_no +1;    
}
foreach($data as $records){ 
if($records['class'] == $student_class){
$student_class_fee=$records[$month_name];
}
}

$grand_total =    $grand_total  + $feec['total_amount'];
if($feec[$month_name] ==1 ){
$current_month_total =$current_month_total +   $student_class_fee;  
}
}
}

//all month reports

$april_month_paid_student_no=0;
$april_month_grand_total=0;
$april_month_total =0;

$may_month_paid_student_no=0;
$may_month_grand_total=0;
$may_month_total =0;

$june_month_paid_student_no=0;
$june_month_grand_total=0;
$june_month_total =0;

$july_month_paid_student_no=0;
$july_month_grand_total=0;
$july_month_total =0;

$august_month_paid_student_no=0;
$august_month_grand_total=0;
$august_month_total =0;

$september_month_paid_student_no=0;
$september_month_grand_total=0;
$september_month_total =0;

$october_month_paid_student_no=0;
$october_month_grand_total=0;
$october_month_total =0;

$november_month_paid_student_no=0;
$november_month_grand_total=0;
$november_month_total =0;

$december_month_paid_student_no=0;
$december_month_grand_total=0;
$december_month_total =0;

$january_month_paid_student_no=0;
$january_month_grand_total=0;
$january_month_total =0;

$february_month_paid_student_no=0;
$february_month_grand_total=0;
$february_month_total =0;

$march_month_paid_student_no=0;
$march_month_grand_total=0;
$march_month_total =0;

$count_new=0;
if($fee_collection){
foreach($fee_collection as $fee){
$count_new ++;    
$student_class=$fee['student_class'];
    



foreach($data as $records){ 

if($records['class'] == $student_class){
$student_class_fee=$records['april'];
}
}
if($fee['month'] ==4){
$april_month_grand_total =$april_month_grand_total  + $fee['total_amount'];
}
if($fee['month'] ==5){
$may_month_grand_total =    $may_month_grand_total  + $fee['total_amount'];    
}
if($fee['month'] ==6){
$june_month_grand_total =    $june_month_grand_total  + $fee['total_amount'];  
}
if($fee['month'] ==7){
$july_month_grand_total =    $july_month_grand_total  + $fee['total_amount'];
}
if($fee['month'] ==8){
$august_month_grand_total = $august_month_grand_total + $fee['total_amount'];
}
if($fee['month'] ==9){
$september_month_grand_total=$september_month_grand_total+ $fee['total_amount'];
}
if($fee['month'] ==10){
$october_month_grand_total = $october_month_grand_total + $fee['total_amount'];
}
if($fee['month'] ==11){
$november_month_grand_total=$november_month_grand_total + $fee['total_amount'];
}
if($fee['month'] ==12){
$december_month_grand_total=$december_month_grand_total + $fee['total_amount'];
}
if($fee['month'] ==1){
$january_month_grand_total=$january_month_grand_total + $fee['total_amount'];
}
if($fee['month'] ==2){
$february_month_grand_total=$february_month_grand_total + $fee['total_amount'];
}
if($fee['month'] ==3){
$march_month_grand_total=$march_month_grand_total + $fee['total_amount'];
}

if($fee['april'] ==1 ){
$april_month_total =$april_month_total +   $student_class_fee;  
}

if($fee['may'] ==1){
$may_month_total =$may_month_total +   $student_class_fee;  
}
if($fee['june'] ==1){
$june_month_total =$june_month_total +   $student_class_fee;   
}
if($fee['july'] ==1){
$july_month_total =$july_month_total +   $student_class_fee;  
}
if($fee['august'] ==1){
$august_month_total =$august_month_total +   $student_class_fee;  
}
if($fee['september'] ==1){
$september_month_total =$september_month_total +   $student_class_fee;  
}
if($fee['october'] ==1){
$october_month_total =$october_month_total +   $student_class_fee;   
}
if($fee['november'] ==1){
$november_month_total =$november_month_total +   $student_class_fee;   
}
if($fee['december'] ==1){
$december_month_total =$december_month_total +   $student_class_fee;  
}
if($fee['january'] ==1){
$january_month_total =$january_month_total +   $student_class_fee;  
}
if($fee['february'] ==1){
$february_month_total =$february_month_total +   $student_class_fee;  
}
if($fee['march'] ==1){
$march_month_total =$march_month_total +   $student_class_fee;   
}




}
}







?>   

<div class="container dashboard mt-3 mb-3">
<div class="row">
<div class="col-sm-12">
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Student's (Total / Paid) </th>
<th><?php echo $month_name1;?> Total Expected Fee</th>
<th><?php echo $month_name1;?> Fee Collected</th>
<th><?php echo $month_name1;?> Due Fee</th>
<th>Other Month Collection</th>
<th>Total Collection</th>
</tr>    
</thead>    
<tbody>
<?php  $count_rows;?> 
<tr>
<td><span><?php echo $count;?>/</span><span> <?php echo $current_month_paid_student_no;?></span></td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $current_month_total;?></td>
<td class="text-danger"><?php echo $current_month_due_fee=$current_month_total_expected - $current_month_total;?></td>
<td  class="text-success"><?php echo $other_month_collection =$grand_total - $current_month_total;?></td>
<td><?php echo $grand_total;?></td>
</tr>    
</tbody>
</table>    
</div> 


<div class="table-responsive" style="margin-top:20px;">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Month</th>
<th>Total Expected Fee</th>
<th class="text-success">Fee For Month</th>
<th>Due Fee</th>
<th class="text-success">Total Collection This Month</th>
</tr>
</thead>    
<tbody>
<tr>
<td>April</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $april_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$april_month_total;?></td>
<td class="text-success"><?php echo $april_month_grand_total; ?></td>
</tr>
<tr>
<td>May</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $may_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$may_month_total;?></td>
<td class="text-success"><?php echo $may_month_grand_total; ?></td>
</tr>

<tr><td>June</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $june_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$june_month_total;?></td>
<td class="text-success"><?php echo $june_month_grand_total; ?></td>
</tr>
<tr>
<td>July</td>    
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $july_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$july_month_total;?></td>
<td class="text-success"><?php echo $july_month_grand_total; ?></td>
</tr>
<tr>
<td>August</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $august_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$august_month_total;?></td>
<td class="text-success"><?php echo $august_month_grand_total; ?></td>
</tr>
<tr>
<td>September</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $september_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$september_month_total;?></td>
<td class="text-success"><?php echo $september_month_grand_total; ?></td>
</tr>
<tr>
<td>October</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $october_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$october_month_total;?></td>
<td class="text-success"><?php echo $october_month_grand_total; ?></td>
</tr>
<tr><td>November</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $november_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$november_month_total;?></td>
<td class="text-success"><?php echo $november_month_grand_total; ?></td>
</tr>
<tr>
<td>December</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $december_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$december_month_total;?></td>
<td class="text-success"><?php echo $december_month_grand_total; ?></td>
</tr>
<tr>
<td>January</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $january_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$january_month_total;?></td>
<td class="text-success"><?php echo $january_month_grand_total; ?></td>
</tr>
<tr>
<td>February</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $february_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$february_month_total;?></td>
<td class="text-success"><?php echo $february_month_grand_total; ?></td>
</tr>
<tr>
<td>March</td>
<td><?php echo $current_month_total_expected;?></td>
<td class="text-success"><?php echo $march_month_total;?></td>
<td class="text-danger"><?php echo $current_month_total_expected -$march_month_total;?></td>
<td class="text-success"><?php echo $march_month_grand_total; ?></td>
<!--<td><?php echo $count_new;?></td>-->
</tr>
</tbody>
</table>    
</div>

</div>    
</div>
</div>



<div class="container  dashboard mt-3 mb-3">
<div class="row">
    
<div class="item">
<p><a href="<?php echo base_url();?>FeeManagement/get_date_fee_collection_pdf/<?php echo $date = date('Y-m-d'); ?>">Today Fee Collection PDF <?php echo $date = date('Y-m-d'); ?></a></p>    
</div>  

<div class="item">

<p><label style="float:left;width:30%;">Collection of </label>
<input style="float:left;width:30%;" type="date" class="form-control" id="fee_for_date">
<button type="button" id="fee_data" class="btn btn-success">Search</button>
</p> 
 
<p id="loadfee_date_data">
<?php 
// if($success){
// echo $suucess;    
// }
// if($error){
// echo $error;
// }
?>    
    
</p>
</div>

<div class="item">
<p class="total-student"><span>Student's (Total / Paid) </span></br>
<span><?php echo $count;?> / </span><span><?php echo $current_month_paid_student_no;?></span></p>
</div>
<div class="item">
<p class="total-fee-recieved"><span><?php echo $month_name1;?> Total Expected Fee</span></br>
<?php echo $current_month_total_expected;?></p>    
</div>

<div class="item">
<p class="total-fee-recieved"><span><?php echo $month_name1;?> Due Fee</span></br>
<?php echo $current_month_due_fee=$current_month_total_expected - $current_month_total;?></p>    
</div>




<div class="item">
<p class="total-fee-recieved"><span><?php echo $month_name1;?> Fee Collected</span></br>
<span><?php echo $current_month_total;?></span></p>    
</div>

<div class="item">
<p class="total-fee-recieved"><span>Other Month Collection</span></br>
<span><?php echo $other_month_collection =$grand_total - $current_month_total;?></span></p>    
</div>

<div class="item">
<p class="total-fee-recieved"><span>Total Collection</span></br>
<span><?php echo $grand_total;?></span></p>    
</div>

<div class="item">
<table class="table table-bordered">
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/PG">Download Class PG Fee Detail  <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/LKG">Download Class LKG Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/UKG">Download Class UKG Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/1">Download Class 1 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/2">Download Class 2 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/3">Download Class 3 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/4">Download Class 4 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/5">Download Class 5 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/6">Download Class 6 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/7">Download Class 7 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/8">Download Class 8 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>

<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/9">Download Class 9 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>
<tr><td><a href="<?php echo base_url();?>FeeManagement/list_fee_pdf_class/10">Download Class 10 Fee Detail <i class="glyphicon glyphicon-download-alt"></i></a></td></tr>

</table>    
</div>


   
</div>
</div>

<script>
    
</script>



<script>
$(document).ready(function(){

$("#fee_data").click(function(){
fee_for_date = $("#fee_for_date").val();    
// alert(month);
if(fee_for_date == ''){
swal("Select a date");
}else{



// $("#loaddata").html(month);        
$.ajax({
url: '<?php echo base_url() ?>FeeManagement/link_for_date/',
type: 'POST', 
data: {fee_for_date:fee_for_date},
success: function(data){
// alert(data);

$("#loadfee_date_data").html(data);
}
});    
    
 
    
}
})
});
</script>
