<?php 
error_reporting(0);
require_once("config/configDB.php"); 
require "userPermission.php";
require "financial_year_calculation.php";




$tripfromDate=$_POST['fromDate'];
				$triptoDate=$_POST['toDate'];
			
			

?>
<!DOCTYPE html>
<html>
<head>
    <title>Overall Report</title>
    <?php require 'header.php' ?>
    <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>
</head>
<body>
    <?php require 'menu.php' ?>


    <div class="container text-center" id="saleStock">
  
  <form class="form-inline" method="post" action="overall_report.php">
  
  
  
    
    <div class="form-group">
      <label for="">From Date:</label><br>
      <input type="date" class="form-control input-lg " id="fromDate" name="fromDate" autocomplete="off">
    </div>
    <div class="form-group">
      <label for="">To Date</label><br>
      <input type="date" class="form-control input-lg" id="toDate" name="toDate" autocomplete="off">
    </div>


  <div class="form-group">
  <br><br>
    <button type="submit" class="btn btn-primary btn-md datewise-submit-sale">Submit</button>

    <button type="button" class="btn btn-info btn-md datewise-submit-sale" onClick="tableToExcel('a', 'W3C Example Table')">Excel</button>
    
     <a href="print_overall.php?fromdate=<?php echo $tripfromDate;?>&& todate=<?php echo $triptoDate;?>" class="btn btn-primary" target="_blank">Print</a>
    </div>
  </form>
  
</div>


<div class="container col-sm-12">
&nbsp;
</div>

<div id="a">
    
<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption align="center"><strong>Purchase With GST</strong></caption>
            <tr>
            <th>S.no</th>
                <th>Invoice No</th>
                <th>Date</th>
				<!--<th>Time</th>-->
                <th>supplier</th>
                <th>Po.No</th>
                
                <th>Product</th>
				<th>Qty</th>
				<th>Rate</th>
				<th>GST%</th>
                <th>Net Amount</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
				
				if($tripfromDate !=''  && $triptoDate !=''  ) {
				$sql_purchase = "SELECT sh.id,sh.invoice_no, sh.purchase_date, sh.supplier_id,sh.btime btime,  sh.po_num, sh.itemcount, sh.tamount, sh.create_date,sh.id,cm.sname,sd.productID,sd.purchase_prate prate,sd.purchase_gst gst,sd.purchase_eqty qt,sd.purchasenetamt,pm.productname pname FROM purchaseheader as sh LEFT JOIN supplier_master as cm on cm.id = sh.supplier_id inner join purchasedetails as sd on sh.id=sd.purchaseheader_id inner join product_master as pm on pm.id=sd.productID where  sh.status='' and sh.purchase_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.purchase_date ASC ";
		
	 }
	 
	
				?>
        
        <tbody>
            <?php
			$query_purchase=mysqli_query($conn, $sql_purchase) ;
			$total_price_gst=0;
			$total_qty_gst=0;
			$pursno=0;
			while($row_purchase=mysqli_fetch_array($query_purchase))
{
	$deliver_date_pur=$row_purchase["purchase_date"];
$date_pur=date_create($deliver_date_pur);
$purchase_date_pur=date_format($date_pur,"d-m-Y");
				
				?>
			<tr>
             <td><?php echo ++$pursno;?></td>
            <td><?php echo $row_purchase["invoice_no"];?></td>
            <td><?php echo $purchase_date_pur;?></td>
			<!--<td><?php echo $row_purchase["btime"];?></td>-->
            <td><?php echo $row_purchase["sname"];?></td>
            <td><?php echo $row_purchase["po_num"];?></td>
           
            <td><?php echo $row_purchase["pname"];?></td>
			<td align="right"><?php echo number_format((float)$row_purchase["qt"], 2, '.', '');?></td>
			<td align="right"><?php echo number_format($row_purchase["prate"],2,'.','');?></td>
			<td><?php echo $row_purchase["gst"];?></td>
            <td align="right"><?php echo number_format(round($row_purchase["purchasenetamt"]), 2, '.', '');?></td>
			</tr>
            <?php
			
			$total_price_gst  += $row_purchase["purchasenetamt"];
			$total_qty_gst  += $row_purchase["qt"];
}


?>
       <tr>
           
           <td colspan="6" align="right"><strong>Total Qty</strong></td>
            <td align="right"><strong><?php echo number_format((float)$total_qty_gst, 2, '.', '');?></strong></td>
           
			<td  align="right" colspan="2"><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price_gst), 2, '.', '');?></strong></td>
			</tr>              
                    
           
        </tbody>
       
    </table>
   
</div>

<div class="container col-sm-12">
&nbsp;
</div>


<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Purchase EST</strong></caption>
            <tr>
            <th>S.No</th>
                <th>Invoice No</th>
                <th>Date</th>
			<!--	<th>Time</th>-->
                <th>supplier</th>
                <th>Po.No</th>
                
                <th>Product</th>
                <th>Rate</th>
				<th>Qty</th>
				
				
                <th>Net Amount</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
				
				if($tripfromDate !=''  && $triptoDate !=''  ) {
				$sql_purchase_est = "SELECT sh.id,sh.invoice_no, sh.purchase_date, sh.supplier_id,sh.btime btime,  sh.po_num, sh.itemcount, sh.tamount, sh.create_date,sh.id,cm.sname,sd.productID,sd.purchase_prate prate,sd.purchase_gst gst,sd.purchase_eqty qt,sd.purchasenetamt,pm.productname pname FROM purchaseheaderwo as sh LEFT JOIN supplier_master as cm on cm.id = sh.supplier_id inner join purchasedetailswo as sd on sh.id=sd.purchaseheader_id inner join product_master as pm on pm.id=sd.productID where sh.flag='1' and sh.status='' and sh.purchase_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.purchase_date ASC  ";
				
		
	 }
	 
	//echo $sql_purchase_est;
	 
	 
				?>
        
        <tbody>
            <?php
			$query_est=mysqli_query($conn, $sql_purchase_est) ;
			$total_price_est=0;
			$total_qty_est=0;
			$estpursno=0;
			while($row_est=mysqli_fetch_array($query_est))
{
	$deliver_date_purwo=$row_est["purchase_date"];
$date_purwo=date_create($deliver_date_purwo);
$purchase_date_purwo=date_format($date_purwo,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$estpursno;?></td>
            <td><?php echo $row_est["invoice_no"];?></td>
            <td><?php echo $purchase_date_purwo;?></td>
			<!--<td><?php echo $row["btime"];?></td>-->
            <td><?php echo $row_est["sname"];?></td>
            <td><?php echo $row_est["po_num"];?></td>
           
            <td><?php echo $row_est["pname"];?></td>
            <td align="right"><?php echo number_format($row_est["prate"],2,'.','');?></td>
			<td align="right"><?php echo number_format((float)$row_est["qt"], 2, '.', '');?></td>
			
			
            <td align="right"><?php echo number_format(round($row_est["purchasenetamt"]), 2, '.', '');?></td>
			</tr>
            <?php
			
			$total_price_est  += $row_est["purchasenetamt"];
			$total_qty_est  += $row_est["qt"];
}


?>
       <tr>
           
           <td colspan="7" align="right"><strong>Total </strong></td>
            <td align="right"><strong><?php echo number_format((float)$total_qty_est, 2, '.', '');?></strong></td>
           
			
            <td align="right"><strong><?php echo number_format(round($total_price_est), 2, '.', '');?></strong></td>
			</tr>              
                    
           
        </tbody>
       
    </table>
    
</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Internal Fuel Purchase</strong></caption>
            <tr>
            <th>S.No</th>
                <th>Invoice No</th>
                <th>Date</th>
				  <th>Vehicleno</th>
                <th>supplier</th>
           
				<th>Qty</th>
				<th>Rate</th>
				
                <th>Net Amount</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
				
				if($tripfromDate !=''  && $triptoDate !='')
				{
				$sql_indiesel = "SELECT sh.id,sh.dieselinvoice, sh.dieseldate, sh.supplierid, sh.amount as tamount, sh.createdate,sh.id,cm.sname,sh.rate1 prate,sh.litres qt,sh.vehicleno FROM purchase_dieselinvoice as sh LEFT JOIN supplier_master as cm on cm.id = sh.supplierid   where  sh.status='' and sh.dieseldate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.dieseldate ASC ";
				}
				
	 //echo $sql_indiesel;
	
				?>
        
        <tbody>
            <?php
			$query_indiesel=mysqli_query($conn, $sql_indiesel) ;
			$total_price_infuel=0;
			$total_qty_infuel=0;
			$sno_infp=0;
			while($row_indiesel=mysqli_fetch_array($query_indiesel))
{
	$deliver_date_indiesel=$row_indiesel["dieseldate"];
$date_indiesel=date_create($deliver_date_indiesel);
$purchase_date_indisel=date_format($date_indiesel,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$sno_infp;?></td>
            <td><?php echo $row_indiesel["dieselinvoice"];?></td>
            <td><?php echo $purchase_date_indisel;?></td>
			 <td><?php echo $row_indiesel["vehicleno"];?></td>
            <td><?php echo $row_indiesel["sname"];?></td>
            
          
           
			<td align="right"><?php echo number_format((float)$row_indiesel["qt"], 2, '.', '');?></td>
			<td align="right"><?php echo number_format($row_indiesel["prate"],2,'.','');?></td>
			
            <td align="right"><?php echo number_format(round($row_indiesel["tamount"]), 2, '.', '');?></td>
			</tr>
            <?php
			
			$total_price_infuel  += $row_indiesel["tamount"];
			$total_qty_infuel  += $row_indiesel["qt"];
}


?>
       <tr>
           
           <td colspan="5" align="right"><strong>Total Qty</strong></td>
            <td align="right"><strong><?php echo number_format((float)$total_qty_infuel, 2, '.', '');?></strong></td>
           
			<td  align="right" ><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price_infuel), 2, '.', '');?></strong></td>
			</tr>              
                    
           
        </tbody>
       
    </table>
   
</div>


<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>External Fuel Filling</strong></caption>
            <tr>
            <th>S.no</th>
                <th>Invoice No</th>
                <th>Date</th>
				 <th>Vehicleno</th>
                <th>supplier</th>
            
				<th>Qty</th>
				<th>Rate</th>
				
                <th>Net Amount</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        <?php
				
				if($tripfromDate !=''  && $triptoDate !='')
				{
				$sql_exf = "SELECT sh.id,sh.invoice,sh.vehicleno, sh.dieseldate, sh.supplierid, sh.amount as tamount, sh.createdate,sh.id,cm.sname,sh.rate prate,sh.litres qt FROM externalfill_diesel as sh LEFT JOIN supplier_master as cm on cm.id = sh.supplierid   where  sh.status='' and sh.dieseldate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.dieseldate ASC ";
				}
				
	 
	
				?>
        
        <tbody>
            <?php
			$query_exf=mysqli_query($conn, $sql_exf) ;
			$total_price_exf=0;
			$total_qty_exf=0;
			$snoexf=0;
			while($row_exf=mysqli_fetch_array($query_exf))
{
	$deliver_date_exf=$row_exf["dieseldate"];
$date_exf=date_create($deliver_date_exf);
$purchase_date_exf=date_format($date_exf,"d-m-Y");
				
				?>
			<tr>
             <td><?php echo ++$snoexf;?></td>
            <td><?php echo $row_exf["invoice"];?></td>
            <td><?php echo $purchase_date_exf;?></td>
			  <td><?php echo $row_exf["vehicleno"];?></td>
            <td><?php echo $row_exf["sname"];?></td>
            
          
           
			<td align="right"><?php echo number_format((float)$row_exf["qt"], 2, '.', '');?></td>
			<td align="right"><?php echo number_format($row_exf["prate"],2,'.','');?></td>
			
            <td align="right"><?php echo number_format(round($row_exf["tamount"]), 2, '.', '');?></td>
			</tr>
            <?php
			
			$total_price_exf  += $row_exf["tamount"];
			$total_qty_exf  += $row_exf["qt"];
}


?>
       <tr>
           
           <td colspan="5" align="right"><strong>Total Qty</strong></td>
            <td align="right"><strong><?php echo number_format((float)$total_qty_exf, 2, '.', '');?></strong></td>
           
			<td  align="right" ><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price_exf), 2, '.', '');?></strong></td>
			</tr>              
                    
           
        </tbody>
       
    </table>
   
</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>External Fuel Part&nbsp;Filling</strong></caption>
            <tr>
            <th>S.No</th>
                <th>Invoice No</th>
                <th>Date</th>
				  <th>Vehicleno</th>
                <th>supplier</th>
           
				<th>Qty</th>
				<th>Rate</th>
				
                <th>Net Amount</th>
               
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
         <?php
				
				if($tripfromDate !=''  && $triptoDate !='')
				{
				$sql_exuf = "SELECT sh.id,sh.invoice,sh.vehicleno, sh.dieseldate, sh.supplierid, sh.amount as tamount, sh.createdate,sh.id,cm.sname,sh.rate prate,sh.litres qt FROM externalpro_diesel as sh LEFT JOIN supplier_master as cm on cm.id = sh.supplierid   where  sh.status='' and sh.dieseldate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.dieseldate ASC  ";
				}
				
	 
	
				?>
        
        <tbody>
            <?php
			$query_exuf=mysqli_query($conn, $sql_exuf) ;
			$total_price_exuf=0;
			$total_qty_exuf=0;
			$fuf=0;
			while($row_exuf=mysqli_fetch_array($query_exuf))
{
	$deliver_date_exuf=$row_exuf["dieseldate"];
$date_exuf=date_create($deliver_date_exuf);
$purchase_dat_exuf=date_format($date_exuf,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$fuf;?>
            <td><?php echo $row_exuf["invoice"];?></td>
            <td><?php echo $purchase_dat_exuf;?></td>
			<td><?php echo $row_exuf["vehicleno"];?></td>
            <td><?php echo $row_exuf["sname"];?></td>
            
           
           
			<td align="right"><?php echo number_format((float)$row_exuf["qt"], 2, '.', '');?></td>
			<td align="right"><?php echo number_format($row_exuf["prate"],2,'.','');?></td>
			
            <td align="right"><?php echo number_format(round($row_exuf["tamount"]), 2, '.', '');?></td>
			</tr>
            <?php
			
			$total_price_exuf  += $row_exuf["tamount"];
			$total_qty_exuf  += $row_exuf["qt"];
}


?>
       <tr>
           
           <td colspan="5" align="right"><strong>Total Qty</strong></td>
            <td align="right"><strong><?php echo number_format((float)$total_qty_exuf, 2, '.', '');?></strong></td>
           
			<td  align="right" ><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_price_exuf), 2, '.', '');?></strong></td>
			</tr>              
                    
           
        </tbody>
       
    </table>
   
</div>
<div class="container col-sm-12">&nbsp;</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Compressor Report</strong></caption>
            <tr>
            
            <th>S.No</th>
         
            <th>Process&nbsp;Date</th>
            <th>Supplier Name</th>
            <th>Process&nbsp;Type</th>
              
               
               <th>Total&nbsp;Holes</th>
               <th>Total&nbsp;Ft</th>
               
               <th>Cost/Ft</th>
               
                <th>Total.Amt</th>
               
            </tr>
        </thead>
<tbody>

<?php
if($tripfromDate !=''  && $triptoDate !='') {
$sql_compressor="select id,utilize_code,utilizedate,contractor,contractor_name,process_type,starting_hrs,closing_hrs,starting_unit,closing_unit,running_hrs,running_unit,one,two,three,four,six,eight,hole,totalfeet,labour,cost_feet,total_cost,remark from explosive_utiliz_hdr where status='' and utilizedate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY utilizedate ASC ";

	 }
	 
	 

//echo $sql;
$querry_compressor=mysqli_query( $conn, $sql_compressor );

$sno=0;
$amt=0;
while($rowu_compressor=mysqli_fetch_array($querry_compressor))
{
$hid=$rowu_compressor['id'];

$deliver_date_compressor=$row_exuf["dieseldate"];
$date_compressor=date_create($deliver_date_compressor);
$purchase_dat_compressor=date_format($date_compressor,"d-m-Y");
?>
<tr>
<td><?php echo ++$sno;?></td>

<td><?php echo $purchase_dat_compressor;?> </td>
<td><?php echo $rowu_compressor['contractor_name'];?> </td>
<td><?php echo $rowu_compressor['process_type'];?> </td>


<td><?php echo $rowu_compressor['hole'];?> </td>
<td><?php echo $rowu_compressor['totalfeet'];?> </td>


<td align="right"><?php echo  number_format($rowu_compressor['cost_feet'],2,'.','');?> </td>
<td align="right"><?php echo number_format($rowu_compressor['total_cost'],2,'.','');?> </td>


</tr>

<?php

$amt_compressor=$amt_compressor+$rowu_compressor['total_cost'];

}
?>
<tr>

<td colspan="7" align="right"> <strong>Total&nbsp;Amount</strong></td>
<td align="right"><strong><?php echo number_format($amt_compressor,2,'.','');?></strong></td>

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

<h3 align="center"><u>Payment Details</u></h3>




<div class="container col-sm-12">&nbsp;</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Purchase Payment Report</strong></caption>
            <tr>
            
            <th>S.No</th>
         <th>Payment.Id</th>
            <th>Date</th>
            <th>Supplier Name</th>
            <th>Amount</th>
              
                <th>Process</th>
               <th>Mode</th>
               <th>Remark</th>
            
               
            </tr>
        </thead>
<tbody>

<?php
if($tripfromDate !=''  && $triptoDate !='') {
$sql_purpayment = "SELECT cc.bank_name,cc.handover,cc.transactionno,cc.paymentreference,cc.id,cc.cashno,cc.payment_through, cc.collectiondate, cc.supplierID, cc.pending,cc.remark, cc.paymenttype, cc.received_amount, cm.sname FROM supplier_payment_header as cc LEFT JOIN supplier_master as cm on cm.id = cc.supplierID  WHERE cc.collectiondate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' and cc.status='' ORDER BY collectiondate ASC ";

	 }
	 
	 

//echo $sql;
$querry_purpay=mysqli_query( $conn, $sql_purpayment );

$sno_purpay=0;
$amt_purpay=0;
while($row_purpay=mysqli_fetch_array($querry_purpay))
{


$date_purpay=$row_purpay["collectiondate"];
$date_purpay1=date_create($date_purpay);
$purchase_date_pay=date_format($date_purpay1,"d-m-Y");
?>
<tr>
<td><?php echo ++$sno_purpay;?></td>
<td><?php echo $row_purpay['cashno'];?> </td>
<td><?php echo $purchase_date_pay;?> </td>
<td><?php echo $row_purpay['sname'];?> </td>



<td align="right"><?php echo  number_format($row_purpay['received_amount'],2,'.','');?> </td>
<td><?php echo $row_purpay['payment_through'];?> </td>
<td><?php echo $row_purpay['paymenttype'];?> </td>
<td><?php echo $row_purpay['remark'];?> </td>


</tr>

<?php

$amt_purpay=$amt_purpay+$row_purpay['received_amount'];

}
?>
<tr>

<td colspan="4" align="right"> <strong>Total&nbsp;Amount</strong></td>
<td align="right"><strong><?php echo number_format($amt_purpay,2,'.','');?></strong></td>

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





<div class="container col-sm-12">&nbsp;</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Purchase EST Payment Report</strong></caption>
            <tr>
            
            <th>S.No</th>
         <th>Payment.Id</th>
            <th>Date</th>
            <th>Supplier Name</th>
            <th>Amount</th>
              
                <th>Process</th>
               <th>Mode</th>
               <th>Remark</th>
            
               
            </tr>
        </thead>
<tbody>

<?php
if($tripfromDate !=''  && $triptoDate !='') {
$sql_purpayment_est = "SELECT cc.bank_name,cc.handover,cc.transactionno,cc.paymentreference,cc.id,cc.cashno,cc.payment_through, cc.collectiondate, cc.supplierID, cc.pending,cc.remark, cc.paymenttype, cc.received_amount, cm.sname FROM supplier_payment_headerwo as cc LEFT JOIN supplier_master as cm on cm.id = cc.supplierID  WHERE cc.collectiondate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' and cc.status='' ORDER BY collectiondate ASC ";

	 }
	 
	 

//echo $sql;
$querry_purpay_est=mysqli_query( $conn, $sql_purpayment_est );

$sno_purpay_est=0;
$amt_purpay_est=0;
while($row_purpay_est=mysqli_fetch_array($querry_purpay_est))
{


$date_purpay_est=$row_purpay_est["collectiondate"];
$date_purpay1_est=date_create($date_purpay_est);
$purchase_date_pay_est=date_format($date_purpay1_est,"d-m-Y");
?>
<tr>
<td><?php echo ++$sno_purpay_est;?></td>
<td><?php echo $row_purpay_est['cashno'];?> </td>
<td><?php echo $purchase_date_pay_est;?> </td>
<td><?php echo $row_purpay_est['sname'];?> </td>



<td align="right"><?php echo  number_format($row_purpay_est['received_amount'],2,'.','');?> </td>
<td><?php echo $row_purpay_est['payment_through'];?> </td>
<td><?php echo $row_purpay_est['paymenttype'];?> </td>
<td><?php echo $row_purpay_est['remark'];?> </td>


</tr>

<?php

$amt_purpay_est=$amt_purpay_est+$row_purpay_est['received_amount'];

}
?>
<tr>

<td colspan="4" align="right"> <strong>Total&nbsp;Amount</strong></td>
<td align="right"><strong><?php echo number_format($amt_purpay_est,2,'.','');?></strong></td>

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


<div class="container col-sm-12">&nbsp;</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Fuel/Contractor Payment Report</strong></caption>
            <tr>
            
            <th>S.No</th>
         
            <th>Date</th>
            <th>Supplier Name</th>
            <th>Mode&nbsp;Of&nbsp;Pay</th>
            <th>Amount</th>
               
               
              
            
               
            </tr>
        </thead>
<tbody>

<?php
if($tripfromDate !=''  && $triptoDate !='') {
$sql_purpayment_fuel = "SELECT cc.invoice,cc.invoicedate,cc.supplierid,cc.amount, cc.pay_type, cm.sname FROM supplier_payment as cc LEFT JOIN supplier_master as cm on cm.id = cc.supplierid WHERE cc.invoicedate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' and cc.status='' ORDER BY invoicedate ASC ";

	 }
	 
	 

//echo $sql_purpayment_fuel;
$querry_purpay_fuel=mysqli_query( $conn, $sql_purpayment_fuel );

$sno_purpay_fuel=0;
$amt_purpay_fuel=0;
while($row_purpay_fuel=mysqli_fetch_array($querry_purpay_fuel))
{


$date_purpay_fuel=$row_purpay_fuel["invoicedate"];
$date_purpay1_fuel=date_create($date_purpay_fuel);
$purchase_date_pay_fuel=date_format($date_purpay1_fuel,"d-m-Y");
?>
<tr>
<td><?php echo ++$sno_purpay_fuel;?></td>

<td><?php echo $date_purpay_fuel;?> </td>
<td><?php echo $row_purpay_fuel['sname'];?> </td>


<td><?php echo $row_purpay_fuel['pay_type'];?> </td>
<td align="right"><?php echo  number_format($row_purpay_fuel['amount'],2,'.','');?> </td>



</tr>

<?php

$amt_purpay_fuel=$amt_purpay_fuel+$row_purpay_fuel['amount'];

}
?>
<tr>

<td colspan="4" align="right"> <strong>Total&nbsp;Amount</strong></td>
<td align="right"><strong><?php echo number_format($amt_purpay_fuel,2,'.','');?></strong></td>

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

<div class="container col-sm-12" >&nbsp;</div>

<div class="container col-sm-12" >

<table id="stockExpenseDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
            <th>S.No</th>
            <th>Cash No</th>
            <th>Date</th>
            <th>Expense Type </th>
            <th>Expense</th>
            <th>Expenser</th>
            <th>Mode Of Pay</th>
            <th>Amount</th>
            <th>Rermark</th>
                <!-- <th>Action</th> -->
            </tr>
        </thead>
        
        
         <?php
				
				
				
				if($tripfromDate !=''  && $triptoDate !='') {
				$sql_expense = "SELECT ee.cashno,ee.mode,ee.remark, ee.expensedate, ee.expense,ee.expensetype,ee.expensetype,ee.expenser,ee.amount,ee.id,em.expense as expensename FROM expense_entry as ee LEFT JOIN expense_master as em ON em.id=ee.expensetype WHERE ee.flag=1  and expensedate BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY ee.expensedate ASC ";

	 }
	 
	
	
				?>
        
        <tbody>
             <?php
			$query_expense=mysqli_query($conn, $sql_expense) ;
			$expense_amount=0;
			$expense_sno=0;
			while($row_expense=mysqli_fetch_array($query_expense))  
			{
			?>
            <tr>
            <td><?php echo ++$expense_sno;?></td>
            <td><?php echo $row_expense['cashno'];?></td>
            <td><?php echo $row_expense['expensedate'];?></td>
            <td><?php echo $row_expense['expensename'];?></td>
            <td><?php echo $row_expense['expense'];?></td>
            <td><?php echo $row_expense['expenser'];?></td>
            <td><?php echo $row_expense['mode'];?></td>
            <td align="right"><?php echo number_format($row_expense['amount'],2,'.','');?></td>
            <td><?php echo $row_expense['remark'];?></td>
            </tr>
            <?php
			$expense_amount=$expense_amount+$row_expense['amount'];
			}
			?>
            <tr>
            <td align="right" colspan="7"><b>Total</b></td>
            <td align="right"><strong><?php echo number_format($expense_amount,2,'.','');?></strong></td>
            </tr>
        </tbody>
       
    </table>
    
</div>

<h3 align="center"><u>PayRoll Details</u></h3>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<caption>Employee Advance</caption>
        <thead>
            <tr>
            
                <th>S.No</th>
                <th>Date</th>
                <th>Employee</th>
               
                <th>Amount</th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				


	 
	  if($tripfromDate !=''  && $triptoDate !=''    ) {
		$sql_advance="SELECT sh.advance_no, sh.advance_date, sh.employee_id, sh.advance_amount, sh.remarks, sh.id,em.ename FROM employee_advance as sh LEFT JOIN employee_master as em on em.id = sh.employee_id WHERE 1=1 and  sh.status=''   and advance_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.advance_date ASC ";

   	 }
	 
	// echo $sql;
	 
				?>
        
        <tbody>
            <?php
			$query_advance=mysqli_query($conn, $sql_advance) ;
			$total_advance = 0;
			$adv_sno = 0;
			while($row_advance=mysqli_fetch_array($query_advance))
{
	$advance_date=$row_advance["advance_date"];
$adv_date=date_create($advance_date);
$adv_date2=date_format($adv_date,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$adv_sno;?></td>
            <td><?php echo $adv_date2;?></td>
			<td><?php echo $row_advance["ename"];?></td>
            
           <td align="right"><?php echo number_format((float)$row_advance["advance_amount"], 2, '.', '');?></td>
           <td><?php echo $row_advance["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_advance  += $row_advance["advance_amount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="3"><strong>Total Advance Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_advance), 2, '.', '');?></strong></td>
			</tr>             
           
        </tbody>
       
    </table>
    </div>
    <!-- Emp Collection-->
    
    <div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption><strong>Advance&nbsp;Collection</strong></caption>
            <tr>
                <th>S.No</th>
                <th>Date</th>
                <th>Employee</th>
               
               
                <th>Collected Amt</th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				
				
	
	 

	 
	  if($tripfromDate !=''  && $triptoDate !=''   ) {
		$sql_collection="SELECT sh.advance_no, sh.advance_date, sh.employee_id,sh.advance_collection_amount, sh.advance_amount, sh.remarks, sh.id,em.ename FROM employee_advance_collection as sh LEFT JOIN employee_master as em on em.id = sh.employee_id WHERE 1=1 and  sh.status=''    and advance_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY sh.advance_date ASC ";

   	 }
	 
	 
	 
				?>
        
        <tbody>
            <?php
			$query_collection=mysqli_query($conn, $sql_collection) ;
			$total_collection = 0;
			$sno_collection=0;
			while($row_colection=mysqli_fetch_array($query_collection))
{
	$deliver_date=$row_colection["advance_date"];
$date_collection=date_create($deliver_date);
$sale_date_collection=date_format($date_collection,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$sno_collection;?></td>
            <td><?php echo $sale_date_collection;?></td>
			<td><?php echo $row_colection["ename"];?></td>
            
           
           <td align="right"><?php echo number_format((float)$row_colection["advance_collection_amount"], 2, '.', '');?></td>
           <td><?php echo $row_colection["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_collection  += $row_colection["advance_collection_amount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="3"><strong>Total Collected Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_collection), 2, '.', '');?></strong></td>
			</tr>             
           
        </tbody>
       
    </table>
    
</div>

<div class="container col-sm-12">

<table class="table table-responsive table-striped table-bordered dt-responsive nowrap" id="accLabourDetailsAdd" cellspacing="0">
          <thead>
          <caption>Attendance&nbsp;Salary</caption>
            <tr>
              <th>S.No</th>
              <th>Date</th>
              <th>Emp.Name</th>
              <th>Total&nbsp;Working&nbsp;Shift </th>
              <th>Extra Working Hours</th>
               <th>Salary/Shift</th> 
              <th>Salary/Extra Hour</th>
              <th>Salary</th>
            </tr>
          </thead>
          <tbody>
          <?php
		  
		  if($tripfromDate !=''  && $triptoDate !=''   ) { 

$sql1 ="SELECT att.invoicedate,emp.ename,att.enameid,att.shifttype as shifttype,att.extraworkinghrs as extraworkinghrs,emp.shiftworkamt,emp.extrahoursamt FROM employee_attendance_dtl as att inner join employee_master as emp on att.enameid=emp.id WHERE  invoicedate between '".$tripfromDate."' AND '".$triptoDate."'  and att.isdelete=1   ";


}
//echo $sql1;

$Query_Adv  = mysqli_query($conn,$sql1); 

		  
            $trlength = 0;
			$att_sal=0;
            //lm.ename,lad.shifttype,lad.extraworkinghrs,lad.shiftworkamt,lad.extrahoursamt,lad.enameid
            while($drow = mysqli_fetch_array($Query_Adv))
            {
			
			$totalshifsalary=$drow['shifttype']*$drow['shiftworkamt'];
			$totalotsalary=$drow['extraworkinghrs']*$drow['extrahoursamt'];
			
			$totalsalary=$totalshifsalary+$totalotsalary;
			
			
			
			$attdate=date_create($drow['invoicedate']);
$att_date=date_format($attdate,"d-m-Y");
              ?>
              <tr>
              <td><?php echo ++$trlength;?></td>
               <td><?php echo $att_date; ?></td>
              <td><?php echo $drow['ename']; ?></td>
              <td><?php echo $drow['shifttype']; ?></td>
              <td><?php echo $drow['extraworkinghrs']; ?></td>
              <td><?php echo $drow['shiftworkamt']; ?></td>
              <td><?php echo $drow['extrahoursamt']; ?></td>
              <td align="right"><strong><?php echo number_format($totalshifsalary,2,'.','');?></strong></td>
              
              
              </tr>
              
              
              
              <?php
                $att_sal+=$totalshifsalary;
            }
          ?>
          <tr>
          <td colspan="7" align="right"><strong>Attendance Salary</strong></td>
          <td align="right"><strong><?php echo number_format($att_sal,2,'.','');?></strong></td> 
          </tbody>
        </table>


</div>

<div class="container col-sm-12">&nbsp;</div>

<div class="container col-sm-12">

<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <caption>Paid Salary</caption>
            <tr>
            <th>S.No</th>
                <th>Emp.Name</th>
                <th>Date</th>
                <th>Salary paid Date</th>
               
               <th>Total&nbsp;Salary</th>
               
                <th>Paid&nbsp;Amount</th>
                <th>Deducted.Adv&nbsp;Amt</th>
                <th>Given Cash</th>
                 <th>Remarks</th>
            </tr>
        </thead>
        
        <?php
				


	 
	  if($tripfromDate !=''  && $triptoDate !=''    ) {
		$sql_salary="SELECT employee_name, given_date,fromdate,todate, paidamount,ecode, givenby, refno,paytype,id,pending_salary,total_salary,remarks,deducted_amt,cash_hand FROM employee_payment WHERE 1=1 and isdelete=1 and status=''   and given_date BETWEEN '".$tripfromDate."' AND '".$triptoDate."' ORDER BY given_date ASC ";

   	 }
	 
	
	// echo $sql_salary;
	 
				?>
        
        <tbody>
            <?php
			$query_salary=mysqli_query($conn, $sql_salary);
			$total_recieved_salary = 0;
		$ssno=0;
			while($row_salary=mysqli_fetch_array($query_salary))
{
	$salary_date=$row_salary["given_date"];
$date_salary=date_create($salary_date);
$salery_date2=date_format($date_salary,"d-m-Y");
				
				?>
			<tr>
            <td><?php echo ++$ssno;?></td>
            <td><?php echo $row_salary["employee_name"];?></td>
            <td><?php echo $salery_date2;?></td>
			<td><?php echo $row_salary["fromdate"]." To ".$row_salary["todate"];?></td>
            
          
            <td align="right"><?php echo number_format((float)$row_salary["total_salary"], 2, '.', '');?></td>
             <td align="right"><?php echo number_format((float)$row_salary["paidamount"], 2, '.', '');?></td>
             <td align="right"><?php echo number_format((float)$row_salary["deducted_amt"], 2, '.', '');?></td>
             <td align="right"><?php echo number_format((float)$row_salary["cash_hand"], 2, '.', '');?></td>
           <td><?php echo $row["remarks"];?></td>
           
			</tr>
            <?php
			
			$total_recieved_salary  += $row_salary["paidamount"];
			
}


?>
       <tr>
           
          
           
			<td  align="right" colspan="5"><strong>Total Amount</strong></td>
            <td align="right"><strong><?php echo number_format(round($total_recieved_salary), 2, '.', '');?></strong></td>
			</tr>             
           
        </tbody>
       
    </table>
   
</div>


<div class="container col-sm-12" >
<table id="salestockDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <th>S.no</th>
        <th>Process</th>
        <th>Purchase&nbsp;Amount</th>
        <th>Paid&nbsp;Amount</th>
        
       </thead>
       <tbody>
       <tr>
       <td>1</td>
       <td>Purchase</td>
       <td align="right"><strong><?php echo number_format(round($total_price_gst), 2, '.', '');?></strong></td>
       <td align="right"><strong><?php echo number_format($amt_purpay,2,'.','');?></strong></td>
       </tr>
       
       <tr>
       <td>2</td>
       <td>Purchase EST</td>
        <td align="right"><strong><?php echo number_format(round($total_price_est), 2, '.', '');?></strong></td>
         <td align="right"><strong><?php echo number_format($amt_purpay_est,2,'.','');?></strong></td>
       </tr>
       
       <tr>
       <td>3</td>
       <td>Fuel Internal</td>
        <td align="right"><strong><?php echo number_format(round($total_price_infuel), 2, '.', '');?></strong></td>
        <td rowspan="3" align="right"><strong><?php echo number_format($amt_purpay_fuel,2,'.','');?></strong></td>
       </tr>
       
       <tr>
       <td>4</td>
       <td>Fuel External</td>
        <td align="right"><strong><?php echo number_format(round($total_price_exf+total_price_exuf), 2, '.', '');?></strong></td>
         </tr>
       
        <tr>
       <td>5</td>
       <td>Compressor&nbsp;Work</td>
        <td align="right"><strong><?php echo number_format(round($amt_compressor), 2, '.', '');?></strong></td>
         </tr>
       
       <tr>
       <td>6</td>
       <td>Expense</td>
       <td align="right"><strong><?php echo number_format(round($expense_amount), 2, '.', '');?></strong></td>
       <td align="right"><strong><?php echo number_format($expense_amount,2,'.','');?></strong></td>
       </tr>
       
       <td>7</td>
       <td>Advance</td>
       <td align="right"><strong><?php echo number_format(round($total_advance), 2, '.', '');?></strong></td>
       <td align="right"><strong><?php echo number_format($total_advance,2,'.','');?></strong></td>
       </tr>
       
       <td>8</td>
       <td>Collection</td>
       <td align="right"><strong><?php echo number_format(round($total_collection), 2, '.', '');?></strong></td>
       <td align="right">-</td>
       </tr>
       
       <tr>
       <td>9</td>
       <td>Total&nbsp;Shift&nbsp;Salary</td>
       <td align="right"><strong><?php echo number_format(round($att_sal), 2, '.', '');?></strong></td>
       <td align="right"><strong><?php echo number_format($total_recieved_salary,2,'.','');?></strong></td>
       </tr>
       
        <tr>
     
       <td colspan="3" align="right"><strong>Total&nbsp;Paid&nbsp;Amount</strong></td>
       <td align="right"><strong><?php echo number_format(round(($amt_purpay+$amt_purpay_est+$amt_purpay_fuel+$expense_amount+$total_recieved_salary+$total_advance)), 2, '.', '');?></strong></td>
       
       
       
       </tr>
       
       <tr>
     
       <td colspan="3" align="right"><strong>Total&nbsp;Collected&nbsp;Advance</strong></td>
       <td align="right"><strong><?php echo number_format(round(($total_collection)), 2, '.', '');?></strong></td>
       
       
       
       </tr>
       
       
       </tbody>
       </table>

<!--<table  class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
        <th>S.no</th>
        <th>Process</th>
        <th>Adv&nbsp;Amount</th>
        <th>Collection&nbsp;Amount</th>
        
       </thead>
       <tbody>
<tr>
       <td>1</td>
       <td>Advance</td>
       <td align="right"><strong><?php echo number_format(round($total_advance), 2, '.', '');?></strong></td>
       <td align="right"><strong><?php echo number_format($total_collection,2,'.','');?></strong></td>
       </tr>
       
       <tr>
       <td>1</td>
       <td>Total&nbsp;Shift&nbsp;Salary</td>
       <td align="right"><strong><?php echo number_format(round($att_sal), 2, '.', '');?></strong></td>
       <td align="right"><strong><?php echo number_format($total_recieved_salary,2,'.','');?></strong></td>
       </tr>
       
       </tbody>
       </table>-->

</div>

</div>



    <?php require 'footer.php' ?>

    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
  
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js"></script>

   
</body>
</html>