<?
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:lightsteelblue;color:black}
//tr{background-color:white}
</style>
<?
$re=mysqli_query($db,"select distinct orderno,date,orderto from saleorder_spare where sup_qty<sqty and brcode='$brcode' order by orderno");
while($ro=mysqli_fetch_array($re))
{
  $res=mysqli_query($db,"select * from saleorder_spare where orderno='$ro[orderno]' and brcode='$brcode' and sup_qty < sqty and closed!='Y'");
 print "<fieldset><legend><b> Order No: $ro[orderno], Date: ".datetohtml($ro[date]).",";
 print " Customer: $ro[orderto]</b></legend>";
 $i=1;
    print "<table cellspacing=1 cellpadding=3 bgcolor='steelblue' width=100%>";
    print "<th width=15>No <th width=175>Partcode <th>Part Name <th width=55>Ord Qty";
    print "<th width=55>Sup Qty <th width=55>Ext.Qty <th width=55>Close";

  while($row=mysqli_fetch_array($res))
  {
    if($row[closed]=='Y')
     print "<tr bgcolor='pink' title='$row[reas]'>";
    else     
    print "<tr bgcolor='white'>";
    print "<td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
    print "<td align=right>$row[sqty]</td><td align=right>$row[sup_qty]</td>";
    print "<td align=right>$row[qty]</td>";
    if($row[closed]=='N')
    print "<td><center><input type=button value='CLS' onClick=clsfun('$ro[orderno]','$row[partcode]')></td>";
    print "</tr>";
  }
 print "</table></fieldset><br>";
}
?>

<script>
 function clsfun(b,a)
 {
  if(confirm('Short close the item '+a+' ?'))
   document.location='shclssale.php?itcode='+a+'&ordno='+b;
 }
</script>
