<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>
<?php   
  
 $sql = "SELECT * FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and std.status='0' and std.branch_id=".$_SESSION['branch']. " ";


 if($_REQUEST['class_id']!=NULL){
      
    if($_REQUEST['class_id']=="All"){
    
    } else {
     $sql .= " AND fee.classs_id = '" .$_REQUEST['class_id']. "' ";

    }

if($_REQUEST['section']=='All'){
} else {
      $sql .= " AND std.section_id =" . $_REQUEST['section']. " ";
 }
   
  if($_REQUEST['session']!=NULL){
    $sql .= " AND fee.session_id = '" .$_REQUEST['session']. "' ";
  }

  if($_REQUEST['month']!=NULL){
    $sql .= " AND fee.month_id = '" .$_REQUEST['month']. "' ";
  }

 


// echo $sql;

  $WorkAssignListings = $m->query($sql);


  // getting branch details
  $branch=getBranch($m);

}

$fee_types = $m->get("eduportal_fee_types");

?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Print Fee Report </title>
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<script type="text/javascript">
// window.print();
</script>
<style type="text/css">

tr th {border-top:1px solid gray;border-left:1px solid gray;border-bottom:1px solid gray;text-align:center;background-color:lightgray;font-size:11px;padding:0.5%;}
tr td {border-bottom:1px solid gray;border-left:1px solid gray;font-size:12px;padding:0.5%;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}


</style>
</head>
<body style="font-size:12px;">



<div style="text-align:center;font-size:24px;font-weight:bold;margin:0 auto;"><?php echo $branch[0]['Branch_Name'];?> 

</div>

<br>

<div style="text-align:center;font-size:18px;font-weight:bold;"> Students Fee Unpaid List

 </div>

<hr style="width:100%;">

<div style="width:50%; float:left;font-size:16px; "> <b> Report Month:</b> <?php echo date("F", mktime(0, 0, 0,$_REQUEST['month'], 10));?>  </div>

<div style="width:50%;text-align:center;float:left;font-size:16px;"> <b> Session:</b> <?php echo getSessionName($m,$_REQUEST['session']);?> </div>

<br>
   
<table style="width:100%;font-size:12px;" cellspacing="0">
      
  <thead>
    <tr>

        <th width="3%" class=" center"> S.No</th>
        <th width="8%" class="center"> Student Name</th>
        <th width="8%" class="center"> Father Name</th>
        <th width="6%" class=" center"> Class</th>
        <th width="5%" class=" center"> R.No </th>  
        
        <?php 
      
     foreach ($fee_types as $type) {
    ?>              
         <th width="5%" class=" center"> <?php echo$type['feetype_name']; ?> </th>
    <?php } ?> 
   
                
    <th width="5%" class=" center"> Transport </th>  
        <th width="5%" class=" center"><?php if ($branch[0]['misc_title']!=NULL){echo $branch[0]['misc_title'];}else {echo 'Misc.';} ?></th>
        <th width="6%" class=" center"> Balance </th>  
        <th width="5%" class=" center"> Monthly Fee </th>  
        <th width="6%" class=" center"> Total </th>
        <th width="6%" class=" center"> Paid </th>
        <th width="6%" class=" center"> Paid Again </th>
        <th width="6%" class=" center"> Paid Date </th>
        <th width="12%" class=" center"  style="border-right:1px solid black;"> Remaning </th>    
        
                         
          </tr>
        </thead>
        <tbody>
   
       <?php 
      $count=1;
      $tf;
      $trf;
      $misc;
      $prof;
      $bal;
      $total_fees;
      $total_paid;
      $total_rem;
      
      
      foreach($WorkAssignListings as $WorkAssignListVal)
      { 
 
    // now getting the other fee parameters of student against current month
        $total_others=0+getFeeAllOtherFee($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],$m);

     $std_total=intVal($WorkAssignListVal['balance'])+intVal($WorkAssignListVal['tutionfee'])+intVal($WorkAssignListVal['transportfee'])+intVal($WorkAssignListVal['misc_fee'])+intVal($total_others)-intVal($WorkAssignListVal['disc_amount']);

     // calculating students total fee 

      $tf+=$WorkAssignListVal['tutionfee'];
      $trf+=$WorkAssignListVal['transportfee'];
      $misc+=$WorkAssignListVal['misc_fee'];
      $bal+=$WorkAssignListVal['balance'];
      
      
          //students whose fee is zero now going to be skip from the list
        if($std_total==0){
          continue;
        }

         // getting students details 
        if($std_total>$WorkAssignListVal['collected_amount']) {
        $m->where("student_id", $WorkAssignListVal['student_id']);
        $m->where("status", 0);
        $student=$m->get("edu_student_details");

        $paid+=$WorkAssignListVal['collected_amount'];
        $paidAgain+=$WorkAssignListVal['paid_again_amount'];
        $remng+=$std_total-$WorkAssignListVal['collected_amount']-$WorkAssignListVal['paid_again_amount'];

      } else {
        continue;
      }

        
        $paid_fee=intVal($WorkAssignListVal['collected_amount']+$WorkAssignListVal['collected_fine']);
        $remaining=intVal($std_total)-intVal($WorkAssignListVal['collected_amount']+$WorkAssignListVal['collected_fine']);

        $total_fees+=$std_total;
        $total_paid+=$paid_fee;
        $total_rem+=$remaining;
   ?>
        <tr> 
                  <td class="center"> <?php echo $count; $count++;?> </td>
                  <td style="padding-left:1%;"><?php echo $student[0]['first_name'];  ?></td>
                  <td style="padding-left:1%;"><?php echo $student[0]['last_name'];  ?></td>
                  <td style="padding-left:1%;">
          <?php echo  getClassName($m,$WorkAssignListVal['class_id'])."-".getSectionName($m,$WorkAssignListVal['section_id']);  ?>              
                  </td>
                  <td class="center">  <?php echo $WorkAssignListVal['candidate_roll_no'];?>  </td>                  
                  
          <?php
            
           $others_fee;
           foreach ($fee_types as $type) {
            $fee=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],$type['feetype_id'],$m);
           // $others_fee+=$fee;
          ?>              
                <td class="center">  <?php echo 0+$fee;?> </td>

          <?php } ?> 
              
                  <td class="center">  <?php echo 0+$WorkAssignListVal['transportfee'];?> </td>
                  <td class="center">  <?php echo 0+$WorkAssignListVal['misc_fee'];?> </td>

                  <td class="center">  <?php echo 0+$WorkAssignListVal['balance'];?> </td>
                  <td class="center">  <?php echo 0+$WorkAssignListVal['tutionfee'];?> </td>
                  <td class="center"> <?php echo $std_total;?> </td>
                  <td class="center"> <?php echo $WorkAssignListVal['collected_amount'];?> </td>
                  <td class="center"> <?php echo $WorkAssignListVal['paid_again_amount'];?> </td>
                  <td class="center"> <?php echo $WorkAssignListVal['paying_date'];?> </td>
                  <td class="center" style="border-right:1px solid gray;font-weight:bold;"><?php echo $std_total-$WorkAssignListVal['collected_amount']-$WorkAssignListVal['paid_again_amount'];?></td>                   
                 
                                 
              </tr>

       <?php $others_fee=""; 

       $Tadm+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],1,$m);
       $Tpap+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],2,$m);
       $Tuni+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],3,$m);
       $Tstat+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],4,$m);
       $Toth+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],5,$m);
       $Tafund+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],8,$m);
       $Rfee+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],6,$m);
       $Sfee+=getFeeOfOtherParameter($WorkAssignListVal['student_id'],$WorkAssignListVal['challan_id'],7,$m);

   }

       // ending loop 


        ?>


        <tr> 
                
          <th colspan="5" style="padding-left:1%;">Total</th>
          
                   <?php 

                   
                   
           /*foreach ($fee_types as $type) {
            $fee=getAllotherFeeWithType($_REQUEST['month'],$from,$to,$type['feetype_id'],0,$m);
          ?>              
          
          <th class="center">  <?php echo number_format($fee,2);?> </td>

          <?php }*/ ?>
                  <th class=" center">  <?php echo number_format($Tadm,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Tpap,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Tuni,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Tstat,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Toth,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Tafund,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Rfee,2);?>  </th>
                  <th class=" center">  <?php echo number_format($Sfee,2);?>  </th>
                  <th class=" center">  <?php echo number_format($trf,2);?>  </th>
                  <th class=" center">  <?php echo number_format($misc,2);?>  </th>
                  <th class=" center">  <?php echo number_format($bal,2);?>  </th>
                  <th class=" center">  <?php echo number_format($tf,2);?>  </th>                
                  <th class=" center"> <?php echo number_format($total_fees,1);?> </th>
                  <th class=" center"> <?php echo number_format($paid,1);?> </th>
                  <th class=" center"> <?php echo number_format($paidAgain,1);?> </th>
                  <th></th>
                  <th class=" center" style="border-right:1px solid black;"> <?php echo number_format($remng,1);?> </th>
                  
              </tr>

              <tr>
            
                <th class=" center" colspan="5"> Total </th>  
                
                <?php
            
             foreach ($fee_types as $type) {
            ?>              
             <th class=" center"> <?php echo$type['feetype_name']; ?> </th>
              <?php } ?> 
                            
              <th class=" center"> Transport </th>  
              <th class=" center"> <?php if ($branch[0]['misc_title']!=NULL){echo $branch[0]['misc_title'];}else {echo 'Misc.';} ?> </th><th class=" center">  Balance </th>  
                <th class=" center"> Tuition </th>  
                <th class=" center"> Total </th>
                <th class=" center"> Total Paid </th>
                <th class=" center"> Paid Again</th>
                <th colspan="2" class=" center" style="border-right:1px solid black;"> Total Remaning </th>  
                
                
              </tr>       
              
       
            
           
        </tbody>
        
    </table>

</body>
</html>
