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

<?php include('Sessioncheck.php');?>
<?php 



  //getting branch details 


  $branch=getBranch($m);

  $branchID=$_SESSION['branch'];



  $month_id=$_GET['month_id'];
  $year_month=explode("-",$month_id);



  $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.from_year_month='$month_id' AND std.branch_id=".$_SESSION['branch']." AND fee.student_id=".$_REQUEST['student_id'];





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

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

}



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

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

}



  //echo $sql;



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



// now getting the other fee parameters of student against selected month

$fee_fine;



if(date("Y-m-d")>$WorkAssignListings[0]['challan_duedate']){

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

 }

 else {

$fee_fine=0;

 }





  $start_date = strtotime($WorkAssignListings[0]['challan_duedate']);

  if ($WorkAssignListings[0]['paid_status']=='1') {

  $end_date = strtotime($WorkAssignListings[0]['paying_date']);

  

   } else {

  $end_date = strtotime(date("Y-m-d"));

  }

  $datediffrence =($end_date - $start_date)/60/60/24;



    $student_fine=0;

    $actual_fine=0;





if (date("Y-m-d")>$WorkAssignListings[0]['challan_duedate']) {

    



  

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



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



  else {

    

    $student_fine= ($datediffrence * $branch[0]['late_fee_fine']);

   }



}





$total_fee=intVal($WorkAssignListings[0]['tutionfee'])+intVal($WorkAssignListings[0]['transportfee'])+intVal($WorkAssignListings[0]['balance11'])+intVal($WorkAssignListings[0]['misc_fee']-$WorkAssignListings[0]['disc_amount']);



// print_r($challan); 



  

 // $m->where("session_id", $_SESSION['current_session']);

  $m->where("class_id", $WorkAssignListings[0]['class_id']);

  $class_fee = $m->get("eduportal_class_fee_details");

  $class_standerd_fee=$class_fee[0]['tution_fee'];
  $class_standerd_adm=$class_fee[0]['admission_fee'];





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

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





  $sessionID=$_SESSION['current_session'];



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

  $signatures = $m->get("eduportal_upload_acadmic_signature");



$m->where("class_id", $WorkAssignListings[0]['class_id']);
$m->where("year", date("Y"));
$m->where("branch_id", $_SESSION['branch']);
$m->where("student_id", $_GET['student_id']);
  $discount=$m->get("eduportal_student_fee_structure");

?>

 <!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 Double 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:45%; height:auto;float:left;padding-right:2%;margin-left:2%;margin-top:0.3%;}

     

tr th {background-color:lightgray; text-align:center;font-size:12px;border:1px solid black;padding:0.1%;}

tr td {border-bottom:1px solid black;border-left:1px solid black;padding:0.3%;}



@media print {

    #Header, #Footer { display: none !important; }

}

@media screen

   {

      p.bodyText {font-family:verdana, arial, sans-serif;}

   }



   @media print

   {

      p.bodyText {font-family:georgia, times, serif;}

   }

   @media screen, print

   {

      p.bodyText {font-size:10pt}

   }

   @media print {

  a[href]:after {

    content: none !important;

  }

}

</style>

</head>

<body>

<?php



 $array1=array("Institute Copy","Student Copy");



 for($i=0; $i<2;$i++){ ?>



 <!-- Vouchere Fist -->

<div class="section" style="<?php if($i<1){echo 'border-right: 2px solid black;border-right-style:dotted;';}?>">

   

 <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:50px;width:50px;" />    

        </div>

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



      </div>

      <br><br>

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

       <div style="font-size:12px; text-align:center;">  Contact: <?php echo $branch[0]['branch_contact'];?><br><span style="float:left;font-size: 10px;">Issue date: <?php echo date("d-M-Y",strtotime($WorkAssignListings[0]['challan_created']));?></span> <span style="float:right;font-size: 10px;margin-left: 20px;">Voucher Valid: <?php echo date("d-M-Y",strtotime($WorkAssignListings[0]['challan_validity_date']));?></span> </div>

<br>

   <hr>







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



         Adm No : <?php echo $WorkAssignListings[0]['ref_no'];?>



   </div>



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



         <!-- <span style="border: 1px solid black;padding: 3px; text-align: center;"> Recp No : <?php echo $_REQUEST['receipt'];?></span> -->



   </div>





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



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



   </div>



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

   

   

      <tr>  

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

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

      

         <td width="15%" style="border:none;"> F.Name:   </td>

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



      </tr>





  

  

      <tr>  

         <td width="15%" style="border:none;"> Class (Sec):   </td>

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

         <?php echo getClassName($m,$WorkAssignListings[0]['classs_id']);?>

          (<?php echo getSectionName($m,$WorkAssignListings[0]['section_id']);?>) </td>



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

                        

         <td width="15%" style="border:none;font-size: 12px;"> Comp No:   </td>

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

         <?php echo $WorkAssignListings[0]['candidate_roll_no'];?>  </td>



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

            

         <td width="15%" style="border:none;font-size: 12px;"> Reg No:   </td>

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

         <?php echo $WorkAssignListings[0]['ref_no'];?>  </td>



        <?php } ?>

      </tr>









      <tr>  

         <td width="15%" style="border:none;"> MonYear:   </td>

         <td width="35%" style="border-bottom: 1px solid black;text-align:center;border-left:none;font-size: 12px;"> 

         <?php
                $fromMonthYear=explode("-",$WorkAssignListings[0]['from_year_month']);
                $toMonthYear=explode("-",$WorkAssignListings[0]['to_year_month']);

              if ($WorkAssignListings[0]['from_year_month']==$WorkAssignListings[0]['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>      

         <td width="15%" style="border:none;"> Vchr/Rcpt No:   </td>

         <td width="35%" style="border-bottom: 1px solid black;text-align:center;border-left:none;font-size:12px;">  

         <?php echo $_REQUEST['againstchallan']." / ".$_REQUEST['receipt']; ?>  </td>

      </tr>

 </table>









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


      <tr>  
        <th style="width: 25%;"> Particulars </th>
        <th style="width: 18%;"> Standard </th>
        <th style="width: 18%;"> S.ship </th>
        <th style="text-align:center;width: 18%;">  Net </th>     
        <th style="width: 21%;text-align:center;border-right:1px solid gray;padding: 0px 14px 0px 14px;">  Rcpt </th>
     
      </tr>


      


      <?php 
      $discount_amount = $class_standerd_fee - $WorkAssignListings[0]['tutionfee'];
      ?>

        

     <?php
          $chID=$_REQUEST['challan'];  
          $mID=$_REQUEST['month_id'];
          $sID=$_REQUEST['student_id'];

      $pre = "select * from eduportal_challan_fee_receiving where branch_id='$branchID' and student_id='$sID' and receipt_no=".$_REQUEST['receipt']; 
      
     $CurrentMonthreceivedAmounts = $m->query($pre);

     $usr = "select * from edu_user_config where user_id=".$CurrentMonthreceivedAmounts[0]['paid_user_id']; 
     $usrName = $m->query($usr);


// get settlement amount

$s="SELECT sum(settellment_amount) as st FROM eduportal_challan_fee_settlement WHERE  branch_id='$branchID' and challan_id='$chID' ";

$stlamt = $m->query($s);
  
  //echo $pre;
     foreach ($CurrentMonthreceivedAmounts as $receivedAmount) { 

        $m->where("feetype_id", $receivedAmount['feetypeid']);
        $HeadName = $m->get("eduportal_fee_types");

        if ($receivedAmount['amount']==NULL) {
            continue;
        }

        if ($receivedAmount['month']!=$mID) {
            continue;
        }

    $cID=$receivedAmount['against_challan_id'];
      $cMquery="SELECT * FROM eduportal_monthly_challan WHERE  branch_id='$branchID' and challan_id='$cID' and student_id=".$sID;    
          $ChallanMonthYear = $m->query($cMquery);

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

        $CTamt+=$receivedAmount['amount'];
        $CRamt+=$receivedAmount['received'];
        $CREamt+=$receivedAmount['remaining'];

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

      <tr>  

         <td width="35%" style="font-size:11px;"> <?php if ($feeHeads[0]['fee_head_title']!=NULL){echo $feeHeads[0]['fee_head_title']. "(". substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0].")" ;}else {echo $HeadName[0]['feetype_name']. "(". substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0].")" ;}?>   </td>
         <td><?php if ($HeadName[0]['feetype_name']=="Monthly Fee") { echo $ChallanMonthYear[0]['standared_fee'];} elseif ($HeadName[0]['feetype_name']=="Admission Fee") {echo $ChallanMonthYear[0]['standared_adm'];} ?></td>
        <td ><?php if ($HeadName[0]['feetype_name']=="Monthly Fee") { echo $discount[0]['std_scholarship'];} elseif ($HeadName[0]['feetype_name']=="Admission Fee") {echo $discount[0]['std_admission_fee'];} ?></td>
         <td width="15%"> <?php echo $receivedAmount['amount'];?>   </td>
         <td width="15%" style="text-align:center;border-right:1px solid gray;">  <?php if ($receivedAmount['received']!=0) { echo $receivedAmount['received'];}?>  </td>
          

      </tr>

<?php }  ?>  

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

<!-- ======================================= previous month receiving ===================================== -->

 
     <?php
          $chID=$_REQUEST['challan'];
          $A_chID=$_REQUEST['againstchallan'];  
          $mID=$_REQUEST['month_id'];
          $std_ID=$_REQUEST['student_id'];

      $pre = "select * from eduportal_challan_fee_receiving where branch_id='$branchID' and student_id='$std_ID' and receipt_no=".$_REQUEST['receipt']; 
     $PreviousMonthreceivedAmounts = $m->query($pre);

     $usr = "select * from edu_user_config where user_id=".$PreviousMonthreceivedAmounts[0]['paid_user_id']; 
     $usrName = $m->query($usr);
  
  //echo $pre;
     $chnageIndex= -1;
     foreach ($PreviousMonthreceivedAmounts as $receivedAmount) { 

        $m->where("feetype_id", $receivedAmount['feetypeid']);
        $HeadName = $m->get("eduportal_fee_types");

        $chi=$receivedAmount['against_challan_id'];
        $ry="SELECT * FROM eduportal_monthly_challan WHERE  branch_id='$branchID' and challan_id='$chi' and student_id=".$_REQUEST['student_id'];
    
          $preStandared = $m->query($ry);

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

        $pr = "select * from eduportal_monthly_challan_details where challan_id='$A_chID' order by chDetail_id asc"; 
        $crMnthChlid = $m->query($pr);
         $chnageIndex++;

        if ($receivedAmount['month']==$crMnthChlid[$chnageIndex]['month']) {
            continue;
        }
        
        if ($receivedAmount['amount']==NULL) {
            continue;
        }

        /*if ($receivedAmount['received']==NULL || $receivedAmount['received']=='0') {
            continue;
        }*/

        $PTamt+=$receivedAmount['amount'];
        $PRamt+=$receivedAmount['received'];
        $PREamt+=$receivedAmount['remaining'];
        
        ?>

      <tr>  

         <td width="35%" style="font-size:11px;"> <?php echo $HeadName[0]['feetype_name']. "(". substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0].")" ;?>   </td>
         <td width="20%"><?php if ($HeadName[0]['feetype_name']=="Monthly Fee") { echo $preStandared[0]['standared_fee'];} elseif ($HeadName[0]['feetype_name']=="Admission Fee") {echo $preStandared[0]['standared_adm'];} ?></td>
         <td width="20%"><?php if ($HeadName[0]['feetype_name']=="Monthly Fee") { echo $discount[0]['std_scholarship'];} elseif ($HeadName[0]['feetype_name']=="Admission Fee") {echo $discount[0]['std_admission_fee'];} ?></td>
         <td width="15%"> <?php echo $receivedAmount['amount'];?>   </td>
         <td width="15%" style="text-align:center;border-right:1px solid gray;">  <?php echo $receivedAmount['received'];?>  </td>
          

      </tr>

<?php }  ?> 

<!-- ========================================== end previous month receiving ================================== -->



<?php if($student_fine>0 && date("Y-m-d")>$WorkAssignListings[0]['challan_duedate']){ ?>

 

      <tr>  

         <td width="40%"> Fine   </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  echo $student_fine;?>

  

         

           </td>

      </tr>

<?php } ?>


      

      <tr>  

         <th width="40%" style="text-align:left;"> &nbsp;&nbsp; Total   </th>
         <th width="20%"> <?php //echo number_format($Tamt);?>   </th>
         <th width="20%"> <?php //echo number_format($Ramt);?>   </th>
         <th width="20%"> <?php echo number_format($CTamt+$PTamt);?>   </th>
         <th width="20%" style="text-align:center;"> <?php echo number_format($CRamt+$PRamt); ?> </th>
          
      </tr>

      <?php if ($stlamt[0]['st'] > 0) { ?>
          
    <!-- <tr>  

    <th width="40%" style="text-align:left;" colspan="3"> &nbsp;&nbsp; Settlement   </th>

    <th width="20%" style="text-align:center;" colspan="2"> <?php echo number_format($stlamt[0]['st']); ?> </th>

    </tr> -->
      
      <?php } ?>
      

      <tr>  

         <th width="40%" style="text-align:left;" colspan="3"> &nbsp;&nbsp; Remaining   </th>
         
         <th width="20%" style="text-align:center;" colspan="2"> <?php echo number_format(($CTamt+$PTamt)-($CRamt+$PRamt/*+$stlamt[0]['st']*/)); ?> </th>
          
      </tr>

      <tr>  

         <th style="text-align:left;" colspan="5"> &nbsp;&nbsp; Received By: <?php echo $usrName[0]['user_fname'];?> , Paid Method: <?php echo $CurrentMonthreceivedAmounts[0]['paid_by'];?>, Date: <?php echo $CurrentMonthreceivedAmounts[0]['paid_date'];?>, Time: <?php echo $CurrentMonthreceivedAmounts[0]['paid_time'];?>, Fee Remarks: <?php echo $CurrentMonthreceivedAmounts[0]['fee_remarks'];?>  </th>
                  
          
      </tr>

      <?php if ($WorkAssignListings[0]['collected_amount']!=NULL) { 

        $m->where("class_id", $WorkAssignListVal['class_id']);
        $class=$m->get("edu_class_config");

        ?>
          
          <tr style="background: lightgray;">
        <td colspan="3" style="text-align:center;">Received By: Paid Amount & Receipt No: (<?php echo $WorkAssignListings[0]['receipt_no']; ?>)</td>
        <td colspan="2" style="text-align:center;"><?php echo number_format($WorkAssignListings[0]['collected_amount'],2); ?></td>
      </tr>
      <?php } ?>
      


 

<?php  if($branch[0]['fine_type']=="0" || $branch[0]['fine_type']==0){  ?>    

    <!--   <tr>  

         <td width="40%" style="text-align:right;"> After Due Date:   </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 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>



 <?php if ($WorkAssignListings[0]['fee_remarks']!=NULL) { ?>

<p style="margin: 1px; border: 1px solid black;padding: 2px; font-size: 11px;"> Fee Remarks: <?php echo $WorkAssignListings[0]['fee_remarks'];?></p>

<?php } ?>





   <!-- <br> -->

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

   <?php 

$CTamt=""; $PTamt=""; $CRamt=""; $PRamt="";

   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>





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

   

   

         <tr>  

         <td width="100%" colspan="2" style="text-align:center;border-left:none;"> <?php if($signatures[0]['principal_signature']!=NULL && $brid[0]['display_signature']==1){ ?>

                        

            <img src="<?php echo DOMAIN;?>Production/signatures/<?php echo $signatures[0]['principal_signature'];?>" id="preview" class="img-thumbnail" style="width:100px;height:55px;"   />



         <?php } ?>  </td>

         

         </tr>



         <tr>  

         <td width="100%" colspan="2" style="text-align:center;border:none;color:black;"> (Signature & Stamp) <br>

            

            <!-- <span style="font-size:11px;"> <?php echo getPrintBottom($m);?>  </span> -->



          </td>

         

         </tr>

   </table>



</div>





</div>





<?php } ?>



</body>

</html>

