<?php
error_reporting(0);

?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<link rel="stylesheet" href="calendar-15/calendar-15/fonts/icomoon/style.css">

<link rel="stylesheet" href="calendar-15/calendar-15/css/rome.css">
<link rel="stylesheet" href="calendar-15/calendar-15/css/style.css">
<!-- <script src = "ajax/loadoutreport1.js"></script>
<script src = "ajax/loadoutreport2.js"></script>
<script src = "ajax/loadoutreport3.js"></script> -->
<script src="js/quotationreport.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:5px;
        padding-right:5px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      
      padding:8px;
     border:1px solid rgba(24, 7, 173); 
      background-color:#FFFFE0;
      color:black;
    }
    th
    {
      background-color:rgba(24, 7, 173);
      text-align:center;
      padding:8px;
     border-bottom:1px solid #FFFFE0; 
     color:#FFFFE0;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
.reportModal
{
  height:800px;
}
.searchfeilds input
{
height:30px;
}
.daterow
{
  margin-top:10px;
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
  function printDiv() 
{

  var divToPrint=document.getElementById('printdiv');

  var newWin=window.open('','Print-Window');

  newWin.document.open();

  newWin.document.write('<html><head><link rel="stylesheet" href="tablestyle/tablereport.css"></head><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
  newWin.document.close();
}
  $(function () {

// INITIALIZE DATEPICKER PLUGIN
$('.datepicker').datepicker({
    clearBtn: true,
    format: "dd/mm/yyyy"
});


// FOR DEMO PURPOSE
$('#reservationDate').on('change', function () {
    var pickedDate = $('input').val();
    $('#pickedDate').html(pickedDate);
});
});

</script>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    <div ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>Day Report</h3>
<br>

<!-- search collaspe -->

<!-- date -->
<form action="dayreport.php" method="post">
<div class="row daterow" style="overflow:auto">  
                <div class="col-sm-1"></div>
                
           <div class="col-sm-2">
                <input type="text" class="form-control" id="input_from" name="fromdate" autocomplete="off" placeholder="Start Date"></div>
                <div class="col-sm-2">
                            
                <input type="text" class="form-control" id="input_to" name="todate" autocomplete="off" placeholder="To Date">
              </div>
			  
			  <div class="col-sm-2">

                            
               <input type="text" class="form-control" value="00:00:00" name="timefrom" placeholder="Start Date">
              </div>
			  
			  <div class="col-sm-2">
                            
               <input type="text" class="form-control" value="23:59:59" name="timeto" placeholder="To Date">
              </div>
			       
              <div class="col-sm-1"><button class="btn btn-info" type="submit"><i class="fas fa-calendar-check" style="font-size:23px;"></i></button></div> 
              <div class="col-sm-1"><button type="button" class="btn btn-primary" onClick="printDiv()">Download</button></div>       
            </div>
            </form>
           

 



    <br>
    
    <div  id="printdiv">
  <div class="row">
    <div class="col-md-12">
   <table >
   
             <thead>
               <?php 
			   $fromdate=$_POST['fromdate'];
			   $todate=$_POST['todate'];
			  $time_from = !empty($_POST['timefrom']) ? $_POST['timefrom'] : '00:00:00';
$time_to   = !empty($_POST['timeto'])   ? $_POST['timeto']   : '23:59:59';
               $proedit=mysqli_query($connect,"select * from partydetail order by id desc");
               while($proshowedi = mysqli_fetch_array($proedit))
               {
                 $party=  $proshowedi['party'];
               }
               //echo $time_from;
			   
			   $fromdate1=date_create($_POST['fromdate']);
			   $todate1=date_create($_POST['todate']);
               ?>
               <tr align="center"><th colspan="20"><?php echo $party ?>&nbsp;-PRIMARY</th></tr>
               <tr align="center"><th colspan="20">Daily Update:<?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Sakkai Purchase</th></tr>
               <tr>
                <th>S.No</th>
				 <th>Quarry&nbsp;Name</th>
				 <th>Loads</th>
				 <th>Veh.Unit</th>
                 <th>Total Unit</th>
                 <th>Amount</th>
                 <th>Permit</th>
                 
<th>P/Cost</th>


<th>T/P/Amount</th>
<th>Net.Amount</th>

<th>Avg</th>


                
                 
               </tr>
             </thead>
             <tbody>
             <?php
			// $sql_qry=mysqli_query($connect,"Select sec.*,cm.name,pm.tax from second_transaction as sec inner join customerdetails as cm on sec.customer=cm.code inner join productdetail as pm on pm.productcode=sec.product where sec.status!='deleted' and sec.date between '$fromdate' and '$todate' and cm.status=''");
			$sql_qry=mysqli_query($connect,"select pd.customer,count(customer) as loads,cm.name,avg(cft) as vehicle_unit,sum(pd.netqty) as netqty,sum(totalamount) as netamount,sum(permit) as permit,sum(permit_price) as permit_price from purchasedetails as pd inner join customerdetails as cm on cm.code=pd.customer where cm.status!='deleted' and pd.status=''  AND CONCAT(pd.date, ' ', pd.time) >= '$fromdate $time_from' 
    AND CONCAT(pd.date, ' ', pd.time) <= '$todate $time_to' and pd.product_category='Boulders' group by pd.customer");
	
	//echo "select pd.customer,count(customer) as loads,cm.name,avg(cft) as vehicle_unit,sum(totalamount) as netamount,sum(permit) as permit,avg(permit_price) as permit_price,sum(totalamount) as netamount from purchasedetails as pd inner join customerdetails as cm on cm.code=pd.customer where cm.status!='deleted' and pd.status=''  AND CONCAT(pd.date, ' ', pd.time) >= '$fromdate $time_from' 
   // AND CONCAT(pd.date, ' ', pd.time) <= '$todate $time_to' group by pd.customer";
		
			
			 
			 $sno=0;
			 $load=0;
			 $totalunits=0;
			 $permit=0;
			 $permitcost=0;
			 $netamt=0;
			 $permit_qty=0;
			  $avg=0;
			 while($row_result=mysqli_fetch_array($sql_qry))
			 {
			 
			 $tamount=$row_result['netamount']+$row_result['permit_price'];
			 
			 $date=date_create($row_result['date']);

			 ?>
             <tr>
             <td><?php echo ++$sno;?></td>
			  <td><?php echo $row_result['name'];?></td>
			 
			 <td align="right"><?php echo $row_result['loads'];?></td>
			 
             <td align="right"><?php echo number_format($row_result['vehicle_unit'],2,'.','');?></td>
             <td align="right"><?php echo number_format($row_result['netqty'],2,'.','');?></td>
             <td align="right"><?php echo number_format($row_result['netamount'],2,'.','');?></td>
            
             <td align="right"><?php echo $row_result['permit'];?></td>
             <td align="right"><?php echo number_format(($row_result['permit_price']/$row_result['permit']),2,'.','');?></td>
              <td align="right"><?php echo number_format($row_result['permit_price'],2,'.','');?></td>
             
             <td align="right"> <?php echo number_format(($row_result['netamount']+$row_result['permit_price']),2,'.','');?></td>
			 <td align="right"> <?php echo number_format(($tamount/$row_result['netqty']),2,'.','');?></td>
             
           
             </tr>
             <?php
			   $load+=$row_result['loads'];
			 $totalunits+=$row_result['netqty'];
			 $permit+=$row_result['permit_price'];
			 $permitcost+=$row_result['permit_price'];
			  $netamt+=$row_result['permit_price']+$row_result['netamount'];
			  $permit_qty+=$row_result['permit'];
			  $avg+=number_format(($tamount/$row_result['netqty']),2,'.','');
			 }
			 ?>
             <tr>
             <td>&nbsp;</td>
            <td><strong>TOTAl SAKKAI RECEIVED</strong></td>
             
            
         
            <td align="right"><?php echo $load;?></td>
             <td>&nbsp;</td>
            <td align="right"><?php echo number_format($totalunits,2,'.','');?></td>
            <td>&nbsp;</td>
			<td align="right"><?php echo $permit_qty;?></td>
             
             <td>&nbsp;</td>
             
             <td align="right"><?php echo number_format($permit,2,'.','');?></td>
             
             
             <td align="right"><?php echo number_format($netamt,2,'.','');?></td>
			 <td align="right"><?php echo number_format($avg,2,'.','');?></td>
             </tr>

             </tbody>
           </table>
           </div></div>
           <div>&nbsp;</div>
		   
		   <div class="row">
    <div class="col-md-12">
   <table >
   
             <thead>
               
             
               <tr align="center"><th colspan="20"><?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Crushing</th></tr>
               <tr>
                <th>S.No</th>
				 <th>Quarry&nbsp;Name</th>
				 <th>Loads</th>
				 <th>Veh.Unit</th>
                 <th>Total Unit</th>
                


                
                 
               </tr>
             </thead>
             <tbody>
             <?php
			// $sql_qry=mysqli_query($connect,"Select sec.*,cm.name,pm.tax from second_transaction as sec inner join customerdetails as cm on sec.customer=cm.code inner join productdetail as pm on pm.productcode=sec.product where sec.status!='deleted' and sec.date between '$fromdate' and '$todate' and cm.status=''");
			$sql_qry_crushing=mysqli_query($connect,"select pd.customer,count(customer) as loads,cm.name,avg(cft) as vehicle_unit,sum(pd.netqty) as netqty,sum(totalamount) as netamount,sum(permit) as permit,sum(permit_price) as permit_price from purchasedetails as pd inner join customerdetails as cm on cm.code=pd.customer where cm.status!='deleted' and pd.status=''  AND CONCAT(pd.date, ' ', pd.time) >= '$fromdate $time_from' 
    AND CONCAT(pd.date, ' ', pd.time) <= '$todate $time_to' and pd.modeof='Crushing' group by pd.customer");
	
	//echo "select pd.customer,count(customer) as loads,cm.name,avg(cft) as vehicle_unit,sum(totalamount) as netamount,sum(permit) as permit,avg(permit_price) as permit_price,sum(totalamount) as netamount from purchasedetails as pd inner join customerdetails as cm on cm.code=pd.customer where cm.status!='deleted' and pd.status=''  AND CONCAT(pd.date, ' ', pd.time) >= '$fromdate $time_from' 
   // AND CONCAT(pd.date, ' ', pd.time) <= '$todate $time_to' group by pd.customer";
		
			
			 
			 $sno1=0;
			 $loads=0;
			 $totalunitss=0;
			
			 
			 while($row_crushing=mysqli_fetch_array($sql_qry_crushing))
			 {
			 
			 

			 ?>
             <tr>
             <td><?php echo ++$sno1;?></td>
			  <td><?php echo $row_crushing['name'];?></td>
			 
			 <td align="right"><?php echo $row_crushing['loads'];?></td>
			 
             <td align="right"><?php echo number_format($row_crushing['vehicle_unit'],2,'.','');?></td>
             <td align="right"><?php echo number_format($row_crushing['netqty'],2,'.','');?></td>
             
            
             </tr>
             <?php
			   $loads+=$row_crushing['loads'];
			 $totalunitss+=$row_crushing['netqty'];
			 
			 }
			 ?>
             <tr>
             <td>&nbsp;</td>
            <td><strong>TOTAl CRUSHING</strong></td>
             
            
         
            <td align="right"><?php echo $loads;?></td>
             <td>&nbsp;</td>
            <td align="right"><?php echo number_format($totalunitss,2,'.','');?></td>
            
             
             
             </tr>

             </tbody>
           </table>
           </div></div>
		   <div>&nbsp;</div>
		   
		   <div class="row">
    <div class="col-md-6">
   <table >
   
             <thead>
               
             
               <tr align="center"><th colspan="20"><?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Material wise Sales</th></tr>
               <tr>
                <th>S.No</th>
				 <th>Material</th>
				 <th>Loads</th>
				 <th>Tot.Unit</th>
                 <th>Total Amount</th>
				 <th>AVG</th>
                


                
                 
               </tr>
             </thead>
             <tbody>
             <?php
			// $sql_qry=mysqli_query($connect,"Select sec.*,cm.name,pm.tax from second_transaction as sec inner join customerdetails as cm on sec.customer=cm.code inner join productdetail as pm on pm.productcode=sec.product where sec.status!='deleted' and sec.date between '$fromdate' and '$todate' and cm.status=''");
			$sql_qry_sales=mysqli_query($connect,"select sec.productname,count(salescode) as loads,cm.name,avg(cft) as vehicle_unit,sum(sec.netqty) as netqty,sum(totalamount) as netamount from second_transaction as sec inner join customerdetails as cm on cm.code=sec.customer where cm.status!='deleted' and sec.status=''  AND CONCAT(sec.date, ' ', sec.time) >= '$fromdate $time_from' 
    AND CONCAT(sec.date, ' ', sec.time) <= '$todate $time_to'  group by sec.productname");
	
	//echo "select pd.customer,count(customer) as loads,cm.name,avg(cft) as vehicle_unit,sum(totalamount) as netamount,sum(permit) as permit,avg(permit_price) as permit_price,sum(totalamount) as netamount from purchasedetails as pd inner join customerdetails as cm on cm.code=pd.customer where cm.status!='deleted' and pd.status=''  AND CONCAT(pd.date, ' ', pd.time) >= '$fromdate $time_from' 
   // AND CONCAT(pd.date, ' ', pd.time) <= '$todate $time_to' group by pd.customer";
		
			
			 
			 $sno1=0;
			 $load_sales=0;
			 $totalunits_sales=0;
			$netamt=0;
			$savg=0;
			 
			 while($row_sales=mysqli_fetch_array($sql_qry_sales))
			 {
			 
			 

			 ?>
             <tr>
             <td><?php echo ++$sno1;?></td>
			  <td><?php echo $row_sales['productname'];?></td>
			 
			 <td align="right"><?php echo $row_sales['loads'];?></td>
			 
             
             <td align="right"><?php echo number_format($row_sales['netqty'],2,'.','');?></td>
             <td align="right"><?php echo number_format($row_sales['netamount'],2,'.','');?></td>
			 <td align="right"><?php echo number_format(($row_sales['netamount']/$row_sales['netqty']),2,'.','');?></td>
            
             </tr>
             <?php
			   $load_sales+=$row_sales['loads'];
			 $totalunits_sales+=$row_sales['netqty'];
			 $netamt+=$row_sales['netamount'];
			 $savg+=$row_sales['netamount']/$row_sales['netqty'];
			 }
			 ?>
             <tr>
             <td>&nbsp;</td>
            <td><strong>TOTAl SALES</strong></td>
             
            
         
            <td align="right"><?php echo $load_sales;?></td>
             
            <td align="right"><?php echo number_format($totalunits_sales,2,'.','');?></td>
			<td align="right"><?php echo number_format($netamt,2,'.','');?></td>
			<td align="right"><?php echo number_format($savg,2,'.','');?></td>
            
             
             
             </tr>

             </tbody>
           </table>
           </div>
		   
		   <div class="col-md-6">
   <table >
   
             <thead>
               
             
               <tr align="center"><th colspan="20"><?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Mode of Receipt</th></tr>
               <tr>
                <th>S.No</th>
				 <th>Sales Mode</th>
				 <th>Amount</th>
				 
                


                
                 
               </tr>
             </thead>
             <tbody>
             <?php
			// $sql_qry=mysqli_query($connect,"Select sec.*,cm.name,pm.tax from second_transaction as sec inner join customerdetails as cm on sec.customer=cm.code inner join productdetail as pm on pm.productcode=sec.product where sec.status!='deleted' and sec.date between '$fromdate' and '$todate' and cm.status=''");
			$sql_qry_mode=mysqli_query($connect,"select modeof,sum(totalamount) as totalamount from second_transaction  where status=''  AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' and status='' group by modeof ");
	
	
			
			 
			 $sno1=0;
			 $total=0;
			
			 
			 while($row_mode=mysqli_fetch_array($sql_qry_mode))
			 {
			 
			 

			 ?>
             <tr>
             <td><?php echo ++$sno1;?></td>
			  <td><?php echo $row_mode['modeof'];?></td>
			 
			 <td align="right"><?php echo number_format($row_mode['totalamount'],2,'.','');?></td>
			 
             
             
            
             </tr>
             <?php
			   $total+=$row_mode['totalamount'];
			 
			 }
			 ?>
             <tr>
             <td>&nbsp;</td>
            <td><strong>TOTAl SALES</strong></td>
             
            
         
            
            <td align="right"><?php echo number_format($total,2,'.','');?></td>
			
            
             
             
             </tr>

             </tbody>
           </table>
           </div>
		   
		   </div>
		   
		   <div>&nbsp;</div><br>
		   
		   <div class="row">
    <div class="col-md-6">
   <table >
   
             <thead>
               
             
               <tr align="center"><th colspan="20"><?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Cash Expenses</th></tr>
               <tr>
                <th>S.No</th>
				 <th>Expense</th>
				 <th>Remark</th>
				 <th>Amount</th>
                
               </tr>
             </thead>
             <tbody>
			 
			 
			 <tr>
			 <td>1</td>
			 <td>Driver&nbsp;Bata(Sales+Purchase)</td>
			 <td>-</td>
			 <td align="right">
			 <?php
			 $pro_bata = mysqli_query($connect,"select sum(driver_amount) as bata from second_transaction where status=''  AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' ");
	
				$driverbata = mysqli_fetch_assoc($pro_bata);
				
				$salesbata= $driverbata['bata'];
				
				$pro_bata_purchase = mysqli_query($connect,"select sum(driver_amount) as purbata from purchasedetails where status=''  AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' ");
	
	
	
				$driverbata_purchase = mysqli_fetch_assoc($pro_bata_purchase);
				
				$purchasebata= $driverbata_purchase['purbata'];
				
				$totalbata=$driverbata['bata']+$driverbata_purchase['purbata'];
				
				echo number_format($totalbata,2,'.','');
			 
			 ?>
			 </td>
			 
			 </tr>
			 
             <?php
			// $sql_qry=mysqli_query($connect,"Select sec.*,cm.name,pm.tax from second_transaction as sec inner join customerdetails as cm on sec.customer=cm.code inner join productdetail as pm on pm.productcode=sec.product where sec.status!='deleted' and sec.date between '$fromdate' and '$todate' and cm.status=''");
			$sql_qry_expense=mysqli_query($connect,"select givento,sum(given_amount) as given_amount from cash_handling where status=''  AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' group by givento");
	
	//echo "select pd.customer,count(customer) as loads,cm.name,avg(cft) as vehicle_unit,sum(totalamount) as netamount,sum(permit) as permit,avg(permit_price) as permit_price,sum(totalamount) as netamount from purchasedetails as pd inner join customerdetails as cm on cm.code=pd.customer where cm.status!='deleted' and pd.status=''  AND CONCAT(pd.date, ' ', pd.time) >= '$fromdate $time_from' 
   // AND CONCAT(pd.date, ' ', pd.time) <= '$todate $time_to' group by pd.customer";
		
			
			 
			 $snob=1;
			 $totalcash=0;
			 
			 
			 while($row_cash=mysqli_fetch_array($sql_qry_expense))
			 {
			 
			 

			 ?>
             <tr>
             <td><?php echo ++$snob;?></td>
			  <td><?php echo $row_cash['givento'];?></td>
			 
			 <td ><?php echo $row_cash['remark'];?></td>
			 
             
             <td align="right"><?php echo number_format($row_cash['given_amount'],2,'.','');?></td>
             
             </tr>
             <?php
			   $totalcash+=$row_cash['given_amount'];
			 
			 }
			 ?>
             <tr>
             <td>&nbsp;</td>
			  <td>&nbsp;</td>
            <td><strong>TOTAl CASH EXPENSE</strong></td>
             
            
         
            
             
            <td align="right"><?php echo number_format($totalcash+$totalbata,2,'.','');?></td>
			
            
             
             
             </tr>

             </tbody>
           </table>
           </div>
		   
		   <div class="col-md-6">
   <table >
   
             <thead>
               
             
               <tr align="center"><th colspan="20"><?php echo date_format($fromdate1,"d/m/Y");?>-<?php echo date_format($todate1,"d/m/Y");?>-Closing Cash Balance</th></tr>
             
             </thead>
             <tbody>
            
			
			 <?php
			 $pro_openingbata = mysqli_query($connect,"select sum(driver_amount) as bata from second_transaction where status=''  AND date < '$fromdate' ");
			 //echo "select sum(driver_amount) as bata from second_transaction where status=''  AND date < '$fromdate' ";
	
				$driverbata_opening = mysqli_fetch_assoc($pro_openingbata);
				
				$opening_salesbata= $driverbata_opening['bata'];
				
				$pro_bata_purchase_opening = mysqli_query($connect,"select sum(driver_amount) as purbata from purchasedetails where status=''  AND date< '$fromdate'  ");
	
				$driverbata_purchase_opening = mysqli_fetch_assoc($pro_bata_purchase_opening);
				
				$purchasebata_opening= $driverbata_purchase_opening['purbata'];
				
				$totalbata_opening=$opening_salesbata+purchasebata_opening;
				
				
				$qry_expenseopening = mysqli_query($connect,"select sum(given_amount) as openingexpense from cash_handling where status=''  AND date< '$fromdate'  ");
	
				$row_expense_opening = mysqli_fetch_assoc($qry_expenseopening);
				
				$expenseopening= $row_expense_opening['openingexpense'];
				
				
				$qry_salesopening = mysqli_query($connect,"select sum(totalamount) as openingsales from second_transaction where status=''  AND date< '$fromdate' and modeof='cash' ");
	
				$row_sales_opening = mysqli_fetch_assoc($qry_salesopening);
				
				$salesopening= $row_sales_opening['openingsales'];
				
				$openingbalance=$salesopening-($expenseopening+$totalbata_opening);
				
				$sql_qry_cashsales=mysqli_query($connect,"select modeof,sum(totalamount) as totalamount from second_transaction  where status=''  AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' and status='' and modeof='cash'");
	$row_sales_cash = mysqli_fetch_assoc($sql_qry_cashsales);
	$cashsales=$row_sales_cash['totalamount'];
	
	$sql_qry_totalexpense=mysqli_query($connect,"select sum(given_amount) as given_amount from cash_handling where status=''  AND CONCAT(date, ' ', time) >= '$fromdate $time_from' 
    AND CONCAT(date, ' ', time) <= '$todate $time_to' ");
	
	$row_expense_cash = mysqli_fetch_assoc($sql_qry_totalexpense);
	$cashexp=$row_expense_cash['given_amount'];
	
	$closingbalance=($openingbalance+$cashsales)-($totalbata+$cashexp);
			 
			 ?>
			 
			 
				 <tr><td>Previous Cash closing Balance</td><td align="right"><?php echo number_format($openingbalance,2,'.','');?></td></tr>
				<tr><td>Total Cash Sales</td><td align="right"><?php echo number_format($cashsales,2,'.','');?></td></tr>
				 <tr><td>Total Driver Bata(Cash)</td><td align="right"><?php echo number_format($totalbata,2,'.','');?></td></tr>
				 <tr><td>Total Cash Expense</td><td align="right"><?php echo number_format($cashexp,2,'.','');?></td></tr>
				 <tr><td><strong>Closing Cash Balance</strong></td><td align="right"><strong><?php echo number_format($closingbalance,2,'.','');?></strong></td></tr>
             

             </tbody>
           </table>
           </div>
		   
		   </div>
           
           </div><!--print-->

</div>
</div>


<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script src="calendar-15/calendar-15/js/rome.js"></script>

<script src="calendar-15/calendar-15/js/main.js"></script>
 <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">

<script >
var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()

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