<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
td{font-size:13}
.right{text-align:right};
</style>
<center>

<?
if(isset($_POST['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 AUTOMOBILES 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>
<h3>PURCHASE RETURN</H3>
<?
$d=$_REQUEST['d'];
$m=$_REQUEST['m'];
$y=$_REQUEST['y'];

$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];
 $dfrom=$y.'-'.$m.'-'.$d;
 $dto=$y1.'-'.$m1.'-'.$d1;

$res=mysqli_query($db,"select * from sparepurreturn where brcode='$brcode' and entrydate>='$dfrom' and entrydate<='$dto' order by purno asc")or die(mysqli_error($db));
print "<table border=1 cellpadding=3> <th>Ret No <th>Date<th>Customer  ";
print "<th>Amount <th>Tax Amt <th>Cess <th>Total";
while($row=mysqli_fetch_array($res))
{
  
print "<tr bgcolor='white'><td>$row[retno]</td><td>".datetohtml($row[entrydate])."</td>";
  print "<td>$row[suplier]</td>";
  print "<td align=right>".putComa($row[aprice])."</td>";
  print "<td align=right>".putComa($row[taxamt])."</td>";
  print "<td align=right>".putComa($row[cessamt])."</td>";
 print "<td align=right>".putComa($row[tot])."</td></tr>";
$t1+=$row[aprice];
$t2+=$row[taxamt];
$t3+=$row[cessamt];
$t4+=($row[tot]+$row[cessamt]);

}
print "<tr><td colspan=3 align=center><b>Total</td>";
print "<td align=right>".putComa($t1)."</td>";
print "<td align=right>".putComa($t2)."</td>";
print "<td align=right>".putComa($t3)."</td>";
print "<td align=right>".putComa($t4)."</td>";

print "</table>";
return;
}// end if
?>
<H3>PURCHASE RETURN - SALETAX REPORT</H3>
<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>
