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

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

<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:lightsteelblue;color:black}
//tr{background-color:white}
</style>
<center>

<?
if($show)
{
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
?>
<table>
<TR><TD COLSPAN=2 ALIGN=CENTER><b> PSN CONSTRUCTION EQUIPMENTS P LTD </b><BR>
	 <?print $brrow[braddr].",".$brrow[brcity].",<br><u> PH - ".$brrow[brphone]?></u>
TIN: <?print $brrow[tin]?>, CST: <?print $brrow[cstno]?>&nbsp;
</td></tr>
<tr><td COLSPAN=2 ALIGN=CENTER>
</td></tr>
</table>
<?
 $dfrom=$y.'-'.$m.'-'.$d;
 $dto=$y1.'-'.$m1.'-'.$d1;
$sql1="select distinct pbillno, purno,suplier,entrydate,porderno,taxtype from sparepurchase where entrydate>='$dfrom' and entrydate<='$dto' and brcode='$brcode' and taxtype='vat' order by purno";
 $re1=mysqli_query($db,$sql1)or die(mysqli_error());
print "<b>Purchase Report from ".datetohtml($dfrom).' to '.datetohtml($dto). "- VAT";
print "<table border=0 bgcolor='steelblue' cellspacing=1 cellpadding=3>";
print "<th>PNo <th>PBill No <th>Date <th>Supplier   <th>Before Tax <th>Tax <th>Cess <th>Total ";

 while($row1=mysqli_fetch_array($re1))
 {
 $sql="select sum(supqty),sum(aprice) aprice, sum(hand) hand,sum(taxamt) tax, sum(cessamt) cessamt,sum(tot) tot from sparepurchase where pbillno='$row1[pbillno]' and purno='$row1[purno]' and brcode='$brcode' and taxtype='vat' ";
 $re=mysqli_query($db,$sql) or die(mysqli_error());

while($row=mysqli_fetch_array($re))
{
 print "<tr bgcolor='white' onMouseOver=bgColor='silver'; onMouseOut=bgColor='white'>";
 print  "<td>$row1[purno]</td><td>$row1[pbillno]</td>";
 print "<td>".datetohtml($row1[entrydate])."</td> ";
 print "<td>$row1[suplier]</td>";
 print "<td align=right bgcolor='ivory'>$row[aprice]</td><td align=right>$row[tax]</td>";
 print "<td align=right>$row[cessamt]</td><td align=right>$row[tot]</td>";
print "</tr>";
 $t1+=$row[aprice];
 $t2+=$row[tax];
 $t3+=$row[cessamt];

 $gtot+=$row[tot];
}
}
print "<tr bgcolor='white'><td colspan=4 align=right><b>Total</td>";
print "<td align=right><b>".putComa($t1)."</td>";
print "<td align=right><b>".putComa($t2)."</td>";
print "<td align=right><b>".putComa($t3)."</td>";

print "<td align=right><b>".putComa($gtot)."</td>";

print "</table><br>";
//*********************************
/*$sql1="select distinct pbillno, purno,suplier,entrydate,porderno,taxtype from sparepurchase where entrydate>='$dfrom' and entrydate<='$dto' and brcode='$brcode' and taxtype='cst' order by purno";
 $re1=mysqli_query($db,$sql1)or die(mysqli_error());
print "<b>Purchase Report from ".datetohtml($dfrom).' to '.datetohtml($dto). "- CST";
print "<table border=0 bgcolor='steelblue' cellspacing=1 cellpadding=3>";
print "<th>PNo <th>PBill No <th>Date <th>Supplier <th>Before Tax <th>Tax <th>Cess <th>Total ";

 while($row1=mysqli_fetch_array($re1))
 {
 $sql="select sum(supqty),sum(aprice) aprice, sum(hand) hand,sum(taxamt) tax, sum(cessamt) cessamt,sum(tot) tot from sparepurchase where pbillno='$row1[pbillno]' and brcode='$brcode' and taxtype='cst' ";
 $re=mysqli_query($db,$sql) or die(mysqli_error());

while($row=mysqli_fetch_array($re))
{
 print "<tr bgcolor='white' onMouseOver=bgColor='silver'; onMouseOut=bgColor='white'>";
 print  "<td>$row1[purno]</td><td>$row1[pbillno]</td>";
 print "<td>".datetohtml($row1[entrydate])."</td> ";
 print "<td>$row1[suplier]</td>";
 print "<td align=right bgcolor='ivory'>$row[aprice]</td><td align=right>$row[tax]</td>";
 print "<td align=right>$row[cessamt]</td><td align=right>$row[tot]</td>";
print "</tr>";
 $gtot+=$row[tot];
}
}
print "<tr><td colspan=7 align=right><b>Total</td><td align=right>".putComa($gtot)."</td>";

print "</table>";*/
return;
}
?>

<form action='<?print $PHP_SELF?>' name='f1' method='post'>
<table>
<tr><td bgcolor='steelblue' colspan=2><center><b><font color=white>PURCHASE REPORT</td></tr>
<tr><td>Date 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>Date 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>
<th colspan=2><INPUT TYPE=SUBMIT VALUE='SHOW' name='show'></td></tr>
</table>
</form>
<script>
function edfun(x,y)
{
 if(confirm('Do you want to edit P.O. No.'+x+' ?'))
  document.location='edpur.php?purno='+x+'&ttype='+y;
}
</script>


