<?
session_start();
include("../opendb.php");
include("../test.php");
?>

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

<style>
	//tr1{background-color:white}
	th{background-color:steelblue;color:white}
</style>
<center>
<?
$tbl="sparetmp".$brcode.$user;

include ("calcsparestock.php");
print "<script> window.open('stockvalid.php'); </script>";
if($sea)
{
 $seare=mysqli_query($db,"select * from $tbl where partcode='$pcode'");
 print "<table bgcolor=silver><th colspan=10>Search Result</th><tr>";
print "<th>No.<th>Part Code <th>Part Name<th>Quantity <th>Lst Price <th>Amount <th>Location";
$i=1;
 while($searow=mysqli_fetch_array($seare))
 {
  print "<tr bgcolor=white><td>".$i++."</td>";
 print "<td>$searow[partcode]</td><td>$searow[partname]</td><td align=right>$searow[supqty]</td>";
  $prres=mysqli_query($db,"select lstprice from spareprmast where partcode='$searow[0]' order by effect from desc limit 1");
  $prrow=mysqli_fetch_row($prres);
 $pr=($prrow[0]*$row[supqty]);
 $tprice+=$pr;
 print "<td align=right>".putComa($prrow[0])."</td><td align=right>".putcoma($pr)."</td>";
  $locres=mysqli_query($db,"select location from sparelocmast where itemcode='$searow[partcode]' and brcode='$brcode'");
  $locrow=mysqli_fetch_row($locres);
 print "<td>$locrow[0]</td></tr>";
 }
 print "</table>";
}
?>

<center>
<h3>SPARE STOCK</H3>
<form action='<?print $PHP_SELF?>'>
<table>
<tr><td>Search by Partcode </td><td><input type=text name='pcode'></td>
<td><input type=submit value='Search' name='sea'>
</td></tr>
</table>
</form>
<?
$gre=mysqli_query($db,"select distinct group1 from partmaster");
while($grrow=mysqli_fetch_array($gre))
{
//$re=mysqli_query($db,"select * from $tbl order by partcode");
$sq="select a.*,b.group1 from  $tbl a,partmaster b where a.partcode=b.partcode and b.group1='$grrow[0]'";
$re=mysqli_query($db,$sq);
print "<h2>$grrow[0]</h2>";
print "<table border=0 cellspacing=1 cellpadding=3 bgcolor='lightsteelblue'>"; 
print "<th>No.<th>Part Code <th>Part Name<th>Quantity <th>Cost Price<th>MRP <th>Amount <th>Location";
$i=1;
$tprice=0;
$tqty=0;
while($row=mysqli_fetch_array($re))
{
 print "<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white'><td>".$i++."</td>";
 print "<td>$row[partcode]</td><td>$row[partname]</td><td align=right>$row[supqty]</td>";
  $prres=mysqli_query($db,"select lstprice,mrp from spareprmast where partcode='$row[0]' order by effectfrom desc");
  $prrow=mysqli_fetch_row($prres);
 $pr=($prrow[0]*$row[supqty]);

 $tprice+=$pr;
 $tqty+=$row[supqty];
 print "<td align=right>".putComa($prrow[0])."</td>";
 print "<td align=right>".putcoma($prrow[1])."</td>";
print "<td align=right>".putcoma($pr)."</td>";
  $locres=mysqli_query($db,"select location from sparelocmast where itemcode='$row[partcode]' and brcode='$brcode'");
  $locrow=mysqli_fetch_row($locres);
 print "<td>$locrow[0]</td></tr>";
 }
 print "<tr ><td colspan=3 align=center bgcolor='silver'>Total</td>";
 print "<td>$tqty</td><td></td><td></td>";
 print "<td  bgcolor='silver' align=right>".putComa($tprice)."</td><td bgcolor='silver'></td></tr>";
print "</table>";
}
?>


