<?
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}
.mnu{margin-left:5}
th{font-size:14}
</style>
<CENTER>
<H2>NET REALISATION</H2>
<?
   $df1=$y.'-'.$m.'-'.$d;
   $dt1=$y1.'-'.$m1.'-'.$d1;

show($df1,$dt1,$brcode);
function show($df,$dt,$brcode)
{
include("../opendb.php");
 $sq="select * from veh_invoice where brcode='$brcode' and invdate<='$dt' and invdate>='$df' order by invno";

 $invre=mysqli_query($db,$sq)or die(mysqli_error());
print "<br><table cellspacing=1 cellpadding=2 bgcolor='c1d7bb'>";
print "<th>No<th>Inv No.<th>Customer<th>DA<th>Inv Amt <th>Cr Note<th>Incentive <th>Comm.";
print "<th>Body<th>Jacky <th>Other";
print "<th>Net <th>P Value <th>Net Real <th>Rem";
$i=1;
 while($row=mysqli_fetch_array($invre))
 {
   $net=0;
   print "\n<tr bgcolor=white><form action='$PHP_SELF'>";
   print "<input type=hidden name='invno' value='$row[invno]'>";

   print "<input type=hidden name='df' value='$d9f'>";
   print "<input type=hidden name='dt' value='$dt'>";


 print "<input type=hidden name='da' value='$row[da]'>";
 print "<td>".$i++."</td><td>$row[invno]</td><td>";
 print "<a href='../vmledger.php?cd=".getCust($row[cust])."' target='a'>".getCust($row[cust])."</a></td>";
 print "<td>$row[da]</td><td align=right>$row[amt2]</td>";
 $crres=mysqli_query($db,"select netamt from crnote where da='$row[da]' and brcode='$brcode'");
 $crrow=mysqli_fetch_array($crres);
 print "<td align=right>$crrow[0]</td>";
 $incen=mysqli_query($db,"select * from incentive where da='$row[da]' and brcode='$brcode'");
 $incenrow=mysqli_fetch_array($incen);
 $net=$row[amt2]-($crrow[0]+$incenrow[inc]+$incenrow[com]+$incenrow[body]+$incenrow[jack]+$incenrow[oth]);
 $netreal=$net-($incenrow[pval]*100/112.625);
  print "<td align=right>$incenrow[inc]</td>";
  print "<td align=right>$incenrow[com]</td>";
  print "<td align=right>$incenrow[body]</td>";
  print "<td align=right>$incenrow[jack]</td>";
  print "<td align=right>$incenrow[oth]</td>";

  print "<td align=right>".putComa($net)."</td>";
  print "<td align=right>".putComa($incenrow[pval]*100/112.625)."</td>";
  print "<td align=right>".putComa($netreal)."</td>";
  print "<td align=right>$incenrow[rem]</td>";

  print "</tr>";

 } // end while invre
 print "</table>";
}// end function;



//************************************************
function getCust($c)
{
if(strlen($c<7))
{
$cres=mysqli_query($db,"select acname from cust_master where code='$c'")or die(mysqli_error());
     $cusrow=mysqli_fetch_row($cres)or die(mysqli_error());
 return $cusrow[0];
}
else
 return "<font color=red>".$c;
}
?>
