<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');

?>
<table width="100%" border="1" cellspacing="0" cellpadding="3" align="center" style="border:#808080 1px solid;">
<tr>
	<th width="5%">Select</th>
    <th width="12%">Asset Code</th>
	<th>Asset Name</th>
	<th width="12%">Asset Group</th>
	<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <th width="12%"><?php echo $r['title_name'];?></th>
    <?php } ?>
	</tr>
	<?php 
	$filter=array();
	if($_REQUEST['group']!='0')
	{
		$filter[]="under_group='".$_REQUEST['group']."'";
	}
	if($_REQUEST['code']!='')
	{
		$filter[]="code LIKE '%".$_REQUEST['code']."%'";
	}
	if($_REQUEST['name']!='')
	{
		$filter[]="name LIKE '%".$_REQUEST['name']."%'";
	}
	if($_REQUEST['site']!='')
	{
		$filter[]="location = '".$_REQUEST['site']."'";
	}
	if($_REQUEST['title']!='0')
	{
		//$filter[]="under_group='".$_REQUEST['group']."'";
		if($_REQUEST['titletext']!='')
		{
			$filter[]="".$_REQUEST['title']." LIKE '%".$_REQUEST['titletext']."%'";
		}
	}
	$filter1='';
	if(!empty($filter))
	{
		$filter1=implode(" AND ", $filter);
	}	

	if($filter1=='')
	{	
		//echo "Select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."' ";
	 $sql=DB_query("Select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); 
	}else{
		//echo "Select * from machine_center where ".$filter1." and CompanyId='".$_SESSION['ACGCompanyId']."' ";
	$sql=DB_query("Select * from machine_center where ".$filter1." and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); 
}
	
	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 
		 $parameter=$myrow['id'];
		 $sqlU=DB_query("Select * from unitsofmeasure where unitid='".$myrow['unit']."' ",$db); 
		 $myrow_unit=DB_fetch_array($sqlU);
      
		 $sqlG=DB_query("Select * from machine_group_master where id='".$myrow['under_group']."' ",$db); 
		 $myrow_group=DB_fetch_array($sqlG);

		 $sqlH=DB_query("SELECT MAX(end_meter_reading) AS HighestPrice FROM tpl_fixed_asset_logbook_details where asset_code=".$myrow['id']." ",$db); 
		 $myrow_mx=DB_fetch_array($sqlH);
		 

$title='';
		   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
		   while($r=DB_fetch_array($title1))
		   {
		    $title[]=$r['db_field_name'];
		   }  
		 
		 
?>
 <tr bgcolor="#fff">
      <td><input type="radio" name="radAnswer" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>" onClick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['code'];?>','<?php echo  $myrow['name'];?>','<?php echo $myrow_group['machine_gp_location']; ?>','<?php echo $myrow['asset_type'];?>','<?php echo $myrow_unit['unitname'];?>','<?php echo $myrow['model_no'];?>','<?php echo $myrow['vehicle_no'];?>','<?php echo $myrow_mx['HighestPrice'];?>','<?php echo $i; ?>','<?php echo $myrow[$title[0]];?>','<?php echo $myrow[$title[1]];?>','<?php echo $myrow[$title[2]];?>')"/></td>
      <td><?php echo $myrow['code'];?></td>
     	<td><?php echo  $myrow['name'];?></td>
      <td><?php echo $myrow_group['machine_gp_location']; ?></td>
      <td><?php echo $myrow[$title[0]]; ?></td>
	   <td><?php echo $myrow[$title[1]]; ?></td>
	   <td><?php echo $myrow[$title[2]]; ?></td>
  </tr>
<?php $i++;} }?>
 </table>

