<?
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>
 NET REALISATION SUMMARY
<form action='<?print $PHP_SELF?>' method=post>
<table bgcolor='silver'>
<tr><td> Date from </td><td>dd<input type=text name='d' size=2 value='<?print date('d',time())?>'>
				mm<input type=text name='m' size=2 value='<?print date('m',time())?>'>
				yy<input type=text name='y' size=4 value='<?print date('Y',time())?>'>
			</td></tr>
<tr><td> To </td><td>dd<input type=text name='d1' size=2 value='<?print date('d',time())?>'>
				mm<input type=text name='m1' size=2 value='<?print date('m',time())?>'>
				yy<input type=text name='y1' size=4 value='<?print date('Y',time())?>'>
			</td>
</tr>
<th colspan=2 align=center><input type=submit name='show' value='Show'>
</td></tr>
</table>
</form>

<?
   $df1=$y.'-'.$m.'-'.$d;
   $dt1=$y1.'-'.$m1.'-'.$d1;

show($df1,$dt1,$brcode);
function show($df,$dt,$brcode)
{
include("../opendb.php");
print "From ".datetohtml($df).' to '.datetohtml($dt);
 $sq="select * from veh_invoice where brcode='$brcode' and invdate<='$dt' and invdate>='$df' and type!='d' and type!='trans-out' 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>Config<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;
$tot=0;
 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>$row[config]</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]);
$pvalres=mysqli_query($db,"select amt2 from veh_purchase where da='$row[da]' and brcode='$brcode'");
$pvalrow=mysqli_fetch_row($pvalres);
if(mysqli_num_rows($pvalres)<=0)
{
$pvalres2=mysqli_query($db,"select pval from vehopstock where dano='$row[da]' and brcode='$brcode'");
$pvalrow=mysqli_fetch_row($pvalres2);
}
// $netreal=$net-($incenrow[pval]);
 $netreal=$net-($pvalrow[0]);//+$incenrow[eiin]);
  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])."</td>";
  print "<td align=right>".putComa($pvalrow[0])."</td>";


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

  print "</tr>";
 $tot+=$netreal;
 } // end while invre
print "<tr><td colspan=14 align=center><b>Total</td> <td align=right>".putComa($tot)."</td>";
 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;
}
?>
