<link rel="stylesheet" href="tablestyle/tablereportdisplay.css">
<script src="javascript/jquery.table2excel.js" type="text/javascript"></script>
<script src="javascript/jspdf.min.js"></script>
    <script src="javascript/jspdf.plugin.autotable.min.js"></script>
    <script src="javascript/tableHTMLExport.js"></script>
<button class="btn btn-warning" id="pdf" onclick = "printDiv()" style="float:right;margin-right:20px;">Print</button>   <button class="btn btn-primary" id="ex" style="float:right;margin-right:20px;">Excel</button><br><br>
<script type="text/javascript">
$("#ex").click(function(){
    var a = $("#todate").val();
      var b = $("#fromdate").val();
  $("#fullreport").table2excel({
    
            exclude:".noExl",
    name:"Salesreport",
    filename:"Salesreport ",//do not include extension
    fileext:".xls" // file extension
  });
});

</script>
<script>function printDiv() 
{

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

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

}</script>
<script type="text/javascript">
$("#pd").on("click", function () {
        $("#fullreport").tableHTMLExport({ type: "pdf", filename: "salesreport.pdf",
        
        });
      });
</script>

<?php 
include "../config.php";
error_reporting(0);
$customer = $_POST['customer'];
$fromd = $_POST['fromd'];
$tod = $_POST['tod'];
$product = $_POST['product'];
$proedit=mysqli_query($connect,"select * from partydetail order by id desc");
while($proshowedi = mysqli_fetch_array($proedit))
{
  $party=  $proshowedi['party'];
}
$datefr = date_create($fromd);
    $datefrom = date_format($datefr,"d/m/Y");
    $datet = date_create($tod);
    $dateto = date_format($datet,"d/m/Y");
// echo $customer;
//  echo $fromd;
//  echo $tod;
 




   $repest = "select *,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction_est.customer )as cusname,(select productdetail.productname from productdetail where productdetail.productcode = second_transaction_est.product )as proname,(select productdetail.unit from productdetail where productdetail.productcode = second_transaction_est.product )as unit,(select ticket.tripsheetno from ticket where ticket.ticket = second_transaction_est.ticket && status !='deleted' )as trip from second_transaction_est where date
   between '$fromd' and '$tod' && status !='deleted'  order by id desc";
   echo 

'<div id="fulltable">
<br>
<table class="table table-striped">

<thead style="">
<tr><th colspan="12" style="text-align:center;">Sales Report-EST Between '.$datefrom.' And '.$dateto.'</th></tr>
<tr><th colspan="12" style="text-align:center;">'.$party.'</th></tr>
   <th>S.no</th>
   <th>Invoicedate</th>
   <th>Invoiceno</th>
   <th>Ticketno</th>
   <th>Customer</th>
   <th>Vehicleno</th>
   <th>Material</th>
   <th>Units</th>
   <th>Invoiceamount</th>
   <th>Customertype</th>
   
   <th>Tripsheetno</th>
   <th>Deliverysite</th>
   </thead>
   
   <tbody style="">';
   
   $qty = 0;
   $amt = 0;
    $rep =mysqli_query($connect,$repest);
while($repshow = mysqli_fetch_array($rep))
{
$sno +=1;

   echo '
   
   <tr>
   <td>'.$sno.'</td>
   <td>'.$repshow['date'].'</td>
   <td>'.$repshow['salescode'].'</td>
   <td>'.$repshow['ticket'].'</td>
   <td>'.$repshow['cusname'].'</td>

   <td>'.$repshow['vehicleno'].'</td>
   <td>'.$repshow['proname'].'</td>
   <td>'.number_format($repshow['netqty'],2,'.','').'</td>
   <td>'.number_format($repshow['totalamount'],2,'.','').'</td>
   <td>'.$repshow['customertype'].'</td>
   
   <td>'.$repshow['trip'].'</td>
   <td>'.$repshow['delivery'].'</td>
   

   </tr>';
   $qty +=number_format($repshow['netqty'],2,'.','');
   $amt +=number_format($repshow['totalamount'],2,'.','');
}

//echo $repp;
   echo'
   <tr style="text-align:center"><th colspan="7">Total</th><th>'.number_format($qty,2,'.','').'</th><th>'.number_format($amt,2,'.','').'</th><th colspan="4"></th></tr>
   
   </tbody>
   
   </table>
   </div>';
   

?>
