<?
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>
<?
if(isset($_POST['show']))
{
$d2=$_REQUEST['d2'];
$m2=$_REQUEST['m2'];
$y2=$_REQUEST['y2'];
$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;
print "<center><h3>PENDING SALE ORDER REPORT </H3> From ".datetohtml($dfrom) .' To '.datetohtml($dto);
$re=mysqli_query($db,"select distinct orderto from saleorder_spare where sup_qty<sqty and brcode='$brcode' and date>='$dfrom' and date<='$dto' order by orderto")or die(mysqli_error($db));
while($ro=mysqli_fetch_array($re))
{
  $res=mysqli_query($db,"select * from saleorder_spare where orderto='$ro[orderto]' and brcode='$brcode' and sup_qty < sqty and closed='N'");
 print "<fieldset><legend><b> Order to: $ro[orderto],";
 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>Order no";

  while($row=mysqli_fetch_array($res))
  {
    print "<tr bgcolor='white'><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><td align=right>$row[orderno]</td></tr>";
  }
 print "</table></fieldset><br>";
}
return;
} //end if
?>

<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>
<tr><td>Date from </td><td>dd <input type=text name='d1' size=2 value='<?print date("d")?>'>
mm <input type=text name='m1' size=2 value='<?print date("m")?>'>
yy <input type=text name='y1' size=4 value='<?print date("Y")?>'></td></tr>

<tr><td align=right>to </td><td>dd <input type=text name='d2' size=2 value='<?print date("d")?>'>
mm <input type=text name='m2' size=2 value='<?print date("m")?>'>
yy <input type=text name='y2' size=4 value='<?print date("Y")?>'>
</td></tr>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></td></tr>
</table>
</td></tr>
</table>
</form>

