<?php 
include "config.php";
error_reporting(0);
?>

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Bill</title></head>
<script>
  function escapekeypressed()
{
	//alert(event.keyCode);
	if(event.keyCode=='13'){ window.print(); }
}
</script>
<body onkeydown="escapekeypressed()" ontouchstart="window.print()">
<div style="margin-bottom:80px">
<div id="p1">
<center>
  <table border="3" width="760"  cellpadding="5" style="border-collapse:collapse;">
       <tr style="border-bottom:1pt solid black;">
       <td style="border-right:2pt solid black;" colspan="11"  >
     
       
  <table width="100%" >
  <!--<tr>
  <td  align="center" colspan="3"><span style="font-size:32px;"><strong>SHRI PANDIAN BLUE METAL</strong></span></td>
  </tr>-->
  <tr style="border:2px solid red">

      <td width="20%" align="left" style="padding-left:10px;padding-bottom:10px">
	 <img src="image/logo.png" style="float:left;margin-top:2px;" width="200px" height="130px">     </td>
     <td align="center" style="padding-bottom:10px">
	
     
     <span style="font-size:32px;"><strong>SIVA CRUSHER</strong></span><br>
     <font style="font-size:16px;">10/111,WEST STREET,SAMATHUVAPURAM,SAPTUR ROAD,KUDISERI VILLAGE,PERAIYUR TALUK,
     <!--</span>
      <span style="margin-left:20px;margin-top:100px;">--> MADURAI-625 705</span><br>
     <span style="margin-left:20px;margin-top:100px;"> <strong>Cell:7094448512</strong></span><br>
   </font>     </span> 
   
   <span style="margin-left:20px;margin-top:100px;"> </span>
     <!--<span style="margin-left:20px;margin-bottom:20px;"><b>GSTIN &nbsp;&nbsp;:33AFJFS7210Q1ZJ</b></span>-->   </font>
       </td>
 <td width="16%" align="center" >
         </td>
      </tr>
</table>
     <table border="0" width="100%">
      <tr>
      <td align="left"><b>E-mail : sivacrusher1@gmail.com</b></td>
      <td align="left"  valign="center" width="255"><B><b>GSTIN &nbsp;&nbsp;: 33AFJFS7210Q1ZJ</b></B></td>
      </tr>
      </table> 
  
       
      
      
       </td>
       </tr>
      <tr >
      <td colspan="5"  style="border-right:1pt solid black; border-bottom:1pt solid black;" valign="top" >
        <div align="left" style="border-radius:10px;border:2px solid black;padding:10px"><U><B><font size="3"></font><font size="3">TO</font></B></U>
        <?php 
 $salescodee=$_GET['print'];
 
 $table = $_GET['table'];
 $go=mysqli_query($connect,"select  * from $table where salescode ='$salescodee' && status !='deleted'&& status!='cancel'");
  while($dis=mysqli_fetch_array($go))
  {  
$datedb = $dis['date'];
	  $date=date_create($datedb);
$datedis=date_format($date,"d/m/Y");
  $customer= $dis['customer'];

$cus=mysqli_query($connect,"select * from customerdetails where  code = '$customer' && status!='deleted' ");
while($cusshow = mysqli_fetch_array($cus))
{
?><br>
 <?php echo $cusshow['name'] ?><br>
 <?php echo $cusshow['address'] ?><br>
 <?php echo $cusshow['district'] ?><br>
           <?php echo $cusshow['state'] ?>-<?php echo $cusshow['pincode'] ?><br><br>
           
          <b>Mobile No:<?php  echo $cusshow['mobile']?></b><b style="margin-left:150px;"><br>GST.No:<?php  echo $cusshow['gst']?> </b>
        </div></td>
      <td colspan="4" ><center>
      <div style="border:2pt solid black;padding-top:30px;padding-bottom:30px;border-radius:10px" >  <b><font size="6" style="text-transform: uppercase;"> <?php echo $dis['modeof'] ?></font></b><br><br>
      
      
      <span style="font-size:"> Invoice No:</span><span style="font-size:20px;font-weight:bold"><?php echo $salescodee ?></span><br>  <br>
        <span> Date :</span><?php echo  $datedis ?>/<?php echo  $dis['time'] ?><br></center></div> </td> 
      </tr>
         
        <?php 
  }}
        ?>
       
    <tr style="border-bottom:2pt solid black; border-top:2pt solid black;">
    <td width="5%" style="border-right:2pt solid black;" ><center><b>Sno.</b></center></td>
    <td width="50%" style="border-right:2pt solid black;" colspan="2"><center><b>Description of Goods</b></center></td>
    <td width="10%" style="border-right:2pt solid black;"><center><b>HSN</b></center></td>
   
    
    <td  width="17%" style="border-right:2pt solid black;"><center>
      <strong>Rate</strong>
    </center>
    </td>
    
    <td width="12%" style="border-right:2pt solid black;"><center>
      <strong>      Qty      </strong>
    </center>    </td>
    <td width="17%"   style="border-right:2pt solid black;"><center>
      <strong>Unit</strong>
    </center>
    
    </td>
    <td width="10%" style="border-right:2pt solid black;"><center>
      <b>Tax%</b>
    </center></td>
    <td width="12%"  style="border-right:2pt solid black;"><center>
      <b>Total</b>
    </center></td>
   
    
     
     <tr style="border-bottom:0pt solid white;">
      
     <?php 
$salescodee=$_GET['print'];
$table = $_GET['table'];
 $go=mysqli_query($connect,"select * from $table where salescode ='$salescodee' && status !='deleted'");
  while($dis=mysqli_fetch_array($go))
  {
   $product = $dis['product'];
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted' && productcode ='$product'");
while($cusshow = mysqli_fetch_array($cus))
{
  $price = $dis['price'];
  $qty = $dis['netqty'];
  $gst = $cusshow['tax'];
  $inclu = $price * 100 /( 100 + $gst);
  $sub = $inclu * $qty;
  $tax = (0.01*$gst*$sub);
    $count +=1;
 ?><br>
      <td  align="center" ><?php echo $count ?></td>
      <td colspan="2"><?php echo $dis['productname'] ?></td>
    
      <td  align="center"><?php echo $cusshow['hsn'] ?>
        </td>
      
      
      <td align="right"><?php echo number_format($inclu,"2",".","") ?></td>
      <td width="6%" align="right">
      <?php echo $dis['netqty'] ?>        </td>
      <td width="12%" align="right">
      <?php echo($cusshow['unit'])?>
        </td>
      
      <td  width="6%" align="right"><?php echo $gst ?>
        </td>
      
      <td style="border-right:2pt solid black;" align="right"><?php echo number_format(($sub),"2",".","") ?></td>
     </tr>
       <tr style="border-bottom:0pt solid white;"> 
       <?php 
  }}
    ?>
      <td  align="center" ></td>
      <td colspan="2"></td>
    
      <td  align="center">
        </td>
      
      
      <td align="right"></td>
      <td width="6%" align="right">
      
      <td width="12%" align="right">
     
        </td>
      
      <td  width="6%" align="right">      </td>
      
      <td style="border-right:2pt solid black;" align="right"></td>
     </tr>
        <tr style="border-bottom:0pt solid white;"> 

        <td  align="center" ></td>
      <td colspan="2"></td>
    
      <td  align="center">
        </td>
      
      
      <td align="right"></td>
      <td width="6%" align="right">
      
      <td width="12%" align="right">
     
        </td>
      
      <td  width="6%" align="right">      </td>
      
      <td style="border-right:2pt solid black;" align="right"></td>
     </tr>
    <tr style="border-bottom:0pt solid white;"> 

    <td  align="center" ></td>
      <td colspan="2"></td>
    
      <td  align="center">
        </td>
      
      
      <td align="right"></td>
      <td width="6%" align="right">
      
      <td width="12%" align="right">
     
        </td>
      
      <td  width="6%" align="right">      </td>
      
      <td style="border-right:2pt solid black;" align="right"></td>
     </tr>
  <tr style="border-bottom:0pt solid white;"> 

  <td  align="center" ></td>
      <td colspan="2"></td>
    
      <td  align="center">
        </td>
      
      
      <td align="right"></td>
      <td width="6%" align="right">
      
      <td width="12%" align="right">
     
        </td>
      
      <td  width="6%" align="right">      </td>
      
      <td style="border-right:2pt solid black;" align="right"></td>
     </tr>
     <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
<tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

    <td  align="center" ></td>
      <td colspan="2"></td>
    
      <td  align="center">
        </td>
      
      
      <td align="right"></td>
      <td width="6%" align="right">
      
      <td width="12%" align="right">
     
        </td>
      
      <td  width="6%" align="right">      </td>
      
      <td style="border-right:2pt solid black;" align="right"></td>
     </tr>
  <tr style="border-bottom:0pt solid white;"> 

  <td  align="center" ></td>
      <td colspan="2"></td>
    
      <td  align="center">
        </td>
      
      
      <td align="right"></td>
      <td width="6%" align="right">
      
      <td width="12%" align="right">
     
        </td>
      
      <td  width="6%" align="right">      </td>
      
      <td style="border-right:2pt solid black;" align="right"></td>
     </tr>
     <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
 <!--<tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>
<tr style="border-bottom:0pt solid white;"> 

<td  align="center" ></td>
  <td colspan="2"></td>

  <td  align="center">
    </td>
  
  
  <td align="right"></td>
  <td width="6%" align="right">
  
  <td width="12%" align="right">
 
    </td>
  
  <td  width="6%" align="right">      </td>
  
  <td style="border-right:2pt solid black;" align="right"></td>
 </tr>-->

    <?php
        function convertNumberToWord($number = false)
{
  
   $no = round($number);
   $point = round($number - $no, 2) * 100;
   $hundred = null;
   $digits_1 = strlen($no);
   $i = 0;
   $str = array();
   $words = array('0' => '', '1' => 'one', '2' => 'two',
    '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
    '7' => 'seven', '8' => 'eight', '9' => 'nine',
    '10' => 'ten', '11' => 'eleven', '12' => 'twelve',
    '13' => 'thirteen', '14' => 'fourteen',
    '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
    '18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
    '30' => 'thirty', '40' => 'forty', '50' => 'fifty',
    '60' => 'sixty', '70' => 'seventy',
    '80' => 'eighty', '90' => 'ninety');
   $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
   while ($i < $digits_1) {
     $divider = ($i == 2) ? 10 : 100;
     $number = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($number) {
        $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
	    $plural =null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($number < 21) ? $words[$number] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($number / 10) * 10]
            . " " . $words[$number % 10] . " "
            . $digits[$counter] . $plural . " " . $hundred;
     } else $str[] = null;
  }
  $str = array_reverse($str);
  $result = implode('', $str);
  $points = ($point) ?
    "." . $words[$point / 10] . " " . 
          $words[$point = $point % 10] : '';
  //echo $result . "Rupees  " . $points . " Paise";
    return  $result;
}
?>
<?php 
$salescodee=$_GET['print'];
$table = $_GET['table'];
 $go=mysqli_query($connect,"select * from $table where salescode='$salescodee' && status !='deleted'");
  while($dis=mysqli_fetch_array($go))
  {
    $product = $dis['product'];
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted' && productcode ='$product'");
while($cusshow = mysqli_fetch_array($cus))
{
	$customer= $dis['customer'];
$customer=mysqli_query($connect,"select * from customerdetails where  code = '$customer' && status!='deleted'");
while($customershow = mysqli_fetch_array($customer))
{
  $price = $dis['price'];
  $qty = $dis['netqty'];
  $gst = $cusshow['tax'];
  $inclu = $price * 100 /( 100 + $gst);
  $sub = $inclu * $qty;
  $tax = (0.01*$gst*$sub);
  $vehicle=$dis['vehicleno'];
  $delivery=$dis['delivery'];
    //$count +=1;
    $total=$price*$qty;
    $state_name = $customershow['state'];
    $state_lower_case=strtolower(preg_replace("/ /i","",$state_name));
 //echo $state_lower_case;
 ?>
  
    <tr style="border-top:2pt solid black;border-bottom:2pt solid black;">
    <!-- <td colspan="6" rowspan="4" align="left" valign="top" style="border-top:2pt solid black; font-size:18px;"><br> -->
        <!-- <strong>opening balance:  + Current Bill Amount:  = Total Pending:         </strong></p>--></td>
    <td colspan="8" align="right"style="border-right:2pt solid black"><b>Total Amount Before Tax</b></td><td style="border-right:2pt solid black;" colspan="" align="right">&nbsp;<?php echo number_format( ($sub),"2",".","")?></td>
    </tr>
    <br>
    <tr> 
    </tr>
    
    <tr style="border-top:1pt solid black;"> 
    <td colspan="5" rowspan="5" align="left" valign="top" style="border-top:1pt solid black;border-right:1pt solid black;"><strong>Account Details: </strong> 
    <table>
    <tr>
    <td>BANK NAME</td>
    <td>:HDFC BANK LTD</td>
    </tr>
    
    <tr>
    <td>A/C NUMBER</td>
    <td>:99954540000100</td>
    </tr>
    
    <tr>
    <td>IFSC CODE</td>
    <td>:HDFC0002409</td>
    </tr>
    <tr>
    <td>BRANCH</td>
    <td>:BY PASS ROAD ,MADURAI</td>
    </tr>
    
    </table>
    
    
       </td>
    <td colspan="3" align="right"><b>CGST <?php echo ($cusshow['tax']/2)."%" ?></b></td><td style="border-right:2pt solid black;" colspan="" align="right">&nbsp;<?php echo ($state_lower_case=="tamilnadu"?number_format( ($tax/2),"2",".",""):number_format(0,2,'.',''))?></td></tr>
    <tr> <td colspan="3" align="right"><b>SGST <?php echo ($cusshow['tax']/2)."%" ?></b></td><td style="border-right:2pt solid black;" colspan="" align="right">&nbsp;<?php echo ($state_lower_case=="tamilnadu")?number_format( ($tax/2),"2",".",""):number_format(0,2,'.','')?></td>
    </tr>
    <tr> <td colspan="3" align="right"><b>IGST <?php echo ($cusshow['tax'])."%" ?></b></td><td style="border-right:2pt solid black;" colspan="" align="right">&nbsp;<?php echo ($state_lower_case =="tamilnadu" ? number_format( 0,"2",".",""):number_format(($tax),2,'.',''))?></td>
    </tr>
	<tr> <td colspan="3" align="right"><b>Total Tax Amount </b></td><td style="border-right:2pt solid black;" colspan="" align="right">&nbsp;<?php echo number_format( ($tax),"2",".","")?></td>
    </tr>
    <tr> <td colspan="3" align="right"><b>Total Amount After Tax</b></td><td style="border-right:2pt solid black;" colspan="" align="right">&nbsp;<?php echo round(number_format( ($price * $qty),"2",".",""))?></td>
    </tr>
    <tr>
      <td colspan="9"><strong>Amount Chargeable (in words)Rupees</strong><strong>:&nbsp;&nbsp;<u><?php echo ucfirst(convertNumberToWord($total)).'rupees only'; ?></u></strong>
      </td>
    </tr>
    
     <tr style="border-bottom:2pt solid black;border-top:2pt solid black; ">
     
  

     
    </tr> 
     
    <tr style="border-bottom:2pt solid black;border-top:2pt solid black; ">
   <td colspan="4">
<b>Vehicle No:<?php echo $vehicle?></b><br>
<br>
<b>Delivery:<?php echo $delivery?></b>
<br><br>
<span style="float:right">Customer Signature</span>
   </td>
   <?php 
  }}}
    ?>
     <td style="border-right:2pt solid black;" colspan="8" align="right"  valign="top"><b><font size="4">FOR SIVA CRUSHER</font> </b><br />
 
 
<br />
<br>Authorized signature</td> 
   </table>
   <table width="760" style="border:2px solid black">
  <tr><th><center>For Emergeny Queries Contact - 7094448512</center></th></tr>
    </table>
   <table width="700">
    <tr><td><center> This is Computer Generated Invoice</center></td></tr>
    </table>
 
</div>
</div>
</body>
</html>