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

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


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

include("../opendb.php");
$sql="select a.itname,sum(b.qty) from itemmaster a,item_purchase b where a.code=b.item_code and b.sale_da='-' group by b.item_code";
$re=mysqli_query($db,$sql);
print "<center><h3>Items in Stock</h3>";
print "<table><th>Configuration <th>Count";
while($row=mysqli_fetch_array($re))
{
 print "<tr><td>$row[0]</td><td align=right>$row[1]</td></tr>";
}
?>
</table>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<BODY BGCOLOR='IVORY'>

<?
$re=mysqli_query($db,"select code,itname from itemmaster where brcode='$brcode' order by itname");
print "<hr>Item wise Report <form action='$PHP_SELF'><table border=1><tr><td>Item </td><td> <select name='itmcode'>";
while ($r=mysqli_fetch_array($re))
{
 print "\n<option value='$r[0]'>$r[1]</option>";
}
print "</select> </td><td><input type=submit value='Show' name='repo'></td></tr></table></form>";
if($repo)
{
$re=mysqli_query($db,"select code,itname from itemmaster where code='$itmcode'");
 $nait=mysqli_fetch_row($re);
 print "Report of $nait[1] <table border=1>";
$sq="create table itmrepo (date date,chasis varchar(100),pqty int(4),sqty int(4))";
 mysqli_query($db,$sq);
mysqli_query($db,"delete from itmrepo");
  $res=mysqli_query($db,"select curdate,chasis,sum(qty) from item_purchase where item_code='$itmcode' group by curdate");
  while($itmrow=mysqli_fetch_array($res))
   mysqli_query($db,"insert into itmrepo values('$itmrow[0]','$itmrow[1]','$itmrow[2]','0')")or die(mysqli_error());

  $res=mysqli_query($db,"select invdate,chasis,sum(qty) from invoice_item where item_code='$itmcode' group by invdate");
  while($itmrow=mysqli_fetch_array($res))
   mysqli_query($db,"insert into itmrepo values('$itmrow[0]','$itmrow[1]','0','$itmrow[2]')")or die(mysqli_error());

print "<table border=1> <th>Date <th>Chasis <th>Pur Qty <th>Sale Qty<th>Balance";
$cnt=0;
$repores=mysqli_query($db,"select * from itmrepo order by date");
while($reporow=mysqli_fetch_array($repores))
{
 $cnt+=$reporow[2];
 $cnt-=$reporow[3];

 print "<tr><td>".datetohtml($reporow[0])."</td><td align=right>$reporow[1]</td><td align=right>$reporow[2]</td><td align=right>$reporow[3]</td><td  align=right>$cnt</td></tr>";
}

} // end if
?>
