<?
session_start();
include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
.right{text-align:right};
</style>
<center>
<form action='<?print $PHP_SELF?>'>
<table>
<tr><td bgcolor='c1d799' align=center colspan=2><h3>SPARE - PURCHASE RETURN</H3></tr></td>
<tr><td> Purchase Bill No </td><td><select name='pbillno'>
<?
$re=mysqli_query($db,"select distinct pbillno from sparepurchase where brcode='$brcode'")or die('err'.mysqli_error());
while($row=mysqli_fetch_row($re))
{
 print "<option>$row[0]</option>";
}
?>
</select></td></tr>
<tr bgcolor='lightsteelblue'><td colspan=2 align=center>
  <input type=submit value='Next ->' name='next'> </td>
</tr>
</table>
</form>
<?
if($next)
{
$i=1;
$re=mysqli_query($db,"select * from sparepurchase where pbillno='$pbillno' and brcode='$brcode'")or die('err'.mysqli_error());
print "<form action='svpurreturn.php'> <input type=hidden name='pbillno' value='$pbillno'>";
?>
<table>
<tr><td>
Return Date </td><td>: dd <input type=text name='d' value='<?print date("d")?>' size=2>
	 mm <input type=text name='m' value='<?print date("m")?>' size=2>
	 yy <input type=text name='y' value='<?print date("Y")?>' size=4></td>
</tr>
<tr><td>
Entry Date </td><td>: dd <input type=text name='d1' value='<?print date("d")?>' size=2>
	 mm <input type=text name='m1' value='<?print date("m")?>' size=2>
	 yy <input type=text name='y1' value='<?print date("Y")?>' size=4>
</tr></td>
</table>
<br>
<?
print "<font color=red>Enter return quantity to return the Item</font><br> <br>";
print "<table border=0 cellpadding=3><th>No. <th>Supplier <th>Pur Date ";
 print "<th>Part Code <th>Part Name";
print "<th>Qty <th>Amount<th>Ret Qty";
while($row=mysqli_fetch_array($re))
{
  $supres=mysqli_query($db,"select supname from sup_master where code='$row[suplier]'")or die('err'.mysqli_error());
  if(mysqli_num_rows($supres)>0)
    $suprow=mysqli_fetch_array($supres);
  else
  {
   $supres1=mysqli_query($db,"select brname,brcode from branch where brcode='$row[brcode]'")or die('err'.mysqli_error());
    $suprow=mysqli_fetch_array($supres1);
  }
  print "\n<tr><td>".$i++."</td><td><select name='suplier'><option value='$suprow[1]'>$suprow[0]</option></select>";
  print "</td><td>".datetohtml($row[purdate])."</td>";
  print "<td><input type=text name='partcode[]' value='$row[partcode]'></td>";
  print "\n<td><input type=text name='partname[]' value='$row[partname]'></td>";
  print "<td><input type=text class=right name='supqty[]' id='$i' value='$row[supqty]' size=6></td>";
  print "<td>$row[tot]</td>";
  print "\n<td><center><input type=text name='retqty[]' id='retqty$i' size=5></td></tr>";
}
print "<TR bgcolor='steelblue'><TD colspan=8 align=center> <input type=submit value='Save'></td></tr>";
print "</table>";
}// end if
?>
