<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:"Purchasereport",
    filename:"Purchasereport ",//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'];
//echo $customer;
// echo $fromd;
// echo $tod;
$datefr = date_create($fromd);
$datefrom = date_format($datefr,"d/m/Y");
$datet = date_create($tod);
$dateto = date_format($datet,"d/m/Y");
$proedit=mysqli_query($connect,"select * from partydetail order by id desc");
while($proshowedi = mysqli_fetch_array($proedit))
{
$party=  $proshowedi['party'];
}
echo 

'<div id="fulltable">
<table class="table table-striped">
<thead style="">
<tr><th colspan="19" style="text-align:center;">Purchase Report Between '.$datefrom.' And '.$dateto.'</th></tr>
<tr><th colspan="19" style="text-align:center;">'.$party.'</th></tr>
<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>Salestype</th>
   <th>Tripsheetno</th>
   <th>Deliverysite</th>
  
   </thead>
   
   <tbody style="">';
   
$rep=mysqli_query($connect,"select *,(select customerdetails.name from customerdetails where customerdetails.code = purchasedetails.customer )as cusname,(select productdetail.productname from productdetail where productdetail.productcode = purchasedetails.product )as proname,(select productdetail.unit from productdetail where productdetail.productcode = purchasedetails.product )as unit,(select ticket.tripsheetno from ticket where ticket.ticket = purchasedetails.ticket )as trip from purchasedetails where  customer like '%$customer%'  &&  date
between '$fromd' and '$tod' && status !='deleted'    order by id desc");
  
   
$qty = 0;
$amt = 0;

while($repshow = mysqli_fetch_array($rep))
{
$sno +=1;
if(mysqli_num_rows($rep) > 0 )
{
   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['customertype'].'</td>
   <td>'.$repshow['trip'].'</td>
   <td>'.$repshow['delivery'].'</td>
   

   </tr>';
   $qty +=number_format($repshow['netqty'],2,'.','');
   $amt +=number_format($repshow['totalamount'],2,'.','');
}
else 
{
    echo' <div class="spinner-border text-primary" style="margin-left:45%;margin-top:20%;margin-bottom:20%;padding:3%"></div>';
}
}
   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>
   ';

?>
