<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:"Taxreport ",//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">
$("#pf").on("click", function () {
        $("#fullreport").tableHTMLExport({ type: "pdf", filename: "salesreport.pdf",
        
        });
      });
</script>
<?php 
include "../config.php";
error_reporting(0);
//$product = $_POST['product'];
$fromd = $_POST['fromd'];
$tod = $_POST['tod'];
    $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;
echo 

'<div id="fulltable">

<table class="table table-striped">

   <thead style="background-color:#101820FF;color:#FEE715FF">
   <tr><th colspan="16" style="text-align:center;">Tax Report Between '.$datefrom.' And '.$dateto.'</th></tr>
   <th>S.no</th>
<th>Bill No</th>
<th>Bill Date</th>
<th>Customer</th>
<th>GSTIN</th>
<th>Cust state</th>
<th>Product Name</th>
<th>HSN</th>
<th>Rate</th>
<th>Qty</th>
<th>Units</th>
<th>Subtotal</th>
<th>CGST 2.5%</th>
<th>SGST 2.5%</th>
<th>IGST 5%</th>

<th>NetAmount</th>

   </thead>
   
   <tbody style="background-color:#FEE715FF;color:#101820FF;font-size:16px">';
   
$rep=mysqli_query($connect,"select *,(select customerdetails.name from customerdetails where customerdetails.code = second_transaction.customer && status!='deleted')as cusname,(select productdetail.productname from productdetail where productdetail.productcode = second_transaction.product && status!='deleted' )as proname,(select productdetail.unit from productdetail where productdetail.productcode = second_transaction.product && status!='deleted')as unit,(select ticket.tripno from ticket where ticket.ticket = second_transaction.ticket && status!='deleted' )as trip from second_transaction where date
between '$fromd' and '$tod' && status !='deleted'");

     
$pricee = 0;
$cgst51 = 0;
$cgst52 = 0;
$cgst91=0;
$cgst92=0;
$igst55=0;
$igst99=0;
$tax = 0;
$subtotal = 0;
$totalamountc = 0; 
while($repshow = mysqli_fetch_array($rep))

{
    $sno +=1;
    $datechk=$repshow['date'];
    $dateval = date_create($datechk);
    $date = date_format($dateval,"d/m/Y");
     
    $product = $repshow['product'];
$pro=mysqli_query($connect,"select * from productdetail where status !='deleted' && productcode = '$product'");
while($reppro = mysqli_fetch_array($pro))
{
    $price = $repshow['price'];
    $qty = $repshow['netqty'];
    $gst = $reppro['tax'];
    $inclu = $price * 100 /( 100 + $gst);
    $sub = $inclu * $qty;
    $tax = (0.01*$gst*$sub);
    if($gst == '5')
    {
        $cgst5 = $tax/2;
        $sgst5 = $tax/2;
        $cgst9 = "0";
        $sgst9 = "0"; 
        $igst5 = "0";
    }
    if($gst == '18')
    {
        $cgst9 = $tax/2;
        $sgst9 = $tax/2;
        $cgst5 = "0";
        $sgst5 = "0";
        $igst9 = "0"; 
        $product = $repshow['product'];
    }
    $customer = $repshow['customer'];
$cus=mysqli_query($connect,"select * from customerdetails where  code = '$customer' && status!='deleted'");
while($repcus = mysqli_fetch_array($cus))
{
    

if(mysqli_num_rows($rep) > 0 )
{
   echo '
   
   <tr>
   <td>'.$sno.'</td>
   <td>'.$repshow['salescode'].'</td>
   <td>'.$repshow['date'].'</td>
   <td>'.$repshow['cusname'].'</td>
   <td>'.$repcus['gst'].'</td>
   <td>'.$repcus['state'].'</td>
   <td>'.$repshow['proname'].'</td>
   <td>'.$reppro['hsn'].'</td>
   <td>'.number_format($inclu,2,'.','').'</td>
   <td>'.$repshow['netqty'].'</td>
   <td>'.$repshow['unit'].'</td>
   <td>'.number_format($sub,2,'.','').'</td>
   <td>'.number_format($cgst5,2,'.','').'</td>
   <td>'.number_format($sgst5,2,'.','').'</td>
   <td>'.number_format($igst5,2,'.','').'</td>
  
   <td>'.number_format($repshow['totalamount'],2,'.','').'</td>
   
   

   </tr>
  ';
  $pricee +=number_format($inclu,2,'.','') ;
  
  $cgst51 +=number_format($cgst5,2,'.','');
  $cgst52 += number_format($sgst5,2,'.','');
  $cgst91+=number_format($cgst9,2,'.','');
  $cgst92+=number_format($sgst9,2,'.','');
  $igst55+=number_format($igst5,2,'.','');
  $igst99+=number_format($igst9,2,'.','');
  
  $subtotal += number_format($sub,2,'.','');
  $totalamountc += 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:right"><th colspan="8">Total</th><th>'.$pricee.'</th><th colspan="2"></th><th>'.$subtotal.'</th><th >'.$cgst51.'</th><th >'.$cgst52.'</th><th >'.$igst55.'</th>
   <th >'.$totalamountc.'</th> </tr>;
   </tbody>
   
   </table>
   </div>
   .';

?>
