<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'];
// echo $fromd;
// echo $tod;
$proedit=mysqli_query($connect,"select * from partydetail order by id desc");
while($proshowedi = mysqli_fetch_array($proedit))
{
  $party=  $proshowedi['party'];
}

// echo $customer;
//  echo $fromd;
//  echo $tod;
 $repp="select *,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction.customer )as cusname from second_transaction where editdate
 between '$fromd' and '$tod' && status ='cancel'  
union 
select *,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction_est.customer )as cusname from second_transaction_est where editdate
between '$fromd' and '$tod' && status ='cancel'  
union
select *,(select customerdetails.name from customerdetails where customerdetails.code = purchasedetails.customer )as cusname from purchasedetails where editdate
between '$fromd' and '$tod' && status ='cancel'  
";
// /echo $repp;
echo 

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

<thead style="">
<tr><th colspan="24" style="text-align:center;">Loadout  Report Canceled Between Ticket '.$fromd.' And '.$tod.'</th></tr>
<tr><th colspan="24" style="text-align:center;">'.$party.'</th></tr>
   <th>S.no</th>
   <th>Ticket</th>
   <th>Date</th>
   <th>Veh.NO</th>
   <th>Veh.Name</th>
   <th>TripSheet.NO</th>
   <th>Customer</th>
   <th>Empty Date</th>
   <th>Empty Time</th>
   <th>Empty Weight</th>
   <th>Load date</th>
   <th>Load Time</th>
      <th>Load Weight</th>
   <th>Net Weight</th>
   <th>Units</th>
   <th>Material</th>
   <th>Type</th>
   <th>Deliverysite</th>
   <th>Supplier</th>
   <th>Customertype</th>
   <th>Remark</th>
   <th>Emp Adj</th>
   <th>In Kgs</th>
   <th>Deleted By</th>
   </thead>
   
   <tbody style="">';
   
   $qty = 0;
   $amt = 0;
    $rep =mysqli_query($connect,$repp);
while($repshow = mysqli_fetch_array($rep))
{
  
   $unitadj =  $repshow['netqtyori']-$repshow['netqty']; 
   $kgadj = $unitadj * 1000;
    $ticket = $repshow['ticket']; 
$tktedit=mysqli_query($connect,"select * from first_transaction where status != 'deleted' and ticket ='$ticket' order by id desc");
while($tktshowedi = mysqli_fetch_array($tktedit))
{
$sno +=1;

   echo '
   
   <tr>
   <td>'.$sno.'</td>
   <td>'.$repshow['ticket'].'</td>
   <td>'.$repshow['date'].'</td>
   <td>'.$repshow['vehicleno'].'</td>
   <td>'.$tktshowedi['vehiclename'].'</td>
   <td>'.$tktshowedi['tripsheet'].'</td>
      <td>'.$repshow['cusname'].'</td>
   <td>'.$tktshowedi['editdate'].'</td>
   <td>'.$tktshowedi['edittime'].'</td>
   <td>'.$repshow['emptyweight'].'</td>
   <td>'.$repshow['editdate'].'</td>
   <td>'.$repshow['edittime'].'</td>
   <td>'.$repshow['loadweight'].'</td>
   <td>'.$repshow['netweight'].'</td>
   <td>'.number_format($repshow['netqty'],2,'.','').'</td>
   <td>'.$repshow['productname'].'</td>
   <td>'.$repshow['processtype'].'</td>
   <td>'.$repshow['delivery'].'</td>
   <td>'.$repshow['supplier'].'</td>
   <td>'.$repshow['customertype'].'</td>
   <td>'.$repshow['remark'].'</td>
   <td>'.number_format($unitadj,2,'.','').'</td>
   <td>'.number_format($kgadj,2,'.','').'</td>
     <td>'.$repshow['editby'].'</td>
   

   </tr>';
   $qty +=number_format($repshow['netqty'],2,'.','');
   $amt +=number_format($repshow['netweight'],2,'.','');
}
}
//echo $repp;
   echo'
   <tr style="text-align:center"><th colspan="13">Total</th><th>'.number_format($amt,2,'.','').'</th><th>'.number_format($qty,2,'.','').'</th><th colspan="9"></th></tr>
   
   </tbody>
   
   </table>
   </div>
   ';

?>
