<?php
error_reporting(0);

if(isset($_POST['Search']))
  {
     $data['site']          =$_REQUEST['site'];
     $data['asset_group']   =$_REQUEST['group'];
     $data['asset_id']      =$_REQUEST['asset'];   
     $data['warranty']   =$_REQUEST['warranty'];
     $data['wo_status']      =$_REQUEST['Status'];  
     $data['CompanyId']     =$_SESSION['ACGCompanyId'];
     $data['created_by']    =$_SESSION['UserID'];   
     $data['created_date'] =date('Y-d-y');
     $s->RecordInsert('tbl_prementive', $data);
     $last_id=DB_Last_Insert_ID($db,'tbl_prementive','id');    
    foreach($_REQUEST['breakdown'] as $key=>$value)
    {
       $data2['tbl_prementive_id']=$last_id;
       $data2['break_down_id']=$value;
       $s->RecordInsert('tbl_prementive_details', $data2);
       $last_id1=DB_Last_Insert_ID($db,'tbl_prementive_details','id');
           foreach($_REQUEST['assetid'][$value] as $key1=>$val)
           {

                    foreach($_REQUEST['subbreak'][$value][$val] as $key2=>$val2)
                    {
                      if($_REQUEST['service_day'][$value][$val][$key2]!='')
                      {
                        $data3['tbl_prementive_details_id']=$last_id1;
                        $data3['asset_id']=$val;
                        $data3['tbl_prementive_id']=$last_id;
                        $data3['sub_break_down_id']=$val2;
                        $data3['service_days']=$_REQUEST['service_day'][$value][$val][$key2];
                        $data3['last_service_date']=FormatDateForSQL($_REQUEST['last_service_date'][$value][$val][$key2]);
                        $s->RecordInsert('tbl_prementive_sub_details', $data3);
                      }
                    }
           }
    }    
  $s->pageLocation("index.php?route=ToolPlants/fixed_assets/sub_asset_master_index".$rurl);
}

?>

<div style="display:none" id="div_id"></div>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?>  </h1>
<form action="" method="Post">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr class="row1">
    <td width="13%" align="right">Branch</td>
    <td width="20%"><select name="site" id="site"  >
      <option value="0">Select</option>
      <?php
       $sql=DB_query("select * from locations where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
       while($r=DB_fetch_array($sql))
       {
       ?>
       <option value="<?php echo $r['loccode']; ?>"><?php echo $r['locationname']; ?></option>
       <?php } ?>
       </select></td>
    <td width="13%" align="right">Asset Group</td>
    <td width="20%"><select name="group"  onchange="show_asset(this.value)" >
      <option value="0">Select</option> 
      <?php
       $sql_group=DB_query("select * from machine_group_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
       while($r_group=DB_fetch_array($sql_group))
       {
       ?>
       <option value="<?php echo $r_group['id']; ?>"><?php echo $r_group['machine_gp_location']; ?></option>
      <?php } ?>
    </select></td>
    <td width="13%" align="right">Asset Name</td>
    <td><select name="asset" id="asset"  onchange="show_asset_info(this.value)" >
       <option value="0">Select</option> 
       <?php
       $sql_asset=DB_query("select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."' and asset_type='A' and id NOT IN (select asset_id from tbl_prementive)",$db);
       while($r_asset=DB_fetch_array($sql_asset))
       {
       ?>
       <option value="<?php echo $r_asset['id']; ?>"><?php echo $r_asset['name']; ?></option>
       <?php } ?></select></td>
  </tr>
  <tr class="row1">
    <td align="right">Warranty</td>
    <td><select name="warranty" id="warranty" >
    </select></td>
    <td align="right">Status</td>
    <td><select name="Status" id="Status" >
    </select></td>
    <td align="right">Code</td>
    <td><input type="text" name="code" id="code"  readonly /></td>
  </tr>
 
</table>
<br>
    <div id="datashow">
    </div>
</form>

</div></div>

<script>
 
 
 function show_asset(str)
 {


  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)
  {   
   //alert(xmlhttp.responseText);
  document.getElementById("asset").innerHTML=xmlhttp.responseText;
  }
  }
  xmlhttp.open("GET","ajax_dynamic_subasset_creation.php?str="+str,true);
  xmlhttp.send();
 }

 function show_asset_info(str)
 {


  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)
  {    
   // alert(xmlhttp.responseText);
  var data=xmlhttp.responseText.split("__");
  document.getElementById("warranty").innerHTML=data[0];
  document.getElementById("Status").innerHTML=data[1];
  document.getElementById("code").value=data[2];
  document.getElementById("datashow").innerHTML=data[3];
  $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
  }
  }
  xmlhttp.open("GET","ajax_dynamic_subasset_creation.php?asset="+str,true);
  xmlhttp.send();
 }
  

</script> 

