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

<?php   


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


//$date1=date('Y-m-d');
$from=$_REQUEST['from_date'];
$to=$_REQUEST['to_date'];
$b=$_SESSION['branch'];
$s=$_SESSION['current_session'];
    $qr3="SELECT SUM(amount) AS total  FROM eduportal_revenue_details WHERE branch_id='$b' and session_id='$s' and paid_date BETWEEN '" .$from. "' AND '" .$to. "'";
  
  //echo $qr;
    $Revenue = $m->query($qr3);

    $TodayRevenue=$Revenue[0]['total'];


 $session=$_SESSION['current_session'];
 $branch=$_SESSION['branch'];
 $todayDate=date("d-m-Y");
 
 $qr="SELECT SUM(fee.collected_amount) as collected FROM eduportal_monthly_challan as fee,edu_student_details as std WHERE std.student_id=fee.student_id and std.status='0' and fee.branch_id='$branch' AND fee.session_id='$session' and fee.paying_date BETWEEN '" .$from. "' AND '" .$to. "'";
//print_r($qr);
  $amount = $m->query($qr);


   $q="SELECT *  FROM eduportal_expense_detail WHERE branch_id='$b' and status='0' and expense_date BETWEEN '" .$from. "' AND '" .$to. "'";
  
  //echo $qr;
    $expenses = $m->query($q);


$qr6="SELECT SUM(fee.tutionfee) as tution, SUM(fee.transportfee) as trans,SUM(fee.collected_fine) as fine, SUM(fee.balance) as balance, SUM(fee.collected_amount) as coll  FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and fee.branch_id='$b' AND fee.session_id='$s' AND fee.paying_date BETWEEN '" .$from. "' AND '" .$to. "'";
//print_r($qr);

$Paidamount = $m->query($qr6);
$recieved=$Paidamount[0]['coll']+$Paidamount[0]['fine'];


$qr7="SELECT SUM(fee.paid_again_amount) as againPay FROM eduportal_monthly_challan as fee, edu_student_details as std WHERE fee.student_id=std.student_id and fee.branch_id='$b' AND fee.session_id='$s' AND fee.paid_again_date BETWEEN '" .$from. "' AND '" .$to. "'";
  $amount = $m->query($qr7);
  
  $againrecieved=$amount[0]['againPay'];
?>
<!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 Daily Income/Exp 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;">Income & Expense Report (Dated:- <?php echo date("d-M-Y",strtotime($_REQUEST['from_date']))." - ".date("d-M-Y",strtotime($_REQUEST['to_date']));?>) </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:98%;padding-left: 2%;" 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:17px;"></th>
                <th width="10%" class="center padng"style="font-size:17px;">Particular</th>
                <th width="10%" class="center padng"style="font-size:17px;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">1</td>
              <td width="10%" class="padng">Collected Fee</td>
              <td width="10%" class="text-center padng" style="border-right: 1px solid black;text-align: center;"><?php echo number_format($recieved+$againrecieved);?></td>
                                      
            </tr>

            <tr>
              <td width="1%" class="center padng">2</td>
              <td width="10%" class="padng">Other Revenue</td>
              <td width="10%" class="padng" style="border-right: 1px solid black;text-align: center;"> <?php echo number_format($TodayRevenue); ?></td>
                                      
            </tr>
  

            <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($recieved+$againrecieved+$TodayRevenue);?> </th>

                
                 
            </tr>





             
        </thead>
        <tbody>
   
                       
              
             
        </tbody>
        
    </table>
<br>
    <table style="width:98%;padding-left: 2%;" 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:17px;"></th>
                <th width="10%" class="center padng"style="font-size:17px;">Particular</th>
                <th width="10%" class="center padng"style="font-size:17px;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_amountExp+=$category['expense_amount'];

?>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">1</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>

<?php  }  ?>



            <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_amountExp)?> </th>
                 
            </tr>





             
        </thead>
        <tbody>
   
                       
           
             
        </tbody>
        
    </table>

    

</body>
</html>
