<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'];
$fromt = $_POST['fromt'];
$tot = $_POST['tot'];
//$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,concat(date,time)as datime from second_transaction where ticket
 between '$fromd' and '$tod' && status !='deleted'  
union 
select *,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction_est.customer )as cusname,concat(date,time)as datime from second_transaction_est where ticket
between '$fromd' and '$tod' && status !='deleted'  
union
select *,(select customerdetails.name from customerdetails where customerdetails.code = purchasedetails.customer )as cusname,concat(date,time)as datime from purchasedetails where ticket
between '$fromd' and '$tod' && status !='deleted' 
union
select id as id , ('-') as salescode,ticket as ticket,vehicleno as vehicleno,customer as customer,delivery as delivery,product as product,((select productdetail.productname from productdetail where productdetail.productcode = single_transaction.product )) as productname,('-') as price,('-')as priceori,entrydate as date,entrytime as time,('In') as processtype,emptyweight as emptyweight,loadweight as loadweight,('-') as unitvalue,netweight as netweight,quantity as netqty,quantityori as netqtyori,('-') as customertype,('-') as totalamount,remark as remark,('-') as billtype,editby as editby,edittime as edittime,editdate as editdate,status as status,('-')as supplier,('-') as financialyear,('-') as tablename,(select customerdetails.name from customerdetails where customerdetails.code = single_transaction.customer )as cusname,concat(entrydate,entrytime)as datime from single_transaction  where ticket
between '$fromd' and '$tod' && status !='deleted'  order by datime asc
";
//echo $repp;
echo 

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

<thead style="">
<tr><th colspan="25" style="text-align:center;">Loadout Report Between Date '.$fromd.' And '.$tod.' && Time '.$fromt.' and '.$tot.'</th></tr>
<tr><th colspan="25" 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>In Date</th>
   <th>In Time</th>
   <th>Empty Weight</th>
   <th>Out date</th>
   <th>Out Time</th>
      <th>Load Weight</th>
   <th>Net Weight</th>
   <th>Unit-Original</th>
   <th>Unit-Adj</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>operator</th>
   </thead>
   
   <tbody style="">';
   
   $qty = 0;
   $amt = 0;
    $rep =mysqli_query($connect,$repp);
while($repshow = mysqli_fetch_array($rep))
{
  $product = $repshow['product'];
$proshow=mysqli_query($connect,"select * from productdetail where productcode = '$product'");
  while($proshowshow = mysqli_fetch_array($proshow))
{
 $unittokg = $proshowshow['unittokg'];
  if( $repshow['netqtyori'] != '-')
  {
   $unitadj =  $repshow['netqty']-$repshow['netqtyori']; 
   $kgadj = $unitadj * $unittokg;
  }
  else
  {
    $unitadj =  "0"; 
    $kgadj = "0";
  }
  $total = $repshow['customertype'];
  if($total != '-')
  {
    $ticket = $repshow['ticket']; 
    $tktquery="select ifnull(time,0)as edittime,ifnull(date,0)as editdate,ifnull(vehicleno,0)as vehicleno,ifnull(vehiclename,0)as vehiclename,ifnull(tripsheet,0)as tripsheet from first_transaction where status != 'deleted' and ticket ='$ticket' ";
  }
  else 
  {
    $tktquery="select sum(id)as editid, ('-')as edittime,('-'),('-')as vehicleno,('-')as vehiclename,('-')as tripsheet from first_transaction where status != 'deleted' ";
  }
//echo $csh;

// echo 
// $tktquery;
$tktedit=mysqli_query($connect,$tktquery);
while($tktshowedi = mysqli_fetch_array($tktedit))
{
$sno +=1;
if(mysqli_num_rows($tktedit) > 0 )
{
   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['date'].'</td>
   <td>'.$repshow['time'].'</td>
   <td>'.$repshow['loadweight'].'</td>
   <td>'.$repshow['netweight'].'</td>
   <td>'.number_format($repshow['netqtyori'],2,'.','').'</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,'.','');
}
else
{
  echo '
   
  <tr>
  <td>'.$sno.'</td>
  <td>'.$repshow['ticket'].'</td>
  <td>'.$repshow['date'].'</td>
  <td>'.$repshow['vehicleno'].'</td>
  <td>-</td>
  <td>-</td>
     <td>'.$repshow['cusname'].'</td>
  <td>-</td>
  <td>-</td>
  <td>'.$repshow['emptyweight'].'</td>
  <td>'.$repshow['date'].'</td>
  <td>'.$repshow['time'].'</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>-</td>
  <td>-</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></th><th>'.number_format($qty,2,'.','').'</th><th colspan="9"></th></tr>
   
   </tbody>
   
   </table>
   </div>
   ';

?>
