<?php session_start();
?>
<?php date_default_timezone_set('Asia/Colombo'); ?>
<!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>Print Quatation</title>
<style type="text/css">
<!--
.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style4 {
	font-size: 14px;
	font-weight: bold;
}
.style5 {
	font-size: 18px;
	font-weight: bold;
}
.style6 {
	font-size: 24px;
	font-weight: bold;
}
.style66 {
	font-size: 32px;
	font-weight: bold;
}
.style7 {font-size: 24px}

.style8 {
	font-size: 18px;
	font-weight: bold;
}

.style10 {
	font-size: 15px;
	font-weight: bold;
}
-->

</style>
</head>

<body><center>
<?php 
require_once("config.inc.php");
	require_once("DBConnector.php");
	$db = new DBConnector();
		
	 
		
		$copy="";
		
		$sql_invpara="SELECT * from invpara where COMCODE='".$_SESSION['company']."'";
		$result_invpara =$db->RunQuery($sql_invpara);
		$row_invpara = mysql_fetch_array($result_invpara);
		
		$sql="Select * from view_quomas_quotrn_s_mas where REF_NO='".$_GET["invno"]."'"; 
		
    	$result =$db->RunQuery($sql); 	
		$row = mysql_fetch_array($result);	
		
		$REMARK =$row["REMARK"];
        
	//echo $row["CANCELL"];
		if ($row["pirnt_serial"]=="0"){
			
			if ($row["CANCELL"]=="0"){	
			 
			}	else {
				$copy="Cancelled"; 
			}
			
		} else if ($row["pirnt_serial"]>0){
			
			if ($_SESSION['User_Type']=="0"){
				
				if ($row["CANCELL"]=="0"){	
					exit("Cannot Print Twice !!!");
				} else {
					exit("Canceled Invoice !!!");
					
				}	
			} else {
				if ($_SESSION['User_Type']=="1"){
					
					if ($row["CANCELL"]=="0"){	
						$copy="CP";
					} else {
						$copy="Cancelled"; 
					}
					
				 
				}
			}	
			
		} 
	
		$sql1="Select * from vendor where CODE='".$row["C_CODE"]."'";  
    	$result1 =$db->RunQuery($sql1);	
		$row1 = mysql_fetch_array($result1);	
		
		$sql_quo="Select * from s_quomas where REF_NO='".$row["REF_NO"]."'";  
    	$result_quo =$db->RunQuery($sql_quo);	
		$row_quo= mysql_fetch_array($result_quo);	
		
		$sql2="Select * from s_stomas where CODE='".$row["DEPARTMENT"]."'";
    	$result2 =$db->RunQuery($sql2);	
		$row2 = mysql_fetch_array($result2);
				
		$TXTDEP= $row2["DESCRIPTION"];
		$rtxtinvno= $row["invno"];
		$rtxtordno= $row["ORD_NO"]; 
		
		$sql2="Select * from s_salrep where REPCODE='".$row["SAL_EX"]."'";
    	$result2 =$db->RunQuery($sql2);	
		$row2 = mysql_fetch_array($result2);
		
		
			
			
			
		$rtxtrep = $row2["Name"];
		$rtxtSupCode= $row_quo["C_CODE"];
		$rtxtSupName=  $row_quo["C_CODE"]." ".$row_quo["CUS_NAME"];
		$txtadd1 = $row1["ADD1"];
		//$txtadd2 = $row1["ADD2"];
		$txtadd2 = $_GET["cus_address2"];
		$txtadd = $row1["ADD1"]."</br>".$row1["ADD2"];
		$rtxtdate=date("Y-m-d", strtotime($row["SDATE"]));
		$rtxttot = $row["GRAND_TOT"];
		
		
		$sql_salrep="Select * from s_salrep where REPCODE=".$row["SAL_EX"];
		$result_salrep =$db->RunQuery($sql_salrep);
		$row_salrep = mysql_fetch_array($result_salrep);
		
		$VAT_per=$row["VAT"];
		
    	
		$sql_para="Select * from invpara  where COMCODE='".$_SESSION['company']."'";
    	$result_para =$db->RunQuery($sql_para);	
		$row_para = mysql_fetch_array($result_para);

		if ($row["VAT"]=="1") {
    		//$txtcusvat= "Customer VAT  " . $row1["vatno"];
			$txtcusvat= "Customer VAT  " . $_GET["vat1"];
    		$txtcomvat= "VAT Reg. " . $row_para["VAT"];
			$RTXTVAT = "VAT ". intval($row["GST"])."%  ";
    		//$RTXVATAMU = $row["BTT"];
    		$txttaxinv = "<b>TAX INVOICE</b>";
    		$txtsubtot = $row["AMOUNT"];
    		$txtsubtotdes= "Sub Total";
		}
		
		if ($row["SVAT"]!="0") {
    		//$txtcusvat= "Customer VAT  " . $row1["vatno"];
			$txtcusvat= "Customer VAT  " . $_GET["vat1"];
    		$txtcomvat= "VAT Reg. " . $row_para["VAT"];
    		$RTXTVAT = "Suspended VAT ".intval($row["GST"])."%  ";
    		//$RTXVATAMU= $row["BTT"];
    		$txttaxinv= "<b>SUSPENDED TAX INVOICE</b>";
    		$txtsubtot= $row["AMOUNT"];
    		$txtsubtotdes = "Net Total";
    
    		$txtoursvat = "SVAT Reg. " . $row_para["svatno"];
    		//$txtcussavat= "Customer SVAT " . $row1["svatno"];
			$txtcussavat= "Customer SVAT " . $_GET["vat2"];
    
		}
                
                $sqloutinv = "select sum(GRAND_TOT-TOTPAY) as totout from view_s_salma where GRAND_TOT>TOTPAY and CANCELL='0' and C_CODE='".$row["C_CODE"]."'  ";
                
                $resultOut =$db->RunQuery($sqloutinv);	
                
                if ($rowoutinv = mysql_fetch_array($resultOut)){
                    if (is_null($rowoutinv["totout"])==false){
			$OutInvAmt=$rowoutinv["totout"]-$rtxttot;  
                    }
                }
                
                

	?>
    
<table width="1000"  border="0">
  <tr></tr>  
  <tr></tr>  
  <tr>
    <td height="50" colspan="3"><span class="style66"><?php echo $row_para["COMPANY"]; ?></span><br />
   <span class="style8">COMPLETE TEA MACHINERY SPARES UNDER ONE ROOF<?php 
   if ($_GET["vat"]=="true"){
   		echo "TAX INVOICE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$row_invpara["VAT"];
	} 
	
	 if ($_GET["svat"]=="true"){
		echo "SUSPENDED TAX INVOICE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$row_invpara["VAT"];
	} 	
	?></span>
    </td>
    <td colspan="4" align="center"><table width="500" border="0">
      <tr>
        <td width="402"><span class="style8"><?php echo $row_para["ADD1"].", ".$row_para["ADD2"]." ".$row_para["ADD3"]; ?></span></td>
      </tr>
      <tr>
        <td><span class="style8">TELE: <?php echo $row_para["TELE"]; ?></span></td>
      </tr>
        <tr>
            <td><span class="style8">EMAIL: <?php echo $row_para["EMAIL"]; ?></span></td>
        </tr>      
        <tr>
            <td><span class="style8">OUR VAT REG.NO : <?php echo $row_para["VAT"]; ?></span></td>
        </tr>     
        <tr>
            <td><span class="style8">&nbsp;</span></td>
        </tr>      
    </table></td>
  </tr>
  <tr>
        <td colspan="8">
           <B>Dear Sir,</B>
        </td>
    </tr>
    <tr>
        <td colspan="8">
            <B>Thank You For Your Inquiry.</B>
        </td>
    </tr>
  <tr>
    <td height="44" colspan="3" align="right"><span class="style6"><u>QUOTATION</u></span></td>
    <td width="55" height="44" align="center">&nbsp;</td>
    <!--<td width="171" align="left">Sales Ex : <?php echo $row_salrep["Name"]; ?></td>-->
    <!--<td width="80" align="right">Entered By: </td>-->
    <!--<td width="186"><?php echo $row["use_name"]; ?></td>-->
  </tr>
  <tr>
    <td height="110" colspan="3" valign="top"><table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0"><tr><td width="428"><table width="500" border="0" >
        <tr>
          <td width="91"><span class="style4">CUSTOMER</span></td>
          <td width="8"><strong>:</strong></td>
          <td width="443"><span class="style5"><?php  echo $rtxtSupName;  ?></span></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><?php  echo $txtadd1;  ?></td>
        </tr>
         
        <tr>
          <td height="21">&nbsp;</td>
          <td>&nbsp;</td>
          <td><?php 
         if (($row_quo["VAT"] == "1")  || ($row_quo["VAT"] == "2"))  {
             echo "Vat No : ";
		  	echo $row_quo["vat_no"]." ".$row_quo["svat_no"];
		  }
		  ?></td>
        </tr>
    </table></td></tr></table></td>
    <td colspan="4" valign="top"><table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0"><tr><td><table width="389" border="0">
      <tr>
        <td width="108"><span class="style4">O. NO</span></td>
        <td width="9">:</td>
        <td width="146"><span class="style8"><?php echo $row["REF_NO"]; ?></span></td>
        <td width="82"><span class="style4">O. DATE</span></td>
        <td width="12">:</td>
        <td width="201"><?php echo $row["SDATE"]; ?></td>
      </tr>
      <tr>
        <td height="50"><span class="style4" </span></td>
        <td> </td>
        <td><span class="style4"></span></td>
        <td><span class="style4"> </span></td>
        <td> </td> 
      </tr>
      
      
      
    </table></td></tr></table>
    <span class="style2">    </span></td>
  </tr>
</table>
<table width="1000" height="21" border="0" cellspacing="0">
    <!--  <tr  bgcolor="#999999">
        <td width="130" height="23"><span class="style1">STK No</span></td>
        <td width="295"><span class="style1">Description</span></td>
        <td width="158"><span class="style1">Rate</span></td>
        <td width="135"><span class="style1">Quantity</span></td>
        <td width="152"><span class="style1">Sub Total</span></td>
        </tr> -->
    <table border="2" bordercolor="#000000" width="900" style="margin-left: -80px;" cellpadding="3" cellspacing="1">
  <tr>
    <td width="100" align="left"><span class="style4">ITEM NO.</span></td>
    <td width="480" align="left"><span class="style4">DESCRIPTION</span></td>
    <td width="50" align="right"><span class="style4">QTY</span></td>
    <td width="120" align="right"><span class="style4">RATE</span></td>
    <td width="50" align="right"><span class="style4">DIS%</span></td>
     
    <td width="100" align="right"><span class="style4">AMOUNT</span></td>
  </tr>
  <?php 
	  	$i=1;
		$totsuntot=0;
		
	  	$sql1="Select * from s_quotrn where REF_NO='".$_GET["invno"]."' ";
    	$result1 =$db->RunQuery($sql1);
                
		while ($row1 = mysql_fetch_array($result1)){
			$sql_part="Select * from s_mas where STK_NO='".$row1["STK_NO"]."'";
    		$result_part =$db->RunQuery($sql_part);	
			$row_part = mysql_fetch_array($result_part);
			
// 			if (($row_quo["VAT"]=="1") or ($row_quo["VAT"]=="2")){
// 				$vatr=100+$row_quo["GST"];
// 				$PRICE=$row1["PRICE"]/$vatr*100;
// 			} else {
				$PRICE=$row1["PRICE"];
// 			}	
			
			
			
			$mprice = $discount1 = $PRICE * $row1["DIS_per"] / 100;
                                $mprice = $PRICE - $mprice;
		 
				echo "<tr><td><span width=100  class=\"style10\">".$row1["STK_NO"]."</span></td>
						<td><span width=500  class=\"style10\">".$row1["DESCRIPT"]."-".$row_part["BRAND_NAME"]."-".$row_part["SIZE"]."</span></td>
						<td align=\"right\"  width=50><span  class=\"style10\">".number_format($row1["QTY"], 0, ".", ",")."</span></td>
						<td  align=\"right\"  width=100><span  class=\"style10\">".number_format($mprice, 2, ".", ",")."</span></td>
						
						<td align=\"right\"  width=50><span  class=\"style10\">".floatval($row1["DIS_per"])."</span></td>";
			
					 $discount1 = $PRICE * $row1["QTY"] * $row1["DIS_per"] / 100;
                                $subtot = ($PRICE * $row1["QTY"]) - $discount1;
				echo "<td align=\"right\"  width=100><span  class=\"style10\">&nbsp;&nbsp;&nbsp;&nbsp;".number_format($subtot, 2, ".", ",")."</span></td>";
			
			
				//echo "<td align=\"right\"><span class=\"style\"></span></td>";
			//}
			echo "</tr>";
			$totsuntot=$totsuntot+$subtot;
			$i=$i+1;
		}
                echo "</table>";
	  
	   
 
	  	while ($i<7){
			echo "<tr><td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td></tr>";
			$i=$i+1;
		}
	   ?>
      
     
</table>
<table width="1000" border="0">
    	
 
  <tr>
    <td colspan="4">
    <?php
	if ($_GET["svat"]=="true"){
		echo "Our SVAT No : ".$row_invpara["svatno"];
	}
	?>    </td>
    <td width="105"></td>
    <td width="51">&nbsp;</td>
    <td width="144" align="right"></td>
    <td width="288" align="right">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">
    <?php
	if ($_GET["svat"]=="true"){
		echo "Your SVAT No : ".$_GET["vat2"];
	}
	?>    </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
  </tr>
  <tr>
    <td width="80">&nbsp;</td>
    <td colspan="3"><span class="style6"></span></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>
    <?php
    if ($_GET["vat"]=="true") {
		echo "VAT ". intval($row["GST"])."%"; 
	}
	if ($_GET["svat"]=="true"){
		echo "SVAT ".intval($row["GST"])."%"; 
	}
	
	?>    </td>
    <td align="right"><table width="250" border="0">
      <tr>
        <td width="175" align="right"><?php
    if (($_GET["vat"]=="true") or ($_GET["svat"]=="true")){
		echo $_GET["tax"];
	}
	
	?></td>
        <td width="66">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
     
   
    <tr>
        <td colspan="7" align="right">
            <?php if ($row["DISCOU"]>0){?>
            <b>(Total Discount Given: <?php echo number_format($row["DISCOU"], 2, ".", ","); ?>)</b>
            <?php }?>
        </td>
    </tr>
    <tr>
        <td colspan="8">
            ALWAYS AT YOUR SERVICE
        </td>
    </tr>
    <tr>
        <td colspan="8">
            &nbsp;
        </td>
    </tr> 
    
    <tr>
   
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
     <td>&nbsp;</td>
    <td></td>
    <td align="right">&nbsp;</td>
    <td align="right"><b>
      <span class="style7">      </span></b>
      <table width="300" border="0">
        <tr>
          <td width="200" align="right"><b><span class="style5">
            <?php
    if ($row_quo["VAT"]=="1") {
		echo "VAT ". intval($row_quo["GST"])."%"; 
	}
	if ($row_quo["VAT"]=="2"){
		echo "SVAT ".intval($row_quo["GST"])."%"; 
	}
	
	?> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php
    if (($row_quo["VAT"]=="1") or ($row_quo["VAT"]=="2")){
		echo $row_quo["VAT_VAL"];
	}
	
	?> 
          </span></b></td>
          <td width="62">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
  
<tr>
    <td>__________</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>____________</td>
    <td></td>
    <td align="right">&nbsp;</td>
    <td align="right"><b>
      <span class="style7">      </span></b>
      <table width="300" border="0">
        <tr>
          <td width="200" align="right"><b><span class="style7">
            <?php if (($totsuntot+$row_quo["VAT_VAL"])>0){echo "TOTAL: ".number_format($totsuntot+$row_quo["VAT_VAL"], 2, ".", ",");} ?>
          </span></b></td>
          <td width="62">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
 
 
   <tr>
        <td colspan="12">
             <CENTER>COMPUTER GENERATED  QUOTATION.NO SIGNATURE REQUIRED</CENTER>
        </td>
    </tr>
    
   </table> 
 <table width="1000" border="0">   
   <tr>
    <table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0"><tbody><tr><td width="800"><table width="500" border="0">
        <tbody> 
        <tr>
          <td><?php echo $REMARK?></td>
          <td>&nbsp;</td>
          <td></td>
        </tr>
        <tr>
          <td height="21">&nbsp;</td>
          <td>&nbsp;</td>
          <td></td>
        </tr>
        <tr>
          <td height="21">&nbsp;</td>
          <td>&nbsp;</td>
          <td></td>
        </tr>
    </tbody></table></td></tr></tbody></table>
   
  </tr>
 
   
    <tr>
        <td colspan="8" align="center">
            <b>DEDICATED TO SERVE TEA INDUSTRY</b>
        </td>
    </tr>
    <br>
    <tr>
        <td colspan="8" align="center">
            <b>SMALL BEGINNINGS TO GREAT HEIGHTS</b>
        </td>
    </tr>
     <br>
    <tr>
        <td colspan="8" align="center">
            <b>FOUR DECADES OF EXPERIENCE BEHIND THIS BUSINESS</b>
        </td>
    </tr>
</table>
    
</body>
</html>
