<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<style type="text/css">
  
    @media only screen and (max-width: 768px) {

    /* For mobile phones: */

    .margin{
       margin-top: 0px;
    }

  }
    @media (min-width:801px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */ 

    .margin{

        
        margin-top: -20px;
       
    }
  
    
}


</style>
<?php

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

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

      $default= date("m");
      $sessionidid= $_SESSION['current_session'];
      $sub_cat= "All";

    }
  
  

  //print_r($expenses);

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

  $branchID=$_SESSION['branch'];
    $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 .= " order by expense_date asc ";
      

    //print_r($sql);

    $expenses = $m->query($sql);


 
     ?>


<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Monthly Expenses report | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
   
  </head>
  




  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">

            <a href="dashboard.php">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
             Monthly Expenses Report
          <br><br>
          
          <div class="" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
       

                                 
 <!-- page content -->
        
          <div class="">
            <?php if (isset($_REQUEST['month'])) { ?>
              
            
            <!-- <a href="print_monthly_expense_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&month=<?php echo $default;?>&session=<?php echo $sessionidid;?>" target="_blank" style="float: right;" class=" btn btn-primary margin" > Print Category Expenses Summary  </a> -->

            <a href="print_headwise_expense_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&month=<?php echo $default;?>&session=<?php echo $sessionidid;?>" target="_blank" style="float: right;" class=" btn btn-primary margin" > Print Head Wise Expenses</a>

              <a href="print_monthly_expense_report_subcategory.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&month=<?php echo $default;?>&session=<?php echo $sessionidid;?>" target="_blank" style="float: right;" class=" btn btn-primary margin" > Print Expenses Summary  </a>

          <a href="print_expenses_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&month=<?php echo $default;?>&session=<?php echo $sessionidid;?>&sub_cat=<?php echo $sub_cat;?>" style="float: right;" target="_blank" class="btn btn-success margin"><i class="fa fa-print">&nbsp;&nbsp;</i>Print Report </a>

        <?php } ?>
        
            <div class="page-title">
              <div class="title_left">
                <h3>Expense List<small> (<?php echo count($expenses);?> records)</small></h3>
              </div>



             
<form action="monthly_expenses_report.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>">

          <div class="col-md-12">
                      
                    <div class="col-md-2 col-sm-12 col-xs-12">
                          <select name="session" class="form-control" >

                              
                        <?php

                       $match;
                        if(!isset($_REQUEST['session'])){
                          $match=$_SESSION['current_session'];
                        }else { $match=$_REQUEST['session']; }
                       
                                 
                        $WorkAssignList = $m->get("edu_session_config");
                        foreach($WorkAssignList as $WorkAssignListVal)
                        { ?>

                           <option <?php if($match==$WorkAssignListVal['session_id']){echo 'selected';}?> value="<?php echo $WorkAssignListVal['session_id']; ?>"><?php echo $WorkAssignListVal['session_year']; ?></option>


                                <?php
                        } ?>

                    </select>
		    </div>

		
            <div class="col-md-3 col-sm-12 col-xs-12">
                          <select name="month" class="form-control"  >
                                <option>Select</option>

                  <?php
                  $query="select * from eduportal_month_config";
                  $categoriess = $m->query($query);
                  foreach($categoriess as $categoryy)
                  { ?>

                         <option <?php if($default==$categoryy['Month_Id']){echo "selected";} ?>  value="<?php echo $categoryy['Month_Id']; ?>"><?php echo $categoryy['Month_Name']; ?></option>


                  <?php } ?>

			        </select>
			    </div>


          <div class="col-md-3 col-sm-2 col-xs-12">
                          <select name="sub_cat" class="form-control"  >
                          <option value="All">All</option>

                  <?php
                  $query="select * from eduportal_expanse_subcategory";
                  $categoriess = $m->query($query);
                  foreach($categoriess as $categoryy)
                  { ?>

                         <option <?php if($_REQUEST['sub_cat']==$categoryy['subcategory_id']){echo "selected";} ?>  value="<?php echo $categoryy['subcategory_id']; ?>"><?php echo $categoryy['subcategory_name']; ?></option>


                  <?php } ?>

              </select>
          </div>

					
      

               <div class="col-md-4 " style="padding:20px;">
                
                    <input type="hidden" name="addaccountAdmin" value="1">

                	<button type="submit" class="btn btn-primary margin">Search</button>
                
              	 
               
              </div> 

        </div>            
 </form>
          <div class="clearfix"></div>
                    <table id="example" class="table table-striped table-bordered"style="background-color: white;">
                      <thead>
                        <tr>
                          <th width="1%">S.No</th>
                           <th width="10%">Category</th>
                          <th width="10%">Sub Category</th>
                          <th width="20%">Details</th>
                          <th width="10%">Date</th>
                          <th width="10%">Month</th>
                          <th width="8%">Amount</th>
                          <!-- <th width="10%">Attach File</th> -->
                          <th width="8%">Action</th>
                         

                        </tr>
                      </thead>
                      <tbody>

                        
<?php  $count=1;
//$date= date("Y-m-d");

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");

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

?>
                        <tr>
                          <td style="text-align:center;"><?php echo $count; $count++;?></td>
                         

                          <td><?php echo $ctgry[0]['category_name'];?></td>
                          <td><?php echo $sbctgry[0]['subcategory_name'];?></td>
                          <td><?php echo $category['expense_details'];?></td>
                          <td><?php echo $category['expense_date'];?></td>
                          <td><?php echo $month_name[0]['Month_Name'];?></td>
                          <td><?php echo $category['expense_amount'];?></td>
                       <!--    <td><?php //echo $category['customer_phone'];?></td> -->
                                                  

                          <td>
          <a style="padding: 0px 5px; font-size:14px;"  href="add_expenses.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&expup=<?php echo $category['expense_id'];?>" class="btn btn-success"> <i style="height: 15px;"class="fa fa-pencil" aria-hidden="true"></i></a> 



        <a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?subject=<?php echo $category['expense_id'];?>&session=<?php echo $_REQUEST['session'];?>&month=<?php echo $_REQUEST['month'];?>&expense_report=expense_report&action=DeleteExpense" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>
                          </td>

                        </tr>
<?php } ?>


<tr style="background-color: lightgray;">
  <td colspan="6" style="text-align:center;"> Total </td>
  <td colspan="2"><?php echo number_format($totalAmt);?></td>

</tr>
                      

                      </tbody>
                    </table>
                  </div>
                </div>
              

            
             
            </div>
          </div>
        </div>
        <!-- /page content -->





  </div>
  <div class="clearfix"></div>
</section>          
    

           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
<?php include('RootMe/js_linksscript.php');?>

<!-- script for table column sorting -->

<script src="https://code.jquery.com/jquery-3.5.1.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap5.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function () {
$('#example').DataTable();
});

</script>
</body>
</html>
