<?php  
$PageSecurity = 3;
 include ('includes/session.inc');
  include ('includes/function_lib.php');
 global $db;
$sql="Select * from invoice where invoice_id='".$_REQUEST['InvoiceId']."'";
$result=DB_query($sql,$db);
$myrow=DB_fetch_array($result);

function number_to_words ($x)
{
	  $nwords = array("","One","Two","Three","Four","Five","Six", 
                  "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", 
                  "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen", 
                  "Nineteen", "Twenty", 30 => "Thirty", 40 => "Fourty",
                     50 => "Fifty", 60 => "Sixty", 70 => "Seventy", 80 => "Eigthy",
                     90 => "Ninety" );

     if(!is_numeric($x))
     {
         $w = '#';
     }else if(fmod($x, 1) != 0)
     {
         $w = '#';
     }else{
         if($x < 0)
         {
             $w = 'minus ';
             $x = -$x;
         }else{
             $w = '';
         }
         if($x < 21)
         {
             $w .= $nwords[$x];
         }else if($x < 100)
         {
             $w .= $nwords[10 * floor($x/10)];
             $r = fmod($x, 10);
             if($r > 0)
             {
                 $w .= ' '. $nwords[$r];
             }
         } else if($x < 1000)
         {
                
                $w .= $nwords[floor($x/100)] .' Hundred';
             $r = fmod($x, 100);
             if($r > 0)
             {
                 $w .= ' '. number_to_words($r);
             }
         } else if($x < 100000)
         {
                $w .= number_to_words(floor($x/1000)) .' Thousand';
             $r = fmod($x, 1000);
             if($r > 0)
             {
                 $w .= ' ';
                 if($r < 100)
                 {
                     $w .= ' ';
                 }
                 $w .= number_to_words($r);
             }
         } 
         
         
         
         else if($x < 1000000)
         {
                $w .= number_to_words(floor($x/100000)) .' Lakh';
             $r = fmod($x, 100000);
             if($r > 0)
             {
                 $w .= ' ';
                 if($r < 100)
                 {
                     $w .= ' ';
                 }
                 $w .= number_to_words($r);
             }
         }
         
         
         else {
             $w .= number_to_words(floor($x/1000000)) .' Million';
             $r = fmod($x, 1000000);
             if($r > 0)
             {
                 $w .= ' ';
                 if($r < 100)
                 {
                     $word .= ' ';
                 }
                 $w .= number_to_words($r);
             }
         }
     }
     return $w;
     }

function convertDate($Dt)
{
	$dateBRK=explode('-',$Dt);
	$newFormat=$dateBRK[2]."/".$dateBRK[1]."/".$dateBRK[0];
	return $newFormat;
}

function convertTime($time,$period)
{
	$timeBRK=explode(':',$time);
	if($period=='PM' && $timeBRK[0]!='12')
	{
		$time=$timeBRK[0]+12;
	}
	else 
	{
		$time=$timeBRK[0];
	}
	return $time.":".$timeBRK[1];
}
?>
<style>
body{font-family:Arial, Helvetica, sans-serif;}
	.caps
	{
		text-transform: uppercase;
	}
</style>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
	
       var e = document.getElementById(id);
	       e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
</script>
<p align="right">
<?php 
if($_REQUEST['ver']=='Buyer'){echo "<b><span style='font-size:22px;'>Original For Buyer</span></b>";}
if($_REQUEST['ver']=='Transporter'){echo "<b><span style='font-size:22px;'>Duplicate For Transporter</span></b>";}
if($_REQUEST['ver']=='Assessee'){echo "<b><span style='font-size:22px;'>Triplicate For Assessee</span></b>";}
if($_REQUEST['ver']=='Quarduplicate'){echo "<b><span style='font-size:22px;'>Quarduplicate</span></b>";}
?>	
</p>
<?php 
	if($_REQUEST['ver']!=''){$width='1100px';}else{$width='800px';}
	?>
<!-- <h2 align="center"><?php echo $myrow['invoiceType']?> INVOICE</h2> -->
<table align="center" border="0" width="100%" cellpadding="0" cellspacing="0" style="width:<?php echo $width;?>">
	<tr>
    	<td width="15%"><img src="css/professional/images/webtech_logo.jpg" width="200" height="75" /></td>
    	<td width="70%"><table border="0" align="center" width="90%">
    	  <tr>
    	    <td class="caps"><div align="center" style="font-size:28px; font-weight:bold;"><?php echo $myrow['invoiceType']?> - INVOICE</div></td>
  	    </tr>
    	  <tr>
    	    <td><div align="center">(Under Rule 11 of Central Excise Rules, 2002)</div></td>
  	    </tr>
  	  </table></td>
<td width="15%">&nbsp;</td>
	</tr>
<tr>
    <td colspan="3" align="right">
    	<table align="right" border="0">
    <tr>
      <td><strong>Serial No.</strong>: </td><td>&nbsp;</td><td style="font-size:22px;"><b><?php echo $myrow['invoiceNo']?></b> </td></tr></table>
     </td>
</tr>
</table>
<!-- <h4 align="center">(Under Rule 11 of Central Excise Rules, 2002)</h4> -->
<form action="" method="post">
	
<table width="100%" height="1147" border="0" align="center" cellpadding="0" cellspacing="0" style="border:2px solid #000;width:<?php echo $width;?>">
<tr>
<td colspan="2">
	<table width="100%" border="0" style="border-bottom:1px solid #000;" align="center" cellpadding="0" cellspacing="0">
    <tr>
	<td valign="top" width="43%" style="border-right:1px solid #000;">
		<table border="0" width="100%">
       <tr><td>
       	<?php $branchAddress=DB_query("Select * from locations where prefix='".$myrow['branch_name']."'",$db);
       	$branchAddressResult=DB_fetch_array($branchAddress);
       	?>
       <font face="Verdana, Geneva, sans-serif"><strong><span style="font-size:20px;"> WEBTECH PACKAGING(I) PVT. LTD.</span> </strong></font></td></tr>
       <tr><td><font size="3px"><?php echo $branchAddressResult['deladd1'].', '.$branchAddressResult['deladd2'];?></font></td></tr>
       <tr><td><font size="3px"><?php echo $cityName=$s->getField('city_master','id',$branchAddressResult['city'],'city');?></font></td></tr>
       <tr><td><font size="3px"><?php echo $stateName=$s->getField('state_master','id',$branchAddressResult['state'],'state').' - '.$branchAddressResult['pincode'];?></font></td></tr>
       <tr><td><font size="3px">E-mail : <?php echo $branchAddressResult['email'];?></font></td></tr>
       <tr><td><font size="3px">Ph. :<?php echo $branchAddressResult['phone1'].', '.$branchAddressResult['phone2'];?></font></td></tr>
    </table>
	</td>
    <td width="57%" valign="top">
		<table border="0" width="100%">
       <tr>
       <td colspan="4"><strong>CONSIGNEE</strong></td></tr>
       <?php 
      // echo "Select * from clientmaster where id='".$myrow['client_id']."'";
	  $clientSql=DB_query("Select * from clientmaster where id='".$myrow['client_id']."'",$db);
	  $clientResult=DB_fetch_array($clientSql);
	  $countryName=$s->getField('country_master','id',$clientResult['pre_country'],'country');
		$stateName=$s->getField('state_master','id',$clientResult['pre_state'],'state');
		$cityName=$s->getField('city_master','id',$clientResult['pre_city'],'city');
	   ?>
       <tr>
       <td width="18%"><strong>Name </strong></td>
       <td width="41%"><font size="2px"><strong>: <?php echo $clientResult['c_name'];?></strong></font></td>
       <td width="21%"><strong>Dt. Of Issue </strong></td>
       <td width="20%"><font size="2px"><strong>:</strong> <?php echo convertDate($myrow['invoiceDate']);?></font></td>
       
       </tr>
		<tr>
       <td><strong>Address</strong></td>
       <td><font size="2px"><strong>:</strong> <?php echo $clientResult['pre_address1'];?></font></td>
       <td><strong>Time Of Issue</strong></td>
       <td><font size="2px"><strong>:</strong> <?php echo convertTime($myrow['invoiceTime'],$myrow['invoiceAMPM']);?>  </font></td>
       
       </tr>
       <tr>
       	<td>&nbsp;</td>
       <td><font size="2px"><strong>:</strong> <?php echo $clientResult['pre_address2'];?></font></td>
       <td><strong>Removal Date</strong></td>
       <td><font size="2px"><strong>:</strong> <?php echo convertDate($myrow['removalDate']);?></font></td>
       
      
       </tr>
       <tr>
         <td>&nbsp;</td>
         <td><font size="2px"><strong>:</strong> <?php echo $cityName.",".$stateName;?></font></td>
         <td><strong>Removal Time</strong></td>
         <td><font size="2px"><strong>:</strong> <?php echo convertTime($myrow['removalTime'],$myrow['removalAMPM']);?></font></td>
       </tr>
       <tr>
       	<td nowrap="nowrap"><strong>LST/CST No. </strong></td>
         <td><font size="2px"><strong>:</strong> <?php echo $clientResult['lst_no']." ".$clientResult['cst_no'];?></font></td>
       <td><strong>GR No. </strong></td>
       <td><font size="2px"><strong>:</strong> <?php echo $myrow['grNo'];?></font></td>
       
       
       </tr>
       <tr>
        <td><strong>Tin </strong></td>
         <td><font size="2px"><strong>:</strong> <?php echo $clientResult['tin_no'];?></font></td>
         <td><strong>GR Date </strong></td>
       <td><font size="2px"><strong>:</strong> <?php echo convertDate($myrow['grDate']);?></font></td>
         
       </tr>
       <tr>
          <td><strong>ECC No. </strong></td>
         <td><font size="2px"><strong>:</strong> <?php echo $clientResult['excies_no'];?></font></td>
         <td><strong>Carrier </strong></td>
         <td nowrap="nowrap"><font size="2px"><strong>: </strong>
             <?php 
         echo $transporterName=$s->getField('suppliers','id',$myrow['transporter'],'vendor_name');
         //$myrow['transporter'];?>
         </font></td>
         </tr>
         
       <tr>
          <td><strong>Ph. No. </strong></td>
         <td><font size="2px"><strong>:</strong> <?php echo $clientResult['pre_phone1'];?></font></td>
         <td><strong>Documents Through</strong></td>
         <td nowrap="nowrap"><font size="2px"><strong>:</strong> <?php echo $myrow['dispatchThrough'];?></font></td>
       </tr>

       <tr>
         <td><strong>Fax No. </strong></td>
         <td><font size="2px"><strong>:</strong> <?php echo $clientResult['fax'];?></font></td>
         <td><strong>Contact </strong></td>
         <td><strong>: &nbsp;</strong></td>
       </tr>
       
    </table>
    </td>
    </tr>
	</table>
    </td>
    </tr>
<tr>
	<td valign="top" style="border-right:1px solid #000; border-bottom:1px solid #000;">
    	<table width="100%" cellspacing="1">
		<tr>
		<td width="30%"><strong>LST No. </strong></td>
		<td width="70%"><font size="2px">: <?php echo $branchAddressResult['lst_cst'];?></font></td>
		</tr>
		<tr>
		<td><strong>Tin</strong></td>
		<td><font size="2px">: <?php echo $branchAddressResult['tin_no'];?></font></td>
		</tr>
		<tr>
		<td><strong>C.E. Regn No.</strong></td>
		<td><font size="2px">: <?php echo $branchAddressResult['ce_regn_no'];?></font></td>
		</tr>
		<tr>
		<td><strong>Range</strong></td>
		<td><font size="2px">: <?php echo $branchAddressResult['site_range'];?></font></td>
		</tr>
		<tr>
		<td><strong>Division</strong></td>
		<td><font size="2px">: <?php echo $branchAddressResult['division'];?></font></td>
		</tr>
		</table>
     </td>
     <td width="50%" valign="top" style="border-bottom:1px solid #000;">
     	<table width="100%" cellspacing="1">
     	<tr>
     	  <td><div align="center"><strong>Pre-Authenticated by:</strong></div></td></tr>
        <tr>
          <td><div align="center"><strong>For WEBTECH PACKAGING(I) PVT. LTD.</strong></div></td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
          <td><div align="center"><strong>Sign. of Director/Auth. Signatory</strong></div></td></tr>
     </table>
     </td>
 </tr>

<tr>
    <td height="170" colspan="2" style="border-bottom:1px solid #000;">
    	<table width="100%" height="152" border="0" cellpadding="3" cellspacing="0">
		<tr>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>S. No</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>Item Code<br />1</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>Description<br />
          2</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>P.o. No.<br />3</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>No. and Description of pkg<br />4</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>Quantity</br>5</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>Unit<br />6</strong></td>
        <td align="center" style="border-right:1px solid #000; border-bottom:1px solid #000;"><strong>Rate per 1000<br />7</strong></td>
        <td align="center" style="border-bottom:1px solid #000;"><strong>Amount<br />8</strong></td>
        </tr>
        <?php
		$productDetails="Select * from invoice_details where invoiceid='".$_REQUEST['InvoiceId']."'";
		$productResult=DB_query($productDetails,$db);
		$i=0;
		$totalBox=0;
		
		while($productRow=DB_fetch_array($productResult)){
			$itemSql=DB_query("Select item_name, unit from item_master where StockID='".$productRow['ItemCode']."'",$db);
			$itemRow=DB_fetch_array($itemSql);
		?>
		<tr>
        <td height="36" style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php echo $i+1;?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php echo $productRow['ItemCode'];?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php echo $itemRow['item_name'];?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php 
		echo $s->getField('salesorder','id',$productRow['saleOrderNo'],'PORefNo');
		//echo $productRow['saleOrderNo'];?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php echo $productRow['PackageDesc'];?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php echo $productRow['Quantity'];?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php 
		echo $s->getField('unitsofmeasure','unitid',$itemRow['unit'],'unitname');
		//echo $itemRow['unit'];?></font></td>
        <td style="border-right:1px solid #000; border-bottom:1px solid #000;"><font size="2px"><?php echo $productRow['RatePerThousand'];?></font></td>
        <td style="border-bottom:1px solid #000;"><font size="2px"><?php echo $productRow['Amount'];?></font></td>
        </tr>
        <?php 
		$totalBox=$totalBox+$productRow['PackageDesc'];
		$i++;}
		if($i=='0'){
			$i=0;
		}
		else
			$i=$i;
		for($i;$i<14;$i++)
		{	//echo $i;
		 ?>
		<tr>
        <td height="28" style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td style="border-right:1px solid #000;">&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
        <?php }?>
	</table>	
    </td>
</tr>

<tr>
	<td colspan="2">
    <table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="28%"><strong>Total No. Of Boxes </strong></td>
<td width="26%"><font size="2px"><?php echo $totalBox;?></font></td>
<td width="21%">&nbsp;</td>
<td width="18%" style="border-right:1px solid #000;"><strong>Amount :  </strong></td>
<td width="7%"><font size="2px"><?php echo $myrow['totalDiscountedPrice'];?></font></td>
</tr>
<tr>
<td><strong>Serial No. Of debit entry in PLA </strong></td>
<td><font size="2px">
<?php 
$rate= $s->getField('excise_tax','id',$myrow['exciseDuty'],'def_rate');

$ExciseValue=$myrow['exciseValue'];
echo "B.E.D @ ".$rate."% = ".$ExciseValue;
//echo $myrow['exciseDuty'];?></font></td>
<td>&nbsp;</td>
<td style="border-right:1px solid #000;">Excise Duty<strong> :</strong></td>
<td><font size="2px"><?php $ECessValue=$myrow['ECessValue'];

$SAHCessValue=$myrow['SAHCessValue'];
$exciseValue=$ExciseValue+$ECessValue+$SAHCessValue;
echo $exciseValue.".00";
  ?></font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><font size="2px">
<?php
echo "EDU Cess @ 2.00% on B.E.D = ".$ECessValue;?></font></td>
<td><font size="2px"><?php echo $s->getField('form_type_master','id',$myrow['formType'],'form_name');?></font></td>
<td style="border-right:1px solid #000;">VAT/CST @ <?php 
$vat_cst_rate= $s->getField('sales_tax_master','salestax_id',$myrow['VatCst'],'taxrate');
//echo $vat_cst_rate;

$vatBrk=explode('.',$vat_cst_rate);

if($vatBrk[1]=='00')
{
	echo $vatBrk[0];
}
else
{
	echo $vat_cst_rate;
}
?>%<strong> :</strong></td>
<td><font size="2px"><?php echo $myrow['VatCstValue'];?></font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><font size="2px">
<?php 

echo "H.EDU.Cess @1.00% on B.E.D = ".$SAHCessValue;?></font></td>
<td>Total Sale Price With <?php if($myrow['formType']!=''){echo "CST";}else{echo "VAT";}?></td>
<td style="border-right:1px solid #000;"><strong>Total :</strong></td>
<td><font size="2px"><?php echo $TOTAL=$myrow['totalDiscountedPrice']+$exciseValue+$myrow['VatCstValue'];?></font></td>
</tr>
<tr>
<td><strong>Serial No. Of debit entry in RG-23</strong></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td style="border-right:1px solid #000;">Freight<strong> :</strong></td>
<td><font size="2px"><?php echo $myrow['freightValue'];?></font></td>
</tr>
<tr>
  <td><strong>Excise Duty in words</strong></td>
  <td><?php echo number_to_words($exciseValue)." Only";
  
 // echo $myrow['excise_duty_inwords']?></td>
  <td>&nbsp;</td>
  <td style="border-right:1px solid #000;"><strong>Grand Total :</strong></td>
  <td style="border-top:1px solid #000;"><strong><font size="2px">
  <?php 
  
  $gTotal=$myrow['totalDiscountedPrice']+$exciseValue+$myrow['VatCstValue']+$myrow['freightValue'];
  //echo $gTotal."<br>";
  $gTotalBrk=explode('.', $gTotal);
  
  if($gTotalBrk[1]<50)
  {
  	$grand=$gTotalBrk[0];
  }
  else if($gTotalBrk[1]>50 || $gTotalBrk[1]==50)
  {
  	$grand=$gTotalBrk[0]+1;
  }
  echo $grand.".00";
  
  ?></font></strong></td>
</tr>
<tr>
  <td><strong>Total in words</strong></td>
  <td nowrap="nowrap"><?php 
  echo number_to_words($grand)." Only";?></td>
  <td>&nbsp;</td>
  <td style="border-right:1px solid #000;">&nbsp;</td>
  <td>&nbsp;</td>
</tr>
</table>
	</td>
</tr>
<tr>
	<td colspan="2" style="border-bottom:1px solid #000; border-top:1px solid #000;">
    	<table width="100%" border="0">
<tr>
<td width="27%"><strong>Name of excisable commodity</strong></td>
<td width="26%">: <?php 
echo $s->getField('excisable_commodity_master','id',$myrow['excisableComm'],'commodityName');?></td>
<td width="15%"><strong>Tarrif Heading No.</strong></td>
<td width="32%">: <?php echo $s->getField('excisable_commodity_master','id',$myrow['excisableComm'],'tarrifHeading');?></td>
</tr>
</table>
    </td>
</tr>
<tr><td colspan="2" style="border-bottom:1px solid #000;"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
	<td width="58%">
    	<table width="100%" border="0">
<tr>
<td width="41%"><strong>Mode Of Transport : </strong><?php echo $myrow['transportMode'];?></td>
<td width="59%" rowspan="4"><p align="justify"><strong><font size="2px">Certified that the particulars given above are true <br />and the amount indicated above represents the <br />price actually charged and there is no flow of <br />additional consideration directly or indirectly from the buyer</font></strong></p></td>
</tr>
<tr>
<td>&nbsp;</td>

</tr>
<tr>
<td><strong>Motor Vehicle RG No. : </strong></td>

</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
	</td>
	<td width="42%" valign="top">
		<table width="100%">
        <tr>
          <td><font size="2px"><div align="center"><strong>For WEBTECH PACKAGING(I) PVT. LTD.</strong></div></font></td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr></tr>
        <tr>
          <td><div align="center"><strong>Director/Auth. Signatory</strong></div></td></tr>
        <tr></tr>
     </table>
    </td></tr></table></td>
</tr>
<tr>
	<td height="136" colspan="2">
    	<table width="100%" border="0">
 <?php 

 if($clientResult['payment_terms']!='1'){
$paymentDays=$s->getField('paymentterms','termsindicator',$clientResult['payment_terms'],'terms'); }
 else {
     {
     	echo $paymentDays=="0 Days";	
     }
 }
 ?>
<tr>
<td height="82"><font size="2px"><p>
  <strong>E. & O.E<br />
--Payment to be made within <?php echo $paymentDays;?> otherwise interest 18% P.A will be charged extra<br />
--Subject to Delhi Jurisdiction<br />
--The above supply is covered under National Insurance Co. Ltd. Policy No. _________ <br />
--Kindly intimate in case of any transits damage/loss within 7 days after receipt of material
  </strong></p></font>
</td>
<td width="35%"><strong><?php if($myrow['formNo']!=''){?>Form No : <?php echo $myrow['formNo'];}?></strong></td>
</tr>
</table>
    </td>
</tr>
</table>
<br>
<?php 
if($_REQUEST['ver']!=''){
?>
<div id="foo"><p align="center">
  <a href="#" onclick="javascript:toggle_visibility('foo');" >Print</a></p>
</div><?php } ?>

 
</form>