<?php 
$url_cancel= "index.php?route=ToolPlants/Transaction/asset_breakdown_management".$rurl;
$url_add = "index.php?route=ToolPlants/Transaction/asset_breakdown_management_add".$rurl;
$url_print = "index.php?route=ToolPlants/Transaction/print_asset_breakdown_management".$rurl;

//echo $url_cancel;

if($_REQUEST['action']=='delete' && !empty($_REQUEST['rid']))
{ 
	if($s->DeleteRecord('tpl_breakdown_mgmt',"id=".$_REQUEST['rid']))
	{
	$s->DeleteRecord('tpl_asset_transfer_request_details',"asset_req_id=".$_REQUEST['rid']);
	if($s!="")
		{
		$delete = DB_query("DELETE FROM tpl_breakdown_mgmt_machine
						WHERE master_id = '".$_REQUEST['rid']."'",$db);
		$delete1= DB_query("DELETE FROM tpl_breakdown_mgmt_details
						WHERE master_id = '".$_REQUEST['rid']."'",$db);
		$_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>Machine Breakdown Management</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 class="overpanel">
<table width="150%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="2%" rowspan="2">S. No.</th>
	<th width="10%" rowspan="2">Branch</th>
	<th width="5%" rowspan="2">Received Date</th>
	<th width="8%" rowspan="2">Job Card No.</th>
	<th width="8%" rowspan="2">Break Down Location</th>
	<th width="8%" rowspan="2">Received By</th>
	<th width="150" rowspan="2">Asset Code</th>
	<th rowspan="2">Asset Name</th>
	<th width="170" rowspan="2">Asset Group</th>
		<?php 
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
    ?>
    <th width="130" rowspan="2"><?php echo $r['title_name'];?></th>
    <?php } ?>
	<th colspan="3" style="text-align:center;">Action</th>
</tr>
<tr>
	<th width="3%" class="text-center">Edit</th>
	<th width="3%" class="text-center">Delete</th>
	<th width="3%" class="text-center">Print</th>
</tr>
<?php 
//$record=$s->GetRecordById('tpl_asset_transfer_request',1);
 $sql = "SELECT tpl_breakdown_mgmt.id, tpl_breakdown_mgmt.created_by, tpl_breakdown_mgmt.site, tpl_breakdown_mgmt.asset_rec_date_time, tpl_breakdown_mgmt.tt_no, tpl_breakdown_mgmt.rec_from, tpl_breakdown_mgmt.rec_by, tpl_breakdown_mgmt_machine.asset_id
FROM tpl_breakdown_mgmt
INNER JOIN tpl_breakdown_mgmt_machine
ON tpl_breakdown_mgmt.id=tpl_breakdown_mgmt_machine.master_id WHERE CompanyId =".$_SESSION['ACGCompanyId']."
ORDER BY tpl_breakdown_mgmt.id DESC;";
		 
//echo $sql;		 
 $record=DB_query($sql,$db);
$i=0;
if(DB_num_rows($record)>0){
while($row=DB_fetch_array($record))
{
$i++;
extract($row);
$status=$s->getField('tpl_breakdown_mgmt_assig','job_id',$id,'id');
?>
<tr>
<td><?php  echo $i;?></td>
<td><?php  
echo $s->GetFieldValue('locations',"loccode='".$site."'",'locationname');
?> </td>
<td><?php  if($asset_rec_date_time!='') echo date('d/m/y',strtotime($asset_rec_date_time)); else echo "";?> </td>
<td><?php  echo $tt_no; ?> </td>
<td><?php  echo $rec_from; ?></td>
<td><?php  echo $rec_by; ?></td>
<td colspan="6" align="left" valign="top" style="padding:0px;">
<div id="amc-tab">
	<table width="100%" border="0" cellpadding="3" cellspacing="0">
	<?php 
		$reqDet_sql = "SELECT * FROM machine_center WHERE ID= ".$asset_id."";
		$result = DB_query($reqDet_sql,$db);
		if(DB_num_rows($result)>0){
			while($assetRow = DB_fetch_array($result)){
			$reqDet_sql1 = "SELECT * FROM machine_group_master WHERE id= ".$assetRow['under_group']."";
		$result1 = DB_query($reqDet_sql1,$db);
		$assetRow1 = DB_fetch_array($result1);
			
			?>
				<tr>
					<td align="left" valign="top" width="150"><?php  echo $assetRow['code'];?></td>
		            <td align="left" valign="top"><?php  echo $assetRow['name'];?></td>
					<td width="170"><?php  echo $assetRow1['machine_gp_location'];?></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="130"><?php echo $assetRow[$r['db_field_name']];?></td>
				    <?php } ?>
				</tr>
		<?php	}
		}
	?>	
	</table>
 </div>
</td>
<td align="center"><a href="<?php echo $url_add;?>&action=edit&rid=<?php  echo $id;?>&uid=<?php  echo $created_by;?>"><img src="images/icon-edit.png" width="15" height="15" title="Edit" /></a></td>
<td align="center"><?php if($status=='') { ?><a href="<?php echo $url_cancel;?>&action=delete&rid=<?php echo $id;?>"><img src="images/Icon_Delete.png" width="15" height="15" title="Delete" onClick="return confirm('Are you sure you wish to delete this Record?')"></a><?php } else { ?><img src="images/Icon_Delete.png" title="No Permission to Delete" width="15" height="15" style="opacity:0.7;"><?php } ?></td>
<td align="center"><a href="print_asset_breakdown_management.php?rid=<?php echo $id;?>&srno=<?php echo $i;?>" target="_blank"><img width="18" height="18" title="Print" 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>
