<?php
session_start();
?>
<!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=utf-8" />
<title>Quotation</title>
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
	font-weight: bold;
	text-decoration:underline;
}
.style2 {
	font-family: Arial;
	font-size: 15px;
}
.style4 {
	font-size: 22px;
	font-weight: bold;
}
-->
</style>
</head>

<body><center>
<?php 
require_once("config.inc.php");
	require_once("DBConnector.php");
	$db = new DBConnector();
	?>
	<?php
    	$sql_s_quomas="SELECT * from s_quomas where REF_NO= '" . trim($_GET["invno"]) . "'  order by id";
			$result_s_quomas =$db->RunQuery($sql_s_quomas);
			$row_s_quomas = mysql_fetch_array($result_s_quomas);
   ?>
    
    <?php
    
			$sql_invpara="SELECT * from invpara";
			$result_invpara =$db->RunQuery($sql_invpara);
			$row_invpara = mysql_fetch_array($result_invpara);
			echo $_GET["CURRENT_USER"];

		   $txtrepono = $_GET["CURRENT_USER"] . " " . date("Y-m-d") . "  " . date("H:i:s");

$adress=$_GET["invdate"];
$cusname=$_GET["cus_name"];
	
	?>
<table width="922"  border="0" >
<tr>
 <img src='images/aas_Auto_Spare.png' style='width:922px;height:120px;'>
  </tr>

   
  <tr>
       <td colspan="6"></td>
     <td colspan="2" align="center"></td>
   
  </tr>
  <tr>
       <td colspan="6"></td>
     <td colspan="2" align="center"></td>
   
  </tr>
  <tr>
       <td colspan="6"></td>
     <td colspan="2" align="center"></td>
   
  </tr>
  <tr>
       <td colspan="6"></td>
     <td colspan="2" align="center"><b>Date : &nbsp
      <?php echo $_GET["invdate"]; ?></b></td>
   
  </tr>
    <tr style="margin-top: 200px;">
        <td colspan="3"><b>To :&nbsp  <?php echo $_GET["cus_name"]; ?></b></td>
     <td colspan="3"></td>
      <td colspan="3"  align="center"><b>Qu No:&nbsp<?php echo $_GET["invno"]; ?></b></td>
   
  </tr>
  <tr style="margin-top: 200px;">
        <td colspan="3"><b>Remark :&nbsp  <?php echo $row_s_quomas["REMARK"]; ?></b></td>
     <td colspan="3"></td> 
   
  </tr>

  
  
  <tr>
     
    <td height="64" colspan="7"><table border="0" cellpadding="0" cellspacing="0"><tr><td>
        
        
      <tr  bgcolor="#999999"> 
          <td width="260"><span class="style1">Part No</span></td>
        <td width="140" align="left"><span class="style1">Brand</span></td>
        <td width="400"><span class="style1">Description</span></td>
        <td width="100" align="right"><span class="style1">Qty</span></td>
        <td width="170" align="right"><span class="style1">PRICE</span></td>
        <td width="90" align="right"><span class="style1">Dis (%)</span></td>
        <td width="130" align="right"><span class="style1">Sub Total</span></td>
        </tr>
        </table>
       <table width="900" height="81" border="0" cellspacing="0"  height=200px;>
      <?php 
      
    
	  	$sql_rsPrInv="SELECT * from s_quotrn where REF_NO= '" . trim($_GET["invno"]) . "'  order by id";
		
		$totdis=0;
		$totsub=0;
		$totaldiscount=0;
    	$result_rsPrInv =$db->RunQuery($sql_rsPrInv);	
		while ($row_rsPrInv = mysql_fetch_array($result_rsPrInv)){
		    
		    $sql_1="SELECT * from s_mas where STK_NO='".$row_rsPrInv["STK_NO"]."' ";
		     
			$result_1 =$db->RunQuery($sql_1);
			$row_1 = mysql_fetch_array($result_1);
                        
                        $part ="";
                        $description = "";
                        $description1 = "";
			if($row_1["PART_NO"]=="PISTON RING SET"){
                           $description = $row_rsPrInv["DESCRIPT"];
			} else{
			    $part =$row_1["PART_NO"];
                            $description = $row_1["DESCRIPT"];
			}
                        $description1 =  str_pad($description, 40, "?");
                        $description1 = str_replace("?", "&nbsp;", $description1);
                        
                        $partNo1 =  str_pad($part, 15, "?");
                        $partNo1 = str_replace("?", "&nbsp;", $partNo1);

                        $brandName = $row_1["BRAND_NAME"];
                        $brandName1 =  str_pad($brandName, 22, "?");
                        $brandName1 = str_replace("?", "&nbsp;", $brandName1);
			
			echo "<tr height=\"30\"> 
			<td><span class=\"style2\">".$partNo1.''."</span></td>
			 <td align=\"left\"><span class=\"style2\">".$brandName1."</span></td>
			 <td><span class=\" style2\">".$description1."</span></td> 
			<td  align=\"right\"><span class=\"style2\">".number_format($row_rsPrInv["QTY"], 0, ".", ",")."</span></td>
			<td align=\"right\"><span class=\"style2\">".number_format($row_rsPrInv["PRICE"], 2, ".", ",")."</span></td>
			<td align=\"right\"><span class=\"style2\">".number_format($row_rsPrInv["DIS_per"], 2, ".", ",")."</span></td>";
			
			$dis=($row_rsPrInv["PRICE"]*$row_rsPrInv["QTY"])-($row_rsPrInv["PRICE"]*$row_rsPrInv["QTY"]*$row_rsPrInv["DIS_per"]/100);
			echo "<td align=\"right\"><span class=\"style2\">".number_format($dis, 2, ".", ",")."</span></td></tr>";
			
			$totdis=$totdis+$dis;
			$totaldiscount=$row_rsPrInv["PRICE"]*$row_rsPrInv["QTY"]*$row_rsPrInv["DIS_per"]/100;
		
		}
		$totsub=$totdis-($row_rsPrInv["PRICE"]*$row_rsPrInv["QTY"]*$row_rsPrInv["DIS_per"]/100);
		
		$tax=0;
		
		
// 		$final_total=0;
// 		if ((trim($_GET["tax"])!="") and ($_GET["tax"]>0) and ($_GET["tax"]!="0.00")){
// 			$tax=$totdis*$row_invpara["vatrate"]/100;
// 			echo "<tr><td colspan=5></td><td align=right><b>".number_format($totdis, 2, ".", ",")."</b></td></tr>";
// 			echo "<tr><td colspan=4></td><td>VAT ".$row_invpara["vatrate"]."%</td><td align=right><b>".number_format($tax, 2, ".", ",")."</b></td></tr>";
// 			$tot=$totdis+$tax;
// 			$final_total=$tot;
// 			echo "<tr><td colspan=5></td><td align=right><b><u>".number_format($tot, 2, ".", ",")."</u></b></td></tr>";
// 		}	else {
// 			echo "<tr><td colspan=5></td><td align=right><b><u>".number_format($totdis, 2, ".", ",")."</u></b></td></tr>";
// 			$final_total=$totdis;
// 		}
		
	   ?>
	    
	   </tr>
</td></tr></table></td>
    </table>
    <footer>
    <table style="table-layout: fixed;"  width="922"  valign="bottom">
    
  </tr>
  <td >
   <tr>
                    <td colspan="5" align="center"></td>
                    <td colspan="2" align="right" ><b>Sub Total</b></td>
                    <td colspan="1" style="padding-left:35px;"><u><?php echo number_format($totsub, 2, ".", ",") ?></u></td>
    </tr>
    <tr>
                    <td colspan="5" align="center"></td>
                    <td colspan="2" align="right" ><b>Discount</b></td>
                    <td colspan="1" style="padding-left:73px;"><?php echo number_format($totaldiscount, 2, ".", ",") ?></td>
    </tr>
    <tr>
                    <td colspan="5" align="center"></td>
                    <td colspan="2" align="right" ><b>Grand Total</b></td>
                    <td colspan="1" style="padding-left:35px;"><u><?php echo number_format($totdis, 2, ".", ",") ?></u></td>
    </tr>
    
    <tr>
                    <td colspan="1" align="left" ><b><u>Instructions </u></b></td>
                    <td colspan="5" align="left" ></td>
                    <td colspan="1" style="padding-left:100px;"></td>
    </tr>
    <tr>
                    <td colspan="5" align="left"><b>1) Credit Period &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp:&nbsp&nbsp<? echo $row_s_quomas["pay_type"]?></b></td>
                    <td colspan="1" align="left"  ></td>
                    <td colspan="1" ></td>
    </tr>
    <tr>
                    <td colspan="5" align="left"><b>2) Deliver Time &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp: &nbsp<? echo $row_s_quomas["delivery"]?></b></td>
                    <td colspan="1" align="right" ></td>
                    <td colspan="1" style="padding-left:100px;"></td>
    </tr><tr>
                    <td colspan="5" align="left"><b>3) Price Validity &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp:&nbsp&nbsp<? echo $row_s_quomas["validity"]?></b></td>
                    <td colspan="1" align="right" ></td>
                    <td colspan="1" style="padding-left:100px;"></td>
    </tr>
    <tr>
                    <td colspan="5" align="left"><b>4) Country of Origin :&nbsp&nbsp<? echo $row_s_quomas["Country"]?></b></td>
                    <td colspan="1" align="right" ></td>
                    <td colspan="1" style="padding-left:100px;"></td>
    </tr>
    
  <tr>
    <td height="94" colspan="2" valign="bottom" align="left">_______________________</td>
    <td colspan="2" valign="bottom" align="left">________________________</td>
    <td colspan="4" valign="bottom" align="center">Please fax or mail the signed price quote to</td>
  </tr>
  <tr>
    <td colspan="2"  align="left">Sales Person </td>
    <td colspan="2"  align="center">Marketing Manager</td>
    <td colspan="4"align="center">the address above customer Acceptance</td>
    
  </tr>
  <tr>
    <td height="50" colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td  colspan="8" align="center">If you have any questions about this price quote,please contact</td>
  </tr>
  <tr>
    <td  colspan="8" align="center"><i><b>Thank You For Your Business</b></i></td>
  </tr>
  </td>
    </table>
    </footer>
  
  






</body>
</html>
