<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form name="form1" action="" method="post">
<table width="100%" border="0" align="left" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td width="10%" align="right">Group</td>
	<td width="20%"><select name="under_group" id="under_group">
		<option value="0">--Select--</option>
		<?php $sql="select * from machine_group_master";
		$query=DB_query($sql,$db);
		while($row1=DB_fetch_array($query))
		{
      $t1='';
      if($row1['id']==$_REQUEST['under_group'])
       $t1="selected";
			?>
			<option value="<?php echo $row1['id']; ?>" <?php echo $t1; ?>><?php echo $row1['machine_gp_location']; ?></option>
		<?php }	?>  
      	</select></td>
    <td width="10%" align="right">Asset Code</td>
	<td width="20%"><input name="asset_code" type="text" id="asset_code" /></td>
	<td width="10%" align="right">Asset Name</td>
	<td><input name="asset_name" type="text" id="asset_name" /></td>
</tr>
<tr class="row1">
	<td colspan="6" style="text-align:center;"><input type="button" onclick="getdataforSearch()" value="Search" class="search" /></td> 
</tr>
</table>

  <div id="ItemListDiv" style="width:100%; float:left; margin-top:10px;">

  <table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" class="thborder">
  <tr>
  	<th width="5%">Select</th>
    <th width="18%">Asset Code</th>
	<th>Asset Name</th>   
    <th width="18%">Working Branch</th>
</tr>
  
	<?php 
	    //echo "Select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."' ";
		$sql=DB_query("Select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); 
?>
	<?php	$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'];
		   }  
		 //echo "Select R.receive_site from tpl_asset_transfer_receive_details AS RD LEFT JOIN tpl_asset_transfer_receive AS R ON RD.receive_id=R.id where asset_id='".$myrow['id']."' order by RD.id DESC limit 0,1";
		 $sqlL=DB_query("Select R.receive_site from tpl_asset_transfer_receive_details AS RD LEFT JOIN tpl_asset_transfer_receive AS R ON RD.receive_id=R.id where asset_id='".$myrow['id']."' order by RD.id DESC limit 0,1",$db); 
		 $myrow_loc=DB_fetch_array($sqlL);

		 if($myrow_loc['receive_site']!='')
		 {
		 	$work_loc=$myrow_loc['receive_site'];
		 }else{
		 	$work_loc=$myrow['work_location'];
		 }

		 
		 
		 
?>
 <tr>
      <td><input type="checkbox" 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]];?>','<?php echo $work_loc;?>')"/></td>
      <td><?php echo $myrow['code'];?></td>
	  <td><?php echo  $myrow['name'];?></td>     
	  <td><?php echo $work_loc;?></td>
    </tr>
<?php $i++;} }?>
 
</table>
</div>
</form>
</div>

</div>
