<?
session_start();
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}
.right{text-align:right};
</style>
<center>

<?
if($show)
{
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;
print "<h3>STOCK AVAILABILITY % REPORT<BR> For the period ".datetohtml($dfrom)." to ".datetohtml($dto)."</h3>";
if($brcode=='ERA153')
$brre=mysqli_query($db,"select distinct brcode,brname from branch order by brname");
else
$brre=mysqli_query($db,"select distinct brcode,brname from branch where brcode='$brcode'");

 print "<table border=1 width=60%> <th>Branch <th>Sale Ord <th>In Suf Stock <th>Avail %"; 
while($brrow=mysqli_fetch_array($brre))
{
 $r1=mysqli_query($db,"select count(*) from saleorder_spare where brcode='$brrow[0]' and date>='$dfrom' and date<='$dto'");
 $row1=mysqli_fetch_row($r1);
 print "<tr><td width=340>$brrow[brname]</td><td align=center>$row1[0]</td>";


$r3=mysqli_query($db,"select count(*) from saleorder_spare where qty<sqty and brcode='$brrow[0]' and date>='$dfrom' and date<='$dto'")or die(mysqli_error());
 $row2=mysqli_fetch_row($r3);
 print "<td align=center>$row2[0]</td>";

 $per=($row1[0]-$row2[0]);
 $per=$per/$row1[0]*100;
 print "<td align=right>".putComa(round($per,2))."</td>";
 print "</tr>";

}
print "</table>";
return;
} // end if show
?>
<center>
<h3>STOCK AVAILABILITY</H3>
<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>

