<?php 
if($_REQUEST['Save']){
	$_REQUEST['qc_product_parameter']['date']=FormatDateForSQL($_REQUEST['qc_product_parameter']['date']);
	$_REQUEST['qc_product_parameter']['process_time']=$_REQUEST['qc_product_parameter']['hrs'].":".$_REQUEST['qc_product_parameter']['min'];
	unset($_REQUEST['qc_product_parameter']['hrs']);
	unset($_REQUEST['qc_product_parameter']['min']);
	$sql1=$s->insertRecord('qc_product_parameter', $_REQUEST['qc_product_parameter']);
	$result1=DB_query($sql1,$db);
	$last_id=DB_Last_Insert_ID($db,'qc_product_parameter','id');
	if($last_id!=''){
		foreach($_REQUEST['qc_product_parameter_details'] as $key=>$val){
			if(isset($val['check']) && !empty($val['check'])){
				unset($val['check']);
				$val['master_id']=$last_id;
				$sql2=$s->insertRecord('qc_product_parameter_details', $val);
				$result2=DB_query($sql2,$db);
			}
		}
	echo "<script>location.href='index.php?route=".$_REQUEST['route']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
	}
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="tab_div">
<center> <h2>Product Parameter Details</h2></center>
<div id="container">
<form action="" method="post">
<input type="hidden" name="qc_product_parameter[created_date]" value="<?php echo date('Y-m-d');?>" />
<input type="hidden" name="qc_product_parameter[created_by]" value="<?php echo $_SESSION['UserID'];?>" />
<table width="100%" align="center" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td colspan="6"><center><h3>General Information</h3></center></td>
    </tr>
  <tr class="row1">
    <td width="13%"><strong>PP No.</strong></td>
    <td width="20%"><input name="qc_product_parameter[auto_code]" id="" type="text" class="" style="width:100%;" />    </td>
    <td width="13%"><strong>Date</strong></td>
    <td width="20%"><input name="qc_product_parameter[date]" id="" type="text" style="width:100%;" class="datepicker" value="<?php echo date('d/m/Y');?>" />    </td>
    <td><strong>Group Name</strong></td>
    <td width="20%"><select name="" style="width:100%" onchange="itemList(this.value)">
					<option value="">Select</option>
					<?php $sql1=DB_query("Select * from stockcategory where CompanyId=".$_SESSION['ACGCompanyId'],$db);
							while($row1=DB_fetch_array($sql1)){
								extract($row1);
							?>
								<option value="<?php echo $id;?>"><?php echo $categorydescription;?></option>
							<?php 
							}
					?>
					</select>
	</td>
  </tr>
  <tr class="row1">
    <td><strong>Process </strong></td>
    <td><select name="qc_product_parameter[process_id]" style="width:100%" onchange="processParameter(this.value)">
		<option value="">Select</option>
		<?php $sql1=DB_query("Select * from production_process_master where CompanyId=".$_SESSION['ACGCompanyId'],$db);
				while($row1=DB_fetch_array($sql1)){
					extract($row1);
				?>
					<option value="<?php echo $id;?>"><?php echo $manuf_process_name;?></option>
				<?php 
				}	
		?>	
		</select></td>
    <td><strong>Part No.</strong></td>
    <td><select name="qc_product_parameter[mst_itemid]" id="part_no_id" style="width:100%" onchange="nameByCode(this.value)"></select></td>
    <td><strong>Part Name </strong></td>
    <td><select name="qc_product_parameter[mst_itemid]" id="part_name_id" style="width:100%" onchange="codeByName(this.value)"></select></td>
  </tr>
  <tr class="row1">
    <td><strong>Unit</strong></td>
    <td><select name="" id="unit_id" style="width:100%"></select></td>
    <td><strong>Prepared By </strong></td>
    <td><input name="" id="" type="text" value="<?php echo $_SESSION['UsersRealName'];?>" style="width:100%;" readonly="true" />    </td>
    <td><strong>Approved By</strong></td>
    <td><input name="qc_product_parameter[approved_by]" id="" type="text" style="width:100%;" /></td>
  </tr>
  
  <tr class="row1">
    <td><strong>Sample Qty. </strong></td>
    <td><input name="qc_product_parameter[sample_qty]" id="" type="text" class="" style="width:100%;" /></td>
    <td><strong>Process Time</strong></td>
    <td><select name="qc_product_parameter[hrs]" style="width:35%">
		<?php 
		for($i=1;$i<25;$i++){
		?>
			<option value="<?php echo $i;?>"><?php echo $i;?></option>
		<?php 
		}
		?>
		</select>&nbsp;Hrs&nbsp;
		<select name="qc_product_parameter[min]" style="width:40%">
		<?php 
		for($i=0;$i<60;$i++){
		?>
			<option value="<?php echo $i;?>"><?php echo $i;?></option>
		<?php 
		}
		?>
		</select>&nbsp;Min</td>
    <td><strong>Method No.</strong></td>
    <td><input name="qc_product_parameter[method_no]" id="" type="text" class="" style="width:100%;" /></td>
  </tr>
  <tr class="row1">
    <td colspan="6"><center><h3>Product Information</h3></center></td>
    </tr>
	<tr class="row1">
    <td colspan="6" style="padding:0px;" id="details_id"><table width="100%" border="1" cellpadding="3" cellspacing="0">

  <tr bgcolor="#CCCCCC" height="25" >
    <td width="6%" align="left"><strong>Sr. No.</strong></td>
	<td width="10%" align="left"><strong>Flow No.</strong></td>
    <td width="10%" align="left"><strong>Parameter</strong></td>
    <td width="20%" align="left"><strong>Specification</strong></td>
    <td width="15%" align="left"><strong>Measurment Instrument</strong></td>
    <td width="15%" align="left"><strong>Min</strong></td>
    <td align="left"><strong>Max</strong></td>
    <td align="left"><strong>Remarks</strong></td>
  </tr>
  <tr class="row1">
    <td><input name=""  type="checkbox" value="" /></td>
	<td><input type="text" name="qc_product_parameter_details[flow_no]" value="" id="" style="width:100%;" /></td>
    <td><input type="text" name="qc_product_parameter_details[parameter_id]" value="" id="" style="width:100%;" /></td>
    <td><input type="text" name="qc_product_parameter_details[parameter_specs]" value="" id="" style="width:100%;"/></td>
    <td><input type="text" name="qc_product_parameter_details[instrument_id]" value="" id="" style="width:100%;" /></td>
    <td><input type="text" name="qc_product_parameter_details[range_min]" value="" id="" style="width:100%;" /></td>
    <td><input type="text" name="qc_product_parameter_details[range_max]" value="" id="" style="width:100%;" /></td>
    <td><input type="text" name="qc_product_parameter_details[remarks]" value="" id="" style="width:100%;" /></td>
  </tr> 
</table></td>
    </tr>
	<tr class="row1">
    <td colspan="6">&nbsp;</td>
    </tr>
	<tr class="row1">
    <td colspan="6" style="text-align:center;"> <input type="submit" name="Save" value="Save" class="search" />&nbsp;<input type="submit" name="Cancel" value="Cancel" class="search" /></td>
    </tr>
</table>
</form>
</div>
</div>
<script language="javascript" type="text/javascript">
function itemList(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){
			var data=xmlhttp.responseText;
			var data_brk=data.split('__');
			document.getElementById("part_no_id").innerHTML=data_brk[1];
			document.getElementById("part_name_id").innerHTML=data_brk[0];
		}
	}
	xmlhttp.open("GET","ajax_sub_cat_item.php?id="+str,true);
	xmlhttp.send();
}
function nameByCode(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){
			var data=xmlhttp.responseText;
			var data_brk=data.split('__');
			document.getElementById("part_name_id").innerHTML=data_brk[0];
			document.getElementById("unit_id").innerHTML=data_brk[1];
		}
	}
	xmlhttp.open("GET","ajax_item_code_name.php?id="+str+"&type=code",true);
	xmlhttp.send();
}
function codeByName(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){
			var data=xmlhttp.responseText;
			var data_brk=data.split('__');
			document.getElementById("part_no_id").innerHTML=data_brk[0];
			document.getElementById("unit_id").innerHTML=data_brk[1];
		}
	}
	xmlhttp.open("GET","ajax_item_code_name.php?id="+str+"&type=name",true);
	xmlhttp.send();
}
function processParameter(str){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(str==''){
		document.getElementById("details_id").innerHTML='';
	}else
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var data=xmlhttp.responseText;
			//alert(data);
			document.getElementById("details_id").innerHTML=data;
		}
	}
	xmlhttp.open("GET","ajax_process_prmtr_table.php?id="+str,true);
	xmlhttp.send();
}
function activate(i){
	if(document.getElementById("check_"+i).checked==true){
		document.getElementById("flow_no_"+i).disabled=false;
		document.getElementById("parameter_"+i).disabled=false;
		document.getElementById("parameter_specs_"+i).disabled=false;
		document.getElementById("instrument_id_"+i).disabled=false;
		document.getElementById("range_min_"+i).disabled=false;
		document.getElementById("range_max_"+i).disabled=false;
		document.getElementById("remarks_"+i).disabled=false;
	}else if(document.getElementById("check_"+i).checked==false){
		document.getElementById("flow_no_"+i).disabled=true;
		document.getElementById("parameter_"+i).disabled=true;
		document.getElementById("parameter_specs_"+i).disabled=true;
		document.getElementById("instrument_id_"+i).disabled=true;
		document.getElementById("range_min_"+i).disabled=true;
		document.getElementById("range_max_"+i).disabled=true;
		document.getElementById("remarks_"+i).disabled=true;
	}
}
</script>