COMPILE FUNCTION obj_Run_Stage_Wfr(Method,Parms)

/*
	Methods for RUN_STAGE_WFR table
    
	06/24/2016 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    Create(DataStruct)		;* Create new record
	
	
*/

DECLARE SUBROUTINE Set_Status, Msg, obj_Tables, 
DECLARE SUBROUTINE obj_WO_Wfr, ErrMsg

DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, NextKey,  obj_Prod_Spec, Send_Dyn, obj_Clean_Insp



$INSERT REACT_RUN_EQUATES
$INSERT RUN_STAGE_WFR_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT WO_WFR_EQUATES

ErrTitle = 'Error in Stored Procedure "obj_Run_Stage_Wfr"'
ErrorMsg = ''
ErrCode  = ''

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 = 'Create'			; GOSUB Create
	CASE Method = 'SetIASig'		; GOSUB SetIASig
	CASE Method = 'CurrStatus'		; GOSUB CurrStatus
	
	CASE 1
		
END CASE

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

RETURN Result




* * * * * * *
Create:
* * * * * * *

RDSNo	= Parms[1,@RM]
Stage	= Parms[COL2()+1,@RM]
WfrID	= Parms[COL2()+1,@RM]
PSNo	= Parms[COL2()+1,@RM]



IF RdsNo = ''	THEN ErrorMsg = 'Null Parameter "RdsNo" passed to routine. (':Method:')'
IF Stage = ''	THEN ErrorMsg = 'Null Parameter "Stage" passed to routine. (':Method:')'
IF WfrID = ''	THEN ErrorMsg = 'Null Parameter "WfrID" passed to routine. (':Method:')'


IF ErrorMsg NE '' THEN RETURN

PRStageRec = XLATE('PRS_STAGE' , PSNo:'*':Stage , '' , 'X' )

RSWRec = ''
RSWRec<RUN_STAGE_WFR_SPEC_TOOL_CLASS$> = PRStageRec<PRS_STAGE_PROC_TOOL_CLASS$>
RSWRec<RUN_STAGE_WFR_SPEC_INV_ACTION$> = PRStageRec<PRS_STAGE_PROC_INV_ACTION$>

WfrKID = WfrID
CONVERT '*' TO '.' IN WfrKID

otParms = 'RUN_STAGE_WFR':@RM:RDSNo:'*':Stage:'*':WfrKID:@RM:@RM:RSWRec
obj_Tables('WriteRec',otParms)

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	DEBUG
END

RETURN



* * * * * * *
SetIASig:
* * * * * * *

RDSNo		= Parms[1,@RM]
Stage		= Parms[COL2()+1,@RM]
WfrID		= Parms[COL2()+1,@RM]
InvAction	= Parms[COL2()+1,@RM]

IF RdsNo = ''		THEN ErrorMsg = 'Null Parameter "RdsNo" passed to routine. (':Method:')'
IF Stage = ''		THEN ErrorMsg = 'Null Parameter "Stage" passed to routine. (':Method:')'
IF WfrID = ''		THEN ErrorMsg = 'Null Parameter "WfrID" passed to routine. (':Method:')'
IF InvAction = ''	THEN ErrorMsg = 'Null Parameter "InvAction" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

CONVERT '*' TO '.' IN WfrID

otParms = 'RUN_STAGE_WFR':@RM:RDSNo:'*':Stage:'*':WfrID
RSWRec = obj_Tables('ReadRec',otParms)


LOCATE InvAction IN RSWRec<RUN_STAGE_WFR_SPEC_INV_ACTION$> USING @VM SETTING Pos THEN

	CurrDTM = ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DT')
	
	RSWRec<RUN_STAGE_WFR_SIA_COMP_BY$,Pos>	= @USER4
	RSWRec<RUN_STAGE_WFR_SIA_COMP_DTM$,Pos>	= CurrDTM

	otParms = FIELDSTORE(otParms,@RM,4,0,RSWRec)
	obj_Tables('WriteRec',otParms)

	IF Get_Status(errCode) THEN
		ErrMsg(errCode)
	END
	
END

RETURN



* * * * * * *
CurrStatus:
* * * * * * *

StageWfrKey	= Parms[1,@RM]
StageWfrRec	= Parms[COL2()+1,@RM]


IF StageWfrKey = '' THEN RETURN

IF StageWfrRec = '' THEN
	StageWfrRec = XLATE('RUN_STAGE_WFR',StageWfrKey,'','X')
	IF StageWfrRec = '' THEN RETURN
END

WfrID = FIELD(StageWfrKey,'*',3)

CONVERT '.' TO '*' IN WfrID

WfrRec = XLATE('WO_WFR',WfrID,'','X')

LOCATE 'UNSPLIT' IN WfrRec<WO_WFR_LOC_EVENT$> USING @VM SETTING Pos THEN
	Partial = 1
END ELSE
	Partial = ''
END

SpecToolClass	= StageWfrRec<RUN_STAGE_WFR_SPEC_TOOL_CLASS$>
SpecInvAct		= StageWfrRec<RUN_STAGE_WFR_SPEC_INV_ACTION$>
CompBy			= StageWfrRec<RUN_STAGE_WFR_COMP_BY$>
SIA_CompBy		= StageWfrRec<RUN_STAGE_WFR_SIA_COMP_BY$>


IAStart = ''
IAStop = ''
	
IF SpecInvAct NE '' THEN

	iaCnt = COUNT(SpecInvAct,@VM) + (SpecInvAct NE '')

	IF SIA_CompBy<1,iaCnt> NE ''	THEN IAStop = 1
	IF SIA_CompBy<1,1> NE ''		THEN IAStart = 1
	
END

BEGIN CASE
	CASE Partial = 1 			; WfrStatus = 'PART'
	CASE CompBy NE '' 			; WfrStatus = 'COMP'
	CASE IAStop = 1				; WfrStatus = 'SIG'
	CASE IAStart = 	1			; WfrStatus = 'RUN'
	CASE 1						; WfrStatus = 'RDY'
END CASE
	
Result = WfrStatus
	

RETURN
