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

<?php   

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

$month;

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

$session;

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

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

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




$sql = "SELECT * FROM eduportal_expense_detail as b  ";
$from;
$to;

$branch=$_SESSION['branch'];


 
      if($_REQUEST['from']!=" " && $_REQUEST['from']!=NULL ) {
        $from=date("Y-m-d",strtotime($_REQUEST['from']));  

      }else {
        $from=date("Y-m-01");  
      }
     
      if($_REQUEST['to']!=" " && $_REQUEST['to']!=NULL   ) {
        $to=date("Y-m-d",strtotime($_REQUEST['to']));
      }else {
        $to=date("Y-m-t");  
      } 
      
     
    $sql .= "where b.branch_id='$branch' and b.expense_date BETWEEN '" .$from. "' AND '" .$to. "' order by expense_id desc";


// echo $sql;

    $expenses = $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 PayRoll Sheet</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 black;border-bottom:1px solid black;text-align:center;background-color:lightgray;font-size:14px; padding:3px;}
tr td {border-bottom:1px solid gray;border-left:1px solid black;font-size:14px; padding:3px;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}
.borderTop{
  border-top: none;
}
</style>
</head>
<body style="font-size:12px;">



  <!-- page content -->
        
          
      <br>
<div style="text-align:center;font-size:20px;font-weight:bold;"><?php echo $branchName[0]['Branch_Name'];?> </div>
<div style="text-align:center;font-size:20px;font-weight:bold;">Monthly Income & Expense Report </div>
<div style="text-align:center;font-size:18px;font-weight:bold;">Session: (<?php echo $session_name[0]['session_year'] ?>) </div>


<?php 
$expense_amount=$expense[0]['total'] + $salary[0]['total'];
?>
<br><br>
<div>

<div style="width: 48%; float: left;">

<!--   <h3 style="text-align: left;margin-left: 10px;">Month Name: <?php echo date("F");?></h3> -->
    <table style="width:100%;float: left;" cellspacing="0">
          
          <thead>
            <tr>
                <th width="3%" class="center padng"style="font-size:17px;">S.No</th>
                <th colspan="2" width="10%" class="center padng"style="font-size:17px;border-right: 1px solid black;">Expenses</th>            
               
                 
            </tr>

            <tr>
                <th width="3%" class="center padng"style="font-size:14px;"></th>
                <th width="10%" class="center padng"style="font-size:14px;">Particular</th>
                <th width="10%" class="center padng"style="font-size:14px;border-right: 1px solid black;">Amount</th>
                
                 
            </tr>
<?php    

$count=1;

foreach($expenses as $category){

   $m->where("category_id", $category['category_id']);
  $ctgry=$m->get("eduportal_expanse_category");

  $m->where("subcategory_id", $category['subcategory_id']);
  $sbctgry=$m->get("eduportal_expanse_subcategory");

  
$total_amount+=$category['expense_amount'];

?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;"><?php echo $count++;?></td>
                <td width="10%" class=" padng"style="font-size:17px;"><?php echo $sbctgry[0]['subcategory_name'];?></td>
                <td width="10%" class="center padng"style="font-size:17px;border-right: 1px solid black;"> <?php echo $category['expense_amount'];?> </td>
                 
            </tr>

<? } ?>



            <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;background-color: lightgray;"colspan="2">Total Amount</th>
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;background-color: lightgray;border-right: 1px solid black;"> <?php echo number_format($total_amount)?> </th>
                 
            </tr>





             
        </thead>
        <tbody>
   
                       
              
             
        </tbody>
        
    </table>
  
</div>
<div style="width: 48%; float: right;">


    <table style="width:100%;float: left;" cellspacing="0">
          
          <thead>
            <tr>
                <th width="3%" class="center padng"style="font-size:17px;">S.No</th>
                <th colspan="2" width="10%" class="center padng"style="font-size:17px;border-right: 1px solid black;">Income</th>
             
               
                 
            </tr>

            <tr>
                <th width="3%" class="center padng"style="font-size:14px;"></th>
                <th width="10%" class="center padng"style="font-size:14px;">Particular</th>
                <th width="10%" class="center padng"style="font-size:14px;border-right: 1px solid black;">Amount</th>
                
                 
            </tr>
<?php        
foreach($expenses as $category){

   $m->where("category_id", $category['category_id']);
  $ctgry=$m->get("eduportal_expanse_category");

  $m->where("subcategory_id", $category['subcategory_id']);
  $sbctgry=$m->get("eduportal_expanse_subcategory");

  
$total_amount+=$category['expense_amount'];

?>

            

<? } ?>

            <tr>
            <td width="1%" class="center padng">0</td>
            <td width="10%" class="padng">Previous Balance</td>
            <td width="10%" class="center padng" style="border-right: 1px solid black;"><?php $pre_bal=getMoreMonthsRegularFee($session,$from,$to,'balance',$m);  echo number_format($pre_bal); ?></td>
                                   
            </tr>

            <tr>
              <td width="1%" class="center padng">1</td>
              <td width="10%" class="padng">Tuition Fee</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;"><?php $tution_fee=getMoreMonthsRegularFee($session,$from,$to,'tutionfee',$m);  echo number_format($tution_fee); ?></td>
                                      
            </tr>

            <tr>
              <td width="1%" class="center padng">2</td>
              <td width="10%" class="padng"><?php if ($brid[0]['misc_title']!=NULL){echo $brid[0]['misc_title'];}else {echo 'Miscellaneous';} ?></td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;"><?php $misc_fee=getMoreMonthsRegularFee($session,$from,$to,'misc_fee',$m);  echo number_format($misc_fee); ?></td>
                                      
            </tr>

             <tr>
              <td width="1%" class="center padng">3</td>
              <td width="10%" class="padng"> Transport Fee</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;"><?php $trans_fee=getMoreMonthsRegularFee($session,$from,$to,'transportfee',$m);  echo number_format($trans_fee); ?></td>                                    
            </tr>

            <tr>
              <td width="1%" class="center padng">4</td>
              <td width="10%"class="padng">Admission Fee</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;">
                <?php $adm_fee=getMoreAllotherFeeWithType_Summary($from,$to,1,0,$m);  echo number_format($adm_fee); ?></td>                                      
            </tr>

             <tr>
              <td width="1%" class="center padng">5</td>
              <td width="10%" class="padng">Paper Fund</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;">
                <?php $pap_fund=getMoreAllotherFeeWithType_Summary($from,$to,2,0,$m);  echo number_format($pap_fund); ?></td>                                      
            </tr>

             <tr>
              <td width="1%" class="center padng">6</td>
              <td width="10%" class="padng">Library Fee</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;">
                <?php $lib_fee=getMoreAllotherFeeWithType_Summary($from,$to,3,0,$m);  echo number_format($lib_fee); ?></td>
                             
             </tr>

             <tr>
              <td width="1%" class="center padng">7</td>
              <td width="10%"class="padng">Lab Fee</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;">
                <?php $lab_fee=getMoreAllotherFeeWithType_Summary($from,$to,4,0,$m);  echo number_format($lab_fee); ?></td>
                                      
            </tr>

             <tr>
              <td width="1%" class="center padng">8</td>
              <td width="10%"class="padng">Other Fee</td>
              <td width="10%" class="center padng" style="border-right: 1px solid black;">
                <?php $othr_fee=getMoreAllotherFeeWithType_Summary($from,$to,5,0,$m);  echo number_format($othr_fee); ?></td>
                                      
            </tr>


            <tr style="background-color:lightgray;color:black;">
              
              <td width="10%" colspan="2" class="center padng">Total Discount         </td>
            <td width="10%" class="center padng" style="border-right: 1px solid black;">

                <?php $disc=getCurrentMonthFeeDiscount($session,$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-$disc;
?>
            <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;background-color: lightgray;"colspan="2">Total Amount</th>
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;background-color: lightgray;border-right: 1px solid black;"> <?php echo number_format($total_amount)?> </th>
                 
            </tr>
             
        </thead>
        <tbody>                      
              
             
        </tbody>
        
    </table>
  
  
</div>

</div>
   
<br><br>


        <!-- /page content -->
     
      
      

</body>
</html>
