COMPILE FUNCTION obj_React_Wand(Method,Parms)

/*
	Methods for REACT_WAND (Quart Wand) table
    
	1/8/2014 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    WandChange(Reactor,Date,ReactLogID)		;* Creates new Line item for Tube Change
	ReactUnload(Reactor,WafersOut)			;* Bumps Wafer Count on current (top) line item by WafersOut
	
*/


DECLARE FUNCTION Get_Status, Utility, obj_Tables
DECLARE SUBROUTINE  Set_Status, ErrMsg, obj_Tables, Send_Dyn, obj_Tube

$INSERT REACTOR_EQUATES
$INSERT REACT_TUBE_EQUATES
$INSERT REACT_READS_EQUATES

ErrTitle = 'Error in Stored Procedure "obj_React_Tube"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'TubeChange'		; GOSUB TubeChange
	//CASE Method = 'ReactUnload'		; GOSUB ReactUnload
	//CASE Method = 'ServiceHrs'		; GOSUB ServiceHrs
	//CASE Method = 'ServiceWfrCnt'	; GOSUB ServiceWfrCnt
	//CASE Method = 'ServicePCRC'		; GOSUB ServicePCRC
	
	CASE 1
		ErrorMsg = 'Unknown Method ':Method:' passed to object routine.'

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


* * * * * * *
TubeChange:
* * * * * * *

* This method is called from the WRITE event on the REACTOR_LOG window 10/1/2009 JCH

ReactorNo	= Parms[1,@RM]
ChangeDtm	= Parms[COL2()+1,@RM]
ReactLogID	= Parms[COL2()+1,@RM]
TubeID		= Parms[COL2()+1,@RM]
ReactHrs	= Parms[COL2()+1,@RM]
ReactWfrCnt = Parms[COL2()+1,@RM]

IF ReactorNo = ''	THEN ErrorMsg = 'Null Parameter "ReactorNo" passed to routine. (':Method:')'
IF ChangeDtm = ''	THEN ErrorMsg = 'Null Parameter "ChangeDtm" passed to routine. (':Method:')'
IF ReactLogID = ''	THEN ErrorMsg = 'Null Parameter "ReactLogID" passed to routine. (':Method:')'
IF TubeID = ''		THEN ErrorMsg = 'Null Parameter "TubeID" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

thisChangeDtm = ICONV(ChangeDtm,'DT')
IF thisChangeDtm = '' THEN
	ErrorMsg = 'Invalid value ':QUOTE(ChangeDtm):' passed in parameter "ChangeDtm". (':Method:')'
	RETURN
END

OtParms = 'REACT_TUBE':@RM:ReactorNo
ReactTubeRec = obj_Tables('ReadRec',OtParms)		;* Read and lock REACT_TUBE record.

IF Get_Status(errCode) THEN
	obj_Tables('UnlockRec',OtParms)
	RETURN
END

* Added LOCATE stuff on 11/23/2013 JCH

* Close out tube being removed line item

LOCATE ReactLogID IN ReactTubeRec<REACT_TUBE_REM_RL_ID$> USING @VM SETTING Pos THEN

	* Already posted -> update data
	
	ReactTubeRec<REACT_TUBE_REM_REACT_HRS$,Pos>		= ReactHrs							;* Update Hrs
	ReactTubeRec<REACT_TUBE_REM_REACT_WFR_CNT$,Pos>	= ReactWfrCnt						;* Update WfrCnt
	
	InstRLId 	= ReactTubeRec<REACT_TUBE_INST_RL_ID$,Pos>
	InstDTM		= ReactTubeRec<REACT_TUBE_INST_DTM$,Pos>
	
END ELSE

	* Close out the active line
	
	Pos = 1
	
	
	ReactTubeRec<REACT_TUBE_REM_DTM$,Pos>			= thisChangeDTM
	ReactTubeRec<REACT_TUBE_REM_RL_ID$,Pos>			= ReactLogID
	ReactTubeRec<REACT_TUBE_REM_REACT_HRS$,Pos>		= ReactHrs
	ReactTubeRec<REACT_TUBE_REM_REACT_WFR_CNT$,Pos>	= ReactWfrCnt

	InstRLId 	= ReactTubeRec<REACT_TUBE_INST_RL_ID$,Pos>
	InstDTM		= ReactTubeRec<REACT_TUBE_INST_DTM$,Pos>
END	



IF ReactTubeRec<REACT_TUBE_TUBE_ID$,1> NE ''  THEN
	RemTubeID = ReactTubeRec<REACT_TUBE_TUBE_ID$,Pos>
	
	IF RemTubeID NE '' THEN
	
		Parms   = RemTubeID:@RM
		Parms  := ReactorNo:@RM
		Parms  := ChangeDTM:@RM
		Parms  := ReactHrs:@RM
		Parms  := ReactWfrCnt:@RM
		Parms  := ReactLogID:@RM
		Parms  := ReactTubeRec<REACT_TUBE_RDS_WAFER_CNT$,Pos>:@RM
		Parms  := InstRLId:@RM
		Parms  := InstDTM		;* DateTime passed in internal format

		Set_Status(0)
		obj_Tube('Remove',Parms)		;* Update the existing tube record

		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
			obj_Tables('UnlockRec',OtParms)
			RETURN
		END
	END
END





Parms  = TubeID:@RM
Parms := ReactorNo:@RM
Parms := ChangeDTM:@RM
Parms := ReactHrs:@RM
Parms := ReactWfrCnt:@RM
Parms := ReactLogID

Set_Status(0)

obj_Tube('Install',Parms)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	
	obj_Tube('ClearRemove',TubeID:@RM:ReactorNo)	;* Back out the Tube Remove already done

	obj_Tables('UnlockRec',OtParms)
	RETURN
END

* Added LOCATE stuff on 11/23/2013 JCH

LOCATE ReactLogID IN ReactTubeRec<REACT_TUBE_INST_RL_ID$> USING @VM SETTING Pos THEN

	ReactTubeRec<REACT_TUBE_INST_REACT_HRS$,Pos>		= ReactHrs
	ReactTubeRec<REACT_TUBE_INST_REACT_WFR_CNT$,Pos>	= ReactWfrCnt
	
END ELSE

	* Insert new line item at top of list for new tube record

	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_INST_DTM$,1,0,thisChangeDtm)
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_TUBE_ID$,1,0,TubeID)
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_INST_RL_ID$,1,0,ReactLogID)
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_RDS_WAFER_CNT$,1,0,0)					;* Set Wafer Count to 0

	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_INST_REACT_HRS$,1,0,ReactHrs)
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_INST_REACT_WFR_CNT$,1,0,ReactWfrCnt)

	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_REM_DTM$,1,0,'')
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_REM_RL_ID$,1,0,'')
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_REM_REACT_HRS$,1,0,'')
	ReactTubeRec = INSERT(ReactTubeRec,REACT_TUBE_INST_REACT_WFR_CNT$,1,0,'')
END

OtParms = FieldStore(OtParms,@RM,4,0,ReactTubeRec)		;* Put record in 4th field of OtParms
obj_Tables('WriteRec',OtParms)

IF Get_Status(errCode) THEN
	obj_Tables('UnlockRec',OtParms)
END

RETURN


