<?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'];


$year=$_REQUEST['year'];

$YearMonth=explode("-",$_REQUEST['month']);

$m->where("Month_Id", $month_id);

$month_name=$m->get("eduportal_month_config");



$sql = " select std.first_name, std.last_name,std.father_name,std.cell_no,std.image,std.status,std.branch_id,std.class_id,std.candidate_roll_no,std.ref_no,std.section_id,std.family_code, 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.from_year_month='$month_id' AND std.branch_id=".$_SESSION['branch'];



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



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

    $sql .= " AND fee.year =" . $_REQUEST['year']. " ";

}



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

    $sql .= " AND fee.classs_id =" . $_REQUEST['class_id']. " ";

}



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

      $sql;

    } else {

    $sql .= " AND std.section_id =" . $_REQUEST['section']. " ";



    }



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

   // continue;  

  } 



  else {

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

    }

    $sql .= " order by std.class_id asc, section_id asc ";

 

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



} else {



  $sql = " select std.first_name, std.last_name,std.father_name,std.cell_no,std.image,std.status,std.branch_id,std.class_id,std.candidate_roll_no,std.ref_no,std.section_id,std.family_code, 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.year='$year' order by fee.classs_id asc";



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

}



//print_r($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 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:gray; text-align:center;font-size:14px;border:1px solid gray;}

tr td {border-bottom:1px solid gray;border-left:1px solid gray;padding:.7%;}







.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']);

 $m->where("class_id", $WorkAssignValue[$counter]['class_id']);

 $m->where("year", date("Y"));

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

 $discount=$m->get("eduportal_student_fee_structure");

//print_r($discount);

 $m->where("session_id", $WorkAssignValue[$counter]['session_id']);

 $sessionName=$m->get("edu_session_config");



     ?>



        

<div class="box" >



<div class="section" style="<?php if($i==2 || $i==4){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: 15%;float: left;">

            <img src="<?php echo DOMAIN.AgentDirectory;?>img/<?php echo $branch[0]['logo']; ?>" style="height:60px;width:60px;" />    

        </div>



        <div style="width:85%;font-size:17px;float: right;margin-top: 25px;text-align:center;"><?php echo $branch[0]['Branch_Name'];?></div>



      </div>



<div style="font-size:11px; text-align:center;"><?php echo $branch[0]['Branch_Location'];?></div>

 <div style="font-size:10px; text-align:center;">  Contact: <?php echo $branch[0]['branch_contact'];?>  </div>
 <br>
<div style="text-align:left;font-size: 10px;">Issue Date: <?php echo date("d-M-Y",strtotime($WorkAssignValue[$counter]['challan_created']));?></div>


     <div style="width:33%; font-size:10px;text-align:left; height:25px; float:left;">



         Validity Date: <?php echo date("d-M-Y",strtotime($WorkAssignValue[$counter]['challan_validity_date']));?>



   </div>



   <div style="width:33%; font-size:10px;text-align:center; height:25px; float:left;">



         Adm : <?php echo $WorkAssignValue[$counter]['ref_no'];?>



   </div>





   <div style="width:33%;font-size:10px; text-align:right; height:25px; float:left;">



        Due Date <?php echo date("d-M-Y",strtotime($WorkAssignValue[$counter]['challan_duedate']));?>



   </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){

             $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;


$m->where("class_id", $WorkAssignValue[$counter]['class_id']);
//$m->where("year", $_REQUEST['year']);
$class_fee = $m->get("eduportal_class_fee_details");
$class_standerd_fee=$class_fee[0]['tution_fee'];
$class_standerd_adm=$class_fee[0]['admission_fee'];

        ?> 



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

   

   

      <tr>  

         <td width="10%" style="border:none;"> Name   </td>

         <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php echo $WorkAssignValue[$counter]['first_name'];?>  </td>

         

         <td width="10%" style="border:none;"> Father   </td>

         <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php echo $WorkAssignValue[$counter]['last_name'];?>  </td>



      </tr>

 

    

  <tr>  

     <td width="10%" style="border:none;"> Class/Sec </td>

     <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php 

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

     echo getClassName($m,$_GET['class_id'])."/".getSectionName($m,$WorkAssignValue[$counter]['section_id']);

       } else {

     echo getClassName($m,$WorkAssignValue[$counter]['class_id'])."/".getSectionName($m,$WorkAssignValue[$counter]['section_id']);

       }?>

     </td>

     

     <td width="10%" style="border:none;">Voucher No  </td>

     <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php echo $WorkAssignValue[$counter]['challan_id'];?> </td>



  </tr>



   

       

  <tr>  

 

    <?php if ($brid[0]['no_type']==1 || $brid[0]['no_type']==0) { ?>

   

     <td width="10%" style="border:none;">  Comp No:  </td>

     <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php echo $WorkAssignValue[$counter]['candidate_roll_no'];?>  </td>



     <?php } elseif ($brid[0]['no_type']==2 || $brid[0]['no_type']==0) { ?>



     <td width="10%" style="border:none;">  Reg No: </td>

     <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php echo $WorkAssignValue[$counter]['ref_no'];?> </td>



     <?php } ?>



     <td width="10%" style="border:none;">  Month-Year  </td>

     <td width="40%" style="border-bottom: 1px solid black;text-align:center;border-left:none;">  <?php 

$fromMonthYear=explode("-",$WorkAssignValue[$counter]['from_year_month']);
$toMonthYear=explode("-",$WorkAssignValue[$counter]['to_year_month']);

if ($WorkAssignValue[$counter]['from_year_month']==$WorkAssignValue[$counter]['to_year_month']) {
echo substr(getMonthName($m,$fromMonthYear[1]), 0, 3)."-".$fromMonthYear[0];
} else {
echo substr(getMonthName($m,$fromMonthYear[1]), 0, 3)."-".$fromMonthYear[0]." / ".substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];
}
     ?>

      </td>





  

  </tr>

   

   </table>





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

      <tr>  
        <th width="37%"> Particulars </th>
        <th width="20%"> Standard </th>
        <th width="20%"> S.ship </th>
        <th width="20%" style="text-align:center;border-right:1px solid gray;">  Net </th>
      </tr>


<?php         
$stID=$WorkAssignValue[$counter]['student_id'];
$mID=$_REQUEST['month'];
$yID=$_REQUEST['year'];
$chID=$WorkAssignValue[$counter]['challan_id'];

$cMquery="SELECT * FROM eduportal_monthly_challan WHERE  branch_id='$branchID' and challan_id='$chID' and student_id=".$stID;
$ChallanMonthYear = $m->query($cMquery);

$cMquery="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branchID' and student_id='$stID' and challan_id='$chID'";
$currentChallan = $m->query($cMquery);

foreach ($currentChallan as $type) {

$typeID=$type['feetype_id'];

$m->where("feetype_id", $type['feetype_id']);
$typesName = $m->get("eduportal_fee_types");

$query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id=".$type['feetype_id'];
$feeHeads = $m->query($query11);    
$fee=$type['fee_amount'];
$totalCurrentMonthfee+=$type['fee_amount'];

$toMonthYear=explode("-",$type['month']);            

?>


<tr>

<td><?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title'];}else {echo $typesName[0]['feetype_name'];} ?> <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?></td>
<td><?php if ($typesName[0]['feetype_name']=="Monthly Fee") { echo $class_standerd_fee;} elseif ($typesName[0]['feetype_name']=="Admission Fee") {echo $class_standerd_adm;} ?></td>
<td ><?php if ($typesName[0]['feetype_name']=="Monthly Fee") { echo $discount[0]['std_scholarship'];} elseif ($typesName[0]['feetype_name']=="Admission Fee") {echo $discount[0]['std_admission_fee'];} ?></td>
<td style="border-right: 1px solid black;text-align: center;"><?php echo $fee;?></td>
</tr>

<?php } ?>  


<?php 

$alreadyFine="SELECT count(*) as total FROM eduportal_monthly_challan_details WHERE  branch_id='$branchID' and student_id='$stID' and challan_id='$chID' and feetype_id=4";         
$alreadyFines = $m->query($alreadyFine);

if(date("Y-m-d")>$WorkAssignValue[$counter]['challan_duedate'] && $WorkAssignValue[$counter]['paid_status']==0 && $alreadyFines[0]['total'] == 0){ ?>

 
      <tr>  
         <td width="40%"> Fine <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?>  </td>
         <td width="20%"> <?php //echo $class_standerd_fee;?>   </td>
         <td width="20%"> <?php //echo $class_standerd_fee;?>   </td>
         <td width="20%" style="text-align:center;border-right:1px solid gray;">         

               <?php if ($WorkAssignValue[$counter]['paid_status']==0) {

                   echo $student_fine;

               } else {

                    echo $student_fine = $WorkAssignValue[$counter]['collected_fine'];

               }

               ?>         

           </td>

      </tr>

<?php } else { $student_fine = 0; } ?>


<tr style="background: lightgray;"> 
<td colspan="4" style="text-align:center;border-right: 1px solid black;">Arrears</td>

</tr>

<?php 

$stdID=$WorkAssignValue[$counter]['student_id'];
$chID=$WorkAssignValue[$counter]['challan_id'];
$againstchID=$WorkAssignValue[$counter]['challan_id'];
$qq="SELECT * FROM eduportal_monthly_challan_arrears WHERE  branch_id='$branchID' and student_id='$stdID' and against_challan_id='$againstchID' order by month desc";
$remainingFees = $m->query($qq);

$other_fee=0;

foreach ($remainingFees as $remainingFee) {

$fees=$remainingFee['arrears_amount'];

if($fees!="" && $fees!="0" ){

$query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id=".$remainingFee['feetype_id'];
$feeHeads = $m->query($query11);

$m->where("feetype_id", $remainingFee['feetype_id']);
$type = $m->get("eduportal_fee_types");

if ($remainingFee['month']==$_REQUEST['month']) {
continue;
}

if ($remainingFee['month'] > $_REQUEST['month']) {
continue;
}


$previousMonthsfee+=$fees;

$toMonthYear=explode("-",$remainingFee['month']);
?>


<tr>  


<td width="40%"><?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title'];}else {echo $type[0]['feetype_name']." ";} ?>  <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?>  </td>
<td width="20%"><?php if ($type[0]['feetype_name']=="Monthly Fee") { echo $class_standerd_fee;} elseif ($type[0]['feetype_name']=="Admission Fee") {echo $class_standerd_adm;} ?></td>
<td width="20%"><?php if ($type[0]['feetype_name']=="Monthly Fee") { echo $discount[0]['std_scholarship'];} elseif ($type[0]['feetype_name']=="Admission Fee") {echo $discount[0]['std_admission_fee'];} ?></td>
<td width= "20%" style="text-align:center;border-right:1px solid gray;"> <?php $other_fee+=$fees;
echo $fees; ?></td>

</tr>
<?php } else continue; } ?>


<tr>  

<th width="40%" style="text-align:left;"> &nbsp;&nbsp; Total   </th>
<th width="20%"> <?php //echo $class_standerd_fee+$class_standerd_adm;?>   </th>
<th width="20%"> <?php //echo $discount_amount;?>   </th>
<th width="20%" style="text-align:center;">  
<?php echo number_format($totalCurrentMonthfee+$previousMonthsfee+$student_fine,2); ?> </th>

</tr>
     

   

<!--       <?php  if($branch[0]['fine_type']=="0" || $branch[0]['fine_type']==0){  ?> 
   
      <tr>  
         <td  style="text-align:right;"> After Due Date:   </td>
         <td  colspan="3" style="text-align:center;border-right:1px solid gray;">  <?php echo number_format($other_fee+$total_fee+$branch[0]['late_fee_fine'],2); ?> </td>
      </tr>
<?php  } else { ?>

       <tr>  
         <td width="100%" colspan="4" style="text-align:left;border-right: 1px solid gray;"><b> After due date <?php echo $branch[0]['late_fee_fine']?> Rs fine will be charged per day.</b></td>
        
      </tr>
 <?php }  ?> -->



  





</table>
    



  <br>

  <p style="font-size:11px;text-align: center; margin: 1px;">

  <?php
$totalCurrentMonthfee="";$previousMonthsfee="";

   if($branch[0]['fee_vouc_note']!=NULL){



          echo $branch[0]['fee_vouc_note'];

        ?>

      

      <?php }else { ?>

          Defaulters of two or more months will be expelled out. 

      <?php } ?>

    </p>



  <!-- <div style="width:100%;font-size:8px;text-align:center;"> <?php echo getPrintBottom($m);?>  </div>  --> 



</div>

 

<!-- ending section  -->







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







 <?php 



 $counter++;

 $total_fee=0;

 





   } ?>









</page>

<br><br>

<?php   $other_fee="";}?>



</body>

</html>

