<?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="0" cellspacing="3" cellpadding="2" align="center">
<tr>
	<td class="tabledata">Select</td>
	<td class="tabledata">Asset Code</td>
	<td class="tabledata">Asset Group</td>
	<td class="tabledata">Asset Name</td>
	<td class="tabledata">Serial No</td>
	<td class="tabledata">UOM</td>
	<td class="tabledata">Available Qty</td>
</tr>
	<?php 
	$filter=array();
	
	if($_REQUEST['code']!='')
	{
		$filter[]="code LIKE '%".$_REQUEST['code']."%'";
	}
	if($_REQUEST['name']!='')
	{
		$filter[]="name LIKE '%".$_REQUEST['name']."%'";
	}
	if($_REQUEST['under_group']!='0')
	{
		$filter[]="under_group = '".$_REQUEST['under_group']."'";
	}
	
	$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'];
		   }  
		   	
  $parameter=$myrow['id'];
  $avalQty=$s->GetFieldValue('opening_stock_for_toolsplants_machine',"machine_id='".$myrow['id']."'",'stock');
 
		 
?>
 <tr bgcolor="#E7E7E7">
	<td><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"<?php echo $c;?> onClick="getAssets('<?php echo $myrow['id'];?>','<?php echo $myrow['code'];?>','<?php echo $myrow['name'];?>','<?php echo $myrow['sr_no']; ?>','<?php echo $myrow['model_no']; ?>','<?php echo $myrow['vehicle_no']; ?>','<?php echo $myrow['purchase_date']; ?>','<?php echo $myrow['purchase_amt']; ?>','<?php echo $i;?>');"/></td>
	<td><?php echo $myrow['code']; ?></td>
	<td><strong><?php echo $s->getField('machine_group_master','id',$myrow['under_group'],'machine_gp_location'); ?></strong></td>
	<td><?php echo $myrow['name'];?></td>
	<td><?php echo $myrow['sr_no']; ?></td>
	<td><?php echo $s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); ?></td>
	<td><?php echo $avalQty; ?></td>         
</tr>
<?php $i++;} }?>
 </table>

