<?
session_start();
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}
.right{text-align:right};
</style>
<center>
<h3>SPARE INVOICE RECEIPT STATUS</H3>
<?
$invre=mysqli_query($db,"select distinct invtype from spareinvoice ");
while($invrow=mysqli_fetch_array($invre))
{
$re1=mysqli_query($db,"select distinct customer,brcode from spareinvoice where invtype='$invrow[0]'  order by brcode");
while($ro=mysqli_fetch_array($re1))
{
$jvre=mysqli_query($db,"select sum(dramt)-sum(cramt) from journal2 where partic='$ro[0]' ");
$jvrow=mysqli_fetch_row($jvre);

$jvop=mysqli_query($db,"select op from ledger where led='$ro[0]' and brcode='$brcode'");
$jvoprow=mysqli_fetch_row($jvop);

$jvbal=$jvrow[0]+$jvoprow[0];

if($jvbal>0)
{
 $bname=getbr($ro[brcode]);
$gtot1=0;
$re=mysqli_query($db,"select invno,invdate,saleordno,customer,sum(tot) gtot ,sum(qty) gqty,vatorcst,invtype from spareinvoice  where  invtype='$invrow[0]' and customer='$ro[0]' group by customer,invno order by customer")or die(mysqli_error());
print "<br>&nbsp;<table border=1 cellspacing=1 cellpadding=3 bgcolor='lightsteelblue' width=100%>";
print "<th colspan=10><h3>Invoice Type $invrow[0] - $bname</th></tr>";
print " <th>Inv No <th>Invoice Date ";
print "<th>Sale Ord <th>Customer<th>Qty <th>Amount";
while($row=mysqli_fetch_array($re))
{
 print "\n<tr bgcolor=white><td>$row[invno]</td><td>".datetohtml($row[invdate]);
 print "</td><td><center>$row[saleordno]</td>";
 print "<td>$row[customer]</td><td align=right>$row[gqty]</td>";
  $tt=($row[gtot]+$jvbal);
 print "<td align=right>".putComa($row[gtot])."</td>";
 
 $gtot1+=$row[gtot];
}
print "<tr><td colspan=5><center><b>Total</td><td align=right>".putComa($gtot1)."</td></tr>";

print "<tr bgcolor='yellow'><td colspan=5><center><b>Account Balance</td><td align=right>".putComa($jvrow[0])."</td></tr>";
//else
//print "<tr><td colspan=5><center><b>Account Balance</td><td align=right><font color='yellow'".putComa($jvrow[0])."</td></tr>";
print "</table>";
}// end if
}
}
?>
<tr><td colspan=10></td>
</table>

<script>
 function delfun(x,y,z)
 {
  if(confirm('Do you want to delete invoice no '+x))
   document.location='delspinvoice.php?invno='+x+'&invtype='+y+'&vatorcst='+z;
 }
</script>
<?
 function getbr($cd)
 {
  $r3=mysqli_query($db,"select brname from branch where brcode='$cd'");
  $r=mysqli_fetch_row($r3);
  return $r[0];
 }
?>

