<?php
$url_cancel= "index.php?route=ToolPlants/Transaction/fixed_asset_sale_entry_index".$rurl;
$url_add= "index.php?route=ToolPlants/Transaction/fixed_asset_sale_entry".$rurl;


if($_REQUEST['action']=='delete' && $_REQUEST['id'] !='')
{
	$condition1 = "id='".$_REQUEST['id']."'";
	$condition2 = "sale_id='".$_REQUEST['id']."'";
	if(	$s->DeleteRecord('tpl_fixed_assetsales_entry_details',$condition2))
	{
		$s->DeleteRecord('tpl_fixed_assetsales_entry',$condition1);
	}
}
?>

<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
#amc-tab{}
  #amc-tab table{border:none; }
  #amc-tab table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td:last-child{border-right:none;}
  #amc-tab table tr:last-child td{border-bottom:none;}
  #amc-tab table tr td > table tr td{border-right:#808080 1px solid; border-bottom:#808080 1px solid;}
  #amc-tab table tr td > table tr td:last-child{border-right:none;}
  #amc-tab table tr td > table tr:last-child td{border-bottom:none;}
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Fixed Asset Sale Entry</h1>
<p align="left"><a href="<?php echo $url_add;?>&action=addNew" class="search">Add New</a></p>
       
	<table width="100%" border="1" cellspacing="0" cellpadding="3" style="border:808080 1px solid; border-collapse:collapse; background:#fff;">
  	<tr>
  		<th width="6%"><strong>S.No.</strong></th>
	  	<th width="9%"><strong>Invoice No.</strong></th>
	  	<th width="10%"><strong>Invoice Date</strong></th>
	   	<th width="9%"><strong>Party Name</strong></th>
		<th width="6%"><strong>PO No.</strong></th>
	  	<th width="8%"><strong>PO Date</strong></th>
	  	<th width="60"><strong>Asset Code</strong></th>
	   	<th><strong>Asset Name</strong></th>
		<th width="50"><strong>UOM</strong></th>
	  	<th width="70"><strong>Sale Qty</strong></th>
	  	<th width="60"><strong>Sale Price</strong></th>
	  	<th width="60"><strong>Sale Value</strong></th>
	    <th width="6%" colspan="2"><strong>Action</strong></th>
   </tr>
   
<?php
$sql = "SELECT S.*, C.c_name 
		FROM tpl_fixed_assetsales_entry S 
		INNER JOIN clientmaster C ON C.id=S.partyname
		WHERE S.CompanyId='".$_SESSION['ACGCompanyId']."'";
		
$result = DB_query($sql,$db);
if(DB_num_rows($result)>0){
$i=1;
	while($saleRow = DB_fetch_array($result)){?>
		<tr>
			<td><?php echo $i;?></td>
			<td><?php echo $saleRow['invoice_no'];?></td>
			<td><?php echo $saleRow['invoice_date'];?></td>
			<td><?php echo $saleRow['c_name'];?></td>
			<td><?php echo $saleRow['party_PO_no'];?></td>
			<td><?php echo ConvertSQLDate($saleRow['PO_date']);?></td>
			<td colspan="6">
			<div id="amc-tab">
			 <table width="100%" border="0" cellspacing="0" cellpadding="3">
			 <?php 
			 	$sqlAst = "SELECT S.sale_qty, S.sale_value, S.sale_price, A.asset_name, A.asset_code_prefix, U.unitname 
						   FROM tpl_fixed_assetsales_entry_details S
						   INNER JOIN tpl_fixed_asset_definition A on A.id=S.asset_id
						   LEFT JOIN unitsofmeasure U on U.unitid=A.unit_of_measurement
						   where S.sale_id='".$saleRow['id']."'";
						   
				$res = DB_query($sqlAst,$db);
				while($assetRow = DB_fetch_array($res)){
			 ?>
			  <tr>
				<td width="60"><?php echo $assetRow['asset_code_prefix'];?></td>
				<td><?php echo $assetRow['asset_name'];?></td>
				<td width="50"><?php echo $assetRow['unitname'];?></td>
				<td width="70"><?php echo $assetRow['sale_qty'];?></td>
				<td width="60"><?php echo $assetRow['sale_price'];?></td>
				<td width="60"><?php echo $assetRow['sale_value'];?></td>
			  </tr>
			  <?php }?>
			 </table>
			 </div>
			</td>
			<td><a href="<?php echo $url_add;?>&action=edit&id=<?php echo $saleRow['id'];?>"><img src="images/icon_edit.gif" title="Edit" /></a></td>
			<td><a href="<?php echo $url_cancel;?>&action=delete&id=<?php echo $saleRow['id'];?>"><img src="images/Icon_Delete.png" title="Edit" onClick="return confirm('Are you sure you wish to delete this Record?')" /></a></td>
		</tr>
	
<?php $i++; } 
}else{?>
<tr bgcolor="#fff"><td colspan="14" align="center"><font color="#FF0000">No Record Found</font></td></tr>
<?php } ?>
</table>
</div>
</div>
