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

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

<?php 



  //getting branch details 


  $branch=getBranch($m);

  $branchID=$_SESSION['branch'];

  $yearMonth=$_GET['yearMonth'];



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





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

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

}



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]['challan_validity_date'] > date("Y-m-d") ) {

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

} else {

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

}



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



    $student_fine=0;

    $actual_fine=0;





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

    



  

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

   }



}

//echo $student_fine;



$total_fee=intVal($WorkAssignListings[0]['tutionfee'])+intVal($WorkAssignListings[0]['transportfee'])+intVal($WorkAssignListings[0]['balance'])+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'];
  $year=$_REQUEST['year'];



$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:2%;}

     

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

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



@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: 25px;text-align:center;"><?php echo $branch[0]['Branch_Name'];?></div>



      </div>

      <br><br>

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

        <br>


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

      Issue date: <?php echo date("d-M-Y",strtotime($WorkAssignListings[0]['challan_created']));?>

   </div>


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

      
        Voucher Valid : <?php echo $WorkAssignListings[0]['challan_validity_date'];?>
       

   </div>
<hr>







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



         

         Issue date: <?php echo date("d-M-Y",strtotime($WorkAssignListings[0]['challan_created']));?>



   </div>



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



         <span style="border: 1px solid black;padding: 3px; text-align: center;"> Adm No : <?php echo $WorkAssignListings[0]['ref_no'];?></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:11px;" 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;"> 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;"> 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;">MonthYear:   </td>

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

            <?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;"> Voucher No:   </td>

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

         <?php

         

         

         if($WorkAssignListings[0]['challan_id']!=NULL){echo $WorkAssignListings[0]['challan_id'];} ?>  </td>



      </tr>



 </table>









   <table width="100%" style="font-size:12px;margin-top:1%;" 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 
      $discount_amount = $class_standerd_fee - $WorkAssignListings[0]['tutionfee'];
      ?>


      <?php         
          $stID=$_REQUEST['student_id'];
          $mID=$_REQUEST['yearMonth'];
          $yID=$_REQUEST['year'];
          $chID=$WorkAssignListings[0]['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 $ChallanMonthYear[0]['standared_fee'];} elseif ($typesName[0]['feetype_name']=="Admission Fee") {echo $ChallanMonthYear[0]['standared_adm'];} ?></td>
    <td ><?php if ($typesName[0]['feetype_name']=="Monthly Fee") { echo $ChallanMonthYear[0]['scholorship'];} 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")>$WorkAssignListings[0]['challan_duedate'] && $WorkAssignListings[0]['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 ($WorkAssignListings[0]['paid_status']==0) {

                   echo $student_fine;

               } else {

                    echo $student_fine = $WorkAssignListings[0]['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=$WorkAssignListings[0]['student_id'];
      $chID=$WorkAssignListings[0]['challan_id'];
      $againstchID=$_REQUEST['challan'];
       $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);
//echo $qq;
      $other_fee=0;

      foreach ($remainingFees as $remainingFee) {

         $chi=$remainingFee['challan_id'];
        $ry="SELECT * FROM eduportal_monthly_challan WHERE  branch_id='$branchID' and challan_id='$chi' and student_id=".$stdID;
          $preStandared = $m->query($ry);
      
      $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['yearMonth']) {
            continue;
        }

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

        // $que="SELECT * FROM eduportal_monthly_challan_arrears WHERE  branch_id='$branchID' and student_id='$stID' and month_id='$mID' and year='$yID'";
        // echo $que;
        // $fee = $m->query($que);

        // if (count($fee)==0) {
        //     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 $preStandared[0]['standared_fee'];} elseif ($type[0]['feetype_name']=="Admission Fee") {echo $preStandared[0]['standared_adm'];} ?></td>
         <td width="20%"><?php if ($type[0]['feetype_name']=="Monthly Fee") { echo $preStandared[0]['scholorship'];} 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 width="40%" style="text-align:right;">  Late Fee 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 $branch[0]['late_fee_fine'];?> </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-left: 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 

$totalCurrentMonthfee="";$previousMonthsfee="";/*$student_fine="";*/

   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:11px;" cellspacing="0">  

   

   

         <tr>  

         <td width="100%" colspan="2" style="text-align:center;border-left:none;color:white;"> .  </td>

         

         </tr>



         <tr>  

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

            

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



          </td>

         

         </tr>

   </table>



</div>





</div>





<?php } ?>



</body>

</html>

