<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>
<?php 

//getting branch details 

  $m->where("branch_id", $_SESSION['branch']);
  $branch_details = $m->get("edu_branch_config");


$branch=getBranch($m);

$month_id=$_REQUEST['month'];
$monthid=date("m");
$branchID=$_SESSION['branch'];
$sessionID=$_SESSION['current_session'];

$sql = " select std.*, fee.* from  edu_student_details as std, eduportal_monthly_challan as fee where std.student_id=fee.student_id AND std.status='0' AND fee.month_id='$month_id' AND std.branch_id=".$_SESSION['branch'];

if($_REQUEST['class_id']!=NULL) { 

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

if ($_REQUEST['class_id']!=NULL){
    $sql .= " AND fee.classs_id =" . $_REQUEST['class_id']. " ";
}
/*if($_REQUEST['section']!=''){
      $sql .= " AND std.section_id =" . $_REQUEST['section']. " ";
 }*/

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

    }

  if($_REQUEST['fee']=="All"){
  
  } 

  else {
   $sql .= " AND paid_status = '" .$_REQUEST['fee']. "' ";
    }

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

} else {

  $sql = " select std.*, fee.* from  edu_student_details as std, eduportal_monthly_challan as fee where std.student_id=fee.student_id AND std.status='0' AND fee.month_id='$monthid' AND std.branch_id='$branchID' AND fee.session_id='$sessionID' order by fee.classs_id asc";
//print_r($sql);
 $WorkAssignListings = $m->query($sql); 
}



$total_fee;
?>
 <!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">
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<title>Print All Single Voucher</title>
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<script type="text/javascript">
 window.print();
</script>
<style> 

.section{width:95%; height:auto;float:left;border-right: 2px solid black;border-right-style:dotted;padding-right:2.5%;margin-left:2%;}
.box{
  width:48%;float:left;height:14.5cm;padding:0.5%;
}  
   
tr th {background-color:lightgray; text-align:center;font-size:14px;border:1px solid gray;}
tr td {border-bottom:1px solid gray;border-left:1px solid gray;padding:1%;}



.tdalign{text-align:center;border:1px solid black;}
  

body {
  background: rgb(204,204,204);
  font-weight:bold; 
}
page {
  background: white;
  display: block;
  margin: 0 auto;
  margin-bottom: 0.5cm;
  border:1px solid black;
  box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
  /*padding:1%;*/
  height: 21cm; 
}
page[size="A4"] {  
  width: 21cm;
  height: 29.7cm; 
}
page[size="A4"][layout="landscape"] {
  width: 29.7cm;
  height: 21cm;  
}
page[size="A3"] {
  width: 29.7cm;
  height: 42cm;
}
page[size="A3"][layout="landscape"] {
  width: 42cm;
  height: 29.7cm;  
}
page[size="A5"] {
  width: 14.8cm;
  height: 21cm;
}
page[size="A5"][layout="landscape"] {
  width: 21cm;
  height: 14.8cm;  
}
@media print {
  body, page {
    margin: 0;
    box-shadow: none;
    border:none;
  }
}
  </style>

</head>
<body>

<?php 
$WorkAssignValue=$WorkAssignListings;

$divission =count($WorkAssignValue);
 $DivideByFour=$divission/4;
$counter=0;

$fee_fine=0;

// loop just printing the number of pages 

for($k=0;$k<$DivideByFour;$k++){

  $fee_fine;
  
  if(date("Y-m-d")>$WorkAssignValue[$counter]['challan_duedate']){

    $fee_fine=$branch[0]['late_fee_fine'];

   }
   else {

  $fee_fine=0;

   }




 



?>

<page size="A4">


  <?php 
  for ($i=1; $i<=4 ; $i++) {


  $total_fee=$WorkAssignValue[$counter]['balance']+$WorkAssignValue[$counter]['tutionfee']+$WorkAssignValue[$counter]['transportfee']+$WorkAssignValue[$counter]['misc_fee']+ $other_fees + $fee_fine;

 /* if($total_fee==0 ){
    continue;
  }*/

 $m->where("student_id", $WorkAssignValue[$counter]['student_id']);
 $discount=$m->get("eduportal_student_fee_structure");

   ?>

    
<div class="box">

<div class="section" style="<?php if($i==1){echo 'border-right:none;';}?>">
   
   <div style="width:100%; text-align:center; height:auto;font-size:12px;">
            <?php echo $array1[$i];?>

   </div>


  <div style="">
        
        <div style="width: 100%;">
           <img src="images/shamimhead.PNG" style="height:60px;width:100%;" />    
        </div>
        

      </div>

      <hr>
     

      <div style="font-size: 12px;">
        <div style="width: 25%;float: left;font-weight: bold;font-size: 12px;">Student Name</div>
        <div style="width: 75%; float: left;border-bottom: 1px solid black;"><?php echo $WorkAssignValue[$counter]['first_name'];?></div>
      </div>
<br>
      <div style="font-size: 12px;">
        <div style="width: 25%;float: left;font-weight: bold;font-size: 12px;">Father Name</div>
        <div style="width: 75%; float: left;border-bottom: 1px solid black;"><?php echo $WorkAssignValue[$counter]['last_name'];?></div>
      </div>
<br>
      <div style="font-size: 12px;">
        <div style="width: 25%;float: left;font-weight: bold;font-size: 12px;">G.R.No</div>
        <div style="width: 25%; float: left;border-bottom: 1px solid black;">(<?php echo $WorkAssignValue[$counter]['ref_no'];?>)</div>
        <div style="width: 25%;float: left;font-weight: bold;font-size: 12px;">Class/Sec</div>
        <div style="width: 25%; float: left;border-bottom: 1px solid black;"><?php echo getClassName($m,$WorkAssignValue[$counter]['class_id']);?>/<?php echo getSectionName($m,$WorkAssignValue[$counter]['section_id']);?></div>
      </div>

  <br>
      <div style="font-size: 12px;">
        <div style="width: 25%;float: left;font-weight: bold;font-size: 12px;">Month</div>
        <div style="width: 25%; float: left;border-bottom: 1px solid black;"><?php echo getMonthName($m,$WorkAssignValue[$counter]['month_id'])."-".date("y");?></div>
        <div style="width: 25%;float: left;font-weight: bold;font-size: 12px;">Session</div>
        <div style="width: 25%; float: left;border-bottom: 1px solid black;"><?php echo getSessionName($m,$_SESSION['current_session']);?></div>
      </div>
      <br>
      <div style="margin-top: 5px;font-size:12px;">
        
        <div style="width: 60%;float: left;background-color: lightgray; border-bottom: 1px solid black; border-top: 1px solid black;font-weight: bold;">Standard Tution Fee <?php echo getMonthName($m,$_GET['month']);?></div>
        <div style="width: 40%; float: left;background-color: lightgray; border-bottom: 1px solid black; border-top: 1px solid black;text-align: center;"><?php 
           
          $m->where("class_id", $WorkAssignValue[$counter]['classs_id']);
          $class_fee = $m->get("eduportal_class_fee_details");
          $class_standerd_fee=$class_fee[0]['tution_fee'];
          echo $class_standerd_fee;
          ?></div>
          
      </div>
     

      <div style="margin-top: 5px;font-size:12px;">

               
        <div style="width: 60%;float: left;background-color: lightgray; border-bottom: 1px solid black; border-top: 1px solid black;margin-top: 5px;font-weight: bold;">Discount <?php  
        $discountAmount=$class_standerd_fee-$WorkAssignValue[$counter]['tutionfee'];
  echo number_format($discountAmount/$class_standerd_fee*100,2)."%";?></div>
 
        <div style="width: 40%; float: left;background-color: lightgray; border-bottom: 1px solid black; border-top: 1px solid black;text-align: center;margin-top: 5px;"><?php 
          echo $class_standerd_fee-$WorkAssignValue[$counter]['tutionfee'];
        ?></div>

      </div>
      

<?php 

    $start_date = strtotime($WorkAssignValue[$counter]['challan_duedate']); 
    $end_date = strtotime(date("Y-m-d"));
    $datediffrence =($end_date - $start_date)/60/60/24;

    $student_fine=0;
    $actual_fine=0;

//echo $start_date;

  
   if($branch_details[0]['fine_type']=="0" || $branch_details[0]['fine_type']==0){  

    $student_fine= $branch_details[0]['late_fee_fine']; } 

  else {
    
    $student_fine= ($datediffrence * $branch_details[0]['late_fee_fine']);
   }


  //if(date("Y-m-d")>$details['challan_duedate'] && $details['paid_status']==1){

// if row is first 

  

        // if row is first and fee is paid then show only collected fine
          if($WorkAssignValue[$counter]['paid_status']==1){
            // echo $WorkAssignValue[$counter]['collected_fine'];
             $actual_fine=$WorkAssignValue[$counter]['collected_fine'];
           
          } 
        // if row is first and fee is not paid then calculate fine
          else if(date("Y-m-d")>$WorkAssignValue[$counter]['challan_duedate'] && $WorkAssignValue[$counter]['paid_status']==0){
           // echo $student_fine; 
            $actual_fine=$student_fine;
          }
      
 

    $totalAmount1+=$actual_fine;

        ?> 

   <table width="100%" style="font-size:11px;margin-top:2%;" cellspacing="0">  
  

      <tr>  
         <th width="70%"> Particulars    </th>
         <th width="30%" style="text-align:center;border-right:1px solid lightgray;">  Amount </th>
      </tr>

      <tr>  
         <td width="70%" style="font-weight: bold;"> Gross Tution Fee (<?php echo getMonthName($m,$WorkAssignListings[0]['month_id']);?>)   </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;">  <?php echo $WorkAssignValue[$counter]['tutionfee']-$WorkAssignListings[0]['disc_amount'];?> </td>
      </tr>


      <tr>  
         <td width="70%"> Arrears    </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;">  <?php echo $WorkAssignValue[$counter]['balance'];?> </td>
      </tr>
      
     
   <?php if($WorkAssignValue[$counter]['transportfee']>0){ ?>
      <tr>  
         <td width="70%"> Transport Fee   </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;">  <?php echo $WorkAssignValue[$counter]['transportfee'];?>  </td>
      </tr>
    <?php } ?>
    <?php if($WorkAssignValue[$counter]['misc_fee']>0){ ?>
      <tr>  
         <td width="70%"> <?php if ($branch[0]['misc_title']!=NULL){echo $branch[0]['misc_title'];}else {echo 'Miscellaneous';} ?>  </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;">  <?php echo $WorkAssignValue[$counter]['misc_fee'];?>  </td>
      </tr>
    <?php } ?>

   <?php 

      $fee_types = $m->get("eduportal_fee_types");
      $other_fees=0;
      foreach ($fee_types as $type) {
        $fees=getFeeOfOtherParameter($WorkAssignValue[$counter]['student_id'],$WorkAssignValue[$counter]['challan_id'],$type['feetype_id'],$m);
     
       if($fees!=""){
   ?>
     <tr>  
         <td width="70%"> <?php echo $type['feetype_name']; ?>   </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;"> 
          <?php 
          $other_fees+=$fees;
          echo $fees;  ?> </td>
      </tr>

    <?php } else {continue;} 



  } 

    ?>
        
<?php if($actual_fine>0){ ?>
      <tr>  
         <td width="70%"> Fine   </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;">  
         
               <?php  echo $actual_fine;?>
  
         
           </td>
      </tr>

    <?php } ?> 

<?php if($WorkAssignValue[$counter]['disc_amount']>0){ ?>
      <tr>  
         <td width="70%"> Fee Discount   </td>
         <td width="30%" style="text-align:center;border-right:1px solid gray;">
  <?php  

  echo ($WorkAssignValue[$counter]['disc_amount']/$WorkAssignValue[$counter]['tutionfee']*100)."% (".$WorkAssignValue[$counter]['disc_amount'].")";?>        
           </td>
      </tr>
<?php } ?>

      <tr>  
         <th width="70%" style="text-align:left;background-color: lightgray;"> Total Payable Amount </th>
         <th width="30%" style="text-align:center;background-color: lightgray;">  <?php echo  $WorkAssignValue[$counter]['balance']+$WorkAssignValue[$counter]['tutionfee']+$WorkAssignValue[$counter]['transportfee']+$WorkAssignValue[$counter]['misc_fee']+ $other_fees + $actual_fine-$WorkAssignValue[$counter]['disc_amount']; ?> 
      </th>
      </tr>

       <table width="100%" style="font-size:11px;" cellspacing="0">  
   
   
         <tr>  
         <td width="100%" colspan="2" style="text-align:center;border-left:none;color:white;"> .  </td>
         
         </tr>

         
   </table>

     <p style="font-size: 10px;">Discount Reasons: <?php echo $discount[0]['discount_reason'];?></p>

     <div style="font-size: 10px;">
        <div style="width: 25%;float: left;">Issue Date</div>
        <div style="width: 25%; float: left;"><?php echo date("d-M-Y");?></div>
        <div style="width: 25%;float: left;">Due Date</div>
        <div style="width: 25%; float: left;"><?php echo date("d-M-Y",strtotime($WorkAssignValue[$counter]['challan_duedate']));?></div>
      </div>

      <div style="width:100%;font-size:13px;text-align:center;float:left;margin-top:5px;">

         <img src="images/shamimfooterchange.jpg" style="height:100px;width:100%;" />

      </div>
      <div width="100%" style="text-align:center;border:none;color:black;margin-top: 100px;"> (Signature & Stamp)          
           
          </div>
      
 

   </table>


</div>
 
<!-- ending section  -->



  </div>  <!-- ending box  -->



 <?php 

 $counter++;
 $total_fee=0;
 


   } ?>

</page>
<br><br>
<?php } ?>

</body>
</html>
