<?php  
$url_cancel= "index.php?route=ToolPlants/Transaction/fixed_assets_transfer_Request_index".$rurl;
$url_add = "index.php?route=ToolPlants/Transaction/fixed_assets_transfer_Request".$rurl;
$url_print = "index.php?route=ToolPlants/Transaction/print_fixed_assets_transfer_Request".$rurl;

//echo $url_cancel;

if($_REQUEST['action']=='delete' && !empty($_REQUEST['rid']))
{
	if($s->DeleteRecord('tpl_asset_transfer_request',"id=".$_REQUEST['rid']))
	{
	$s->DeleteRecord('tpl_asset_transfer_request_details',"asset_req_id=".$_REQUEST['rid']);
	$_SESSION['success_msg']="Delete Successfully";
	}
}

if($_REQUEST['Cancel']!='')
{
unset($_SESSION['manvi']);
unset($_SESSION['qutotation_itemcode']);	
	unset($_REQUEST);
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Fixed Asset Transfer Request</h1>
<p align="left">
<a href="<?php echo $url_add.'&action=addnewdata';?>"><input type="button" name="Add New" value="Add New" class="search" /></a>
</p>
<div style="width:1246px; overflow:auto;">
<table width="1900" border="1" cellspacing="0" cellpadding="3" style="border:#808080 1px solid;">
<tr bgcolor="#CCCCCC" height="25">
	<td width="2%"><strong>S. No.</strong></td>
	<td width="10%"><strong>Branch</strong></td>
	<td width="5%"><strong>ATR No.</strong></td>
	<td width="3%"><strong>ATR Date</strong></td>
	<td width="10%"><strong>Requested By</strong></td>
	<td width="150"><strong>Asset Code</strong></td>
	<td width="200"><strong>Asset Name </strong></td>
	<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <td width="150"><strong><?php echo $r['title_name'];?></strong></td>
    <?php } ?>
	
	<td width="100"><strong>Status</strong></td>
	<td><strong>Approval Status </strong></td>
	<td width="70"><strong>Issue Status </strong></td>
	<td><strong>Receive Status </strong></td>
	<td  colspan="3" style="text-align:center;"><strong>Action</strong></td>
</tr>
<?php 
//$record=$s->GetRecordById('tpl_asset_transfer_request',1);
$sql = "select R.id, R.request_no, R.request_date, R.approved_status,R.issued_status,R.received_status,
         E.emp_name, L.loccode	from tpl_asset_transfer_request R 
		INNER JOIN empmaster E on E.id=R.requested_by
		INNER JOIN locations L on L.loccode=R.requested_site
		where R.CompanyId='".$_SESSION['ACGCompanyId']."' and R.request_date 
		 BETWEEN '".$_SESSION['financialYrStart']."' AND '".$_SESSION['financialYrEnd']."'";
		 
//echo $sql;		 
 $record=DB_query($sql,$db);
$i=0;
if(DB_num_rows($record)>0){
while($row=DB_fetch_array($record))
{
$i++;
extract($row);



?>
<tr bgcolor="#FFFFFF">
<td><?php  echo $i;?></td>
<td><?php  echo $loccode;?> </td>
<td><?php  echo $request_no;?> </td>
<td><?php  if($request_date!='') echo date('d/m/y',strtotime($request_date)); else echo ""; ?> </td>
<td><?php  echo $emp_name;?></td>
<td colspan="6" style="padding:0px;">
	<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<?php
		$reqDet_sql = "SELECT R.required_qty, R.status AS RS, A.* FROM tpl_asset_transfer_request_details R
					   INNER JOIN machine_center A ON A.id=R.asset_code
					   WHERE R.asset_req_id='".$id."'";
		$result = DB_query($reqDet_sql,$db);
		if(DB_num_rows($result)>0){
			while($assetRow = DB_fetch_array($result)){?>
				<tr>
					<td width="149" style="border-right:#808080 1px solid;"><?php  echo $assetRow['code'];?></td>
				  <td width="200" style="border-right:#808080 1px solid;"><?php  echo $assetRow['name'];?></td>
					<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <td width="150" style="border-right:#808080 1px solid;"><?php echo $assetRow[$r['db_field_name']];?></td>
    <?php } ?>
	<td width="99"><?php  echo $assetRow['RS'];?></td>
	</tr>
		<?php	}
		}
	?>
	
	</table>
</td>
<td ><?php  echo $approved_status;?> </td>
<td><?php  echo $issued_status;?> </td>
<td><?php  echo $received_status;?> </td>

<td width="3%">
<?php 
if($approved_status!='Pending'){
echo "Not allowed";
}else{?>
<a href="<?php echo $url_add;?>&action=edit&rid=<?php echo $id;?>"><img src="images/icon-edit.png" width="10" height="10"></a> 
<?php }?>
</td>
<td>
<?php if($approved_status!='Pending'){
echo "Not allowed";
}else{?>

<a href="<?php echo $url_cancel;?>&action=delete&rid=<?php echo $id;?>"><img src="images/Icon_Delete.png" width="10" height="10" onClick="return confirm('Are you sure you wish to delete this Record?')"></a>
<?php }?></td>
<td><a href="atr_print.php?rid=<?php echo $id;?>" target="_blank"><img width="18" height="18" src="images/icon_print.jpg"></a> </td>
</tr><?php 
} 

}else{?>
<tr>
<td colspan="15"><font color="#FF0000">No Record Found</font></td>
</tr>
<?php }?>
</table>
</div>
<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
}	unset($_SESSION['success_msg']);
?>
</div>
</div>