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

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



?>



<div id="myID" style="">

  <form action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="post" enctype="multipart/form-data" class="form-horizontal form-label-left" >

    <input type="hidden" name="action" value="PayFullFamilyFee"/>
    <input type="hidden" name="fee_recv_sms" value="<?php echo $brid[0]['fee_recv_sms']; ?>">

    <table width="100%"  class="responsive">  


    <tr>

 <th class="thStyle" style="padding:6px 5px;"> Adm#  </th>
 <th class="thStyle" style="padding:6px 5px;"> Roll#  </th>
 <th class="thStyle" style="padding:6px 5px;"> Student Name  </th>
 <th class="thStyle" style="padding:6px 5px;"> Father Name  </th>
 <th class="thStyle" style="padding:6px 5px;"> Class/Sec  </th>
 <th class="thStyle" style="padding:6px 5px;"> Family Code  </th>
 <th class="thStyle" style="padding:6px 5px;"> Month  </th>
 <th class="thStyle" style="padding:6px 5px;"> Current Balance </th>
 <th class="thStyle" style="padding:6px 5px;"> Received </th>
 <th class="thStyle" style="padding:6px 5px;"> Paid Date </th>

  </tr>


    <?php 
/*$count=1;*/

$branch_id=$_SESSION['branch'];
$family_code=$_REQUEST['family_code'];
$sessionIDs=$_SESSION['current_session'];
$month=date("m");

 

  $sql="SELECT * FROM edu_student_details WHERE family_code='$family_code' and branch_id='$branch_id' and status='0' and session_id='$sessionIDs' ";
//print_r($sql);


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

 foreach($WorkAssignListings as $WorkAssignListVal)
      { 

        $studendtID=$WorkAssignListVal['student_id'];

      $sql1="SELECT * FROM eduportal_monthly_challan WHERE branch_id='$branch_id' and session_id='$sessionIDs' and student_id='$studendtID' order by challan_id desc limit 1 ";
    //print_r($sql1);   
      $familyfees = $m->query($sql1);

      $counter++;

      $OthersTotal=0+getFeeAllOtherFee($WorkAssignListVal['student_id'],$familyfees[0]['challan_id'],$m);
      $totalAmount= $familyfees[0]['tutionfee']+$familyfees[0]['transportfee']+$familyfees[0]['balance']+$familyfees[0]['misc_fee']+$OthersTotal; 
//echo $WorkAssignListVal['tutionfee'];
    $start_date = strtotime($familyfees[0]['challan_duedate']); 
    $end_date = strtotime(date("Y-m-d"));
    $datediffrence =($end_date - $start_date)/60/60/24;


      $totalAmount1=$totalAmount-$familyfees[0]['disc_amount'];

        ?>
      <input type="hidden" name="stdID[]" value="<?php echo $WorkAssignListVal['student_id'];?>">
      <input type="hidden" name="std_no" value="<?php echo $cell_no;?>">
      <input type="hidden" name="std_id" value="<?php echo $WorkAssignListVal['student_id'];?>">
      <input type="hidden" name="month_name" value="<?php echo getMonthName($m,$familyfees[0]['month_id']);?>">
      <input type="hidden" name="father_name" value="<?php echo $WorkAssignListVal['last_name'];?>">
      <input type="hidden" name="FeeStatus[]" value="<?php echo $familyfees[0]['paid_status'];?>">
      <input type="hidden" name="challanID[]" value="<?php echo $familyfees[0]['challan_id'];?>">
      <tr>  
         <td><?php echo $WorkAssignListVal['ref_no'];?></td>
         <td><?php echo $WorkAssignListVal['candidate_roll_no'];?></td>
         <td><a target="_blank" href="pay_fee.php?student=<?php echo $WorkAssignListVal['student_id'];?>"><?php echo $WorkAssignListVal['first_name'];?></a></td>
         <td><?php echo $WorkAssignListVal['last_name'];?></td>
         <td><?php echo getClassName($m,$WorkAssignListVal['class_id']);?> (<?php echo  getSectionName($m,$WorkAssignListVal['section_id']);?>)</td>
         <td><?php echo $WorkAssignListVal['family_code'];?></td>
         <td><?php echo getMonthName($m,$familyfees[0]['month_id'])?></td>

         <?php 

    $student_fine=0;
    $actual_fine=0;

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

        // echo $WorkAssignListVal['collected_fine'];
         $actual_fine=$familyfees[0]['collected_fine'];
    }    



    $totalAmount1+=$actual_fine;
        ?>         
         <td style="text-align: center;"><?php echo $totalAmount1-($familyfees[0]['collected_amount']+$familyfees[0]['collected_fine']+$familyfees[0]['paid_again_amount']+getMoreFee($familyfees[0]['challan_id'],$m));?></td>

         <td> <input type="text" style="width: 70px;" value="<?php echo $totalAmount1-($familyfees[0]['collected_amount']+$familyfees[0]['collected_fine']+$familyfees[0]['paid_again_amount']+getMoreFee($familyfees[0]['challan_id'],$m));?>" id="feerecv<?php echo $WorkAssignListVal['student_id'];?>"  name="feerec[]"  onkeyup="total_received(<?php echo $WorkAssignListVal['student_id'];?>)"> </td> 

         <td><?php if ($familyfees[0]['paying_date']!="") {
           echo date("d-M-Y",strtotime($familyfees[0]['paying_date']));
         } ?></td>     

                 
      </tr>
<script type="text/javascript">
   
</script>

<input type="hidden" name="totalAmount[]" value="<?php echo $totalAmount1;?>">
<input type="hidden" name="collectedFine[]" value="<?php echo $actual_fine;?>">

<script type="text/javascript">



  </script>


<?php 
$GrandTotal+=$totalAmount1-($familyfees[0]['collected_amount']+$familyfees[0]['collected_fine']+$familyfees[0]['paid_again_amount']+getMoreFee($familyfees[0]['challan_id'],$m));

 }  ?>

<tr>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>

  <td colspan="2" style="text-align: center; font-weight: bold;background-color: lightgray;">Grand Total</td>
  <td style="text-align: center; font-weight: bold;background-color: lightgray;"> <?php echo $GrandTotal;?></td>
  <td style="text-align: center; font-weight: bold;background-color: lightgray;">


    <input type="text" value="<?php echo $GrandTotal;?>" id="totaltotal" style="width: 70px;" name="totalreceivedAmt">



  </td>
  <td style="text-align: center; font-weight: bold;background-color: lightgray;"></td>
</tr>

<tr>
  <td style="color: red;font-size: 14px;"><b>Note*:</b></td>
  <td colspan="5" style="color: red; font-size: 14px;">Pay full family fee will only apply to the students with unpaid challan.</td>
  
<td colspan="2" style="text-align: center;">
<!-- <a type="submit" style="padding: 0px 5px; font-size:14px;float: right;"  class="btn btn-danger">
Pay Full Fee 
</a> -->
<button id="send" type="submit" style="padding: 0px 5px; font-size:14px;float: right;" class="btn btn-danger" >Pay Family Fee</button>
</td>
</tr>
</table>
</form>
</div>





