<?php include 'connection.php';?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Invoice</title>
<?php 
$query2 = "select * from  tax_servicetax where inv_no='".$_REQUEST['inv_no']."' and job_no= '".$_REQUEST['Job_No']."'";
			//echo $query2;
$result2 = mysql_query($query2,$conn);	
while($row=mysql_fetch_array($result2))
	                                              	{
$our_company_name = $row['our_company_name'];
$cha_name = $row['cha_name'];
$transport_req = $row['transport_req'];
$customer_id = $row['customer_id'];
$expoter_name = $row['expoter_name'];
$exporter_address = $row['exporter_address'];
$final_job_no=$row['final_job_no'];
$final_job_date = $row['final_job_date'];
$s_b_no = $row['s_b_no'];
$s_b_dt=$row['s_b_dt'];
$mbl_no=$row['mbl_no'];
$mbl_dt=$row['mbl_dt'];
$hbl_no = $row['hbl_no'];
$hbl_dt = $row['hbl_dt'];
$container_no=$row['container_no'];
$port_shipment_pod=$row['port_shipment_pod'];
$country = $row['country'];
$supply_inv_no=$row['supply_inv_no'];
$supply_inv_dt=$row['supply_inv_dt'];
$no_pkgs=$row['no_pkgs'];
$gross_wt = $row['gross_wt'];
$net_wt = $row['net_wt'];
$descrition_goods=$row['descrition_goods'];
$fit_vessel_no=$row['fit_vessel_no'];
$consignee=$row['consignee'];
$consignee_address=$row['consignee_address'];
$types_of_pkg=$row['types_of_pkg'];		
													}
													?>
													
<?php												
$query2 = "select * from customer_master where customer_id = '$customer_id'";
$result2 = mysql_query($query2,$conn);	
while($row = mysql_fetch_array($result2))
{
$billing_address = $row['billing_address'];
$bgst_no = $row['bgst_no'];
$customer_name = $row['customer_name'];
$bstate_code = $row['bstate_code'];

}
?>
<style type="text/css">
<!--
.style1 {
	font-family: arial;
	font-size: 12px;
}
.style3 {font-size: 14px; font-weight: bold; }
.style4 {font-size: 14px; padding:3px; font:Arial, Helvetica, sans-serif;}
.style6 {font-size: 13px; padding: 3px; font: Arial, Helvetica, sans-serif; font-weight: bold; }
-->
</style>
</head>

<body>

<table width="100%" style="border-collapse:collapse">
  <tr>
    <td><div align="center"><?php if($_REQUEST['our_company_name']=='Aashirvadh') {?>
	<img src="header_barA.jpg"/>
	<?php } ?>
	<?php if($_REQUEST['our_company_name']=='Threestar') {?>
	<img src="header_bar.jpg"/>
	<?php } ?>
	<?php if($_REQUEST['our_company_name']=='Vector') {?>
	<img src="header_barV.jpg"/>
	<?php } ?>
    </div>
      <table width="100%" border="1"  style="border-collapse:collapse">
      
      <tr>
        <td height="30" colspan="4" class="style1"><div align="center" class="style3">INVOICE CUM DEBIT NOTE </div></td>
      </tr>
      <tr>
        <td colspan="4" class="style1"><table width="100%"  style="border-collapse:collapse">
          
          <tr valign="top">
            <td width="48%"><table width="100%"   style="border-collapse:collapse">
              <tr>
                <td><div align="left" style="padding:3px;">M/S</div></td>
                <td><div align="left" style="padding:3px;"><?php echo $customer_name?></div></td>
              </tr>
              
              <tr>
                <td width="17%"><div align="left" style="padding:3px;">Add</div></td>
                <td width="83%"><div align="left" style="padding:3px;"><?php echo $billing_address?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;">GST No.: </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $bgst_no?></div></td>
              </tr>
            </table></td>
            <td width="52%"><table width="100%"   style="border-collapse:collapse">
              <tr>
                <td width="28%"><div align="left" style="padding:3px;">BILL NO. </div></td>
                <td width="36%"><div align="left" style="padding:3px;"><?php echo $_REQUEST['trans_inv_no']?></div></td>
                <td width="36%"><div align="left" style="padding:3px;">Date</div></td>
                <td width="72%"><div align="left" style="padding:3px;"><?php echo $_REQUEST['inv_date']?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;">Job No. </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $final_job_no?></div></td>
                <td><div align="left" style="padding:3px;">Date</div></td>
                <td><div align="left" style="padding:3px;"><?php echo $final_job_date?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;">MBL No.  </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $mbl_no?></div></td>
                <td width="36%"><div align="left" style="padding:3px;">Date</div></td>
                <td><div align="left" style="padding:3px;"><?php echo $mbl_dt?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;">HBL No.  </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $hbl_no?></div></td>
                <td><div align="left" style="padding:3px;">Date</div></td>
                <td><div align="left" style="padding:3px;"><?php echo $hbl_dt?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;">S/B No.  </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $s_b_no?></div></td>
                <td width="36%"><div align="left" style="padding:3px;">Date</div></td>
                <td><div align="left" style="padding:3px;"><?php echo $s_b_dt?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;">INV No. </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $supply_inv_no?></div></td>
                <td><div align="left" style="padding:3px;">Date</div></td>
                <td><div align="left" style="padding:3px;"><?php echo $supply_inv_dt?></div></td>
              </tr>
              

            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td width="48%" class="style1"><table width="100%" style="border-collapse:collapse">
          
          <tr>
            <td width="17%"><div align="left" style="padding:3px;">Vessal Name</div></td>
            <td width="83%"><div align="left" style="padding:3px;"><?php echo $fit_vessel_no?></div></td>
          </tr>
          <tr>
            <td><div align="left" style="padding:3px;">No. of Pkg. </div></td>
            <td><div align="left" style="padding:3px;"><?php echo $no_pkgs?></div></td>
          </tr>
          <tr>
            <td valign="top"><div align="left" style="padding:3px;">Gross Wt. </div></td>
            <td valign="top"><div align="left" style="padding:3px;"><?php echo $gross_wt?></div></td>
          </tr>
          <tr>
            <td><div align="left" style="padding:3px;">Net Wt. </div></td>
            <td><div align="left" style="padding:3px;"><?php echo $net_wt?></div></td>
          </tr>
          
          
        </table></td>
        <td width="52%" colspan="3" valign="top" class="style1"><table width="100%" style="border-collapse:collapse">
          <tr>
            <td width="25%"><div align="left" style="padding:3px;">Port: </div></td>
            <td width="75%"><div align="left" style="padding:3px;"><?php echo $port_shipment_pod?></div></td>
          </tr>
          <tr>
            <td><div align="left" style="padding:3px;">Country</div></td>
            <td><div align="left" style="padding:3px;"><?php echo $country?></div></td>
          </tr>
          <tr>
            <td><div align="left" style="padding:3px;">Bill for You </div></td>
            <td><div align="left" style="padding:3px;"><?php echo $bill_for_you?></div></td>
          </tr>
          <tr>
            <td><div align="left" style="padding:3px;">Assess Value </div></td>
            <td><div align="left" style="padding:3px;"><?php echo $ass_value?> &nbsp;&nbsp;&nbsp;</div></td>
          </tr>
          
        </table></td>
        </tr>
      <tr>
        <td colspan="4"><div align="left"  class="style4" style="font-family:Arial, Helvetica, sans-serif"><strong>Description : </strong><?php echo $descrition_goods?></div></td>
        </tr>
      <tr>
        <td colspan="4"><div align="left"  class="style4"  style="font-family:Arial, Helvetica, sans-serif"><strong>Container no.:</strong> <?php echo $cntr_no?></div></td>
      </tr>
      <tr>
        <td colspan="4" class="style1"><table width="100%" border="1" bordercolor="#D1D1D1" style="border-collapse:collapse">
          <tr>
            <td width="4%" rowspan="2"><div align="left" class="style4">Sr No. </div></td>
            <td colspan="3"><div align="center" class="style4">Particular</div></td>
            <td width="13%"><div align="center" class="style4">SAC/HSN</div></td>
            <td width="10%"><div align="center" class="style4">Expenses</div></td>
            <td width="5%"><div align="center" class="style4">TAX</div></td>
            <td colspan="2"><div align="center" class="style4">CGST</div></td>
            <td colspan="2"><div align="center" class="style4">SGST</div></td>
            <td colspan="2"><div align="center" class="style4">IGST</div></td>
          </tr>
          <tr>
            <td width="20%"><div align="left" style="padding:2px;">Rcpt No. </div></td>
            <td width="12%"><div align="left" style="padding:2px;">Rcpt Date </div></td>
            <td width="11%"><div align="left" style="padding:2px;">Rcpt Amt</div></td>
            <td><div align="left" style="padding:2px;"></div></td>
            <td><div align="center" style="padding:2px;">Amount</div></td>
            <td><div align="center" style="padding:2px;">Type</div></td>
            <td width="4%"><div align="center" style="padding:2px;">Per</div></td>
            <td width="4%"><div align="center" style="padding:2px;">Amt</div></td>
            <td width="4%"><div align="center" style="padding:2px;">Per</div></td>
            <td width="4%"><div align="center" style="padding:2px;">Amt</div></td>
            <td width="4%"><div align="center" style="padding:2px;">Per</div></td>
            <td width="5%"><div align="center" style="padding:2px;">Amt</div></td>
          </tr>
		<?php 
	  $i =1; 
	  $querytax = "select * from  job_services where job_no='".$_REQUEST['Job_No']."' and inv_no = '".$_REQUEST['inv_no']."' and transporter_bill='YES' ORDER BY job_service_no";
		//echo $querytax;
		                 $resulttax = mysql_query($querytax,$conn);	
						  while($row=mysql_fetch_array($resulttax))
	                                              	{
													$particular= $row['particular'];
													$paid_by_party = $row['paid_by_party'];
													$non_taxable = $row['non_taxable'];
													$taxable = $row['taxable'];
													$sumnon_taxable +=$non_taxable;
													$sumtaxable += $taxable;
													$sumpaid_by_party += $paid_by_party;
													$rcpt_no = $row['rcpt_no'];
													$rcpt_date = $row['rcpt_date'];
													$rcpt_amt = $row['rcpt_amt'];
													$services_name = $row['services_name'];
													$job_service_no = $row['job_service_no'];
													$CGST = $row['CGST_rate'];
													$SGST = $row['SGST_rate'];
													$IGST = $row['IGST_rate'];
													$HSN_code = $row['HSN_code'];
													$total_amt = $sumnon_taxable+$sumtaxable+$sumpaid_by_party;
													?> 
	<?php 
	$query21 = "select * from services_master where service_id ='$services_name'";
$result21 = mysql_query($query21,$conn);
while($row=mysql_fetch_array($result21))
{
$services_name = $row['services_name'];
}?>												

          <tr>
            <td rowspan="2"><div align="center" style="padding:2px;"><?php echo $i?></div></td>
            <td colspan="3"><div align="left" style="padding:2px;"><?php echo $services_name?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;"><?php echo $HSN_code?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;"><?php echo number_format($paid_by_party,2)?><?php echo number_format($taxable,2)?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;"><?php if($paid_by_party!='' and $paid_by_party!=' ') {echo "P"; } elseif($taxable!='' and $taxable!=' ') {echo "T"; } else {echo "NT"; }?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;"><?php if($bstate_code =='27' and $taxable!='' and $taxable!=' ') { echo $CGST; }?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;">
			<?php if($bstate_code =='27' and $taxable!='' and $taxable!=' ') { echo $taxcgstval = $taxable*$CGST/100; $sumCGST+=$taxcgstval;}?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;"><?php if($bstate_code =='27' and $taxable!='' and $taxable!=' ') { echo $SGST; }?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;">
			<?php if($bstate_code =='27' and $taxable!='' and $taxable!=' ') { echo $taxsgstval = $taxable*$SGST/100; $sumSGST+=$taxsgstval; }?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;"><?php if($bstate_code !='27' and $taxable!='' and $taxable!=' ') { echo $IGST; }?></div></td>
            <td rowspan="2"><div align="left" style="padding:2px;">
			<?php if($bstate_code !='27' and $taxable!='' and $taxable!=' ') { echo $taxigstval = $taxable*$IGST/100; $sumIGST+=$taxigstval;}?></div></td>
          </tr>
		
          <tr>
		    <?php if($rcpt_no!='' and $rcpt_no!=' ' ) {?>
            <td><div align="left" style="padding:2px;"><?php echo $rcpt_no?></div></td>
            <td><div align="left" style="padding:2px;"><?php echo $rcpt_date?></div></td>
            <td><div align="left" style="padding:2px;"><?php echo $rcpt_amt?></div></td><?php } ?>
          </tr>
         
          
          <?php $i++;} ?>
		  <tr>
            <td>&nbsp;</td>
            <td colspan="3"><div align="right" class="style4"><strong>Total Rs. </strong></div></td>
            <td>&nbsp;</td>
            <td><div align="left" class="style6"><?php echo number_format($total_amt,2)?></div></td>
            <td>&nbsp;</td>
            <td colspan="2"><div align="right" class="style6"><?php if($sumCGST!='') { echo number_format($sumCGST,2); }?></div></td>
            <td colspan="2"><div align="right" class="style6"><?php if($sumSGST!='') { echo number_format($sumSGST,2);}?></div></td>
            <td colspan="2"><div align="right" class="style6"><?php if($sumIGST!='') {echo number_format($sumIGST,2);}?></div></td>
            </tr>
		  <tr>
		    <td colspan="5"><div align="left" class="style6">(T : Taxble &nbsp;&nbsp;P: Pure Agent &nbsp;&nbsp;E: Exemption &nbsp;&nbsp;R: Reverse Charges) </div></td>
		    <td colspan="6"><div align="right" class="style6">Gross Total Rs.<br />Tax Payable On Reverse Charges  </div></td>
		    <td colspan="2"><div align="right" class="style6"><?php $grandtotal = $total_amt+$sumCGST+$sumSGST+$sumIGST; echo number_format($grandtotal,2);?></div></td>
		    </tr>
		  <tr>
		    <td colspan="5"><div align="left" class="style6" style="padding:2px;"> Amount Chargeable (in words) Rupeess:
		      <? 
   $no = round($grandtotal);
      $point = round($grandtotal - $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;
     $finaltotal = floor($no % $divider);
     $no = floor($no / $divider);
     $i += ($divider == 10) ? 1 : 2;
     if ($finaltotal) {
        $plural = (($counter = count($str)) && $finaltotal > 9) ? '' : null;
        $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
        $str [] = ($finaltotal < 21) ? $words[$finaltotal] .
            " " . $digits[$counter] . $plural . " " . $hundred
            :
            $words[floor($finaltotal / 10) * 10]
            . " " . $words[$finaltotal % 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=ucwords(strtolower($result)); "  "; ?>
		      only</div></td>
		    <td colspan="6"><div align="right" class="style6">Bill Total Rs.<br />
		    </div></td>
		    <td colspan="2"><div align="right" class="style6">
		      <?php $grandtotal = $total_amt+$sumCGST+$sumSGST+$sumIGST; echo number_format($grandtotal,2);
			  $taxamt = $sumCGST+$sumSGST+$sumIGST;
			  
			  ?>
		      </div></td>
		    </tr>
          
        </table></td>
      </tr>
	  
	  
     
	
      <tr>
        <td colspan="4" class="style1"><table width="100%" style="border-collapse:collapse">
          <tr>
            <td width="70%" valign="top">&nbsp;</td>
            <td width="30%" valign="top"><div align="left" style="padding:2px;">For THREESTAR SOLUTIONS &amp; SERVICES PVT LTD <BR /><BR /><BR /> Authorised Signatory </div></td>
          </tr>
        </table></td>
      </tr>
    </table></td></tr>
</table>

<?php 

$query1fa="update tax_servicetax set IGST_amt ='$sumIGST',CGST_amt='$sumCGST',SGST_amt='$sumSGST',total_gst_amt='$taxamt',gross_amt='$grandtotal' where inv_no = '".$_REQUEST['inv_no']."' AND customer_id = '".$_REQUEST['customer_id']."'";
$r1fa=mysql_query($query1fa,$conn);

?><div align="center" style="font-size:12px;">This is a Computer generated invoice, Signature is not required.</div>
</body>
</html>
