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

<?php

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

$m->where("section_id", $_REQUEST['section']);
$sectionName=$m->get("edu_adm_section_detail");

$m->where("session_id", $_REQUEST['session']);
$sessionName=$m->get("edu_session_config");

$NameOfMonths=explode(",",$_REQUEST['months']);
//$NumberOfTerms=count($NumberOf);

 $session;

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

    $session=$_REQUEST['session'];

  } else { $session=$_SESSION['current_session']; }

 


function ordinal($number) {
    $ends = array('th','st','nd','rd','th','th','th','th','th','th');
    if ((($number % 100) >= 11) && (($number%100) <= 13))
        return $number. 'th';
    else
        return $number. $ends[$number % 10];
}


 $branch=$_SESSION['branch'];
     $classID=$_REQUEST['class_id'];
     $sectionID=$_REQUEST['section'];
     $sessionIDs=$_REQUEST['session'];
     $sql = "SELECT * FROM  edu_student_details  WHERE branch_id='$branch' and status='0' and session_id='$sessionIDs' and class_id='$classID' and section_id='$sectionID'";
     //print_r($sql);
     $WorkAssignListings = $m->query($sql);

     ?>


<!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">
<title>Print Students Fee Records</title>
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<script type="text/javascript">
// window.print();
</script>
<style type="text/css">

tr th {border-top:1px solid gray;border-left:1px solid gray;border-bottom:1px solid gray;text-align:center;background-color:lightgray;font-size:14px; padding: 5px;}
tr td {border-bottom:1px solid gray;border-left:1px solid gray;font-size:14px;padding: 5px;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}
.padng{padding:1%;}

</style>
</head>
<body style="font-size:12px;">


<br>

<div style="text-align:center;font-size:30px;font-weight:bold;">Multi Months Students Fee Records </div>
<br>
<div style="width:23%; float:left;font-size:18px; margin-left:10px; "> <b> Class:</b> <?php echo $className[0]['Class_Name'];?> </div>
<div style="width:23%; float:left;font-size:18px; margin-left:10px; "> <b> Section:</b> <?php echo $sectionName[0]['section_name'];?> </div>
<div style="width:23%; float:left;font-size:18px; margin-left:10px; "> <b> Session:</b> <?php echo $sessionName[0]['session_year'];?> </div>


<input type="hidden" name="saleman" value="">
<input type="hidden" name="customer" value="">

<br><br><br>
<?php 
$expense_amount=$expense[0]['total'] + $salary[0]['total'];
?>
   
    <table id="listofstudents" data-page-length='10' class="table table-striped table-bordered" style="width:100%;font-size:11px;">
          
          <thead>
            <tr>
                <th width="2%">S.No</th>
                <th width="10%">Student Name</th>
                <th width="10%">Roll/Adm</th>
                <?php 
                foreach ($NameOfMonths as $NameOfMonth) {

                $m->where("Month_Id", $NameOfMonth);
          $MonthName = $m->get("eduportal_month_config");
             ?>
                  <th width="10%">Total / Paid / Rem<br><?php echo $MonthName[0]['Month_Name'];  ?></th>
                <?php } ?>              
            
                 
            </tr>
        </thead>
        <tbody>
  
     
     <?php 

     

     $count=1;     

  foreach ($WorkAssignListings as $Students) {


      $m->where("Month_Id", $NameOfMonth);
      $MonthName = $m->get("eduportal_month_config");

     $stdID=$Students['student_id'];
     
   
   ?>
                  <td style="text-align: center;"> <?php echo $count++; ?> </td>

                  <td style=""><?php echo $Students['first_name'];  ?></td>

                  <td style=""><?php echo $Students['candidate_roll_no']." / ".$Students['ref_no'];  ?></td>       

                  <?php 

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

                foreach ($NameOfMonths as $NameOfMonth) {
//echo $NameOfMonth;
                  $sqlFee = "SELECT * FROM  eduportal_monthly_challan  WHERE branch_id='$branch' and student_id='$stdID' and session_id='$sessionIDs' and classs_id='$classID' and month_id='$NameOfMonth'";
             //print_r($sqlFee);
             $StdFeeHistory = $m->query($sqlFee);

             $start_date = strtotime($StdFeeHistory[0]['challan_duedate']); 
            $end_date = strtotime(date("Y-m-d"));
            $datediffrence =($end_date - $start_date)/60/60/24;

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

  $others_fee=0+getFeeAllOtherFee($Students['student_id'],$StdFeeHistory[0]['challan_id'],$m);


        $totalAmount= $StdFeeHistory[0]['tutionfee']+$StdFeeHistory[0]['transportfee']+$StdFeeHistory[0]['balance']+$StdFeeHistory[0]['misc_fee']+$others_fee+$student_fine-$StdFeeHistory[0]['disc_amount'];

        /*if($totalAmount==0 ||  $totalAmount=="0"){
          
          continue;
        } */

        $paidAmount=$StdFeeHistory[0]['collected_amount']+$StdFeeHistory[0]['collected_fine']+$StdFeeHistory[0]['paid_again_amount'];

        $remaning=$totalAmount-$paidAmount;

                 ?>

                <td style=""><input style="width: 40px;float: left;" type="text"  readonly="" value="<?php echo $totalAmount ?>">
                 <input style="width: 40px;float: left;" type="text" width="34px" readonly="" value="<?php echo $paidAmount ?>">
                <input style="width: 40px;float: left;" type="text" width="34px" readonly="" value="<?php echo $remaning ?>"></td>

                 <?php } ?>
                                 

        
              </tr>
              

  <?php  
  
      } 

      
      ?>

   
        </tbody>
        
    </table>

</body>
</html>
