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

<?php   
$branchID=$_SESSION['branch'];

   $m->where("status",'0');
   $Subcategories = $m->get("eduportal_expanse_subcategory");

     $default;
    
    if($_GET["month"]!=NULL ){

      $default= $_GET["month"];
    }
    else {

      $default= date("m");
    }  

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


        $cash = "SELECT SUM(expense_amount) as totalCash FROM eduportal_expense_detail where branch_id='$branchID' and month_id='$default' and paid_by='Cash'  ";
        $cash_head=$m->query($cash);

        $jazz = "SELECT SUM(expense_amount) as totalJazz FROM eduportal_expense_detail where branch_id='$branchID' and month_id='$default' and paid_by='JazzCash'  ";
        $jazz_head=$m->query($jazz);

        $EasyPaisa = "SELECT SUM(expense_amount) as totalEasyPaisa FROM eduportal_expense_detail where branch_id='$branchID' and month_id='$default' and paid_by='Easypaisa'  ";
        $EasyPaisa_head=$m->query($EasyPaisa);

        $BankAccount = "SELECT SUM(expense_amount) as totalBank FROM eduportal_expense_detail where branch_id='$branchID' and month_id='$default' and paid_by='BankAccount'  ";
        $Bank_head=$m->query($BankAccount);

        $UblOmni = "SELECT SUM(expense_amount) as totalOmni FROM eduportal_expense_detail where branch_id='$branchID' and month_id='$default' and paid_by='UblOmni'  ";
        $Omni_head=$m->query($UblOmni);
 


?>



<!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 SubCategory Expenses 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:1%;}

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


<br>

<div style="text-align:center;font-size:30px;font-weight:bold;">Monthly Expense Head Wise Report: (<?php echo $month_name[0]['Month_Name'] ?>) </div>

<hr style="width:100%;">

<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>
   
    <table style="width:60%; margin-left:245px;" 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;">Sub Category</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black">Amount</th>
                 
            </tr>
        </thead>
        <tbody>
   
    <?php  $count=1;
    
      
 $nt=0;
      

$date= date("Y-m-d");

foreach($Subcategories as $Subcategory){


  $qr="SELECT SUM(exp.expense_amount) as amount FROM `eduportal_expense_detail` as exp where exp.month_id='$default' and exp.subcategory_id=".$Subcategory['subcategory_id']." and branch_id=".$_SESSION['branch']." and session_id=".$_GET['session'];

  //echo $qr;

$exp_details=$m->query($qr);
if($exp_details[0]['amount']>0){}else{ continue; }


// calculating students total fee 

     
      
      $nt+=$exp_details[0]['amount'];
      

?>
        <tr> 
                <td class="center padng"> <?php echo $count; $count++;?> </td>
                  <td class="padng"style="padding-left:1%;"><?php echo $Subcategory['subcategory_name'];?></td>
                  <td class="center padng"style="border-right:1px solid black;">  
                  <?php echo $exp_details[0]['amount'];?>  </td>                  
                  
                             

                                 
              </tr>

       <?php } ?>


              <tr> 
                
                  <th colspan="2" class="padng"style="font-size:18px;">Total</th>
                  <th colspan="3" class="center padng" style="border-right:1px solid black;font-size:18px;">  <?php echo number_format($nt,2);?>  </th>
               
                                  
              </tr>

                     
              
             
        </tbody>
        
    </table>
<br>
    <table style="width:60%; margin-left:245px;" cellspacing="0">
          
          <thead>
            <tr>
                
                <th colspan="3" class="center padng"style="font-size:17px;border-right:1px solid black">Expense Details</th>
                 
            </tr>
        </thead>
        <tbody>
   
    

              <tr> 
                <td class="center padng"> 1 </td>
                  <td class="padng"style="padding-left:1%;">Cash</td>                  
                  <td class="center padng"style="border-right:1px solid black;">  
                  <?php echo $cash_head[0]['totalCash'];?>  </td>                  
                                                   
              </tr>

              <tr> 
                <td class="center padng"> 2 </td>
                  <td class="padng"style="padding-left:1%;">JazzCash</td>                  
                  <td class="center padng"style="border-right:1px solid black;">  
                  <?php echo $jazz_head[0]['totalJazz'];?>  </td>                  
                                                   
              </tr>

              <tr> 
                <td class="center padng"> 3 </td>
                  <td class="padng"style="padding-left:1%;">Easypaisa</td>                  
                  <td class="center padng"style="border-right:1px solid black;">  
                  <?php echo $EasyPaisa_head[0]['totalEasyPaisa'];?>  </td>                  
                                                   
              </tr>

              <tr> 
                <td class="center padng"> 4 </td>
                  <td class="padng"style="padding-left:1%;">Bank Account</td>                  
                  <td class="center padng"style="border-right:1px solid black;">  
                  <?php echo $Bank_head[0]['totalBank'];?>  </td>                  
                                                   
              </tr>

              <tr> 
                <td class="center padng"> 5 </td>
                  <td class="padng"style="padding-left:1%;">Ubl Omni</td>                  
                  <td class="center padng"style="border-right:1px solid black;">  
                  <?php echo $Omni_head[0]['totalOmni'];?>  </td>                  
                                                   
              </tr>

      

              <tr> 
                
                  <th colspan="2" class="padng"style="font-size:18px;">Total</th>
                  <th colspan="3" class="center padng" style="border-right:1px solid black;font-size:18px;">  <?php echo number_format($cash_head[0]['totalCash']+$jazz_head[0]['totalJazz']+$EasyPaisa_head[0]['totalEasyPaisa']+$Bank_head[0]['totalBank']+$Omni_head[0]['totalOmni'],2);?>  </th>
               
                                  
              </tr>

                     
              
             
        </tbody>
        
    </table>

</body>
</html>
