<?
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>
<form action='<?print $PHP_SELF?>' name='f1'>
<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>
<?
if($show)
{
 $dfrom=$y.'-'.$m.'-'.$d;
 $dto=$y1.'-'.$m1.'-'.$d1;
$sql1="select distinct pbillno, purno,suplier,entrydate,porderno,taxtype,jvno 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($db));
print "<b>Purchase Report from ".datetohtml($dfrom).' to '.datetohtml($dto). "- VAT";
print "\n<table border=0 bgcolor='steelblue' cellspacing=1 cellpadding=3>";
print "<th>PO No  <th>PBill No <th>Supplier <th>Entry Date  <th>Before Tax <th>Tax <th>Cess <th>Total<th colspan=2>Edit";

 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 purno='$row1[purno]' and brcode='$brcode' and taxtype='vat' ";
 $re=mysqli_query($db,$sql) or die(mysqli_error($db));

while($row=mysqli_fetch_array($re))
{
 print "\n<tr bgcolor='white' onMouseOver=bgColor='silver'; onMouseOut=bgColor='white'>";
 print  "<td>$row1[porderno]</td><td>$row1[pbillno]</td><td>$row1[suplier]</td>";
 print "<td>".datetohtml($row1[entrydate])."</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 "\n<td><center><input type=button value='Edit' onClick=edfunvat('$row1[purno]','$row1[taxtype]','$row1[jvno]')></td>";
 print "<td><input type=button value='Del' onClick=delfun('$row1[purno]','$row1[taxtype]','$row1[jvno]')></td>";
 print "</tr>";
 $gtot+=$row[tot];
}
}
print "<tr><td colspan=8 align=right><b>Total</td><td align=right>".putComa($gtot)."</td>";

print "</table><br> <hr>";
//*********************************
$gtot=0;
$sql1="select distinct pbillno, purno,suplier,entrydate,porderno,taxtype,jvno 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($db));
print "<b>Purchase Report from ".datetohtml($dfrom).' to '.datetohtml($dto). "- CST";
print "\n\n<table border=0 bgcolor='steelblue' cellspacing=1 cellpadding=3>";
print "<th>PO No  <th>PBill No <th>Supplier <th>Entry Date <th>Before Tax <th>Tax <th>Edu Cess <th>HR Edu Cess<th>Total<th colspan=2>Edit";

 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 purno='$row1[purno]' and brcode='$brcode' and taxtype='cst' ";
 $sql="select * from purtaxdet where purno='$row1[purno]' and jvno='$row1[jvno]' and brcode='$brcode'";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));
 print "\n<tr bgcolor='white' onMouseOver=bgColor='silver'; onMouseOut=bgColor='white'>";
 print  "<td>$row1[porderno]</td><td>$row1[pbillno]</td><td>$row1[suplier]</td>";
 print "<td>".datetohtml($row1[entrydate])."</td> ";

while($row=mysqli_fetch_array($re))
{
 print "<td align=right bgcolor='ivory'>$row[tprice]</td><td align=right>$row[tax]</td>";
 print "<td align=right>$row[educess]</td><td align=right>$row[hreducess]</td>";
 print "<td align=right>$row[gtot]</td>";
 $gtot+=$row[tot];
}
print "\n<td><center><input type=button value='Edit' onClick=edfun('$row1[purno]','$row1[taxtype]','$row1[jvno]')></td>";
 print "<td><input type=button value='Del' onClick=delfun('$row1[purno]','$row1[taxtype]','$row1[jvno]')></td>";
print "</tr>";

}
print "<tr><td colspan=8 align=right><b>Total</td><td align=right>".putComa($gtot)."</td>";

print "</table>";

}
?>
<script>
function edfun(x,y,jvno)
{
 if(confirm('Do you want to edit P.O. No.'+x+' ?'))
  {

   document.location='edpur.php?purno='+x+'&ttype='+y+'&jvno='+jvno;
  }
}
function edfunvat(x,y,jvno)
{
 if(confirm('Do you want to edit P.O. No.'+x+' ?'))
  {

   document.location='edpurvat.php?purno='+x+'&ttype='+y+'&jvno='+jvno;
  }
}

function delfun(x,y,z)
{
 if(confirm('Do you want to Delete P.O. No.'+x+' ?'))
  document.location='delpur.php?purno='+x+'&ttype='+y+'&jv='+z;
}

</script>



