<?
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 where brcode='$brcode'");
while($invrow=mysqli_fetch_array($invre))
{

$re1=mysqli_query($db,"select distinct customer from spareinvoice where brcode='$brcode' and invtype='$invrow[0]'  order by customer");
while($ro=mysqli_fetch_array($re1))
{


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

$jvre=mysqli_query($db,"select sum(dramt)-sum(cramt) from journal2 where partic='$ro[0]' and brcode='$brcode'");
$jvrow=mysqli_fetch_row($jvre);

$jvbal=$jvrow[0]+$jvoprow[0];
if($jvbal>0)
{
$gtot1=0;
$re=mysqli_query($db,"select invno,invdate,saleordno,customer,sum(tot) gtot ,sum(qty) gqty,vatorcst,invtype from spareinvoice  where brcode='$brcode' and invtype='$invrow[0]' and customer='$ro[0]' group by customer,invno order by customer");
print "<br>&nbsp;<table border=1 cellspacing=1 cellpadding=3 bgcolor='lightsteelblue' width=100%>";
print "<th colspan=10><h3>Invoice Type $invrow[0]</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>";
  
 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($jvbal)."</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>
