<?php
$title = _('Shop Floor Process Inspection');

$sql=DB_query("select * from job_card where id='".$_REQUEST['mrnid']."'",$db);
$row=DB_fetch_array($sql);
extract($row);
		$totalproduct=DB_query("select  move_qty as prodqty from daily_process_qty_maintain where jobcard='".$id."' and from_process='".$_REQUEST['process']."'",$db);
					$numrow1=DB_num_rows($totalproduct);
		if($numrow1==0)
		{
      $totalproduct=DB_query("select  move_qty as prodqty from daily_process_qty_maintain where jobcard='".$id."'
	                and to_process='".$_REQUEST['process']."'",$db);
					$numrow1=DB_num_rows($totalproduct);
						
					$row_productqty=DB_fetch_array($totalproduct);
					$data4=$row_productqty['prodqty']; 
       }
	   else
	   {
	   $row_productqty=DB_fetch_array($totalproduct);
	   $data4=$row_productqty['prodqty']; 
	   }


	if(isset($_POST['Save']))
	{
				  
				    $prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$title."'",$db);
					$prefix_row=DB_fetch_array($prefix_sql);
					$prefix1=$prefix_row['prefix_code'];
					$financial=substr($_SESSION['YearStart'],-2)."-".substr($_SESSION['YearEnd1'],-2);
					  $sql="Select qc_no from qc_shop_floor where  
					   INSTR(`qc_no`, '$financial') > 0 order by id desc limit 0,1";
				
					$result=DB_query($sql,$db);
					$myrow=DB_fetch_array($result);
					
					if(DB_num_rows($result)>0)
					{
						$ExplBill=explode("/",$myrow['qc_no']);
						$maxval = $ExplBill[2];
						$req_final=$maxval+1;
						
					}
					else
					{
					$req_final="1";
					}
					
					$string=$prefix1."/".$financial."/";
					
					$final_string=$string.str_pad($req_final,4,"0",STR_PAD_LEFT);
					
	
	
								$data['qc_no']=$final_string;
								$data['qc_date']=FormatDateForSQL($_REQUEST['qc_date']);
								$data['jobid']=$_REQUEST['jobid'];
								$data['mst_itemid']=$_REQUEST['itemid'];
								$data['production_qty']=$_REQUEST['prdqty'];
								$data['processid']=$_REQUEST['processid'];
								$data['sample_no']=$_REQUEST['sampleno'];
								$data['sample_date']=FormatDateForSQL($_REQUEST['sampledate']);
								$data['sample_by']=$_REQUEST['sampleby'];
								$data['analysed']=$_REQUEST['analysed'];
								$data['methodid']=$_REQUEST['method'];
								$data['accepted_qty']=$_REQUEST['actqty'];
								$data['rejectqty']=$_REQUEST['rejectqty'];
                                                                $data['sitecode']=$site;
								$data['preparedby']=$_REQUEST['preparedby'];
								$data['CompanyId']=$_SESSION['ACGCompanyId'];
                        $data['scrap_item_id']=$_REQUEST['scrap'];
								$data['created_by'] = $_SESSION['UserID'];
								$data['created_date'] = date('Y-m-d');
								$s->RecordInsert('qc_shop_floor',$data);			//INSERT INTO PARANT TABLE
								$last_id=DB_Last_Insert_ID($db,'qc_shop_floor','id');
				
				
				//**********   Updating  daily_process_qty_maintain  *************************************//
				
								$toprocess=$s->GetFieldValue('daily_process_qty_maintain',"jobcard='".$_REQUEST['jobid']."' 
								    and 	from_process='".$_REQUEST['processid']."'",'to_process');
				
								$data2['status']=1;
								$data2['move_qty']=$_REQUEST['actqty'];	
								$data2['pending_qty']=$_REQUEST['rejectqty'];	
								$cond="jobcard='". $_REQUEST['jobid']."'
								and to_process='". $toprocess."'";
								$s->RecordEdit('daily_process_qty_maintain',$data2,$cond);
				
				
				
				
				
				
			$update=DB_query("update job_process_details set qc_status=1 where jobid='". $_REQUEST['jobid']."' and 
						process='". $_REQUEST['processid']."' ",$db);	
				
				
				
				
				//*****************************************************************************************//
				
				
				
				
			
			
			for($i=0;$i<count($_REQUEST['paraid']);$i++)
			{
			
                        if($_REQUEST['result'][$i]!='')
                            {
                                    $dataArr['parentid']=$last_id;
                                    $dataArr['parameterid']=$_REQUEST['paraid'][$i];
                                    //$dataArr['instrumentid']=$_REQUEST['instrumentid'][$i];
                                    //  $dataArr['obs_low']=$_REQUEST['obs_low'][$i];
                                    // $dataArr['obs_max']=$_REQUEST['obs_max'][$i];
                                    $dataArr['result']=$_REQUEST['result'][$i];
                                    $dataArr['remarks']=$_REQUEST['remarks1'][$i];
                                    $s->RecordInsert('qc_shop_floor_details',$dataArr);//INSERT INTO CHIELD TABLE
                                }
			
			
			
			
			
			
			
			}	
				
				
				
				
				
				
				
				
		$s->pageLocation("index.php?route=QC/transactions/quality_inspection_index".$rurl);		
				
	}





?>




<link rel="stylesheet" href="css/new_mxerp.css">
<div class="tab_div">
<center> <h2>Shop Floor Process Inspection</h2></center>
<div id="container">
<form action="" method="post">
<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 colspan="6" style="text-align:center"><b>Branch</b>&nbsp;&nbsp;[<strong><?php echo $s->getField('locations','loccode',$site,'locationname'); ?></strong>]</td>
	</tr>
  <tr class="row1">
    <td width="13%"><strong>Qc No.</strong></td>
    <td width="20%"><input name="qc_no" id="qc_no" type="text" class="" style="width:100%;" value="Auto Generate" readonly="true" />    </td>
    <td width="13%"><strong>Qc Date</strong></td>
    <td width="20%"><input name="qc_date" id="qc_date" type="text" class="datepicker" style="width:100%;" value="<?php echo date('d/m/Y'); ?>" />    </td>
    <td><strong>Job Card No.</strong></td>
    <td width="20%"><input name="jobid" id="jobid" type="hidden"  style="width:100%;" value="<?php echo $id; ?>" />
	<input name="" id="" type="text"  style="width:100%;" readonly="true"  value="<?php echo $job_card_no; ?>"/></td>
  </tr>
  <tr class="row1">
    <td><strong>Job Card Date </strong></td>
    <td><input name="" id="" type="text"  readonly="true" style="width:100%;"  value="<?php echo ConvertSQLDate($job_date); ?>"/></td>
    <td><strong>Part No.</strong></td>
    <td><input name="itemid" id="itemid" type="hidden" value="<?php echo $work_itemid; ?>" style="width:100%;" />
	<input name="" id="" type="text" value="<?php echo $s->getField('item_master','id',$work_itemid,'StockID'); ?>" style="width:100%;"  readonly="true"/>
	</td>
    <td><strong>Part Name </strong></td>
    <td><input name="" id="" type="text" value="<?php echo $s->getField('item_master','id',$work_itemid,'item_name'); ?>" 
	style="width:100%;"  readonly="true"/>
	</td>
  </tr>
  <tr class="row1">
    <td><strong>Unit</strong></td>
	<?php
	$unitid=$s->getField('item_master','id',$work_itemid,'mst_unitid'); 
	$unitname=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');
	?>
	
    <td><input name="" id="" type="text" class="" style="width:100%;" value="<?php echo $unitname; ?>" readonly="true" /></td>
    <td><strong>Batch No.</strong></td>
    <td><input name="" id="" type="text" class="" style="width:100%;" value="<?php echo $lotno; ?>" readonly="true" />    </td>
    <td><strong>Production Qty.</strong></td>
    <td><input name="prdqty" id="prdqty" type="text"   value="<?php echo $data4; ?>" style="width:100%;" readonly="true" /></td>
  </tr>
  <tr class="row1">
    <td><strong>Production Process </strong></td>
    <td><input name="processid" id="processid" type="hidden" class="" value="<?php echo $_REQUEST['process']; ?>"  />
	<input name="" id="" type="text" class=""
	value="<?php echo $s->getField('production_process_master','id',$_REQUEST['process'],'manuf_process_name');  ?>" 
	style="width:100%;" readonly="true" /></td>
    <td><strong>Production Date </strong></td>
    <td><input name="" id="" type="text"  style="width:100%;" readonly
	value="<?php echo ConvertSQLDate($s->getField('daily_production_process','job_card_id',$id,'process_prod_date')); ?>" />    </td>
    <td><strong>Sample No. </strong></td>
    <td><input name="sampleno" id="" type="text" class="" style="width:100%;" /></td>
  </tr>
  <tr class="row1">
    <td><strong>Sample Date </strong></td>
    <td><input name="sampledate" id="" type="text" class="datepicker" style="width:100%;" /></td>
    <td><strong>Sample By</strong></td>
    <td><input name="sampleby" id="" type="text" class="" style="width:100%;" />    </td>
    <td><strong>Analysed Name</strong></td>
    <td><input name="analysed" id="" type="text" class="" style="width:100%;" /></td>
  </tr>
  <tr class="row1">
    <td><strong>Method No. </strong></td>
    <td><select name="method" id="method" style="width:100%" onchange="showdetails(this.value)">
	<option value="0">Select</option>
	<?php 
	$sql_method=DB_query("select * from qc_product_parameter where CompanyId='".$_SESSION['ACGCompanyId']."' and  process_id='".$_REQUEST['process']."'",$db);
	while($row_method=DB_fetch_array($sql_method))
	{
	?>
	<option value="<?php echo $row_method['id']; ?>"><?php echo $row_method['method_no']; ?></option>
	
	<?php } ?>
	</select></td>
    <td><strong>Accepted Qty. </strong></td>
    <td><input name="actqty" id="actqty" type="text" class="" style="width:32%;" onkeyup="calamt(this.value)" onkeypress="return isNumberKey(event)"  />&nbsp;&nbsp; <strong>Rejected Qty.</strong>&nbsp;&nbsp;<input name="rejectqty" id="rejectqty" type="text" class="" style="width:32%;" /></td>
   <td><strong>Scrap Items</strong></td>
    <td><select name="scrap" id="scrap" style="width:100%"> 
      <option value="0">Select</option>
      <?php
      $scrpid=$s->GetFieldValue("stockmaincategory","stockmaincategoryname like'%scrap%'","id");
      $sql_row=DB_query("select * from item_master where CategoryID='".$scrpid."'",$db);
      while($row1=DB_fetch_array($sql_row))
      {
      ?>
      <option value="<?php echo $row1['id']; ?>"><?php echo $row1['item_name']; ?></option>
      <?php } ?>
     </select>
    </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;">
	<table width="100%" border="1" cellpadding="3" cellspacing="0"  id="itemdetails">
  <tr bgcolor="#CCCCCC" height="25" >
    <td width="6%" align="left"><strong>Sr. No.</strong></td>
    <td width="10%" align="left"><strong>Parameter</strong></td>
    <td width="20%" align="left"><strong>Specification</strong></td>
    <td width="20%" align="left"><strong>Mesurement Instrument</strong></td>
    <td width="20%" align="left"><strong>Obs. Low</strong></td>
    <td align="left"><strong>Obs. High</strong></td>
    <td align="left"><strong>Results</strong></td>
    <td align="left"><strong>Remarks</strong></td>
  </tr>
  
</table></td>
	</tr>
	<tr class="row1">
    <td colspan="6">&nbsp;</td>
    </tr>
	<tr class="row1">
    <td colspan="6"><table width="100%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
    <td width="15%">&nbsp;</td>
    <td width="35%" align="center"><strong>Prepared By:</strong></td>
    <td width="15%"><input name="preparedby" id="preparedby" type="text" class="" style="width:100%;" /></td>
    <td width="35%">&nbsp;</td>
  </tr>
  
</table></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>
function showdetails(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)
    {
    
	document.getElementById("itemdetails").innerHTML=xmlhttp.responseText;		
    }
  }

 
xmlhttp.open("GET","ajax_getmethod_details.php?mid="+str,true);
xmlhttp.send();








}

function calamt(str)
{
 

 
if(document.getElementById("actqty").value=='')
{
alert("Must Enter Accepted Qty First");
document.getElementById("actqty").focus();
return false;
}

else
{
var actqty=parseFloat(document.getElementById("actqty").value);
var prdqty=parseFloat(document.getElementById("prdqty").value);
if(actqty>prdqty)
{
alert("Accepted Qty Should be less then Production Qty ");
document.getElementById("actqty").value='';
document.getElementById("actqty").focus();
return false;
}
else
{
var amt=prdqty-actqty;
document.getElementById("rejectqty").value=amt.toFixed(2);
}
}
return true;

}

function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode!=46 && (charCode > 31 && (charCode < 48  || charCode > 57)))
	{
	alert("Only Numeric Value Allowed");
    return false;
	}
    return true;
}


</script>