
<? 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:12}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>
<form action='<?print $PHP_SELF?>'>
<table border=1 >
<tr><td align=center>Form No. <input type=text name='seafno' size=5> customer Name <input type=text name='seaname'></td><td>Rep.
<select name='exe'><option></option>
<?
 $r=mysqli_query($db,"select * from rep_master where branch='$brcode' order by repname")or die(mysqli_error());
 while($reprow=mysqli_fetch_row($r))
 {
  print "<option value='$reprow[0]'>$reprow[1]</option>";
 }
?>
</select></td><td>
<input type=submit value='Search' name='sea'>
</td></tr>
</table>
</form>
<br>
<?
$sql="select * from orderform where brcode='$brcode' and exch='Y' and dt>='2009-04-01' order by formno desc";

if($sea)
{ print '<font color=blue> Search Result: </font>';
 if(strlen($seafno)>0)
  $sql="select * from orderform where brcode='$brcode' and formno='$seafno' and sale_invno='-' order by formno";
 else if(strlen($seaname)>0)
  $sql="select * from orderform where brcode='$brcode' and cust like '%$seaname%' and sale_invno='-' order by formno";
 else if(strlen($exe)>0)
  $sql="select * from orderform where brcode='$brcode' and rname= '$exe' and sale_invno='-' order by formno";

}
else
 print "<font color=blue>Printing last 100 order forms</font>";

$re=mysqli_query($db,$sql) or die(mysqli_error());
if(mysqli_num_rows($re)<=0)
{
 print "<font color=red>Record does not exist</font>";
 return;
}
print "<table border=1> <th>Form No <th>Date <th>Veh.No.<th>Ex.Div Rate<th>Ex.Value<th>Ex.SalePrice<th>Ex.Expenses<th>Ex.Diff<th>Ex.Description<th>Customer <th>Model <th>Config";
print "<th>Net Amt <th>Edit";
while($row=mysqli_fetch_array($re))
{
 print "\n<tr><td align=center>";
if($row[stat]=='In-Active')
$amt=0;
$amt=$row[exsalevalue]-($row[exdivrate]+$row[exexpenses]);

if($row[exdivrate]==Null ||$row[exdivrate]==0 )
{
$exdiv=0;
}
else
{
$exdiv=$row[exdivrate];

}


if($row[exsalevalue]==Null ||$row[exsalevalue]==0 )
{
$exsale=0;
}
else
{
$exsale=$row[exsalevalue];

}
if($row[exexpenses]==Null ||$row[exexpenses]==0 )
{
$exexpense=0;
}
else
{
$exexpense=$row[exexpenses];

}

if($row[exvehno]==Null ||$row[exvehno]=='0' )
{
$exveh='0';
}
else
{
$exveh=$row[exvehno];
}

if($row[descr]==Null ||$row[descr]=='0' )
{
$des='0';
}
else
{
$des=$row[descr];
}


if($exsale==0 )
{
$amt=0;
}
else
{
$amt=0;
$amt=$row[exsalevalue]-($row[exdivrate]+$row[exexpenses]);
}






 print "<font color=red size=3><b> * </b></font>";
print "$row[formno]</td><td>".datetohtml($row[dt])."</td><td>$exveh</td><td>$exdiv</td><td>$row[exvalue]</td><td>$exsale</td><td>$exexpense</td><td>$amt</td><td>$des</td><td>".strtoupper($row[cust])."</td><td>$row[model]</td><td>$row[config]</td><td align=right>$row[netamt]</td><td>";
if($level>=2) 
 print "<a href='exeditoform.php?code=$row[formno]'>[Edit]</a>";
else
 print "&nbsp;</td>";
print "</tr>";
}
?>
</table>

