<?
session_start();
include("opendb.php");
include("test.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Xpress</title>

  



<body onload='window.print()' >



<table border='0' width='100%'>
<tr>
<td align='left' width='33%'> 
<?
$qry1=mysqli_query($db,"select * from company_master where brcode='$brcode'");
$row1=mysqli_fetch_array($qry1);
print $row1[2]."<br>".$row1[4]."<br>".$row1[5]."<br>".$row1[6]."<br>Tel: ".$row1[7]."/ Fax: ".$row1[8]."<br>Email: ".$row1[10];
if($row1[11]!='')
print ",<br>".$row1[11]."<br>Web: ".$row1[12];
else
print "<br>Web: ".$row1[12];
?>
  </td>
<td align='center'  width='33%'><h4><b>INVOICE TILL REPORT FROM </b> <? echo $fromdt; ?> <b> TO </b>  <? echo $todt; ?></h4></td>
<td align='right'  width='33%'> <img src="images/logo.gif" width="70" height="70"  />  </td></tr>
<tr><td colspan='3' align='right'>Finance Code:<? echo $row1[13]; ?></td></tr></table>
  
  <table align='center' style="border-collapse:collapse;font-size:10px;" width='100%' border='1'> 
    
<tr><td><h3>SNo </h3></td><td><h3>Invoice No</h3></td><td><h3>Date</h3></td><td><h3>Car No</h3></td><td><h3>Oil<br>Total</h3></td><td><h3>Filter<br>Total</h3></td><td><h3>Labour<br>Total</h3></td><td><h3>Total<br>Discount</h3></td><td><h3> Net<br>Total </h3></td></tr>
<?
$i=1;
$goiltot=0;
$gfiltot=0;
$glabtot=0;
$distot=0;
$gnettot=0;
$sql=mysqli_query($db,"select distinct(invno) ,vehno,invdate from invoice where invdate between '$fromdt' and '$todt' and brcode='$brcode' order by invno");
while($row=mysqli_fetch_array($sql))
    {
     $sql1=mysqli_query($db,"select sum(total),sum(dis) from invoice where invno='$row[0]' and flag='spares' and group2='Oil' and brcode='$brcode'");
     $sql2=mysqli_query($db,"select sum(total),sum(dis) from invoice where invno='$row[0]' and flag='spares' and group2='Filters' and brcode='$brcode'");
     $sql3=mysqli_query($db,"select sum(total),sum(dis) from invoice where invno='$row[0]' and flag='labour' and brcode='$brcode'");
     $row1=mysqli_fetch_array($sql1);
     $row2=mysqli_fetch_array($sql2);
     $row3=mysqli_fetch_array($sql3);
     $oiltot=$row1[0]+$row1[1];
     $filtot=$row2[0]+$row2[1];
     $labtot=$row3[0]+$row3[1];
     $distot=$row1[1]+$row2[1]+$row3[1];
     $nettot=$row1[0]+$row2[0]+$row3[0];
     print "<tr><td>".$i++."</td><td>$row[0]</td><td>$row[2]</td><td>$row[1]</td><td>".$oiltot."</td><td>".$filltot."</td><td>".$labtot."</td><td>".$distot."</td><td>".$nettot."</td></tr>";
     $goiltot+=$oiltot;
     $gfiltot+=$filtot;
     $glabtot+=$labtot;
     $gdistot+=$distot;
     $gnettot+=$nettot;
     }
     print "<tr><td colspan='4' ><b>Total</td><td><b>".putcoma($goiltot)."</td><td><b>".putcoma($gfiltot)."</td><td><b>".putcoma($glabtot)."</td><td><b>".putcoma($gdistot)."</td><td><b>".putcoma($gnettot)."</td></tr>";

  print "<tr><td colspan='9' >  <b>Payment Mode </b></td></tr>";   

  $qry_sum=mysqli_query($db,"select sum(total),pmode from invoice where brcode='WOR155' group by pmode");
  
  while($row10=mysqli_fetch_array($qry_sum))
   {

   print"<tr><td align='right' colspan='8'>$row10[1]</td><td align='right'>$row10[0]</td></tr>";
    }


print "</table>";


?>
