<?
session_start();
print 'order no:'.$orderno1;
include("../opendb.php");
$tbl="declare_spare";
 $orderno=$orderno1;

if($save)
{
 $sql="update declare_spare set orderto='$to' where orderno='$orderno' and brcode='$brcode'";
 mysqli_query($db,$sql) or die('Err:save'.mysqli_error($db));
}

?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
	tr{background-color:white}
	th{background-color:steelblue;color:white}
</style>
<center>
<form action='<?print $PHP_SELF?>'>
<table border=1 width=100%>
<tr><td><center>Order To : 
<?
$brres=mysqli_query($db,"select brcode,brname from branch where brcode!='$brcode' order by brname");
print "<select name='to'>";
 while($brrow=mysqli_fetch_array($brres))
 {
   print "<option value='$brrow[0]'>$brrow[1]</option>";
 }
$brres1=mysqli_query($db,"select distinct code,supname from sup_master order by supname");
 while($brrow1=mysqli_fetch_array($brres1))
 {
   print "<option value='$brrow1[0]'>$brrow1[1]</option>";
 }

print "</select>";
?>
&nbsp;
<input type=submit value='Save' name='save'>
</td></tr></table>
</form>

<br>
<?

if($add)
{
  $res1=mysqli_query($db,"select * from $tbl where partcode='$partcode' and brcode='$brcode' and orderno='$orderno'");
  if(mysqli_num_rows($res1)>0)
  {
    print "<script> alert('Duplicate Entry')</script>";
    return;
  }

 $sql="insert into $tbl (partcode,partname,qty,brcode,orderno)values('$partcode','$prtname','$qty', '$brcode','$orderno1')";
 mysqli_query($db,$sql)or die('Err:'.mysqli_error($db));
}

$res=mysqli_query($db,"select * from declare_spare where orderno='$orderno1' and brcode='$brcode' order by partcode");
if(mysqli_num_rows($res)>0)
{
  $i=1;
  print "<table border=1 cellpadding=3> <th>No <th>Item Code <th>Item Name <th>Qty <th> Del";
  while($row=mysqli_fetch_array($res))
  {
    print "\n<form action='$PHP_SELF'> <input type=hidden name='partcode' value='$row[0]'><tr><td>";
    print $i++."</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
    print "<td><input type=submit value='Del' name='Del'></td></tr></form>";
  }
 print "</table>";
}

if($Del)
{
 mysqli_query($db,"delete from $tbl where partcode='$partcode' and orderno='$orderno' and brcode='$brcode'")or die('err'.mysqli_error($db));
 print "<script> document.location='Epurtempdeclare.php' </script>";
}
?>
