<? 
session_start();
$brcode = $_SESSION['brcode'];
$user = $_SESSION['user'];
$level = $_SESSION['level'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
?>
<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 DA '+da+' ?'))
   document.location='delvehinvoice.php?da='+da+'&invno='+invno+'&jvno='+jv;
}
</script>
<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?>' method='POST'>
<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");
$invno= $_REQUEST['invno'];
$yf = $_REQUEST['yf'];
$mf = $_REQUEST['mf'];
$df = $_REQUEST['df'];
$yt = $_REQUEST['yt'];
$mt = $_REQUEST['mt'];
$dt = $_REQUEST['dt'];

if(strlen($invno)>0)
 {
 $sql="select a.invno,a.invdate,b.custname,a.formno,a.rep,a.model_code,a.da,a.config,a.netamt,a.chasis,a.engno,a.jvno from  veh_invoice a,cust_master b  where a.brcode='$brcode' and a.cust=b.code and a.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.'-'.$df;
 $datet=$yt.'-'.$mt.'-'.$dt;

  $sql="select a.invno,a.invdate,b.custname,a.formno,a.rep,a.model_code,a.da,a.config,a.netamt, a.chasis,a.engno from  veh_invoice a,cust_master 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.model_code,a.da,a.config,a.netamt,a.jvno, a.chasis,a.engno from  veh_invoice a,cust_master b  where a.brcode='$brcode' and a.cust=b.code and a.taxtype='VAT' order by invno desc limit 100";
  print "Showing last 100 records : ";
 }
 //echo $sql;
$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>Inv <th>Date <th>Customer <th>O Frm<br>No <th>Rep";
print "<th>D.A <th>Config <th>Chasis<th>Net Amt.<th>Action";
while($row=mysqli_fetch_array($re))
{
 print "\n<tr><td>$row[invno]</td><td>".implode('-', array_reverse(explode('-', $row['invdate'])))."</td><td>$row[custname]</td><td>$row[formno]</td>";
 print "<td>$row[rep]</td><td>$row[da]</td><td>$row[config]</td><td>$row[chasis]</td><td>$row[netamt]</td>";

 if($level>=4)
 print "\n
<td><input type=button value='Edit' onClick=edfun('".
str_replace(' ','*',$row['da'])."','$row[invno]')> \n<input type=button value='Del' onClick=delfun('".str_replace(' ','*',$row['da'])."','$row[invno]','$row[jvno]')>";
 else
   print "<td>&nbsp;</td>";
print "</tr>";
}
print "</table>";
// }
print "<h2>CST</h2>";
$sql="select a.invno,a.invdate,b.custname,a.formno,a.rep,a.model_code,a.da,a.config,a.netamt,a.jvno from  veh_invoice a,cust_master b  where a.brcode='$brcode' and a.cust=b.code and a.taxtype='INTERSTATE' order by invno desc limit 100";
  print "Showing last 100 records : ";

$re1=mysqli_query($db,$sql)or die(mysqli_error());
if(mysqli_num_rows($re1)<=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>D.A <th>Config <th>Chasis<th>Engno<th>Net Amt.<th>Action";
while($row=mysqli_fetch_array($re1))
{
 print "\n<tr><td>$row[invno]</td><td>".implode('-', array_reverse(explode('-', $row['invdate'])))."</td><td>$row[custname]</td><td>$row[formno]</td>";
 print "<td>$row[rep]</td><td>$row[model_code]</td><td>$row[da]</td><td>$row[config]</td><td>$row[chasis]</td><td>$row[engno]</td>";
 if($level>=4)
 {print "\n<td>$row[netamt]</td>";
 print "<td><input type=button value='Edit' onClick=edfun('".str_replace(' ','*',$row['da'])."','$row[invno]')>";
print " \n<input type=button value='Del' onClick=delfun('".str_replace(' ','*',$row['da'])."','$row[invno]','$row[jvno]')>";}
 else
   print "<td>&nbsp;</td>";
print "</tr>";
}

?>


