<?php 

require_once("config/configDB.php");

//header('Content-disposition: attachment; ');
//header('Content-type: application/pdf');
$invoice_id  = $_GET['saleID'];

$re = mysqli_query($conn,"select * from saleheaderwo where id='".$invoice_id."' "); 
//$re=mysqli_query($sql);
 while($row = mysqli_fetch_array($re))
 {
    $invoice_no= $row['invoice_no'];
    
   $customer_code = $row['customer_id'];
   $date1 = $row['sale_date'];
    $date = date("d-m-Y", strtotime($date1));  
   
   $po = $row['po_num'];
   $delivery_address = $row['delivery_address'];
   $tamount = round($row['tamount']);
  // $status = $row[6]; 
   // $others = $row[5];
//	$others_amount = $row[6];

   //$sql2="select * from customer_master where id='".$customer_code."' ";
   }
   $re2 = mysqli_query($conn,"select * from customer_master where id='".$customer_code."' "); 
   //$re2=mysqli_query($sql2);
   while($row2 = mysqli_fetch_array($re2))
    {

	   $client_name= $row2['customername_tamil'];
	   $address= $row2['caddress'];
  	   //$address2= $row2['city'];
   	   $address3= $row2['customer_state'];
	   $gstin= $row2['gstin'];
       $state_code = $row2['customer_state'];
	    
	  
    }
	
	$sql3 ="SELECT sii.*,pm.productcode,pm.productname,pm.productname_tamil,pm.isdelete,pm.hsn  FROM saledetailswo as sii LEFT JOIN product_master as pm on pm.id=sii.productID  WHERE sii.saleheader_id = '$invoice_id'";

    $re3 = mysqli_query($conn,$sql3); 
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>EST Invoice</title>
  <style>
    body {
      width: 72mm;
      font-family: 'Courier New', monospace;
      font-size: 14px;
      margin: 0;
      padding: 0;
    }
    .center {
      text-align: center;
    }
    .bold {
      font-weight: bold;
    }
    table {
      width: 100%;
      border-collapse: collapse;
    }
    td, th {
      padding: 2px 0;
    }
    .border-top {
      border-top: 1px dashed #000;
    }
    .border-bottom {
      border-bottom: 1px dashed #000;
    }
    .totals td {
      text-align: right;
    }
  </style>
</head>
<body onLoad="window.print()">
<div style="margin-top:20px;">&nbsp;</div>

  <div class="center bold">ஐடிசி  என்டர்பிரைஸ்</div>
  <div class="center">நெ.461, பிரின்ஸ் கினிட்டிங் கம்பெனி பில்டிங்,காமராஜ் சாலை,</div>
  <div class="center">தென்னம்பாளையம் உழவர் மார்க்கெட் அருகில்</div>
  <div class="center">திருப்பூர்-641604.</div>
  
 <!-- <div class="center">GSTIN: 33ALFPP8724J1ZT</div>-->
  <div class="center border-bottom">Ph: 9698312300/9976494417</div>

  <p>Invoice : <?php echo $invoice_no;?><br>
  Date: <?php echo $date;?><br>
  
  Customer: <?php echo $client_name;?><br>
  <!--GSTIN: <?php echo $gstin;?></p>-->

  <table class="border-top border-bottom">
    <thead>
      <tr>
        <th>Item</th>
        
        <th>Qty</th>
        <th>Rate</th>
        <th>Total</th>
      </tr>
    </thead>
    <tbody>
    <?php
	$sub=0;
	while($row3 = mysqli_fetch_array($re3))
     {
	   $item = $row3['productname_tamil'];//.'('.$row3['productcode'].')';
	   $price= $row3['sale_prate'];
	   $qty = $row3['sale_eqty'];
       $gst_per = $row3['sale_gst'];
       $hsncode = $row3['hsn'];  
	    $salenetamt = $row3['salenetamt'];
		$subtot = $price*$qty;
	   ?>
      <tr>
        <td><?php echo $item;?></td>
       
       <td><?php echo $qty;?></td>
        <td><!--₹--><?php echo number_format($price,2,'.','');?></td>
        <td align="right"><!--₹--><?php echo number_format($subtot,2,'.','');?></td>
      </tr>
      <?php
	  $sub+=$subtot;
	  }
	  ?>
      
    </tbody>
  </table>

  <table class="totals">
    <tr>
      <td>Grand Total:</td>
      <td align="right">₹<?php echo number_format($sub,2,'.','');?></td>
    </tr>
   
  </table>

  <p class="center border-top">Thank you for your business!</p>
  <p class="center">Visit Again</p>


</body>
</html>
