<? 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: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='25' value='<?print $ch?>'></td></tr>
<th colspan=2><input type=submit value='Search' name='sea'></th>

<table border=1 align=left>
<tr><td>Branch Code</td><td>Branch Name</td></tr>
<tr><td>AUT141</td><td>CALICUT</td></tr>
<tr><td>AUT009</td><td>MANGLORE</td></tr>
<tr><td>AUT103</td><td>BANGLORE</td></tr>
<tr><td>PSN236</td><td>ERNAKULAM</td></tr>

</table>
</table>

</form>
<?
if($sea)
{
/*
vehopstock
veh_purchase
 veh_transin
veh_transout
veh_purchreturn
veh_salereturn
 veh_invoice
*/
if(strlen($ch)>0)
{


$flag1=0;
$flag2=0;
$flag3=0;
$flag4=0;
$flag5=0;
$flag6=0;
$flag7=0;

$flag8=0;

$sql1=mysqli_query($db,"select * from veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag1=1;

}


$sql1=mysqli_query($db,"select * from psndb1314.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag7=1;
}



$sql1=mysqli_query($db,"select * from psndb1213.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag7=1;
}


$sql1=mysqli_query($db,"select * from psndb1112.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag6=1;
}


$sql1=mysqli_query($db,"select * from psndb1011.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag2=1;
}


$sql1=mysqli_query($db,"select * from psndb0910.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag3=1;
}

$sql1=mysqli_query($db,"select * from psndb0809.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag4=1;
}

$sql1=mysqli_query($db,"select * from psndb0708.veh_purchase where chasis like'%$ch' ");
if(mysqli_num_rows($sql1)>0)
{
$flag5=1;
}



/*
if ($flag==0)
{
print "<script> alert('No')</script>";
}
*/


//*****************************************************************************

if ($flag8==1)
{

$sql=mysqli_query($db,"select * from psndb.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb1314.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb1314.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb1314.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb1314.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>Branch <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[brcode]</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 psndb1314.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb1314.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>Branch <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[brcode]</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>";
}

if(mysqli_num_rows($sql1)>0)
{

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

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb1314.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>Branch <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[brcode]</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 psndb1314.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}
//print "<script> alert('10-11')</script>";
}



//*****************************************************************************

if ($flag7==1)
{

$sql=mysqli_query($db,"select * from psndb.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb1213.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb1213.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb1213.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb1213.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>Branch <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[brcode]</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 psndb1213.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb1213.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>Branch <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[brcode]</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>";
}

if(mysqli_num_rows($sql1)>0)
{

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

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb1213.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>Branch <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[brcode]</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 psndb1213.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}
//print "<script> alert('10-11')</script>";
}

//***********************************************************************************************



//*****************************************************************************

if ($flag6==1)
{

$sql=mysqli_query($db,"select * from psndb.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb1112.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb1112.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb1112.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb1112.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>Branch <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[brcode]</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 psndb1112.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb1112.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>Branch <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[brcode]</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>";
}

if(mysqli_num_rows($sql1)>0)
{

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

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb1112.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>Branch <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[brcode]</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 psndb1112.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}
//print "<script> alert('10-11')</script>";
}

//***********************************************************************************************


if ($flag1==1)
{
$sql=mysqli_query($db,"select * from vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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' ");
$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>Branch <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[brcode]</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' ")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>Branch <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[brcode]</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' ");

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>Branch <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[brcode]</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' ");

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>Branch <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[brcode]</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' ");

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>Branch <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[brcode]</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' ")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>Branch <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[brcode]</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>";
}
//print "<script> alert('11-12')</script>";
}

//****************************************************************************************************
if ($flag2==1)
{

$sql=mysqli_query($db,"select * from psndb.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb1011.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb1011.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb1011.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb1011.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>Branch <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[brcode]</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 psndb1011.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb1011.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>Branch <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[brcode]</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>";
}

if(mysqli_num_rows($sql1)>0)
{

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

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb1011.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>Branch <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[brcode]</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 psndb1011.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}
//print "<script> alert('10-11')</script>";
}

//**************************************************************************************************************
if ($flag3==1)
{


$sql=mysqli_query($db,"select * from psndb1011.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb0910.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb0910.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb0910.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb0910.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>Branch <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[brcode]</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 psndb0910.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb0910.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>Branch <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[brcode]</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>";
}

if(mysqli_num_rows($sql)>0)
{

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

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb1011.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>Branch <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[brcode]</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 psndb0910.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}

//print "<script> alert('09-10')</script>";
}

//****************************************************************************************************


if ($flag4==1)
{


$sql=mysqli_query($db,"select * from psndb0910.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb0809.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb0809.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb0809.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb0809.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>Branch <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[brcode]</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 psndb0809.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb0809.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>Branch <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[brcode]</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>";
}
if(mysqli_num_rows($sql11)>0)
{
$sql4=mysqli_query($db,"select * from psndb0910.veh_invoice where chasis like'%$ch' ");

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb0910.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>Branch <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[brcode]</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 psndb0809.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}

//print "<script> alert('08-09')</script>";
}


//****************************************************************************************************


if ($flag5==1)
{


$sql=mysqli_query($db,"select * from psndb0809.vehopstock where chno like '%$ch' ");

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 Opening Stock</td></tr><tr>";
print "<th>Engine No<th>Chasis No<th>Branch <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[brcode]</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 psndb0708.veh_purchase where chasis like'%$ch' ");
$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>Branch <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[brcode]</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 psndb0708.veh_purchreturn where da='$da' ")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>Branch <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[brcode]</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 psndb0708.veh_transin where da='$da' ");

while($row=mysqli_fetch_array($sql2))
{
 $cusres=mysqli_query($db,"select brname from psndb0708.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>Branch <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[brcode]</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 psndb0708.veh_transout where da='$da' ");

while($row=mysqli_fetch_array($sql3))
{
 $cusres=mysqli_query($db,"select brname from psndb0708.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>Branch <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[brcode]</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>";
}

if(mysqli_num_rows($sql11)>0)
{

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

while($row=mysqli_fetch_array($sql4))
{
$da=$row[da];
 $cusres=mysqli_query($db,"select acname from psndb0809.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>Branch <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[brcode]</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 psndb0708.veh_salereturn where da='$da' ")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>Branch <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[brcode]</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>";
}

//print "<script> alert('07-08')</script>";
}
//****************************************************************************************************

}
}
?>
