<link rel="stylesheet" href="css/new_mxerp.css">
<script type="text/javascript">
function validate_breakMaster() 
{
  
   if(document.breakdown_master.shift_category.value=='')
	 {
	  	alert("Please Enter Breakdown Type");
		  return false;
	 }
   return true;
}
</script>

<?php
if($_REQUEST['action']=='delete')
{
$del=DB_query("delete from break_down_type where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=ToolPlants/maintenance/Break_down_type&daction=Updated".$rurl);	
}
if($_REQUEST['Save'])
{
$insert="insert into break_down_type set breakdown_reason='".$_REQUEST['shift_category']."',branch_code='".$_REQUEST['site']."',CompanyId='".$_SESSION['ACGCompanyId']."' ";
$query=Db_query($insert,$db);
}
if($_REQUEST['action']=='edit')
{ 
$con ="id='".$_REQUEST['id']."'";
$Get_id = $s->GetRecordById('break_down_type',$con);
$var = DB_fetch_array($Get_id);
if($_REQUEST['Update']){
$update=DB_query("update break_down_type set breakdown_reason='".$_REQUEST['shift_category']."'
,branch_code='".$_REQUEST['site']."' where id='".$_REQUEST['Id']."'",$db);	
$s->pageLocation("index.php?route=ToolPlants/maintenance/Break_down_type&daction=Updated".$rurl);	
}
}
?>

<div class="body_contain">
<div class="tab_div">
<h1>Break Down Type</h1>
<form action="" method="post" name="breakdown_master">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1"> 
  <td width="30%" style="text-align:right;">Break Down Type <font color="#FF0000"> *</font></td>	
  <td width="35%"><input name="shift_category" id="shift_category" style="width:98%;" type="text"></td>
  <td style="text-align:left;"><input name="Save" type="submit" class="search" onclick="return validate_breakMaster()" value="Save" /></td>
</tr>    
</table>

</form>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
<tr>
  <!--<td class="tabledata">Asset Type</td>-->
  <th rowspan="2">Break Down Type</th>
  <th colspan="2" style="text-align:center;">Action</th>  
</tr>
<tr>
  <th width="5%" style="text-align:center;">Edit</th>
  <th width="5%" style="text-align:center;">Delete</th>
</tr>
<?php
$undergroup='<select name="under_group" >';
   $sql="select * from machine_group_master";
		$query=DB_query($sql,$db);
		while($row1=DB_fetch_array($query))
		{

$undergroup.='<option value='.$row1['id'].'>'.$row1['machine_gp_location'].'</option>';
     }
    $undergroup.='</select>';

$sql="select * from break_down_type where CompanyId='".$_SESSION['ACGCompanyId']."'";
$query=DB_query($sql,$db);
while($row=DB_fetch_array($query))
{
	
?>
<tr>	
<!--<td><?php echo $s->getField('machine_group_master','id',$row['asset_group'],'machine_gp_location')?></td>-->
<td><?php echo $row['breakdown_reason']; ?></td>
<td style="text-align:center;"><img src="images/icon-edit.png" width="15" title="Edit" onclick="createForEdit('<?php echo $row['emp_id']; ?>',this,'<?php echo $row['asset_group']; ?>','<?php echo $row['breakdownid'];?>');" style="cursor:pointer;"><span onclick="saveForEdit('<?php echo $row['id']; ?>',this);" style="color:green;display:none;cursor:pointer;">Save</span></td>
<td style="text-align:center;"><a href="index.php?route=ToolPlants/maintenance/Break_down_type&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $row['id'];?>" onclick="return confirm('Are you sure you want to delete?')"><img src="images/Icon_Delete.png" width="15" height="15" title="Delete" /></a></td>
</tr>
<?php } ?>
</table>

</div></div>


<script type="text/javascript">
  function createForEdit(empid,obj,undergp12,breaddwon12)
  {//ajax_emp_loan_edit
  	//alert(breaddwon12)
  	 $(obj).hide();
  	 $(obj).next().show();
      var subbreak=$(obj).closest('tr').find('td:eq(0)').html();  	  
  	  $(obj).closest('tr').find('td:eq(0)').html('<input type="text" value="'+subbreak+'" />');
  }

  function saveForEdit(empId,obj)
  {

     $(obj).hide();
  	 $(obj).prev().show();
  	 	  
       var subbreak=$(obj).closest('tr').find('td:eq(0)').find('input[type="text"]').val();
      $(obj).closest('tr').find('td:eq(0)').html(subbreak);
   
   //alert(undergp);

     $.ajax({
            url : "ajax_breakdown_edit.php",
            type : "POST",
            data : {             
            emp_id:empId,                   
            subbreak:subbreak
         
            },
            success : function(data)
             {
             	//var data1=data.split("<__>");
             // var data1=data;
      // $(obj).closest('tr').find('td:eq(0)').html(data1[0]);
      //$(obj).closest('tr').find('td:eq(1)').html(data1[1]);
     
            	//alert(data);
              
            alert('You have update record successfully !');  
                          }
          });
  }
</script>