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

<?php   

$month;

if($_GET["month"]!=NULL ){
  $month= $_GET["month"];
}
else{
  $month= date("m");
}

$sessionIDs;

if($_GET["session"]!=NULL ){
  $sessionIDs= $_GET["session"];
}
else{
  $sessionIDs= $_SESSION['current_session'];
}

$m->where("Month_Id", $month);
$month_name=$m->get("eduportal_month_config");

$m->where("session_id", $sessionIDs);
$session_name=$m->get("edu_session_config");

$branchID=$_SESSION['branch'];




// ===================================================================================================


  $month_name=getMonthName($m,$month);




    function getAllotherFeeWithType_Summary_new($month,$feetype,$status,$m)
{
    $branchID=$_SESSION['branch'];
    $curr_session23=$_SESSION['current_session'];

    $qr="SELECT SUM(fee.fee_amount) as total FROM eduportal_monthly_challan_details as fee, eduportal_monthly_challan as cha, edu_student_details as std WHERE std.student_id=cha.student_id and std.status='0' and cha.session_id='$curr_session23' and cha.month_id='$month' and cha.challan_id=fee.challan_id and cha.branch_id='$branchID' and fee.feetype_id='$feetype' ";

   $amount = $m->query($qr);
    return $amount[0]['total'];
}

function getCurrentMonthFeeReceivedWithStruckOff_new($session,$month,$m)
{

 $branch=$_SESSION['branch']; 
  $qr="SELECT SUM(fee.collected_amount) as received, SUM(fee.paid_again_amount) as againPay, SUM(fee.collected_fine) as total_fine FROM eduportal_monthly_challan as fee,edu_student_details as std WHERE std.student_id=fee.student_id  and fee.branch_id='$branch' AND fee.session_id='$session' AND fee.month_id='$month' ";
//print_r($qr);
  $amount = $m->query($qr);
  $received_amount=$amount[0]['received']+$amount[0]['total_fine']+$amount[0]['againPay'];

   return $received_amount;

}


?>
<!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 Monthly Fee Report</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;}
tr td {border-bottom:1px solid gray;border-left:1px solid gray;font-size:14px;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}
.padng{padding:2%;}

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


<br>

<div style="text-align:center;font-size:20px;font-weight:bold;">Monthly Fee Summary: (<?php echo $month_name[0]['Month_Name'] ?>) </div>
<div style="text-align:center;font-size:18px;font-weight:bold;">Session: (<?php echo $session_name[0]['session_year'] ?>) </div>

<div style="width:33%;float:left;font-size:16px;">  <b> <!-- Class Name: --></b> 

<?php echo $class[0]['Class_Name'];?> 

</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 style="width:100%;" cellspacing="0">
          
          <thead>
            <tr>
                <th width="3%" class="center padng"style="font-size:17px;">S.No</th>
                <th width="10%" class="center padng"style="font-size:17px;">Particularly</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black">Amount</th>
                 
            </tr>
           


            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">1</td>
                <td width="10%" class=" padng"style="font-size:17px;">Previous Balance</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $pre_bal=getMonthlyRegularFee($sessionIDs,$month,'balance',$m);  echo number_format($pre_bal); ?> </td>
                 
            </tr>
             <tr>
                <td width="3%" class="center padng"style="font-size:17px;">2</td>
                <td width="10%" class=" padng"style="font-size:17px;"> Monthly Fee</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $tution_fee=getMonthlyRegularFee($sessionIDs,$month,'tutionfee',$m);  echo number_format($tution_fee); ?> </td>
                 
            </tr>
             <tr>
                <td width="3%" class="center padng"style="font-size:17px;">3</td>
                <td width="10%" class=" padng"style="font-size:17px;"> 
                    <?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?>
                </td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $misc_fee=getMonthlyRegularFee($sessionIDs,$month,'misc_fee',$m);  echo number_format($misc_fee); ?> </td>
                 
            </tr>
            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">4</td>
                <td width="10%" class=" padng"style="font-size:17px;"> Transport Fee</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $trans_fee=getMonthlyRegularFee($sessionIDs,$month,'transportfee',$m);  echo number_format($trans_fee); ?> </td>
                 
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='1'";     
               $feeHeads1 = $m->query($query11);
             ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">5</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads1[0]['fee_head_title']!=NULL){echo $feeHeads1[0]['fee_head_title'];} else {echo "Admission Fee";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $adm_fee=getAllotherFeeWithType_Summary_new($month,1,0,$m);  echo number_format($adm_fee); ?></td>
                 
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='2'";   

               $feeHeads2 = $m->query($query11);
           ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">6</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads2[0]['fee_head_title']!=NULL){echo $feeHeads2[0]['fee_head_title'];} else {echo "Paper Fund";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black">  <?php $pap_fund=getAllotherFeeWithType_Summary_new($month,2,0,$m);  echo number_format($pap_fund); ?></td>
                                      
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='3'";     
               $feeHeads3 = $m->query($query11);
           ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">7</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads3[0]['fee_head_title']!=NULL){echo $feeHeads3[0]['fee_head_title'];} else {echo "Uniform/Card Fee";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $lib_fee=getAllotherFeeWithType_Summary_new($month,3,0,$m);  echo number_format($lib_fee); ?></td>
            </tr>

             <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='4'";     
               $feeHeads4 = $m->query($query11);
           ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">8</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads4[0]['fee_head_title']!=NULL){echo $feeHeads4[0]['fee_head_title'];} else {echo "Stationery";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black">   <?php $lab_fee=getAllotherFeeWithType_Summary_new($month,4,0,$m);  echo number_format($lab_fee); ?></td>
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='5'";     
               $feeHeads5 = $m->query($query11);
            ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">9</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads5[0]['fee_head_title']!=NULL){echo $feeHeads5[0]['fee_head_title'];} else {echo "Other Fee";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $othr_fee=getAllotherFeeWithType_Summary_new($month,5,0,$m);  echo number_format($othr_fee); ?></td>
                 
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='8'";     
               $feeHeads8 = $m->query($query11);
            ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">10</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads8[0]['fee_head_title']!=NULL){echo $feeHeads8[0]['fee_head_title'];} else {echo "Annual Fund";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $anual_fnd=getAllotherFeeWithType_Summary_new($month,8,0,$m);  echo number_format($anual_fnd); ?></td>
                 
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='6'";     
               $feeHeads6 = $m->query($query11);
            ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">11</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads6[0]['fee_head_title']!=NULL){echo $feeHeads6[0]['fee_head_title'];} else {echo "Registration Fee";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $Reg_fee=getAllotherFeeWithType_Summary_new($month,6,0,$m);  echo number_format($Reg_fee); ?></td>
                 
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branchID' and fee_head_id='7'";     
               $feeHeads7 = $m->query($query11);
            ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">12</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads7[0]['fee_head_title']!=NULL){echo $feeHeads7[0]['fee_head_title'];} else {echo "Security Fee";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $security_fee=getAllotherFeeWithType_Summary_new($month,7,0,$m);  echo number_format($security_fee); ?></td>
                 
            </tr>

            <?php 
            $query11="SELECT * FROM eduportal_manage_fee_heads_details WHERE  branch_id='$branch' and fee_head_id='9'";     
               $feeHeads9 = $m->query($query11);
            ?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">13</td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php               
              if ($feeHeads9[0]['fee_head_title']!=NULL){echo $feeHeads9[0]['fee_head_title'];} else {echo "Books Pack";} ?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php $bookPack_fee=getAllotherFeeWithType_Summary_new($month,9,0,$m);  echo number_format($bookPack_fee); ?></td>
                 
            </tr>


              
           <tr>
                <td width="3%" class="center padng"style="font-size:17px;">14</td>
                <td width="10%" class=" padng"style="font-size:17px;">Total Discount</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> 
                    <?php $disc=getCurrentMonthFeeDiscount($sessionIDs,$month,$m); echo number_format($disc); ?></td>
                 
            </tr>
              


<?php 
$total_amount=$pre_bal+$tution_fee+$misc_fee+$trans_fee+$adm_fee+$pap_fund+$lib_fee+$lab_fee+$othr_fee+$anual_fnd+$Reg_fee+$security_fee+$bookPack_fee-$disc;
?>
            <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;"colspan="2">Total Amount</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black;border-top: none;"> <?php echo number_format($total_amount)?> </th>
                 
            </tr>




            <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;"colspan="2">Total Received</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black;border-top: none;"> <?php $recieved=getCurrentMonthFeeReceivedWithStruckOff_new($sessionIDs,$month,$m);  echo number_format($recieved); ?> </th>
                 
            </tr>
             <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;"colspan="2">Total Recveiable</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black;border-top: none;"> <?php echo number_format($total_amount - $recieved );?> </th>
                 
            </tr>
        </thead>
        <tbody>
   
                       
              
             
        </tbody>
        
    </table>

</body>
</html>
