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

<?php   

 /*  $m->where("Status",'0');
   $m->orderBy("expense_id","desc");
   $m->where("month_id",$_REQUEST['month']);
   $m->where("session_id",$_REQUEST['session']);
   $m->where("branch_id",$_SESSION['branch']);
   $categories = $m->get("eduportal_expense_detail");*/

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

$getYear=(explode("-",$getYearAgainstSession[0]['session_year']));

$default;
$year;
    
    if($_GET["month"]!=NULL ){
      $default= $_GET["month"];   
     $default = sprintf("%02d", $default);

    }
    else{
      $default= date("m");
      $default = sprintf("%02d", $default);
    }

    if ($_GET['year']!=NULL) {

      $year=$_GET['year'];
      
      } else {

        $year=date("Y");

      }
 

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



    $branchID=$_SESSION['branch'];
    $sessionidid=$_REQUEST['session'];
    $monthID=$_REQUEST['month'];
    $paidDate=$getYear[0]."-".$default;
    $sql = " select * from  eduportal_expense_detail where branch_id='$branchID' ";



 if($_REQUEST['sub_cat']=="All"){
      $sql;
    } else {
    $sql .= " AND subcategory_id = '" .$_REQUEST['sub_cat']. "' ";

    }

    $sql .= " AND month_id = '" .$default. "' ";
  
    $sql .= " AND session_id = '" .$sessionidid. "' ";
   // $sql .= " AND expense_date LIKE '$paidDate%' ";

    $sql .= " order by expense_date asc ";
      

    //print_r($sql);

    $categories = $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 Sales 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;}

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


<br>

<div style="text-align:center;font-size:30px;font-weight:bold;"> Expenses Report </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>

<div style="width:33%; float:left;font-size:20px; "> <b> Report Month:</b> <?php echo $month_name[0]['Month_Name'] ?></div>

<div style="width:33%; float:right;font-size:20px; "> <a style="padding: 6px 8px; font-size:14px;float: right;" target="_blank" href="export_excel_expenses_report.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&session=<?php echo $_REQUEST['session'] ;?>&month=<?php echo $_REQUEST['month'] ;?>&sub_cat=<?php echo $_REQUEST['sub_cat'] ;?>" style="cursor:pointer;"  class="btn btn-success" class="btn btn-success  fa fa-download pull-right"> Export Excel </a> </div>

<br><br>
   
    <table style="width:100%;" cellspacing="0">
          
          <thead>
            <tr>
                <th width="3%" class=" center"style="font-size:17px;">S.No</th>
                <th width="10%" class=" center"style="font-size:17px;">Category</th>
                <th width="10%" class=" center"style="font-size:17px;">Sub Category</th>
                <th width="20%" class=" center"style="font-size:17px;">Details</th>
                <th width="8%" class=" center"style="font-size:17px;">Month</th>
                <th width="8%" class=" center"style="font-size:17px;">Date</th>
                <th width="10%" class=" center"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($categories 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");


// calculating students total fee 

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

?>
        <tr> 
                <td class="center"> <?php echo $count; $count++;?> </td>
                  <td style="padding-left:1%;"><?php echo $ctgry[0]['category_name'];?></td>
                  <td style="padding-left:1%;"><?php echo $sbctgry[0]['subcategory_name'];?></td>
                  <td style="padding-left:1%;"><?php echo $category['expense_details'];?></td>
                  <td class="center"><?php echo $month_name[0]['Month_Name'];?></td>
                  <td class="center"><?php echo date("d-M-Y",strtotime($category['expense_date']));?></td>           
                  <td class="center"style="border-right:1px solid black;">  <?php echo $category['expense_amount'];?>  </td>                  
                  
                             

                                 
              </tr>

       <?php } ?>


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

                     
              
             
        </tbody>
        
    </table>

</body>
</html>
