<?
 session_start();
 include("../opendb.php");
 include ("../test.php");
 function getLocation($cde,$br)
 {
  $sql="select location from sparelocmast where itemcode='$cde' and brcode='$br'";
  $locre=mysqli_query($db,$sql)or die(mysqli_error());
  $locrow=mysqli_fetch_array($locre);
  return $locrow[0];
 }
?>
<center>
<style>
th,td,body{font-family:'arial narrow';letter-spacing:1;font-size:16}
th{background-color:steelblue;color:white}
</style>
<?
if($show)
{
$df=$y.'-'.$m.'-'.$d;
$dto=$y1.'-'.$m1.'-'.$d1;

 $sql="select * from sparepurchase where brcode='$brcode' and entrydate>='$df' and entrydate<='$dto'";
 $re=mysqli_query($db,$sql)or die(mysqli_error());
 $rr=mysqli_fetch_array($re)or die('Err'.mysqli_error());
 if(mysqli_num_rows($re)<=0)
 {
  print "<center> <font color=red>Record does not exist";
  return;
 }
 $brre=mysqli_query($db,"select * from branch where brcode='$rr[brcode]'")or die('err2'.mysqli_error());
 $brr=mysqli_fetch_array($brre)or die('err3'.mysqli_error());

 $brre1=mysqli_query($db,"select * from branch where brcode='$brcode'")or die('err2'.mysqli_error());
 $brr1=mysqli_fetch_array($brre1)or die('err3'.mysqli_error());

?>

<TABLE width=100% border=0>
<tr><td colspan=2 align=center><b>PSN CONSTRUCTION EQUIPMENTS P LTD </b><BR>
<?print $brr1[braddr]?><br> <?print $brr1[brcity]?><br><?print $brr1[brstate]?><br>
<u>PH :<?print $brr1[brphone]?></u>
</td></tr>
<tr><td colspan=2 align=center><B>Purchase report from <?print datetohtml($df).' - '.datetohtml($dto)?> </b><br></td></tr>
</table>
<br>
<table border=1 width=90% cellpadding=2>
<th> No <th>Location <th>Description of Goods <th>Quantity 
<?
$t=0;
$amt=0;
$i=1;
 $sql="select * from sparepurchase where brcode='$brcode' and entrydate>='$df' and entrydate<='$dto' order by partname";
$re1=mysqli_query($db,$sql);
 while($row=mysqli_fetch_array($re1))
{
  $loc=getLocation($row[partcode],$brcode);
  print "<tr><td>".$i++."</td><td>$loc</td><td>$row[partname]($row[partcode])</td><td align=right>".($row[supqty])."</td>";
 $t+=$row[supqty];
}
print "<tr><td>&nbsp;</td><td>&nbsp;</td><td align=right><b>Total </td><td align=right><b>$t Nos</td></tr>";
?>
</table>
</center><br>

<?
return;
}// end if

?>
<form action='<?print $PHP_SELF?>'>
<table>
<th colspan=2>DATE WISE PURCHASE REPORT</TH>
<tr><td>From </td><td>dd <input type=text name='d' size=2 value='<?print date('d');?>'>
mm <input type=text name='m' size=2 value='<?print date('m');?>'>
yy <input type=text name='y' size=4 value='<?print date('Y');?>'>
</td></tr>
<tr><td>To </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 bgcolor='steelblue'><td colspan=2 align=center><input type=submit value='Show' name='show'></td></tr>
</table>
</form>
