<?php include("../../include/dbconnect.php");
// Get all _POST VALUES HERE..

foreach($_POST as $p=>$t)
{
	$_POST[$p] = trim($t);
}

$myCustomer = $_POST['Customer'];

foreach($_POST as $q=>$r)
{
	$_POST[$q] = trim($r);
}

$myProduct = $_POST['Product'];
?>
<title>Quotation Entry</title>
<body background=blater01.gif  topmargin=0>
<center> 
<table cellpadding=0 cellspacing=4 width=590>
  <tr> 
    <td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font face="Verdana, Arial, Helvetica, sans-serif"><b><b>Quotation Edit</b></font></td>
  </tr>
  <tr valign="top"> 
    <td colspan=2> <font >&nbsp;</font> </td>
  </tr>
</table>
<table border=0 cellpadding=3 cellspacing=4 width="590">

<?

// Pull all the data from Customer master & populate it


?>

<form name='myForm01' method='POST' action='<?=$_SERVER[PHP_SELF]?>'>
 
 <tr> 
<td width="139" height="31" align="left" ><font color="#003366" size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>1. Customer Name
  &nbsp;</b></font></td>
  <td>
<?

// Pull all the data from Customer master & populate it
//$stQuery = mysql_query("select distinct enquiry.bcode,buy.name,unit,buy.buyertype from enquiry, buy  where enquiry.bcode = buy.bcode order by buy.name")or die( mysql_error() );
$stQuery = mysql_query("select distinct quotation.bcode,buy.name,unit,buy.buyertype from quotation, buy  where quotation.bcode = buy.bcode order by buy.name")or die( mysql_error() );

?>
 <form name='myForm01' method='POST' action='<?=$_SERVER[PHP_SELF]?>'>
  <SELECT name='Customer' onChange="javascript:submit();">
    <?
echo "<option selected value=\" 0\"> Select Customer";
while($row = mysql_fetch_row($stQuery))
{
	   if($row[3]== 'LABOUR')
	   {
		   	$type='------>>'.$row[3];
		}
		elseif($row[3]!= 'LABOUR')
		{
			$type ='';
		}	
	$temp = $row[1].'&nbsp;&nbsp;'.$row[2].$type;
	if(isset($myCustomer) && eregi("$myCustomer",$row[0]))
	{
		echo "<option selected value=\"$row[0]\">$temp";
	}
	else{
		echo "<option value=\"$row[0]\">$temp";
	}
}
?>
  </SELECT></td></tr>
  
<tr>
<td width="139" height="31" align="right" ><div align="left"><font color="#003366" size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>2. Product Name
  &nbsp;</b></font></div></td>
<td width="174">
<SELECT name="Product"  onChange="javascript:submit();">
<?
$stQuery = mysql_query("select distinct quotation.bcode,buy.name,unit,buy.buyertype from quotation, buy  where quotation.bcode = buy.bcode order by buy.name")or die( mysql_error() );

$bkquery = "SELECT DISTINCT quotation.prodname, quotation.drawing_no, quotation.prodcode
FROM quotation, product WHERE quotation.bcode = '$myCustomer' AND quotation.prodcode = product.prodcode  order by quotation.prodname, quotation.drawing_no";
    $bkquery=stripslashes($bkquery);
    $result=mysql_query($bkquery) or       die( mysql_error() );
   echo "<option selected value=' '> Select Product";
   while($row1 = mysql_fetch_row($result))
{
//          echo "<option value='$row1[2]'>";
//          echo ($row1[0].'&nbsp;&nbsp;Dr. No:'.$row1[1]);
		  	$temp = $row1[0].'&nbsp;&nbsp;'.$row1[1].$type;
  	if(isset($Product) && eregi("$Product",$row1[2]))
	{
		echo "<option selected value=\"$row1[2]\">$temp";
	}
	else{
		echo "<option value=\"$row1[2]\">$temp";
	}

}
?>
</SELECT></td>
</tr>



</table>
</form> 

<table border=0 cellpadding=3 cellspacing=4 width="590">
<?
//echo "prod" . "$myProduct";
//echo "cus" . "$myCustomer";
 ?> 


<?
$i=0;
// Pull all Customers from Customer  based on Selected Customer id and populate it.
$result = mysql_query("SELECT  distinct record, bcode,  quot_refno, quot_refdt,  prodcode, drawing_no, prodname,   tlcost FROM quotation WHERE (quotation.bcode ='$myCustomer') and  quotation.prodcode= '$myProduct'") or die(mysql_error());
$number_cols=mysql_num_fields($result);
echo "<table border=1> \n";
echo "<tr align=center> \n";
for($i=0;$i<$number_cols;$i++)
{
echo "<th>" . mysql_field_name($result,$i).   "</th>\n";
}
echo "<tr>\n";

//layout table

while($row = mysql_fetch_row($result))
{
echo "<tr align=left> \n";
echo "<td>";
if(!isset($row[0])) //test for null value
{
echo "NULL";
}
else
{
?>

<a href = "newqedit.php?record=<?echo($row[0]);?>"><?echo($row[0]);?></a>
<?

}

for($i=1;$i<$number_cols;$i++)
{
echo "<td>";
if(!isset($row[$i])) //test for null value
{
echo "NULL";
}
else
{
echo $row[$i];
}
echo "</td>\n";
}
echo "</tr> \n";
}
echo"</table>";

?>
</form>
</body>

<input type="hidden" name="fname" value="<? echo $filename;?>">
<form><br><br><font size=1><center><a href= "index.html">Return to index page</center></font>
</form>

