<? session_start();
$brcode = $_SESSION['brcode'];
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:13}
th{background-color:c1d7bb;font-size:13}
.mnu{margin-left:5}
</style>
<center>
<form action='<?print $PHP_SELF?>'>
<table>
<th colspan=2>Search by Chasis No</th>
<tr><td> Enter Chasis No </td><td><input type=text name='ch' size='40' value='<?print $ch?>'></td></tr>
<th colspan=2><input type=submit value='Search' name='sea'></th>
</table>
</form>
<?
$sea = $_REQUEST['sea'];
$ch = $_REQUEST['ch'];
if($sea)
{
/*
vehopstock
veh_purchase
 veh_transin
veh_transout
veh_purchreturn
veh_salereturn
 veh_invoice
*/
if(strlen($ch)>0)
{
$sql=mysqli_query($db,"select * from vehopstock where chno like '%$ch' and brcode='$brcode'");

while($row=mysqli_fetch_array($sql))
{
$da=$row[dano];
print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='5' bgcolor='lightsteelblue' align='center'>Vehicle Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>DA No<th>Purchase Value<th>Purchase Date<th>Config</tr>";
print "<tr><td align='center'>$row[engno]</td><td align='center'>$row[chno]</td><td align='center'>$row[dano]</td><td align='center'>$row[pval]</td><td align='center'>".datetohtml($row[pdate])."</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";
}

$sql1=mysqli_query($db,"select * from veh_purchase where chasis like'%$ch' and brcode='$brcode'");
$da='';
while($row=mysqli_fetch_array($sql1))
{
$da=$row[da];
print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='8' bgcolor='lightsteelblue' align='center'>Vehicle Purchase</td></tr><tr>";
print "<th>Ledger<th>Invoice No<th>Invoice Date<th>DA<th>Engine No<th>Chasis No<th>Amount<th>Config</tr>";
print "<tr><td align='center'>$row[ledger]</td><td align='center'>$row[invno]</td><td align='center'>".datetohtml($row[invdate])."</td><td align='center'>$row[da]</td>";
print "<td align='center'>$row[engno]</td><td align='center'>$row[chasis]</td><td align='center'>$row[amt2]</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";

$sql11=mysqli_query($db,"select * from veh_purchreturn where da='$da' and brcode='$brcode'")or die(mysqli_error());
if(mysqli_num_rows($sql11)>0)
{
while($row=mysqli_fetch_array($sql11))
{
$da=$row[da];
print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='8' bgcolor='lightsteelblue' align='center'>Vehicle Purchase Return</td></tr><tr>";
print "<th>Ledger<th>Ret No<th>Invoice Date<th>DA<th>Engine No<th>Amount<th>Config</tr>";
print "<tr><td align='center'>$row[retto]</td><td align='center'>$row[ret_num]</td><td align='center'>".datetohtml($row[date])."</td><td align='center'>$row[da]</td>";
print "<td align='center'>$row[engno]</td><td align='center'>$row[amt2]</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";
}
}


}


$sql2=mysqli_query($db,"select * from veh_transin where da='$da' and brcode='$brcode'");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from br_master where code='$row[ledger]'");
 $cusrow=mysqli_fetch_array($cusres);

print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='5' bgcolor='lightsteelblue' align='center'>Vehicle Transin</td></tr><tr>";
print "<th>Ledger<th>Invoice No<th>Invoice Date<th>DA<th>Engine No<th>Config</tr>";
print "<tr><td align='center'>$cusrow[0]</td><td align='center'>$row[invno]</td>";
print "<td align='center'>".datetohtml($row[invdate])."</td><td align='center'>$row[da]</td><td align='center'>$row[engno]</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";
}

$sql3=mysqli_query($db,"select * from veh_transout where da='$da' and brcode='$brcode'");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from br_master where code='$row[ledger]'");
 $cusrow=mysqli_fetch_array($cusres);

print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='5' bgcolor='lightsteelblue' align='center'>Vehicle Transout</td></tr><tr>";
print "<th>Ledger<th>Invoice No<th>Invoice Date<th>DA<th>Engine No<th>Config</tr>";
print "<tr><td align='center'>$cusrow[0]</td><td align='center'>$row[invno]</td>";
print "<td align='center'>".datetohtml($row[invdate])."</td><td align='center'>$row[da]</td><td align='center'>$row[engno]</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";
}

$sql4=mysqli_query($db,"select * from veh_invoice where chasis like'%$ch' and brcode='$brcode'");

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from cust_master where code='$row[cust]'");
 $cusrow=mysqli_fetch_array($cusres);
print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='8' bgcolor='lightsteelblue' align='center'>Vehicle Sales</td></tr><tr>";
print "<th>Customer<th>Invoice No<th>Invoice Date<th>DA<th>Engine No<th>Chasis No  <th>Amount<th>Config</tr>";
print "<tr><td align='center'>";
if($row[type]=='d') 
 print $row[cust];
else 
 print $cusrow[0];
print "</td><td align='center'>$row[invno]</td>";
print "<td align='center'>".datetohtml($row[invdate])."</td><td align='center'>$row[da]</td>";
print "<td align='center'>$row[engno]</td><td align='center'>$row[chasis]</td><td align='center'>$row[amt2]</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";
}


$sql11=mysqli_query($db,"select * from veh_salereturn where da='$da' and brcode='$brcode'")or die(mysqli_error());

while($row=mysqli_fetch_array($sql11))
{
$da=$row[da];
print "<table bgcolor='lightsteelblue' cellpadding='1' cellspacing='1'><tr><td bgcolor='#ffffff'>";
print "<table>";
print "<tr><td colspan='8' bgcolor='lightsteelblue' align='center'>Vehicle Sales Return</td></tr><tr>";
print "<th>Ledger<th>Invoice No<th>Invoice Date<th>DA<th>Engine No<th>Amount<th>Config</tr>";
print "<tr><td align='center'>$row[retfrom]</td><td align='center'>$row[ret_num]</td><td align='center'>".datetohtml($row[date])."</td><td align='center'>$row[da]</td>";
print "<td align='center'>$row[engno]</td><td align='center'>$row[amt2]</td><td align='center'>$row[config]</td>";
print "</tr></table>";
print "</td></tr></table><br>";
}

}
}
?>
