<?
 session_start();
 include("../opendb.php");
 include ("../test.php");
 $sql="select * from sparepurchase where purno='$purno' and taxtype='$ttype' and brcode='$brcode'";
 $re=mysql_query($sql);
 $rr=mysql_fetch_array($re)or die('Err'.mysql_error());
 if(mysql_num_rows($re)<=0)
 {
  print "<center> <font color=red>Record does not exist";
  return;
 }
 $brre=mysql_query("select * from branch where brcode='$rr[brcode]'")or die('err2'.mysql_error());
 $brr=mysql_fetch_array($brre)or die('err3'.mysql_error());

 $brre1=mysql_query("select * from branch where brcode='$brcode'")or die('err2'.mysql_error());
 $brr1=mysql_fetch_array($brre1)or die('err3'.mysql_error());

?>
<center>
<style>
th,td,body{font-family:'arial narrow';letter-spacing:1;font-size:16}
</style>

<TABLE width=100% border=0>
<TR><TD>Purchase: 
<?
print $purno;
?>

</td><td align=right>Date: <?print datetohtml($rr[entrydate])?></td></tr>
<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</b><br></td></tr>
<tr>
<td colspan=4><center> Supplier:<b><?print $rr[suplier].' (P Bill No: '.$rr[pbillno].')'?> 
</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;
 $re1=mysql_query("select * from sparepurchase where purno='$purno' and taxtype='$ttype' and brcode='$brcode'");
 while($row=mysql_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>

<?
 function getLocation($cde,$br)
 {
  $sql="select location from sparelocmast where itemcode='$cde' and brcode='$br'";
  $locre=mysql_query($sql)or die(mysql_error());
  $locrow=mysql_fetch_array($locre);
  return $locrow[0];
 }
?>

