<?
 session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<CENTER>
<H3>SALES REGISTER - DETAILED</H3>
<?
   $result=mysqli_query($db,"select * from veh_invoice where invdate>='$df' and invdate<='$dt' and brcode='$brcode' and type!='trans-out'") or die(mysqli_error());
   if(mysqli_num_rows($result)>0)
   {
?>
<font size=3><b>Report From <?print datetohtml($df).' To '.datetohtml($dt)?></b></font> <br>
<table bgcolor=silver cellspacing=1 cellpadding=1>
<th>No.<th>To <th>Inv NO.<th>Inv. Date <th>DA <th>Addr1 <th>Addr2 <th>City <th>Dist.<th>PAN
<th>Phone1 <th>Phone 2<th>Fine<th>Model <th>Config <th>Eng No. <th>Chasis <th>Segment.<th>Rep
<th>Before<br>Tax<th>Tax <th>Cess <th>Net
<?
$i=1;
     while($row=mysqli_fetch_array($result))
     {
    $addr1='';
    $dist='';
 if($row[type]=='-'||$row[type]=='sale-ret')
  { 
   $cus_result=mysqli_query($db,"select custname,addr1,addr2,city,dist,phone1,phone2,kgst from cust_master where code='$row[cust]'")or die  (mysqli_error());
    $cus_row=mysqli_fetch_array($cus_result);
    $cust=$cus_row[0];
    $addr1=$cus_row[addr1];
    $dist=$cus_row[dist];
    $addr2=$cus_row[addr2];

$rep_result=mysqli_query($db,"select repname from rep_master where 
code='$row[rep]'")or die (mysqli_error());
    $rep_row=mysqli_fetch_row($rep_result);
    $rep=$rep_row[0];

  }
 else if($row[type]=='trans-out')
 {
   $cus_result=mysqli_query($db,"select brname from br_master where code='$row[cust]'")or die  (mysqli_error());
    $cus_row=mysqli_fetch_row($cus_result);
    $cust="<font color='brown'>".$cus_row[0];
}  
else
 $cust="<font color='green'>".$row[0];
if($row[taxtype]=='CST')
	$minvno = 'CST'.$row[invno];
else
	$minvno = $row[invno];

      print "\n<tr bgcolor=white><td align=center>".$i++."</td><td>$cust</td><td align=center>$minvno</td><td>".datetohtml($row[invdate])."</td><td>$row[da]</td><td>$addr1</td><td>$addr2</td>";
print "<td>$cus_row[city]</td><td>$dist</td><td>$cus_row[kgst]</td><td>$cus_row[phone1]</td>";
  print "<td>$cus_row[phone2]</td>";
  print "<td>$row[fin]</td>";

      print "\n<td>$row[model_code]</td><td>$row[config]</td><td>$row[engno]</td>";
      print "<td>$row[chasis]</td><td>$row[segment]</td><td>$rep</td>";
     print "\n<td align=right>$row[amt2]</td><td align=right>$row[tax]</td>";
     print "<td align=right>$row[cessamt]</td><td align=right>$row[netamt]</td></tr>";
$tamt2+=$row[amt2];
$ttax+=$row[tax];
$tcessamt+=$row[cessamt];
$tnetamt+=$row[netamt];
    }
print "<tr><td colspan=19 align=right><b>Total</td><td align=right>".putComa($tamt2)."</td>";
print "<td align=right>".putComa($ttax)."</td>";
print "<td align=right>".putComa($tcessamt)."</td>";
print "<td align=right>".putcoma($tnetamt)."</td>";

}
else
 print "Record does not exist";

?>
</table>
