<?php
$PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
//echo "test";
if(isset($_GET['name']))
{ 
	$type=ucwords($_GET['name']);
	$idx=explode(' ',$type);
	for($i=0;$i<count($idx);$i++)
	{
	$prefix_type[$i]=substr($idx[$i], 0, 1);
	}
	
	$prefix_type1=implode("",$prefix_type);
	//echo 	 $prefix_type=	 $s->GetFieldValue('stockcategory',"id='".$type."'" ,'item_prefix');
	
	$sql='select id from tpl_fixed_asset_definition where 1=1 order by id desc limit 1';
	$result = DB_query($sql,$db);
	$myrow=DB_Fetch_array($result);
	$myrow['id'];
	if($myrow['id']!='')
	{
	$itemcode=$myrow['id'];
	$final_num=$myrow['id']+1;
	$final_string= str_pad($final_num,4,"0",STR_PAD_LEFT);
	}
	else
	{
	$final_string='0001';
	}
	
	
	$asset_code_prefix=$prefix_type1.'-'.$final_string;	  
	
	?>
	<input type="text" value="<?php echo $asset_code_prefix;?>" style="width:150px;"   name="asset_code_prefix" id="asset_code_prefix" readonly="true">
<?php } ?>

<?php if($_REQUEST['code']!='')
{
$SQLREq1=DB_query("select * from tpl_asset_transfer_request where id='".$_REQUEST['code']."'",$db);
$reqDetails=DB_fetch_array($SQLREq1);
extract($reqDetails);

$data1="";
$data1.="<input type='text' name='req_date' id='req_date' value='".ConvertSQLDate($request_date)."' class='datepicker' style='width:150px;' />";


$data2="";
$data2.="<input type='text' name='req_by' id='req_by' value='".$requested_by."' style='width:150px;' />";

$data3="";
$data3.="<input type='text' name='purpose' id='purpose' value='".$purpose."' style='width:150px;' />";






$data4="";
$result2=DB_query("select * from tpl_asset_transfer_request_details  where tpl_asset_transfer_request_id='".$_REQUEST['code']."' 
and tpl_asset_transfer_request_details.required_qty!=0 and status='N'" , $db);
$data4.="<input type='hidden' name='reqid' id='reqid' value='".$_REQUEST['code']."' />";
$data4.="<table width='100%' border='0' cellspacing='0' cellpadding='3'>";
$data4.="<tr class='row1'>";
$data4.="<td class='tabledata'>Sr No.</td>";
$data4.="<td class='tabledata'>Assect Code</td>";
$data4.="<td class='tabledata'>Assect Group</td>";
$data4.="<td class='tabledata'>Serial No</td>";
$data4.="<td class='tabledata'>Machine Name</td>";
$data4.="<td class='tabledata'>UOM</td>";
$data4.="<td class='tabledata'>Available Qty</td>";
$data4.="<td class='tabledata'>Required Qty</td>";
$data4.="<td class='tabledata'>IssueQty</strong></td>";
$data4.="</tr>";
$i=0;
while($myrow2=DB_fetch_array($result2))
{
$asset=DB_query("select * from tpl_materialcategorydefinition where id='".$myrow2['asset_group']."' ",$db);
$asset1=DB_fetch_array($asset);
$assetgroupt=$asset1['asset_capitalisation'];	
$AssetCode=$s->GetFieldValue('tpl_fixed_asset_definition',"id='".$myrow2['machine_id']."'",'asset_code_prefix');
$SerialNo=$s->GetFieldValue('tpl_fixed_asset_definition',"id='".$myrow2['machine_id']."'",'serial_no');
$MachineName=$s->GetFieldValue('tpl_fixed_asset_definition',"id='".$myrow2['machine_id']."'",'asset_name');
$UnitId=$s->GetFieldValue('tpl_fixed_asset_definition',"id='".$myrow2['machine_id']."'",'unit_of_measurement');
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$UnitId."'",'unitname');
$avalQty=$s->GetFieldValue('opening_stock_For_Toolsplants_machine',"machine_id='".$myrow2['machine_id']."'",'stock');
$data4.="<tr class='row1'>";
$data4.="<td>";
$data4.=$i+1;
$data4.="</td>";
$data4.="<td>".$AssetCode."
<input type='hidden' name='reeq_details_id[]' id='reeq_details_id_".$i."' value='".$myrow2['id']."' />
	<input type='hidden' name='asset_group[]' id='asset_group_".$i."' value='".$myrow2['asset_group']."' /></td>";
$data4.="<td>".$assetgroupt."</td>";
$data4.="<td>".$SerialNo."</td>";
$data4.="<td>".$MachineName."<input type='hidden' name='machine_id[]' id='machine_id_".$i."' value='".$myrow2['machine_id']."'></td>";
$data4.="<td>".$UnitName."</td>";
$data4.="<td>".$avalQty."<input type='hidden' name='avail_qty[]' id='avail_qty_".$i."' readonly  value='".$avalQty."'/></td>";
$data4.="<td>".$myrow2['required_qty']."<input type='hidden' name='required_qty[]' id='required_qty_".$i."' readonly  value='".$myrow2['required_qty']."'/></td>";
$data4.="<td><input type='text' name='issue_qty[]' id='issue_qty_".$i."' onkeyup='ChkIssuQty(this.value,this.id)'  value=''/></td>";
$data4.="</tr>";
 $i++;}
$data4.="<input type='hidden' name='count' id='count' value='".$i."' />";	
$data4.="</table>";
echo $data=$data1."__".$data2."__".$data3."__".$data4;
 } 