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

<?php   
     

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

    $yr=explode("-",$dateSession[0]['session_year']);

   

$session;
$sessionID= $_SESSION['current_session'];
$PaidDateSession;
    
    if($_GET["year"]!=NULL ){
      $session= $_GET["session"];
      $PaidDateSession= $yr[0];
    }
    else{
      $session= $_SESSION['current_session'];
      $PaidDateSession= date("Y");
    }

$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", $default);
    $month_name=$m->get("eduportal_month_config");

    $paidDate=$year."-".$default;

    //echo $paidDate;

   /* $session=$_REQUEST["session"];*/
    $branch=$_SESSION['branch'];
   $qr="SELECT SUM(paid_amount) as total, SUM(paid_again_amount) as again_total, SUM(paid_again_salary_amount) as again_salary_total FROM employee_payroll where branch_id ='$branch' and paid_date like '$paidDate%'";
   //echo $qr;
   $salary=$m->query($qr);

   $qr="SELECT SUM(expense_amount) as total FROM eduportal_expense_detail where branch_id ='$branch' and status = '0' and expense_date like '$paidDate%'  /*and session_id='$sessionID'*/ ";
   //echo "$qr";
   $expense=$m->query($qr);


$days=cal_days_in_month(CAL_GREGORIAN, $default, date("Y"));

$from=date("$year-$default-01");
$to=date("$year-$default-$days");
  

$qr1="SELECT SUM(collected_amount) as received, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan WHERE branch_id='$branch' /*AND session_id='$session'*/ and paid_status='1' ";

  $qr1 .= " AND paying_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr1);
  $revenue = $m->query($qr1);



  $qr2="SELECT SUM(paid_again_amount) as againreceived FROM eduportal_monthly_challan WHERE branch_id='$branch' /*AND session_id='$session'*/ and paid_status='1' ";

  $qr2 .= " AND paid_again_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr);
  $againReceivedrevenue = $m->query($qr2);




  $bank="SELECT SUM(collected_amount) as received, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='BankAccount' /*AND session_id='$session'*/ and paid_status='1' ";

  $bank .= " AND paying_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($bank);
  $BankAccount = $m->query($bank);


  $bankAgain="SELECT SUM(paid_again_amount) as againreceived FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='BankAccount' /*AND session_id='$session'*/ and paid_status='1' ";

  $bankAgain .= " AND paid_again_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr1);
  $BankAccountAgain = $m->query($bankAgain);



  $easy="SELECT SUM(collected_amount) as received, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='Easypaisa' /*AND session_id='$session'*/ and paid_status='1' ";

  $easy .= " AND paying_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($easy);
  $easyPaisa = $m->query($easy);
 

  $easyAgain="SELECT SUM(paid_again_amount) as againreceived FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='Easypaisa' /*AND session_id='$session'*/ and paid_status='1' ";

  $easyAgain .= " AND paid_again_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr1);
  $easyPaisaAgain = $m->query($easyAgain);




  $Jazz="SELECT SUM(collected_amount) as received, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='JazzCash' /*AND session_id='$session'*/ and paid_status='1' ";

  $Jazz .= " AND paying_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr1);
  $JazzCash = $m->query($Jazz);


  $JazzAgain="SELECT SUM(paid_again_amount) as againreceived FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='JazzCash' /*AND session_id='$session'*/ and paid_status='1' ";

  $JazzAgain .= " AND paid_again_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr1);
  $JazzCashAgain = $m->query($JazzAgain);


   $Cash="SELECT SUM(collected_amount) as received, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='Cash' /*AND session_id='$session'*/ and paid_status='1' ";

  $Cash .= " AND paying_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($Cash);
  $CashReceived = $m->query($Cash);


  $CashAgain="SELECT SUM(paid_again_amount) as againreceived FROM eduportal_monthly_challan WHERE branch_id='$branch' AND paid_by='Cash' /*AND session_id='$session'*/ and paid_status='1' ";

  $CashAgain .= " AND paid_again_date BETWEEN '" .$from. "' AND '" .$to. "' ";
//print_r($qr1);
  $CashReceivedAgain = $m->query($CashAgain);
 



 /*   $qr="SELECT SUM(collected_amount) as total, SUM(paid_again_amount) as againPaid, SUM(collected_fine) as total_fine FROM eduportal_monthly_challan where branch_id ='$branch' and month_id='$default'  and session_id='$session'";
  // echo "$qr";
   $revenue=$m->query($qr);*/

   $b=$_SESSION['branch'];

    $qr="SELECT SUM(amount) AS total  FROM eduportal_revenue_details WHERE branch_id='$b' /*and session_id='$session'*/ and paid_date like '$paidDate%'";

  //echo $qr;
    $Revenue = $m->query($qr);

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



?>



<!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 P&L 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 Report: (<?php echo $month_name[0]['Month_Name'] ?>) </div>
<div style="text-align:center;font-size:18px;font-weight:bold;">Session: (<?php echo $session1[0]['session_year'] ?>) </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>
<?php 
$expense_amount=$expense[0]['total'] + $salary[0]['total']+$salary[0]['again_total']+$salary[0]['again_salary_total'];
?>
   
    <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;">Category</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black">Amount</th>
                 
            </tr>
            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">1</td>
                <td width="10%" class="center padng"style="font-size:17px;">Expenses</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php echo number_format($expense[0]['total']);?> </td>
                 
            </tr>
             <tr>
                <td width="3%" class="center padng"style="font-size:17px;">2</td>
                <td width="10%" class="center padng"style="font-size:17px;">Salary/Wages</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php echo number_format($salary[0]['total']+$salary[0]['again_total']+$salary[0]['again_salary_total']);?> </td>
                 
            </tr>
             <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;"colspan="2">Total Expenses</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black;border-top: none;"><?php echo number_format($expense_amount);?>  </th>
                 
            </tr>
            <tr>

                           <td width="1%" style="padding-left:65px;" rowspan="5">3</td>
                          <td width="10%" rowspan="5" style="padding-left: 200px;">Revenue</td>
                          <td width="10%" style="padding: 8px;border-right: 1px solid black;">Cash:<?php echo number_format($CashReceived[0]['received']+$CashReceived[0]['total_fine']+$CashReceivedAgain[0]['againreceived']);?></td>
                          <?php $totalCash=$CashReceived[0]['received']+$CashReceived[0]['total_fine']+$CashReceivedAgain[0]['againreceived'];?>
                        </tr>


                        <tr>

                           <td width="1%" style="padding:8px;border-right: 1px solid black;">Jazz Cash: <?php echo number_format($JazzCash[0]['received']+$JazzCash[0]['total_fine']+$JazzCashAgain[0]['againreceived']);?></td>
                          
                          <?php $totalJazzCash=$JazzCash[0]['received']+$JazzCash[0]['total_fine']+$JazzCashAgain[0]['againreceived'];?>
                        </tr>


                         <tr>

                           <td width="1%" style="padding:8px;border-right: 1px solid black;">Easypaisa: <?php echo number_format($easyPaisa[0]['received']+$easyPaisa[0]['total_fine']+$easyPaisaAgain[0]['againreceived']);?></td>
                         
                            <?php $totalEasyPaisa=$easyPaisa[0]['received']+$easyPaisa[0]['total_fine']+$easyPaisaAgain[0]['againreceived'];?>
                        </tr>

                         <tr>

                           <td width="1%" style="padding:8px;border-right: 1px solid black;">Bank Account:

                            <?php echo number_format($BankAccount[0]['received']+$BankAccount[0]['total_fine']+$BankAccountAgain[0]['againreceived']);?>
                            <?php $totalBankAmt=$BankAccount[0]['received']+$BankAccount[0]['total_fine']+$BankAccountAgain[0]['againreceived'];?>
                           </td>
                          
                          
                        </tr>


                        <tr style="background-color:lightgray;color: black;">

                           <td width="1%" style="padding:8px;border-right: 1px solid black;" class="text-center">Revenue:

                            <?php echo number_format($revenue[0]['received']+$revenue[0]['total_fine']+$againReceivedrevenue[0]['againreceived']);?>
                           </td>
                          
                          
                        </tr>

            <tr>
                <td width="3%" class="center padng"style="font-size:17px;">4</td>
                <td width="10%" class="center padng"style="font-size:17px;">Other Revenue</td>
                <td width="10%" class="center padng"style="font-size:17px;border-right:1px solid black"> <?php echo number_format($RevenueMonthly);?> </td>
                 
            </tr>

            <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;"colspan="2">Total Revenue</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black;border-top: none;"> <?php echo number_format($revenue[0]['received']+$revenue[0]['total_fine']+$againReceivedrevenue[0]['againreceived']+$RevenueMonthly);?> </th>
                 
            </tr>
            <tr>
                
                <th width="10%" class="center padng"style="font-size:17px;border-top: none;"colspan="2">Profit</th>
                <th width="10%" class="center padng"style="font-size:17px;border-right:1px solid black;border-top: none;"><?php echo number_format($RevenueMonthly+$revenue[0]['received']+$revenue[0]['total_fine']+$againReceivedrevenue[0]['againreceived'] - $expense_amount );?> </th>
                 
            </tr>
        </thead>
        <tbody>
   
                       
              
             
        </tbody>
        
    </table>

</body>
</html>
