<!-- <link rel="stylesheet" href="css/jquery.ui.all.css">

<script src="js/jquery-1.11.1.min.js"></script>


<script src="ui/jquery.ui.core.js"></script>
<script src="ui/jquery.ui.widget.js"></script>
<script src="ui/jquery.ui.datepicker.js"></script> -->
<script src="ui/jquery.ui.timepicker.js"></script>

<?php 
$url_cancel= "index.php?route=ToolPlants/Transaction/asset_breakdown_management".$rurl;
include('includes/Class_Branch.php');
include('includes/AccountGroupMaster_Class.php');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$rurl="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=ToolPlants/Transaction/asset_breakdown_management".$rurl;
$msgErr=array();

?>

<?php
if($_REQUEST['Save'])
{
	$startYr = explode('-', $_SESSION['financialYrStart']);
	 $endYr = explode('-', $_SESSION['financialYrEnd']);
	  $startYr[0];
	  $endYr[0];
	  $financial=substr($startYr[0],-2)."-".substr($endYr[0],-2); 
	  $prefixcode=$s->getField('prefix_tbl','prefix_name','Machine Breakdown Management','prefix_code');

      $sql="select slip_no from tpl_breakdown_mgmt_assig where site = '".$_REQUEST['site']."'
     and INSTR(`slip_no`, '$financial') > 0 order by id DESC LIMIT 0,1";
	$result = DB_query($sql,$db);
	 $numrows = DB_num_rows($result);
	if($numrows>0)
	{
		$myrow=DB_Fetch_array($result);
     	$ExplBill=explode("/",$myrow['slip_no']);
		$maxval = $ExplBill[3];
	}
	else
	{$maxval=0;}	
	
		$strChar=$_REQUEST['site']."/".$prefixcode."/".$financial."/";
		 $strFinal = $maxval+1;
		$strBothFinal = $strChar.str_pad($strFinal,5,"0",STR_PAD_LEFT); 
	
	$data['site']=$_REQUEST['site'];
	$data['assign_date'] = FormatDateFORSQL($_REQUEST['assign_date']);
	$data['slip_no'] = $strBothFinal;
	$data['job_id'] = $_REQUEST['machine_break_id'];
	$data['CompanyId'] = $_SESSION['ACGCompanyId'];
	$data['created_by'] = $_SESSION['UserID'];
   $data['created_date'] = date('Y-m-d');
	//print_r($data);
	$s->RecordInsert('tpl_breakdown_mgmt_assig',$data);
	$last_id=DB_Last_Insert_Id($db,"tpl_breakdown_mgmt_assig","id");
   //$last_id=1;
	if($last_id !='')
	{ 
	for($l=0; $l<count($_REQUEST['sub_break_down1']); $l++)
		{					
		$data5['break_type'] = $_REQUEST['sub_break_down1'][$l];
		$data5['break_sub_type'] = $_REQUEST['sub_break_down'][$l];
		$data5['break_reason'] = $_REQUEST['break_reason'][$l];
		$data5['technician'] = $_REQUEST['technician'][$l];
		$data5['rec_date'] = FormatDateFORSQL($_REQUEST['rec_date'][$l]);
		$data5['rec_time'] = $_REQUEST['rec_time'][$l];
		$data5['com_date'] = FormatDateFORSQL($_REQUEST['com_date'][$l]);
      $data5['safty'] = $_REQUEST['break_safty'][$l];
		$data5['master_id'] = $last_id;		
		
		$s->RecordInsert('tpl_breakdown_mgmt_details',$data5);			
		 
		}
      
      for($l=0; $l<count($_REQUEST['break_safty']); $l++)
		{
					
		$data6['safty'] = $_REQUEST['break_safty'][$l];
		$data6['status'] = $_REQUEST['bk_done'][$l];
		$data6['master_id'] = $last_id;		
		$s->RecordInsert('tpl_break_safty',$data6);		 
		}      
   }
   
  $update=DB_query("update tpl_breakdown_mgmt set status=1 where id='".$_REQUEST['machine_break_id']."'",$db);
	//it;	
   $s->pageLocation("index.php?route=ToolPlants/Transaction/machine_breakdown_assingment_index".$rurl);
		}	

// upadating Record
if($_REQUEST['action']=='edit')
{    
	$con ="id='".$_REQUEST['rid']."'";
	$Get_id = $s->GetRecordById('tpl_breakdown_mgmt',$con);
	$var = DB_fetch_array($Get_id);
	
	// asset details
	 $assetSql = "SELECT * FROM tpl_breakdown_mgmt_machine WHERE master_id= ".$var['id']."";
	$resultAsset = DB_query($assetSql,$db);
	$rowAsset=DB_fetch_array($resultAsset);
	$sqlAset = "SELECT * FROM machine_center WHERE ID= ".$rowAsset['asset_id']."";
	$resultDisplay = DB_query($sqlAset,$db);
	$assetRows = DB_fetch_array($resultDisplay);
	// asset group	
		
	// unit of measurement
	$sqlU=DB_query("Select * from unitsofmeasure where unitid='".$assetRows['unit']."' ",$db); 
		 $myrow_unit=DB_fetch_array($sqlU);			
}
	// update query 	
?>


<script>
$(document).ready(function(){
  $(".timepicker").timepicker();
});

function addRow(tableID) 
{ 
	//if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//alert("manoj");
	var newcell = row.insertCell(i);    
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;

  $(".datepicker").removeClass("hasDatepicker").datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
  $(".timepicker").removeClass("hasTimepicker").timepicker({ showCloseButton: true });

	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value="";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "hidden":
	newcell.childNodes[0].value="";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "select":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}   
}
</script>

<script>
function showSubBreak(str,id)
{
   var abc=id.split("_");
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      if(abc[1]==undefined)
    document.getElementById("subbreakdown").innerHTML=xmlhttp.responseText;
    else
      document.getElementById("subbreakdown_"+abc[1]).innerHTML=xmlhttp.responseText;   
    }
  }
xmlhttp.open("GET","getsubBreak1.php?q="+str,true);
xmlhttp.send();
}
</script>

<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<form method="post" name="tech_master">
<h1>General Details</h1>
<input type="hidden" name="machine_break_id" value="<?php echo $_REQUEST['rid']; ?>">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <input type="hidden" name="machine_break_id" value="<?php echo $_REQUEST['rid']; ?>">
    <td width="13%" align="right">Branch <font style="color:#FF0000;">*</font></td>
    <td width="20%"><div id= "txtHint">
      <select  id="site" name="site"  >
        <option value = "">--Select--</option>
        <?php 
            $site_sql=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
                        while($site_row=DB_fetch_array($site_sql))
						{
						$p='';
						if($site_row['loccode']==$var['site'])
						$p="selected";
			?>
        <option value="<?php echo $site_row['loccode']?>"<?php echo $p;?>><?php echo $site_row['locationname']?></option>
        <?php } ?>
      </select>
    </div></td>
    <td width="13%" align="right">Receiving Date <font style="color:#FF0000;">*</font></td>
    <td width="20%"><input type="text"  name = "recieving_date" class="datepicker" value="<?php if($var['asset_rec_date_time']!='') echo date('d/m/y',strtotime($var['asset_rec_date_time'])); else echo "";?>"></td>
    <td width="13%" align="right">Job Card No. <font style="color:#FF0000;">*</font></td>
    <td>
     <?php
    
      $autonumber=$var['tt_no'];
    
     ?>
      <input type="text" value = "<?php echo $autonumber; ?>" readonly=""  name = "ttno" ></td>
  </tr>
  <tr class="row1">
    <td align="right">Break Down Loc. <font style="color:#FF0000;">*</font></td>
    <td><input type="text" value = "<?php echo $var['rec_from']; ?>" name = "rec_from" ></td>
    <td align="right">Received By <font style="color:#FF0000;">*</font></td>
    <td><input type="text" id ="oo" value = "<?php echo $var['rec_by']; ?>" name = "received_by" ></td>
    <td align="right">Assingment Slip No.</td>
    <td><input type="text" value="Auto Generated" name="slipno"  readonly="readonly"></td>
   </tr>
   <tr class="row1">
    <td align="right">Assign Date <font style="color:#FF0000;">*</font></td>
    <td colspan="5"><input type="text" value="<?php echo date('d/m/Y'); ?>" name="assign_date" style="width:22%;" class="datepicker"></td>
   </tr>
 </table>
 <br>
<h1>Asset Details</h1>
    <table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
    <th width="10%">Asset Code</th>
    <th>Asset Name</th>
    <th width="16%">Asset Group</th>
    <th width="12%">UOM</th>
     <?php 
   $title='';
   $title1=DB_query("select * from tbl_title_master order by serial_no ASC limit 0,3",$db);
   while($r=DB_fetch_array($title1))
   { 
   	$title[]=$r['db_field_name'];
   	?>
    <th width="12%"><?php echo $r['title_name'];?></th>
    <?php } ?>
  </tr>
  <tr>
    <td><input type="text"  value= "<?php echo $assetRows['code']; ?>" name="asset_code" id="assetcode"   readonly /></td>
    <td><input type="text" value= "<?php echo $assetRows['name']; ?>" name="Input" id="assetname"   readonly="" /></td>
    <td><input type="text" value = "<?php  echo $s->getField('machine_group_master','id',$assetRows['under_group'],'machine_gp_location')    ;?>" name="" id="asset_group"  readonly="" /></td>
    <td><input type="text" value = "<?php echo $myrow_unit['unitname']; ?>" name="" id="asset_unit"   readonly="" /></td>    
    <td><input type="text" value= "<?php echo $assetRows[$title[0]]; ?>" name="" id="asset_model"   readonly="" /></td>
    <td><input type="text" value= "<?php echo $assetRows[$title[1]]; ?>" id = "asset_vechile"  readonly="" ></td>
    <td><input type="text" value= "<?php echo $assetRows[$title[2]]; ?>" id = "asset_meter"  readonly="" ></td>
  </tr>
</table>

<br>
<table width="100%" border="0" cellspacing="0" cellpadding="3"> 
  <tr class="row1">
   <td width="13%">Break Down Descriptions</strong></td>
   <td><textarea name="remarks" id="remarks" style="height:60px;"> <?php echo $var['remarks'] ?> </textarea></td>
</tr>  
</table>
<p align="left"><input name="button" type="button" class="search" accesskey="A" onClick="addRow('dataTable')" value="Add Rows" /> <input type="button" class="search"  onclick="deleteRowOrder('dataTable')" value="Delete" /></p>

<h1>Add Breakdown Details</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
      <th width="5%"></th>
      <th width="15%">Breakdown Type <font style="color:#FF0000;">*</font></th>
      <th width="15%">Breakdown Sub Type</th>
      <th width="20%">Breakdown Reason <font style="color:#FF0000;">*</font></th>
      <th>Technician Name</th>    
      <th width="8%">Rec.Date</th>
      <th width="8%">Rec.Time</th>
      <th width="10%">Exp.Com.Date</th>
  </tr> 
    <tbody id="dataTable">
    	<?php
    	$t=1;
         $sql_sub_breakdown=DB_query("select * from tpl_breakdown_mgmt_machine_breakdown where parent_id='".$var['id']."'",$db);
         while($row=DB_fetch_array($sql_sub_breakdown))
         {
    	 ?>
    <tr>
      <td><input name="delitem[]" type="checkbox" value="<?php echo $row['id'];?>" id="delitem" /></td>
      <td><select name="sub_break_down1[]" id="ab" onchange="showSubBreak(this.value,this.id)">
        <option value="">Select</option>
          <?php 
            $site_sql1=DB_query("Select id,breakdown_reason from break_down_type where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
                        while($site_row1=DB_fetch_array($site_sql1)){
						$s='';
						if($site_row1['id']==$row['breakdown_id'])
						$s="selected";
			    ?>
         <option value="<?php echo $site_row1['id']; ?>" <?php echo $s;?>><?php echo $site_row1['breakdown_reason']; ?></option>
         <?php } ?>
        </select></td>
      <td><select name="sub_break_down[]" id="subbreakdown"> 
         <option value="">Select</option>
         <?php
        	$id_query1=DB_query("Select * from tbl_sub_break_type where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
        	while($id_row_type=DB_fetch_array($id_query1))
        	 {
        	 $q='';
        	if($id_row_type['id']==$row['sub_breakdown_id'])
        	$q="selected";
        	 ?>
         <option value="<?php echo $id_row_type['id']; ?>" <?php echo $q;?>><?php echo $id_row_type['sub_breaktype']; ?></option>
         <?php } ?>
        </select></td>
      <td><input type="text" value="" id="res" name="break_reason[]" /></td>
      <td><select name="technician[]">
        	<option value="0">Select</option>
        	<?php
        	$id_query2=DB_query("Select * from technicians", $db);
        	while($id_row_technician=DB_fetch_array($id_query2))
        	 {
        	  $g='';
        	if($id_row_technician['id']==$rowBd['technician'])
        	$g="selected";
        	 ?>
        	<option value="<?php echo $id_row_technician['id']; ?>" <?php echo $g;?>><?php echo $id_row_technician['technician']; ?></option>
        	<?php } ?>
        	</select></td>   
      <td><input type="text" value="" name="rec_date[]" id="<?php echo $t; ?>" class="datepicker" /></td>
      <td><input type="text" value="" name="rec_time[]" id="time1_<?php echo $t; ?>" class="timepicker" onkeypress="return isNumberKey(event)" /></td>
      <td><input type="text" value="" name="com_date[]" id="con_<?php echo $t; ?>" class="datepicker" /></td>
  </tr>
  <?php $t++; } ?>
 </tbody>  
</table>
<input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
      <input type="hidden" name="" value="" id="edit_cnt" />
      <input type="hidden" name="item_code" id="itemid" />
<br>
<h1>Safty Details Descriptions</h1>
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
    <tr>
       <th>Breakdown Safty Description</th>
       <th colspan="2" style="text-align:center">Action</th>
    </tr> 
    <?php
    $j=0;
    $sql_bk_type=DB_query("select * from prd_safty where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
    while($row_bk=DB_fetch_array($sql_bk_type))
    {
    
    ?> 
    <tr>
       <td><?php echo $row_bk['description']; ?> <input type="hidden" name="break_safty[]" value="<?php echo $row_bk['id']; ?>"</td>
       <td width="12%"><input type="radio" id="bkdone_<?php echo $j; ?>" name="bk_done[<?php echo $j; ?>]" value="Y">Done</td>
       <td width="12%"><input type="radio" name="bk_done[<?php echo $j; ?>]" id="bkdone_<?php echo $j; ?>" value="N">N/R</td>   
    <?php $j++;} ?>
  </tr> 
</table>
  <p align="center"><input name="Save"  class="search" type="submit" onClick="return validates()" value="Save" />
      &nbsp;<a href="<?php echo $url_cancel;?>"><input name="" class="search" value="Cancel" type="button"></a></p>
</form>
</div>
</div>

<script type="text/javascript">
function validates()
 {

	if(document.tech_master.site.value=='')
	{
		alert("Please Select Branch First");
		(document.tech_master.site).focus();
		return false;
	}
	else if(document.tech_master.recieving_date.value=='')
	{
		alert("Please Enter Asset Receiving Date& Time");
		(document.tech_master.recieving_date).focus();
		return false;
	}
	else if(document.tech_master.ttno.value=='')
	{
		alert("Please Enter TT No");
		(document.tech_master.ttno).focus();
		return false;
	}
	else if(document.tech_master.rec_from.value=='')
	{
		alert("Please Enter Received  From Value");
		(document.tech_master.rec_from).focus();
		return false;
	}
	else if(document.tech_master.received_by.value=='')
	{
			alert("Please Enter Received by Value");
		(document.tech_master.received_by).focus();
		return false;
	}
		else if(document.getElementById("assetcode").value =='')
	{
		alert("Select at least 1 Asset");
		return false;
	}
	else if(document.getElementById("ab").value=='')
	{
		alert("Please Enter Breakdown Type");
		(document.getElementById("ab")).focus();
		return false;
	}
	else if(document.getElementById("res").value=='')
	{
		alert("Please Enter Breakdown Reason");
		(document.getElementById("res")).focus();
		return false;
	}
	
}
</script>
<script language="JavaScript">

function open_items()
{ 

window.open("fixedAssetItems.php?&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>","itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

  function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57) && charCode!=58)
             return false;

          return true;
       }

       function deleteRowOrder(tableID) 
{
  try 
  {
    var table = document.getElementById(tableID);
    //alert(table);
    var rowCount = table.rows.length;
    //alert(rowCount);
    for(var i=0; i<rowCount; i++) 
      {
        var row = table.rows[i];
        var chkbox = row.cells[0].childNodes[0];
        if(null != chkbox && true == chkbox.checked) 
        {
          if(rowCount <= 1) 
          {
            alert("Cannot delete all the rows.");
            break;
          }
        table.deleteRow(i);
        rowCount--;
        i--;
        }
        
      }
  document.getElementById("hiditemcount").value=parseInt(rowCount)-1;   
  }
  catch(e) 
  {
    alert(e);
  }

}

// var jh = $.noConflict();
// jh(function() {
// jh(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
//     changeYear: true,
//     yearRange: '-80:+20'});
// });

// jh(".timepicker").timepicker();
</script>


