<?
session_start();
$brcode = $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
//echo $puno;
//echo $jvno;
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
 </head>
<body>
<blockquote>
<?
//$sql="select * from sparepurchase where jvno='$jvno' and brcode='$brcode'";
//echo $sql; 
$purno = $_REQUEST['purno'];
$result=mysqli_query($db,"select * from sparepurchase where purno='$purno' and brcode='$brcode'");
$row=mysqli_fetch_array($result);
$br=mysqli_query($db,"select supname,code from sup_master order by supname");
?>
<table border=1 cellspacing=1 cellpadding=3 ><th colspan=2> SPARE PURCHASE</TH>
<tr><td>Pur Order No </td><td><? echo $row[porderno] ?></td></tr>

<tr><td>Pur Order Date </td><td><? echo datetohtml($row[purdate]) ?></td></tr>
<tr><td>Supplier </td><td>

<? echo $row[suplier] ?>

</td></tr>
<tr><td>Pur Bill No.</td><td><? echo $row[pbillno] ?></td></tr>
<tr><td>Pur Date</td><td><? echo $row[purdate] ?></td></tr>
<tr><td>Entry Date</td><td><? echo $row[entrydate] ?></td></tr>
</table>
<table border=0 cellspacing=1 cellpadding=3 bgcolor='silver'>
<th>No<th>P Code <th> Name <th>Ord Qty <th> Sup Qty<th>FOC<th>Price <th>Disc% <th> A Price<th>Hand Chrge 
<?
if($taxtype=='CST')
   print "<th>CST%";
else
 print "<th>VAT%";
?>
<th>Tax Amt <th>Cess% <th>Cess <br>Amt<th> Total
<?
    $taxres=mysqli_query($db,"select tax from taxmaster where type='$taxtype'");
    $taxrow=mysqli_fetch_row($taxres);
    $tax=$taxrow[0];
$i=1;
$sq="select * from sparepurchase where purno = '$purno' and brcode='$brcode'";
//print $sq;
$result1=mysqli_query($db,$sq);
$aprice_tot=0;
$hand_tot=0;
$taxamt_tot=0;
$tot_tot=0;

while($row=mysqli_fetch_array($result1))
{
 	$itmres=mysqli_query($db,"select * from partmaster where partcode='$row[0]'");
 	$prtrow=mysqli_fetch_array($itmres);
	$prres=mysqli_query($db,"select * from spareprmast where partcode='$row[0]' order by effectfrom desc");
	$prrow=mysqli_fetch_array($prres);
	print "\n<tr bgcolor='white'; onMouseOver=bgColor='c1d7bb'; onMouseOut=bgColor='white'>\n<td>".$i."</td><td>$row[partcode]</td><td>";
	print "$row[partname]</td>";
	print "<td align=center>".($row[qty]-$row[sup_qty])."</td>";
 	print "\n<td align=center>$row[supqty]</td>";
 	print "<td align=center>$row[foc]</td>";
 	print "<td align=center>$row[price]</td>";
 	print "<td align=center>$row[disc]</td>";
 	print "<td align=center>$row[aprice]</td>";
 	print "<td align=center>$row[hand]</td>";
	print "<td align=center>$row[tax]</td>";
	print "<td align=center>$row[taxamt]</td>";
	print "<td align=center>$row[cessp]</td>";
	print "<td align=center>$row[cessamt]</td>";
	print "<td align=center>$row[tot]</td></tr>";
	$aprice_tot=$aprice_tot+$row[aprice];
	$hand_tot=$hand_tot+$row[hand];
	$taxamt_tot=$taxamt_tot+$row[taxamt];
	$tot_tot=$tot_tot+$row[tot];
	$i++;
}
print "\n<tr><td colspan=7> <center><b>Total </td><td align=center></td>";
print "<td align=center>$aprice_tot</td>";
print "<td align=center>$hand_tot</td><td></td>";
print "<td align=center>$taxamt_tot</td><td></td><td></td>";
print "<td align=center>$tot_tot</td>";
print "\n<td colspan=6 align=center></td><td align=center>";
print "</td></tr>";
$mdiff = round(round($tot_tot,0)-$tot_tot,2); 
print "<tr><td colspan=12 align=right>Round Off</td><td></td><td></td><td align=right>$mdiff</td>";
print "<td></td>";
print "</tr>";
$mtot=round(round($tot_tot,0),2);
print "<tr><td colspan=12 align=right><b>Invoice Total</td><td></td><td></td><td align=right><b>$mtot</td></b>";
?>
</table>
</blockquote>
</body>
</html>
