<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];

if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");

?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>

	th{background-color:steelblue;color:white}
</style>
<center>
<?
$res=mysqli_query($db,"select distinct orderno from purorder_spare where brcode='$brcode'") or die(mysqli_error($db));
while($ordrow=mysqli_fetch_array($res))
{
 $res2=mysqli_query($db,"select * from purorder_spare where orderno='$ordrow[0]' and brcode='$brcode'");
   print "<fieldset> <legend> Order No : $ordrow[0]</legend>";
 print "\n<form action='clsall.php' method='post'><input type=hidden name='ordno' value='$ordrow[0]'>";
 print "<input type=submit value='Close this order'></form>\n\n";
   print "<table border=1 width=90%> <th width=100>Part Code <th width=350>Part Name <th>Qty <th>Date <th>Ord To <th>Close";
$tqty=0;
 while($row=mysqli_fetch_array($res2))
 {
    $ordtores=mysqli_query($db,"select * from branch where brcode='$row[orderto]'");
    if(mysqli_num_rows($ordtores)>0)
     {
      $ordertorow=mysqli_fetch_array($ordtores);
      $orderto=$ordertorow[brname];
     }
    else
     {
       $ordtores1=mysqli_query($db,"select * from sup_master where code='$row[orderto]'")or die(mysqli_error($db));
      $ordertorow1=mysqli_fetch_array($ordtores1);
      $orderto=$ordertorow1[supname];
     }
 if($row[closed]=='N')
    print "\n<tr bgcolor='white'>";
 else
    print "\n<tr bgcolor='pink' title='$row[reas]'>";
 print "<td>$row[0]</td><td>$row[1]</td><td>$row[qty]</td><td>".datetohtml($row[3])."</td><td>$orderto</td><td>\n";
 if($row[closed]=='N')
  print "<input type=button value='Cls' onClick=cls('$row[0]','$ordrow[0]')>";
 else
   print "Closed";
    $tqty+=$row[qty];
    print "</td></tr>";
 }
 print "\n<tr><td colspan=2><center><b>Total </td><td>".putComa($tqty)."</td><td colspan=3>&nbsp;</td></tr>";
 print "</table></fieldset>";
}
?>
<script>
 function cls(a,b)
 {
  if(confirm('Short close the item '+a+' ?'))

   document.location='shclspur.php?itcode='+a+'&ordno='+b;
 }
</script>