<?session_start();
include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:12}
th{background-color:c1d799}
//tr{background-color:c1d799}
.mnu{margin-left:5}
.summ{font-size:13};
</style>
<center>
 NET REALISATION SUMMARY
<form action='netreal1.php' 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>
<?
if($show)
{
$df=$y.'-'.$m.'-'.$d;
$dt=$y1.'-'.$m1.'-'.$d1;
?>
</center>
<table border=0 width=100%>
<th colspan=2 align=center><?print $branch?><br>NET REALISATION SUMMARY <BR>FOR THE PERIOD FROM <?PRINT datetohtml($df).' To '.datetohtml($dt)?></th>
<tr><td align=center>[Printed by <?print $user?> on <?print date("r")?>
<tr><td align=center VALIGN=TOP>
<table border=0 cellspacing=1 cellpadding=3 bgcolor=silver style={font-size:13}>
<th>Ledger <th>DA <th>Chasis  <th>Config <th>Amount <th>Entry Date <th>Body <th>Amount
<th>Inv NO <th>Inv Date <th>Sale Config <th>Sale Amt. <th>Customer <th>Disc Allowed
<?
$sq="select * from veh_invoice where invdate>='$df' and invdate<='$dt' and brcode='$brcode' order by invno";
$re=mysqli_query($db,"select * from veh_invoice where invdate>='$df' and invdate<='$dt' and brcode='$brcode' order by invno");
while($invrow=mysqli_fetch_array($re))
{
$x=0;
print "<tr>";
 $repurch=mysqli_query($db,"select * from veh_purchase where chasis='$invrow[chasis]' and brcode='$brcode'");
if(mysqli_num_rows($repurch)>0)
{
  $prow=mysqli_fetch_array($repurch);
   print "<tr bgcolor='white'><td>$prow[ledger]</td><td><a href='viewpur.php?da=$prow[da]'>$prow[da]</a></td><td>$prow[chasis]</td>";
   print "<td>$prow[config]</td>";
   print "<td>$prow[amt2]</td><td>".datetohtml($prow[entrydate])."</td>";
$x=1;
}
else
{
 $repurch=mysqli_query($db," select a.supname,b.dano,b.pval,b.pdate,b.config,b.chno from sup_master a,vehopstock b where a.code=b.sup and b.chno='$invrow[chasis]' and b.brcode='$brcode'");
if(mysqli_num_rows($repurch)>0)
{
  $prow=mysqli_fetch_array($repurch);
   print "<tr bgcolor='white'><td>$prow[0]</td><td>$prow[dano]</td><td>$prow[chno]</td>";
   print "<td>$prow[config]</td>";
   print "<td>$prow[pval]</td><td>".datetohtml($prow[pdate])."</td>";
$x=1;
}
}
 $sq="select a.itname,b.code from itemmaster a,invoice_item b where a.code=b.item_code and b.chasis='$invrow[chasis]' and b.brcode='$brcode'";

    $itpurch=mysqli_query($db,$sq)or die(mysqli_error());

    $itprow=mysqli_fetch_array($itpurch);
 $sq="select uni_amt from item_purchase where code='$itprow[1]'";
    $itamtres=mysqli_query($db,$sq)or die(mysqli_error());
    $itamtrow=mysqli_fetch_array($itamtres);
   if($x==0)
   print "<td colspan=6></td>";
     print "<td>$itprow[0]-$itprow[1]</td><td align=right>$itamtrow[0]</td>";
     print "<td>$invrow[invno]</td><td>$invrow[invdate]</td><td>$invrow[config]</td><td>$invrow[amt2]</td>";
 if($invrow[type]=='trans-out')
 {
  $ss="select brname from br_master where code='$invrow[cust]'";
   $supres=mysqli_query($db,$ss)or die(mysqli_error());
   $suprow=mysqli_fetch_row($supres)or die('err'.mysqli_error());
   print "<td>$suprow[0]</td>";
 }
 else if(strlen($invrow[cust])>7)
   print "<td>$invrow[cust]</td>";
 else
  {
    $cres=mysqli_query($db,"select acname from cust_master where code='$invrow[cust]'");
     $cusrow=mysqli_fetch_row($cres);
     print "<td>$cusrow[0]</td>";
  }
 $crres=mysqli_query($db,"select * from crnote where da='$invrow[da]'");
 $crrow=mysqli_fetch_array($crres);
 print "<td align=right>$crrow[amt2]</td></tr>";
}
} // end show
?>
