<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$level=$_SESSION['level'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='../index.html' </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:12}
.right{text-align:right};
</style>
<center>
<h3>SPARE INVOICE REPORT -1</H3>
<?
$invre=mysqli_query($db,"select distinct invtype from spareinvoice where brcode='$brcode'");
while($invrow=mysqli_fetch_array($invre))
{
$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]' group by invno");
print "<table border=0 cellspacing=1 cellpadding=3 bgcolor='lightsteelblue'>";
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";
if($level==5)
print"<th>Action";
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>";

if($level>=4)
 print "\n<td><input type=button value='Del' name='del' onClick=javascript:delfun('$row[invno]')></td></tr>";
 $gtot1+=$row[gtot];
}
print "<tr><td colspan=5><center><b>Total</td><td>".putComa($gtot1)."</td></tr></table><br>";

}
?>
<tr><td colspan=10></td>
</table>

<script>
 function delfun(x)
 {
  if(confirm('Do you want to delete invoice no '+x))
  document.location='delspinvoice.php?invno='+x;
 }
</script>
