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

<?php  include("sessioncheck.php"); ?>

<?php include('RootMe/css_links.php');?>
<br><br>
<h4 class="modal-title" style="text-align: center;"> Show Settlement Details</h4>


  <table class="table table-striped table-bordered" style="width:96%;margin: 10px;font-size: 12px;">

<thead>
<tr style="background-color:lightgray;">

<th style="text-align: center;" width="5%">S.no</th>
<th style="text-align: center;" width="35%">Heads Name</th>
<th style="text-align: center;" width="20%">Fee</th>
<th style="text-align: center;" width="20%">Settelment</th>
<th style="text-align: center;" width="20%">Balance</th>

</tr>
</thead>
<tbody>
<?php 
$s_id=$_REQUEST['std'];
$branchID=$_SESSION['branch'];
if ($_REQUEST['sttleNo']!=NULL) {
  $showSettle = "select * from  eduportal_challan_fee_settlement where branch_id='$branchID' and student_id='$s_id' and settellment_no=".$_REQUEST['sttleNo'];
$showSettles =  $m->query ($showSettle);
}

$sno=1;
foreach ($showSettles as $show) { 

  if ($show['month']!=$_REQUEST['month']) {
    continue;
  }
$fid=$show['feetypeid'];
$mm=$show['month'];

$HeadTotal="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branchID' and student_id='$s_id' and feetype_id='$fid' and month='$mm'";
$HeadTotals = $m->query($HeadTotal);

$HeadRecev="SELECT SUM(received) as rcv FROM eduportal_challan_fee_receiving WHERE  branch_id='$branchID' and student_id='$s_id' and feetypeid='$fid' and month='$mm'";
$HeadRecevs = $m->query($HeadRecev);

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

/*if ($show['settellment_amount']==0) {
  continue;
}*/

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

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

$TT +=$show['amount'];
$stl+=$show['settellment_amount'];
$bals+=($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settellment_amount']);
  ?>

  <tr style="text-align: center;">

<td width="10%"><?php echo $sno++;?></td>
<td width="25%"><?php if ($feeHeadsN[0]['fee_head_title']!=NULL){echo $feeHeadsN[0]['fee_head_title'];}else {echo $typesN[0]['feetype_name'];} ?> <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?></td>
<td><?php echo $show['amount'] ;?></td>
<td width="25%"><?php echo $show['settellment_amount'];?></td>
<td width="25%"><?php echo ($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settellment_amount']) ;?></td>

</tr>

  <?php } ?>

   <tr style="background-color:lightgray; text-align: center;">
    <td colspan="5" style="text-align:center;">Arrear</td>
      
  </tr>

  <!-- ============================== start previus settlemetn code ===================================== -->

<?php
  $sno=1;
foreach ($showSettles as $show) { 

  if ($show['month']==$_REQUEST['month']) {
    continue;
  }
$fid=$show['feetypeid'];
$mm=$show['month'];

$HeadTotal="SELECT * FROM eduportal_monthly_challan_details WHERE  branch_id='$branchID' and student_id='$s_id' and feetype_id='$fid' and month='$mm'";
$HeadTotals = $m->query($HeadTotal);

$HeadRecev="SELECT SUM(received) as rcv FROM eduportal_challan_fee_receiving WHERE  branch_id='$branchID' and student_id='$s_id' and feetypeid='$fid' and month='$mm'";
$HeadRecevs = $m->query($HeadRecev);

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

/*if ($show['settellment_amount']==0) {
  continue;
}*/

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

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

$TT +=$show['amount'];
$stl+=$show['settellment_amount'];
$bals+=($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settellment_amount']);
  ?>

  <tr style="text-align: center;">

<td width="10%"><?php echo $sno++;?></td>
<td width="25%"><?php if ($feeHeadsN[0]['fee_head_title']!=NULL){echo $feeHeadsN[0]['fee_head_title'];}else {echo $typesN[0]['feetype_name'];} ?> <?php echo substr(getMonthName($m,$toMonthYear[1]), 0, 3)."-".$toMonthYear[0];?></td>
<td><?php echo $show['amount'] ;?></td>
<td width="25%"><?php echo $show['settellment_amount'];?></td>
<td width="25%"><?php echo ($show['amount']) - (/*$HeadRecevs[0]['rcv']+*/$show['settellment_amount']) ;?></td>

</tr>

  <?php } ?>

  <!-- ============================== end previus settlemetn code ===================================== -->

  <tr style="background-color:lightgray; text-align: center;">
    <td colspan="2" style="text-align:center;">Total</td>
    <td><?php echo $TT;?></td>    
    <td><?php echo $stl;?></td>
    <td><?php echo $bals;?></td>   
  
  </tr>



</tbody>

</table> 

  <?php include('RootMe/js_linksscript.php');?>
