<?php include("../../include/dbconnect.php");
?>
<title> Entry</title>
<body bgcolor="#ffffff"  topmargin=0>
<center>
<table cellpadding=0 cellspacing=4 width=590>
<tr>
<td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font >Quotation Entry Sheet</font></td>
</tr><tr valign="top"><td colspan=2>
<font >&nbsp;</font>
</td>
</tr>
</table>
<form  name="form1" method="POST"  action="quotsave.php">
<?php 


$result = mysql_query("select compcode,account_year from company where compcode like '%$compcode' ") or die(mysql_error());
$row = mysql_fetch_row($result);

$account_year = $row[1];

$result = mysql_query("select max(quot_refno) from quotation where account_year = '$account_year' ") or die(mysql_error());
$row = mysql_fetch_row($result);
$quot_refno = $row[0]+1;
//echo "$quot_refno";
$query = "select distinct record, bcode, prodcode, drawing_no, enquiry_refno, enquiry_refdt,  tools_cost, quot_sub_dt, quot_refno, quot_refdt, quot_rev_by  FROM enquiry where record ='$record'";
$result=mysql_query($query) or die('Queryproblem: ' . mysql_error() . '<br />Executed query: ' . $query);

$row=mysql_fetch_row($result);
$temp = $row[6];
$qrefno = $row[8];
$qrefdt = $row[9];


if (empty($qrefno))
{
?>
<input type="hidden" name="record" value="<? echo($row[0]); ?>">
<input type="hidden" name="bcode" value="<? echo($row[1]); ?>">
<input type="hidden" name="prodcode" value="<? echo($row[2]); ?>">
<input type="hidden" name="drawing_no" value="<? echo($row[3]); ?>">
<input type="hidden" name="enqrefno" value="<? echo($row[4]); ?>">
<input type="hidden" name="enqrefdt" value="<? echo($row[5]); ?>">

<?

$result1 = mysql_query("SELECT distinct record, bcode, enquiry_refno, enquiry_refdt, drawing_no, prodname, cost_refno, cost_refdt,  rawdraw, rawoffer, rawsize, rawwgt, rawrate, rawqty,  tlcost, rawcost, processcost, admnexp, remarks, appby FROM toolscost WHERE  enquiry_refno='$row[4]' and enquiry_refdt='$row[5]'") or die(mysql_error());
$row1=mysql_fetch_row($result1);


$result2 = mysql_query("SELECT distinct product.bcode,product.prodname,product.drawing_no, product.prodcode FROM product WHERE   product.prodcode= '$product'") or die(mysql_error());
$row2=mysql_fetch_row($result2);
//echo "$row2[1]";
//echo "$row2[2]";
$bcode = $row2[0];
//echo "$bcode";
?>

<table border=0 cellspacing=1 cellpadding=1>
<tr>
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Enquiry Ref No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="enquiry_refno"  value=  <? if (empty($row[4])){?>''<? } else { echo ($row[4]); }?> > 
</td>
</tr>

<?
$edt = date(d).'-'.date(m).'-'.date(Y); 
?>

<tr>
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Enquiry Ref Dt &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="enquiry_refdt"  value=  <? if (empty($row[5])){ echo ($edt); } else { echo ($row[5]); }?>> 
</td>
</tr>


<tr>
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Quotation No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="quot_refno"  value= <? echo "$quot_refno" ?> > 
</td>
</tr>

<?
$sdt = date(d).'-'.date(m).'-'.date(Y); 
?>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Quotation Date &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="quot_refdt" value= <?php echo($sdt); ?> > 
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Kind Attn : &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="attn"  value= '' > 
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Your Reference No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="your_refno"  value= '' > 
</td>
</tr>

<?
$ydt = date(d).'-'.date(m).'-'.date(Y); 
?>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Your Reference Date &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="yr_refdt" value= <?php echo($ydt); ?> > 
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Drawing No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="drawing_no"  value=  <? if (empty($row[3])){ echo ($row2[2]); } else { echo ($row[3]); }?> >  
</td>
</tr>

<?

?>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Product Name &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"  name="prodname"  value=  <? if (empty($row1[5])){ echo  "$row2[1]"; } else { echo ($row1[5]); }?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Material offered &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawoffer"  value=  <? if (empty($row1[9])){?>''<? } else { echo ($row1[9]); }?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Raw Material (in Kgs) &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawqty"  value=  <? if (empty($row1[11])){?>''<? } else { echo ($row1[11]); }?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Raw Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawcost"  value=  <? if (empty($row1[15])){?>''<? } else { echo ($row1[15]); }?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Cost of the Materails Per Kg &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawrate"  value=  <? if (empty($row1[12])){?>''<? } else { echo ($row1[12]); }?> >  
</td>
</tr>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Inventory % &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="invper"  value= '' >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Inventory Carrying Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="invcost"  value=  0.00 >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Process Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="processcost"  value=  <? if (empty($row1[16])){?>0.00<? } else { echo ($row1[16]); }?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>O. H & Margin &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="admnexp"  value=  <? if (empty($row1[17])){?>0.00<? } else { echo ($row1[17]); }?>>  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Scrap Realization &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="scrapval"  value=  0.00>  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Tool Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="tlcost"  value=  <? if (empty($row1[14])){?>0.00<? } else { echo ($row1[14]); }?>>  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Delivery Period &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="delperiod"  value=  ''>  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Sales Tax &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="st"  value=''>  
</td>
</tr>


<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Excise Duty &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="exduty"  value=  ''>  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Packing & Forwarding Charges &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="pandf"  value=  ''>  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Payment Terms &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="payterms"  value=  ''>  
</td>
</tr>
<table cellpading=0 cellspacing=10 width= 50>
      <tr> 
 <tr> 
      <td> <blockquote> <input type =submit name="submit" value = "Submit"></td></blockquote>
</tr>
  </table>
</table>

<?
}
else
{
echo "$qrefno";
echo "updating existing quotaton or taking the value to the new customer";
$result3 = mysql_query("SELECT  distinct record, bcode,  quot_refno, quot_refdt, attn, yr_refno, yr_refdt, drenq, enquiry_refno, enquiry_refdt, prodcode, drawing_no, prodname, rawoffer, rawqty, rawrate, rawcost, invper, invcost, processcost, admnexp, scrapcost, tlcost, delperiod, st, exduty, pandf, payterms FROM quotation WHERE   quot_refno= '$qrefno'") or die(mysql_error());
$row3=mysql_fetch_row($result3);
echo "$row3[1]";
?>

<table border=0 cellspacing=1 cellpadding=1>
<tr>
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Enquiry Ref No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="enquiry_refno"  value=  <?  echo("'$row3[8]'"); ?> > 
</td>
</tr>

<?
//$edt = date(d).'-'.date(m).'-'.date(Y); 
?>

<tr>
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Enquiry Ref Dt &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="enquiry_refdt"  value=  <? echo("'$row3[9]'"); ?> > 
</td>
</tr>


<tr>
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Quotation No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="quot_refno"  value= <? echo("'$row3[2]'"); ?> > 
</td>
</tr>

<?
//$sdt = date(d).'-'.date(m).'-'.date(Y); 
?>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Quotation Date &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="quot_refdt" value= <?php echo("'$row3[3]'"); ?> > 
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Kind Attn : &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="attn"  value= <? echo("'$row3[4]'"); ?> > 
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Your Reference No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="your_refno"  value= <? echo("'$row3[5]'"); ?> > 
</td>
</tr>

<?
//$ydt = date(d).'-'.date(m).'-'.date(Y); 
?>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Your Reference Date &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="yr_refdt" value= <? echo("'$row3[7]'"); ?> > 
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Drawing No &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="drawing_no"  value=  <? echo("'$row3[11]'"); ?> >  
</td>
</tr>

<?

?>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Product Name &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"  name="prodname"  value=  <? echo("'$row3[12]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Material offered &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawoffer"  value=  <? echo("'$row3[13]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Raw Material (in Kgs) &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawqty"  value=  <? echo("'$row3[14]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Raw Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawcost"  value=  <? echo("'$row3[16]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Cost of the Materails Per Kg &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="rawrate"  value=  <? echo("'$row3[15]'"); ?> >  
</td>
</tr>
<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Inventory % &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="invper"  value= <? echo("'$row3[17]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Inventory Carrying Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="invcost"  value=  <? echo("'$row3[18]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Process Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="processcost"  value=  <? echo("'$row3[19]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>O. H & Margin &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="admnexp"  value=  <? echo("'$row3[20]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Scrap Realization &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="scrapval"  value=  <? echo("'$row3[21]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Tool Cost &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="tlcost"  value=  <? echo("'$row3[22]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Delivery Period &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="delperiod"  value=  <? echo("'$row3[23]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Sales Tax &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="st"  value= <? echo("'$row3[24]'"); ?>  >  
</td>
</tr>


<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Excise Duty &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="exduty"  value=  <? echo("'$row3[25]'"); ?>  >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Packing & Forwarding Charges &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="pandf"  value=  <? echo("'$row3[26]'"); ?> >  
</td>
</tr>

<tr > 
<td width="164" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Payment Terms &nbsp;</b></font></td>
<td width="414" > <input type="text"    onKeyPress="return event.keyCode!=13"   name="payterms"  value=  <? echo("'$row3[27]'"); ?>  >  
</td>
</tr>

<?
if ($temp > 0.00)
{
?>
<table cellpading=0 cellspacing=10 width= 50>
<tr>
<td nowrap> <font class="sbd"><b>Tool Cost Value for New Customer</b></font></td>
<td><input type="checkbox" name="new" value="Yes" ></td>
</tr>
</table>
<?
}
?>
</table>
<?
}
?>
<table cellpading=0 cellspacing=10 width= 50>
      <tr> 
 <tr> 
      <td> <blockquote> <input type =submit name="update" value = "update"></td></blockquote>
</tr>
  </table>
</table>





<br><br><font size=1><center><a href= "../../index.html">Return to index page</a></center></font>
</body></form>

