<? 
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
?>
<style>
body,td,th{font-family:'arial narrow';letter-spacing:1;font-size:14}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>
<h3>Search Invoice </h3>
<form action ='<?print $PHP_SELF?>'>
<table border=1>
<tr><td>Search Inv No </td><td colspan=2><input type=text name='invno' size=8></td>
<tr>   <td align=right>Date From </td><td>dd <input type=text name='df' size=2>
			   mm <input type=text name='mf' size=2>
			   yy <input type=text name='yf' size=4 value='<?print date("Y",time());?>'>	
			</td>

</tr>
<tr>   <td align=right>To </td><td>dd <input type=text name='dt' size=2 value='<?print date("d",time());?>'>
			   mm <input type=text name='mt' size=2 value='<?print date("m",time());?>'>
			   yy <input type=text name='yt' size=4  value='<?print date("Y",time());?>'>	
			</td>

</tr>
<tr><td colspan=2 align=center><input type=submit value='Show'></td></tr>
</table>
</form>

<?
include("../opendb.php");
include("../test.php");
if(strlen($invno)>0)
 {
  $sql="select * from  veh_invoice where brcode='$brcode' and invno='$invno'";
  print "Search result : ";
 }

else if(strlen($df)>0 && strlen($mf)>0 && strlen($yf)>0 &&strlen($dt)>0 && strlen($mt)>0 && strlen($yt)>0)
 {
 $datef=$yf.'-'.$mf.'-'.$yf;
 $datet=$yt.'-'.$mt.'-'.$yt;

  $sql="select a.invno,a.invdate,b.custname,a.formno,a.rep,a.model1,a.msno,a.config,a.netamt from  veh_invoice a,customer b  where a.brcode='$brcode' and a.cust=b.code and a.invdate>'$datef' and a.invdate<'$datet'";
  print "Search result : ";
 }
else
{
$sql="select a.invno,a.invdate,b.custname,a.formno,a.rep,a.model1,a.msno,a.config,a.netamt,a.jvno from  veh_invoice a,customer b  where a.brcode='$brcode' and a.cust=b.code order by invno desc limit 100";
  print "Showing last 100 records : ";
 }
$re=mysqli_query($db,$sql)or die('Err:'.mysqli_error());
if(mysqli_num_rows($re)<=0)
{
 print "<font color=red>Record does not exist</font>";
 return;
}
print "<table border=1> <th>Inv <th>Date <th>Customer <th>O Frm<br>No <th>Rep";
print "<th>M.Code <th>MSNO<th>Config <th>Net Amt.<th>Action";
while($row=mysqli_fetch_array($re))
{
 $brres=mysqli_query($db,"select * from branch where brcode='$row[cust]'")or die(mysqli_error());
 if(mysqli_num_rows($brres)>0)
 {
   $brrow=mysqli_fetch_array($brres);
 print "<tr><td>$row[invno]</td><td>".datetohtml($row[invdate])."</td><td>$brrow[brname]</td><td>$row[formno]</td>";
}
else
{
 print "<tr><td>$row[invno]</td><td>".datetohtml($row[invdate])."</td><td>$row[cust]</td><td>$row[formno]</td>";
}
 print "<td>$row[rep]</td><td>$row[model1]</td><td>$row[msno]</td><td>$row[config]</td>";
 if($level>=0)
 print "<td>$row[netamt]</td><td><input type=button value='Edit' onClick=edfun('$row[da]','$row[invno]')> <input type=button value='Del' onClick=delfun('$row[msno]','$row[invno]','$row[jvno]')>";
 else
   print "<td>&nbsp;</td>";
print "</tr>";
}
?>

<script>
function edfun(da,invno)
{
 document.location='editvehinvoice.php?da='+da+'&invno='+invno;
}

function delfun(da,invno,jv)
{
 if(confirm('Do you want to delete MSNO '+da+' ?'))
   document.location='delvehinvoice.php?da='+da+'&invno='+invno+'&jvno='+jv;
}
</script>
