<?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 company_info where name = '".$_REQUEST['our_company_name']."'";
$result2 = mysql_query($query2,$conn);	
while($row = mysql_fetch_array($result2))
{
$full_name_com = $row['full_name_com'];
}
?>
<?php												
$query2 = "select * from customer_master where customer_id = '".$_REQUEST['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'];

}
?>

<?php
$str = $_REQUEST['trans_inv_no'];
				$resultset = explode("/",$str);
				
			 $transport_name = current($resultset);
				
				?>
				
				<?php 
$query2tm = "select * from transport_master where short_form = '$transport_name'";
$result2tm = mysql_query($query2tm,$conn);	
while($row = mysql_fetch_array($result2tm))
{
$full_name = $row['transport_name'];
}
?><?php 
 $queryac = "select * from  tax_transtax where trans_inv_no='".$_REQUEST['trans_inv_no']."' and customer_id='".$_REQUEST['customer_id']."'";
$resultac = mysql_query($queryac,$conn);	
while($row = mysql_fetch_array($resultac))
{
$an_ac_of = $row['an_ac_of'];
$challan_id = $row['challan_id'];
$main_id = $row['main_id'];
$bstate_code=$row['bstate_code'];
$gst_inv_type=$row['gst_inv_type'];

}$query2c = "select * from main_job_details where main_id='$main_id'";
		                 				$result2c = mysql_query($query2c,$conn);	
										while($row = mysql_fetch_array($result2c)){
													 $main_job_no = $row['main_job_no'];
													 $main_id = $row['main_id'];
													 $ref_no=$row['ref_no'];
													 $account_of=$row['account_of'];
												}
												?>
<?php

$querytax = "select * from  transporter_details_expenses where trans_inv_no='".$_REQUEST['trans_inv_no']."' and inv_no = '".$_REQUEST['inv_no']."' and customer_id='".$_REQUEST['customer_id']."'";
		//echo $querytax;
		                 $resulttax = mysql_query($querytax,$conn);	
						  while($row=mysql_fetch_array($resulttax))
						  {
						  $customer_name_direct=$row['customer_name'];	
$address_direct = $row['address'];
$pan_no_direct = $row['pan_no'];

						  
						  }
						  
					


?>

<style type="text/css">
#printable { display: ; }
#footer {
    position : absolute;
    bottom : 0;
    
  }
    @media print
    {
    	#non-printable { display: none; }
    	#printable { display: block; }
    }
</style>
<style type="text/css">
<!--
.style1 {
	font-family: arial;
	font-size: 14px;
}
.style3 {font-size: 18px; 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; }
.style8 {font-size: 12px; line-height:150%;}
-->
</style>
</head><body>
 
<table width="100%" style="border-collapse:collapse">
<tr  class="non-printable"><td width="89%"><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="style10" >
        <input type="hidden" id="inv_no" name="inv_no" value="<? echo $_REQUEST['inv_no'] ?>" >
		<input type="hidden" id="Job_No" name="Job_No" value="<? echo $_REQUEST['Job_No'] ?>" >
			 			  <input type="hidden" id="trans_inv_date" name="trans_inv_date" value="<? echo $_REQUEST['trans_inv_date'] ?>" >
						   <input type="hidden" id="customer_id" name="customer_id" value="<? echo $_REQUEST['customer_id'] ?>" >
						   <input type="hidden" id="trans_inv_no" name="trans_inv_no" value="<? echo $_REQUEST['trans_inv_no'] ?>" >
						    <input type="hidden" id="our_company_name" name="our_company_name" value="<? echo $_REQUEST['our_company_name'] ?>" >
							    
        <div class="login-fields" id="non-printable" style="padding-left:5px;">
         <div class="field">
        			 <select name="space_01" id="space_01" class="login username-field input-small" required >
			<option>Select</option>
			<option value="<?php echo $_REQUEST['space_01']?>" selected="selected"><?php echo $_REQUEST['space_01']?></option>
			<option value="Null">Null</option>
			<option value="1">1</option>
			<option value="2">2</option>
    		<option value="3">3</option>
			<option value="4">4</option>
			</select>
			
			<input type="submit" value="Submit"></div></div></form></td>
	<td width="11%">
			
			 <div class="non-printable" id="non-printable" style="padding-left:10px;"><a href="index.php">Back to Dashbaord </a></div>
			
			</td></tr>
  <tr>
    <td colspan="2"><div align="center">
	<img src="header_bar_shigmoda.jpg"/>
	
	
    </div>
      <table width="100%" border="2"  style="border-collapse:collapse">
      
      <tr>
        <td width="204%" height="30" colspan="4" class="style1"><div align="center" class="style3">INVOICE</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;"><? if($customer_name_direct!='') { ?><? echo $customer_name_direct; ?> <? }else { ?><?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 if($address_direct!='') { ?>  <? echo $address_direct; ?> <? } else { ?><? if($billing_address_tax!=''){echo $billing_address_tax;}else { echo $billing_address; }
				}?></div></td>
              </tr>
              <tr>
                <td><div align="left" style="padding:3px;"><? if($pan_no_direct!='') { ?>PAN No <? } else { ?>GST No.<? } ?>: </div></td>
                <td><div align="left" style="padding:3px;"><? if($pan_no_direct!='') { ?> <? echo $pan_no_direct;?> <? } else { ?><? if($gst_no_tax!='') { echo $gst_no_tax; } else { ?><?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>
                </tr>
				
              <tr>
                <td><div align="left" style="padding:3px;">Bill Date </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $_REQUEST['trans_inv_date']?></div></td>
                </tr>
              <tr>
                <td><div align="left" style="padding:3px;">Ref. No.  </div></td>
                <td><div align="left" style="padding:3px;"><?php echo $ref_no;?></div></td>
                </tr>
				 <tr>
                <td><div align="left" style="padding:3px;">    </div></td>
                <td><div align="left" style="padding:3px;"> </div></td>
                </tr>
              
            </table></td>
          </tr>
        </table></td>
      </tr>
      
      <tr>
        <td colspan="4"><table width="100%"   style="border-collapse:collapse">
          <tr>
            <td width="8%" class="style4"><div align="left" style="padding:3px;"><span class="style4" style="font-family:Arial, Helvetica, sans-serif">A/C of </span></div></td>
            <td width="92%" class="style4"><div align="left" style="padding:3px;"><span class="style4" style="font-family:Arial, Helvetica, sans-serif"><? echo $account_of;?>
			</span></div></td>
          </tr>
 
        </table>
          </td>
      </tr>
      
      <tr>
        <td colspan="4" class="style1">
		
		<table width="100%" border="1" bordercolor="#000000" style="border-collapse:collapse">
          <tr>
            <td width="4%"><div align="left" class="style4">Sr No. </div></td>
            <td width="43%"><div align="center" class="style4">Particular</div></td>
            <td width="13%"><div align="center" class="style4">Vehicle no</div></td>
            <td width="10%"><div align="center" class="style4">Amount</div></td>
            </tr><?php
			  $i=1;
$querytax = "select * from  transporter_details_expenses where trans_inv_no='".$_REQUEST['trans_inv_no']."' and inv_no = '".$_REQUEST['inv_no']."' and customer_id='".$_REQUEST['customer_id']."'";
		//echo $querytax;
		                 $resulttax = mysql_query($querytax,$conn);	
						  while($row=mysql_fetch_array($resulttax))
	                                              	{
													
													$particular=$row['particular'];
													$vehicle_no=$row['vehicle_no'];
													$chargable_amount=$row['chargable_amount'];
													$challan_id=$row['challan_id'];
													
$query2 = "select * from  challan_master where challan_id='$challan_id'";
			//echo $query2;
$result2 = mysql_query($query2,$conn);	
while($row=mysql_fetch_array($result2))
	                                              	{
$consignor= $row['consignor'];
$consignee= $row['consignee'];
$consignee_gst_no= $row['consignee_gst_no'];
$from_consignor= $row['from_consignor'];
$to_consignor= $row['to_consignor'];
$vehicle_no = $row['vehicle_no'];
$articles_no= $row['articles_no'];
$challan_to= $row['challan_to'];
$weight= $row['weight'];
$freight= $row['freight'];
$transportations_service= $row['transportations_service'];
$loaded_export_import= $row['description'];
$charge_weight= $row['loaded_export_import'];
$container_no= $row['container_no'];
$paid= $row['paid'];
$transportation= $row['transportation'];
$loaded= $row['loaded'];
$container_no= $row['container_no'];
$seal_no= $row['seal_no'];
$destinations= $row['destinations'];
$shipping_agent= $row['shipping_agent'];
$booking_no= $row['booking_no'];
$in_time= $row['in_time'];
$out_time= $row['out_time'];
$receiver_signature_with_seal= $row['receiver_signature_with_seal'];
$delivery_at= $row['delivery_at'];
$description= $row['description'];	
	$date= $row['date'];
  $consignor_address= $row['consignor_address'];
  $consignee_addess= $row['consignee_addess'];
  $actual_weight=$row['actual_weight'];
$charged_weight=$row['charged_weight'];
$topay_freight=$row['topay_freight'];
$no_of_pkgs=$row['no_of_pkgs'];
$paid_freight=$row['paid_freight'];		
$challan_no=$row['challan_no'];	
$no_of_pkgs=$row['no_of_pkgs'];
$actual_weight=$row['actual_weight'];
$charged_weight=$row['charged_weight'];
$topay_freight=$row['topay_freight'];
$paid_freight=$row['paid_freight'];
$total_container_no=$row['total_container_no'];
$container_type=$row['container_type'];
$b_e_no=$row['b_e_no'];
$b_e_date=$row['b_e_date'];
$sb_no=$row['sb_no'];
$sb_date=$row['sb_date'];
$type_pkgs=$row['type_pkgs'];

  									}
		

    											?>
          
		<tr>
            <td width="4%"><div align="left" class="style4"><?php echo $i; $i++;?> </div></td>
            <td width="43%"><div align="left" class="style4"> <div align="left" style="padding:3px;"><?php echo $particular;?> </div> <div align="left" style="padding:3px;"> 	</div> Container No : <?php echo $container_no?>, &nbsp;&nbsp;&nbsp;Type :<?php echo $container_type;?>, No Pkgs. <? echo $no_of_pkgs;?> <? echo $type_pkgs;?>, Weight : <?php echo $charged_weight;?>  </div>
               <div align="left" style="padding:3px;">B/E No./ SB No. :<?php echo $b_e_no;?> <?php echo $sb_no;?> Dt. <?php echo $b_e_date;?> <?php echo $sb_date;?> </div></td>
            <td width="13%"><div align="center" class="style4"><?php echo $vehicle_no;?></div></td>
            <td width="10%"><div align="center" class="style4"><?php echo $chargable_amount; $totalamt+=$chargable_amount;?></div></td>
            </tr>
			<? } ?>
			
			<tr height="40"><td colspan="2"> <? if($gst_inv_type=='RCM') {?><span class="style22" style="padding:3px; font-size:14px;"align="left" ><strong>GST Tax Payable by : Consignor/Consignee </strong></span><? } ?></td></td><td><? if($gst_inv_type=='GST') {?><div class="style22" align="right"  style="padding:3px;"><strong> Basic Amt</strong></div> <? }?></td> 
					<td><? if($gst_inv_type=='GST') {?><div class="style22"  align="center">
				    <? echo $totalamt;?>
					</div><? }?></td>
					</tr>	

          <? if($gst_inv_type=='GST') {?>
		  
		 <?php  $CGST='9'; $SGST='9';$IGST='18';
		 ?>
		  <tr height="40"><td colspan="3"><div class="style22" align="right"><strong>CGST</strong></div></td> 
					<td><div class="style22"  align="center">
				    <?  if($bstate_code =='27'){ $cgstvalue = $totalamt*$CGST/100; echo round($cgstvalue,0);  $sumcgst+=$cgstvalue; }?>
					</div></td>
					</tr>	
					<tr height="40"><td colspan="3"><div class="style22" align="right"><strong>SGST</strong></div></td> 
					<td><div class="style22"  align="center">
				    <? if($bstate_code =='27'){ $sgstvalue = $totalamt*$SGST/100; echo round($sgstvalue,0);  $sumsgst+=$sgstvalue; } ?>
					</div></td>
					</tr>
					<tr height="40"><td colspan="3"><div class="style22" align="right"><strong>IGST</strong></div></td> 
					<td><div class="style23"  align="center"><? if($bstate_code !='27'){ $igstvalue = $totalamt*$IGST/100; echo round($igstvalue,0);  $sumigst+=$igstvalue; } ?></div></td>
					</tr>	
							<tr height="40"><td colspan="3"><div class="style22" align="right"><strong>Tax Amount</strong></div></td> 
							<td><div class="style22"  align="center">
						    <?  $gstamt = $cgstvalue+$sgstvalue+$igstvalue; echo round($gstamt,0);  ?>
							</div></td>
							</tr>	
							
		  
		  <? } ?>
			
           <tr height="40">
            <td colspan="2"><div align="left" class="style6" style="padding:2px;"> Amount Chargeable (in words) Rupeess:
		      <? 
   $no = round($totalamt+$gstamt);
      $point = round(($totalamt+$gstamt) - $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><div align="right" style="padding:5px;"><b>Total Amount </b></div></td>
            <td><div align="center" style="padding:5px;"><b><?php echo $totalamt+$gstamt;?></b></td>
          </tr>
        </table>
		
		
		</td>
      </tr>
	  
	  
     
	
      <tr>
        <td colspan="4" class="style1"><table width="100%" style="border-collapse:collapse">
          <tr>
            <td width="70%" valign="top"><span class="style8">1) Payment should be made with in 15 Days from Invoice submission<br />
              2) Interest will be charged @24% in the invoice if not paid with in 80 days after Ipreparation.<br />
             
              3) Subject to Thane Jurisdication only</span><br />
			  <?php if($transport_name=='SMCL') {?><b>PAN No : AFKPC9808D </b><? } ?></td>
            <td width="30%" valign="top"><div align="right" style="padding:2px; text-transform:uppercase">For <?php echo $full_name?> <BR /><BR /><BR /></div><div align="right" style="padding:2px;"> Authorised Signatory </div></td>
          </tr>
        </table></td>
      </tr>
    </table></td></tr>
</table>

<?php 


//$query3fa="update export_job_main_01 set trans_inv_noEdit ='DONE' where trans_inv_no = '".$_REQUEST['trans_inv_no']."' AND customer_id = '".$_REQUEST['customer_id']."'";
//$r3fa=mysql_query($query3fa,$conn);

//echo $query2fa;
?>

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

</html>