<?
 session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); 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}
//tr{background-color:white} 
th{background-color:c1d799;font-size:13}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<center>
<h2><?print $branch?> <br>VEHICLES NOT SOLD</h2>
[Printed by <?print $user?> On <?print date("r")?><br>&nbsp;
<?
if($go)
{
$df=$y1.'-'.$m1.'-'.$d1;
$dto=$y2.'-'.$m2.'-'.$d2;

$rr=mysqli_query($db,"select formno from veh_invoice where formno!=0 and brcode='$brcode'");
while($vrow=mysqli_fetch_array($rr))
{
 $s.=$vrow[0].",";
}
$s=substr($s,0,strlen($s)-1);
//print $s;
$rloc=mysqli_query($db,"select distinct location from orderform where brcode='$brcode'");
while($locrow=mysqli_fetch_row($rloc))
{
$sq="select * from orderform where brcode='$brcode' and  formno not in($s) and location='$locrow[0]' and stat='Active' and dt>='$df' and dt<='$dto'";
$res=mysqli_query($db,$sq)or die(mysqli_error());
$i=1;
print "<h3>$locrow[0]</h3>";
?>
<table border=0 bgcolor=gray cellspacing=1 cellpadding=1 width=100%>
<th>NO.<th>Form NO <th>Date <th>Customer <th>Rep. <th>Config <th>Location<th>Amt Recd.
<?
while($row=mysqli_fetch_array($res))
{
$sq9="select * from ledger where  brcode='$brcode' and led='$row[cust]'" ;
$result=mysqli_query($db,$sq9)or die(mysqli_error());
$row9=mysqli_fetch_array($result);
$balres=mysqli_query($db,"select sum(dramt),sum(cramt) from journal2 where brcode='$brcode' and partic='$row[cust]'");
 $balrow=mysqli_fetch_row($balres);
 if($row[drcr]=='Dr')
 {$bal=($balrow[0]+$row9[2])-$balrow[1]; //print '<br>bal'.$row[2];
 }
 else
{
 $bal=$balrow[1]+$row9[2]-$balrow[0];
}
  $repres=mysqli_query($db,"select repname from rep_master where code='$row[rname]'");
  $reprow=mysqli_fetch_row($repres);

 print "<tr bgcolor=white valign=top><td align=center  valign=top>".$i++."</td><td align=center  valign=top>$row[formno]</td><td>".datetohtml($row[dt])."</td>";
print "<td><a href='../vmledger.php?cd=".str_replace('&','~',$row[cust])."'>".strtoupper($row[cust])."</a></td><td align=center>$reprow[0]</td>";
 print "<td>$row[config]</td><td>$row[location]</td>";
print "<td align=right>".number_format($bal,2)."</td>";
}   
print "</tr></table>";
}
return;
} // endif
?>

<form action='<?print $PHP_SELF?>'>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td bgcolor='ivory'><center>
<table>
<tr><td>From </td><td>dd<input type=text name='d1' value='1' size=2>
mm<input type=text name='m1' value='<?print date('m')?>' size=2>
yy<input type=text name='y1' value='<?print date('Y')?>' size=4>
</td></tr>
<tr><td>To </td><td>dd<input type=text name='d2' value='<?print date('d')?>' size=2>
mm<input type=text name='m2' value='<?print date('m')?>' size=2>
yy<input type=text name='y2' value='<?print date('Y')?>' size=4>
</td></tr>
<tr><td colspan=2 align=center><input type=submit value='Show' name='go'></td></tr>
</table>
</td></tr>
</table>

</form>
<!--
$advres=mysqli_query($db,"select * from advcollection where formno='$row[formno]'");
    print "<tr bgcolor=white><td colspan=8><table bgcolor=silver width=300><tr><td colspan=3 align=center><b>Payment Details</td></tr>";
    if(mysqli_num_rows($advres)>0)
    {
     print "<th>Date <th>Type <th>Amount";
     $t=0;
    while($advrow=mysqli_fetch_array($advres))
    {
      
       print "<tr bgcolor=white><td>".datetohtml($advrow[date])."</td><td>$advrow[type]</td><td align=right>$advrow[amount]</td></tr>";
    $t+=$advrow[amount];
   }
     print "<tr bgcolor=white><td colspan=2><b>Total</td><td align=right><b>".putComa($t)."</td></tr>";
   print "<tr><td colspan=2>Vehicle Amount</td><td align=right>".putComa($row[netamt])."</td></tr>";
 $bal=putComa($row[netamt]-$t);
  if($bal<=0)
   print "<tr><td colspan=2><font color=red><blink><b>Balance Amount</td><td align=right><b>".$bal."</td></tr>";
else
   print "<tr><td colspan=2><b>Balance Amount</td><td align=right><b>".$bal."</td></tr>";

  }
print " </table>";
}
-->
