<?php 
include "config.php";
error_reporting(0);
date_default_timezone_set("Asia/Calcutta");
?>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Bill</title></head>
<script>
  function enterkeypressed()
{
	//alert(event.keyCode);
	if(event.keyCode=='13'){ window.print(); }
}
</script>
<body onkeydown="enterkeypressed()"><div style="margin-bottom:80px">
<div id="p1">
<center>
  <table border="3" width="760"  cellpadding="5" style="border-collapse:collapse;">
       <tr style="border-bottom:2pt solid black;">
       <td style="border-right:2pt solid black;" colspan="11"  >
     
       
  <table width="100%" >
  <tr>
  <td colspan="3" align="center"><span style="font-size:32px;"><strong>YOGA SAND AND STONES COMPANY</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="130px">
     </td>
     <td width="39%" align="left" style="padding-left:10px;padding-bottom:10px">
	
     <br><br>
      <span style="margin-left:20px;margin-bottom:20px;"><b><u>Office Address</u></b></span><br>
     <font style="margin-left:20px;font-size:16px;">No 520-9-3 Poriyalar Nagar,8th Street<br> <span style="margin-left:20px;">Kannendal,Madurai
     -625 014</span> <br>
     <span style="margin-left:20px;margin-top:100px;"> </span><br>
     <span style="margin-left:20px;margin-bottom:20px;"><b>GSTIN &nbsp;&nbsp;:33AACFY7179C1Z3</b></span>
   </font>

 <br>
</td>
<td width="41%"  align="left" style="padding-left:10px;padding-bottom:10px">
	 <span ><strong><font size="5dp"><span style="margin-left:10px;">&nbsp;</span></font></strong>
     <br>
     <span style="margin-left:20px;margin-bottom:20px;"><b><u>Crusher Address</u></b></span><br>
     <font style="margin-left:20px;font-size:16px;">No 4/5.1 Vadipatti,Kachakatti Main Road<br> <span style="margin-left:20px;">Thathampatti Village (P.o)
     </span> <br>
      <span style="margin-left:20px;margin-top:100px;"> Vadipatti (T.k),Madurai-625 218</span><br>
     <span style="margin-left:20px;margin-top:100px;"> Cell:7094430990/7094430994</span><br>
    
   </font>
</span>
     
     </td>


      <!-- <td width="16%" align="center" >
         </td> -->
   
      </tr>
</table>
<!-- <table border="0" width="100%">
<tr>
<td align="left"><b>E-mail : feenix@gmail.com</b></td>
<td align="left"  valign="center" width="255"><B><b>GSTIN &nbsp;&nbsp;: 33BMRPS7277P1ZT</b></B></td>
</tr>
</table> -->




</td>
</tr>

      <tr >
      <td colspan="5" rowspan="3" style="border-right:2pt solid black; border-bottom:2pt solid black;" valign="top" >
        <div align="left"><U><B><font size="3">Customer</font><font size="3"> Name & Address</font></B></U>
        <?php 

  $customer= $_GET['customer'];
  $sales = $_GET['sales'];
  $vehicle=$_GET['vehicle'];
  $delivery=$_GET['delivery'];
  $date_ori = $_GET['date'];
  $time_ori = $_GET['time'];
  $mode_trans = $_GET['modetrans'];
  $date_val = empty($date_ori) ? date_format(date_create(),"d-m-y") : date("d-m-Y", strtotime($date_ori));
$cus=mysqli_query($connect,"select *,CURTIME() as curtime from customerdetails where status !='deleted' && code = '$customer'");
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;">GST.No:<?php  echo $cusshow['gst']?> </b>
        </div></td>
      <td colspan="4" style="border-right:2pt solid black;"><center>
        <b><font size="6" style="text-transform: uppercase;"><b><font size="6" style="text-transform: uppercase;"><?php echo $mode_trans; ?></font></b>
      </center></td></tr>
         <td colspan="2">Invoice No.</td>:<td colspan="2" style="border-right:2pt solid black;"><?php echo $sales ?><br>  </td> 
         </tr>
         <!--<td colspan="2"><b>Bill Amount</b></td><td colspan="2" style="border-right:2pt solid black;">: <b  id="amd"></b> </td> </tr>-->    
        <tr><td colspan="2">Date.</td>:<td colspan="2"  style="border-right:2pt solid black;"><?php  echo $date_val ?><br><?php  echo empty($time_ori) ? $cusshow['curtime'] : $time_ori ?><br> </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 

 
    $product = $_GET['product'];
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted' && productcode='$product'");
while($cusshow = mysqli_fetch_array($cus))
{
  $price = $_GET['price'];
  $qty = $_GET['quantity'];
  $gst = $cusshow['tax'];
  $inclu = $price * 100 /( 100 + $gst);
  $sub = $inclu * $qty;
  $tax = (0.01*$gst*$sub);
    $count +=1;
 ?>
      <td  align="center" ><?php echo $count ?></td>
      <td colspan="2"><?php echo $cusshow['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 $_GET['quantity'] ?>        </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>

    <?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 

 
    $product = $_GET['product'];
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted' && productcode='$product'");
while($cusshow = mysqli_fetch_array($cus))
{
  $price = $_GET['price'];
  $qty = $_GET['quantity'];
  $gst = $cusshow['tax'];
  $inclu = $price * 100 /( 100 + $gst);
  $sub = $inclu * $qty;
  $tax = (0.01*$gst*$sub);
    //$count +=1;
    $total=$price*$qty;
     $customer= $_GET['customer'];
    $customer=mysqli_query($connect,"select * from customerdetails where  code = '$customer' && status!='deleted'");
while($customershow = mysqli_fetch_array($customer))
{

    $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>    </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>
    <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" >&nbsp;<b>Total Tax Amount</b></td><td align="right"><?php echo number_format( ($tax),"2",".","")?></td>
    <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>
    <?php 
  }}
    ?>
     <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>
<b>Delivery:<?php echo $delivery?></b>

   </td>
     <td style="border-right:2pt solid black;" colspan="8" align="right"  valign="top"><b><font size="4">FOR YOGA SAND AND STONES COMPANY</font> </b><br />
 
<br />
<br>Authorized signatory</td> 
   </table>
  
    <table width="760" style="border:2px solid black">
    <tr><th><center>For Emergeny Queries Contact - 7094430990/7094430994</center></th></tr>
    </table>
    <table width="700">
    <tr><td><center> This is Computer Generated Invoice</center></td></tr>
    </table>
</div>
</div>
</body>
</html>