<?php 
$url_cancel= "index.php?route=ToolPlants/Transaction/asset_breakdown_assignment_add".$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);
}
?>

<h3>Assigned List</h3>
<div class="overpanel">
<table width="150%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="2%">S. No.</th>
	<th>Branch</th>
	<th width="8%">Slip No.</th>
	<th width="6%">Job Card No.</th>
	<th width="8%">Break Down Location</th>
	<th width="8%">Received By</th>
    <th width="8%">Assigned To</th>
	<th width="150">Asset Code</th>
	<th>Asset Name</th>
	<th width="170">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"><?php echo $r['title_name'];?></th>
    <?php } ?>
    <th width="3%" style="text-align:center;">Action</th>
</tr>
<?php 
//$record=$s->GetRecordById('tpl_asset_transfer_request',1);
$sql = "select * from tpl_breakdown_mgmt_assig where CompanyId='".$_SESSION['ACGCompanyId']."'";		 
//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>
	<td><?php echo $i;?></td>
	<td><?php echo $s->GetFieldValue('locations',"loccode='".$site."'",'locationname'); //$site; ?></td>
	<td><?php echo $slip_no;?></td>
	<td><?php echo $s->getField('tpl_breakdown_mgmt','id',$job_id,'tt_no'); ?></td>
	<td><?php echo $s->getField('tpl_breakdown_mgmt','id',$job_id,'rec_from');?></td>
	<td><?php echo $s->getField('tpl_breakdown_mgmt','id',$job_id,'rec_by'); ?></td>
	<td><?php $sql_row=DB_query("select distinct(technician) from tpl_breakdown_mgmt_details where master_id='".$id."'",$db);
	while($row1=DB_fetch_array($sql_row))
	{
	echo $s->getField('technicians','id',$row1['technician'],'technician')."<br>";
	} ?></td>
	<td colspan="6" valign="top" style="padding:0px;">
	  <div id="amc-tab">
		<table width="100%" border="0" cellpadding="3" cellspacing="0">
		<?php
	   $sql_2=DB_query("select * from tpl_breakdown_mgmt_machine where master_id='".$job_id."'",$db);
	   while($row1=DB_fetch_array($sql_2))
	   {	   
			$reqDet_sql = "SELECT * FROM machine_center WHERE id= ".$row1['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 width="150"><?php  echo $assetRow['code'];?></td>
				<td><?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 style="text-align:center;"><a href="print_asset_breakdown_assignment.php?rid=<?php echo $id;?>&srno=<?php echo $i;?>" target="_blank"><img width="18" height="18" src="images/icon_print.jpg" title="Print" /></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']);
?>
