<?
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,th,pre{font-family:'arial narrow';letter-spacing:1;font-size:13}
//tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>
<center>
<h3>ORDER FORM REPORT </H3>
<?
{


//***********************************************************
$sql="select a.formno,a.cust,a.dt,a.addr,a.phone,b.repname,b.dist,a.model,a.config,a.netamt,a.invalue,a.op,a.sale_invno,a.location from ordf a, rep_master b where a.brcode='$brcode' and a.rname=b.code and a.dt>='$f' and a.dt<='$t' and formno in (select formno from payments where brcode='$brcode' and type!='Cash' and type!='Cheque') order by config";
$re=mysqli_query($db,$sql) or die(mysqli_error());

print "<p align=right><input type=button value='Print' onClick=window.open('prnoformrepo.php?df=$f&dto=$t')></p>";
?>
<table border=1 width=100%>
<th>No<th>Inv No<th>Form<br> NO <th>Customer <th>Date   <th>Model <th>Config <th>Amt@HO <th>Amt@Br<th>Inv Amt <th>Net Amt<th>OP. Bal<th>Balance<th>Rep <th>Dist<th>Address <th>Phone
<?
$sno=1;
while($form_row=mysqli_fetch_array($re))
{
$t=0;
 print "\n<tr onMouseOver=bgColor='c1d7bb'; onMouseOut=bgColor='ivory'><td>".$sno++."</td>";
 $invres=mysqli_query($db,"select invno from veh_invoice where formno='$form_row[formno]'");
 if(mysqli_num_rows($invres)>0)
 {
  $invrow=mysqli_fetch_row($invres);
  print "<td>$invrow[0]</td>";
 }
 else
  print "<td>-</td>";
  //print "<td>$form_row[sale_invno]</td>";
 print "<td><a href='editoform.php?code=$form_row[formno]'>$form_row[formno]</a></td><td>$form_row[cust]</td><td>".datetohtml($form_row[dt])."</td>";

 print "<td>$form_row[model]</td><td>$form_row[config]</td>";

 $sql="select sum(amount) from advcollection where formno='$form_row[0]' and brcode='$brcode' and clearing='y' group by clearing order by clearing desc";
 $res=mysqli_query($db,$sql)or die(mysqli_error());

 $r1=mysqli_fetch_row($res);
  if($r1[0]>0)
   { print "<td align=right>".putComa($r1[0])."</td>";$t=$r1[0];}
  else
    print "<td align=right>0.0</td>";
		//8***********************
 $sql="select sum(amount) from advcollection where formno='$form_row[0]' and brcode='$brcode' and clearing='n' group by clearing order by clearing desc";
 $res=mysqli_query($db,$sql)or die(mysqli_error());

 $r2=mysqli_fetch_row($res);
  if($r2[0]>0)
   { print "<td align=right><a href='svadv.php?formno=$form_row[0]'>$r2[0]</a></td>"; $t+=$r2[0];}
  else
    print "<td align=right>0.0</td>";


$bal=($form_row[netamt]-$form_row[op])-$t;
 print "<td>".putComa($form_row[invalue])."</td><td>".putComa($form_row[netamt])."</td>";
 print "<td align=right>".putcoma($form_row[op])."</td><td align=right>".putComa($bal)."</td>";
print "<td>$form_row[repname]</td><td>$form_row[location]</td>";
 print "<td width=120>".str_replace(',',', ',$form_row[addr])."</td><td>$form_row[phone]</td></tr>";

}
?>
</table>
<?
return;
}
?>


<?
 function getRep($code)
 {
   $reep=mysqli_query($db,"select repname from rep_master where code='$code'");
   $reeprow=mysqli_fetch_row($reep);
   return $reeprow[0];
}
?>

