COMPILE FUNCTION obj_WO_Wfr_WIP(Method,Parms)

/*
	Methods for the WO_WFR_WIP (Wafer WIP) Tables
	
	6/9/2016 JCH - Initial coding
	
	
*/

DECLARE FUNCTION Get_Status, Msg, obj_Tables, ErrMsg, obj_Tables, obj_Prod_Spec
DECLARE SUBROUTINE ErrMsg, Set_Status, Send_Dyn, FieldStore, obj_Tables, obj_WO_Wfr, obj_WO_Mat_Wfr, Set_Property
DECLARE SUBROUTINE Rlist, obj_Tool_Wfr, obj_Location, obj_Notes

$INSERT WO_WFR_EQUATES
$INSERT WO_WFR_WIP_EQUATES
$INSERT WO_MAT_WFR_EQUATES
$INSERT PROD_SPEC_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQUATES


Equ CRLF$	To \0D0A\


EQU WAFER_ID$		TO 1		;* Columns in data structure returned by Reconcile_Epi_Pro
EQU LOT_NO$			TO 2
EQU LOADED_INTO$	TO 3
EQU RAN_IN$			TO 4
EQU POCKET_CHAR$	TO 5
EQU UNLOADED_INTO$	TO 6
EQU WAFER_DISP$		TO 7


ErrTitle = 'Error in Stored Procedure "obj_WO_Wfr_WIP"'
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 = ''


************************ DEAD DEAD DEAD  **********************

BEGIN CASE
	CASE Method = 'SetWfrSigProfile'		; GOSUB SetWfrSigProfile
	CASE Method = 'SetSignature'			; GOSUB SetSignature
	
	CASE 1
		NULL

END CASE

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

RETURN Result



* * * * * * *
SetWfrSigProfile:
* * * * * * * 

WfrID = Parms[1,@RM]

IF Parms = '' THEN ErrorMsg = 'Null parameter "WfrID" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

WONo =WfrID[1,'*']

IF WONo < 128680 THEN RETURN			;* This is the first WO No on 7/29/2005 - The day we cut over to the new system.

WOStepKeys = XLATE('WO_LOG',WONo,WO_LOG_WO_STEP_KEY$,'X')

SigProfile = ''

StepCnt = COUNT(WOStepKeys,@VM) + (WOStepKeys NE '')

FOR I = 1 TO StepCnt
	PSNo = XLATE('WO_STEP',WOStepKeys<1,I>,WO_STEP_PROD_SPEC_ID$,'X')
	
	StepProfile = obj_Prod_Spec('GetWfrSigProfile',PSNo)
	
	SigCnt = COUNT(StepProfile,@VM) + (StepProfile NE '')
	FOR N = 1 TO SigCnt
		StepSig = StepProfile<1,N>
		IF StepSig[1,2] NE 'RN' THEN
			SigProfile := I:StepProfile<1,N>:@VM
		END
	NEXT N
NEXT I
IF SigProfile[-1,1] = @VM THEN SigProfile[-1,1] = ''

WfrWipRec = ''
WfrWipRec<WO_WFR_WIP_SIG_PROFILE$> = SigProfile

otParms = 'WO_WFR_WIP':@RM:WfrID:@RM:@RM:WfrWipRec
obj_Tables('WriteRec',otParms)			;* Creates new WO_WFR_WIP record with a sig profile


Result = SigProfile<1,1>

RETURN


* * * * * * *
SetSignature:
* * * * * * *

WfrID		= Parms[1,@RM]
WOStep		= Parms[COL2()+1,@RM]
SigProfKeys	= Parms[COL2()+1,@RM]
Signatures	= Parms[COL2()+1,@RM]
SigDTMs		= Parms[COL2()+1,@RM]


IF WfrID = ''		THEN ErrorMsg = 'Null parameter "WfrID" passed to routine. (':Method:')'
IF WOStep = ''		THEN ErrorMsg = 'Null parameter "WOStep" passed to routine. (':Method:')'
IF SigProfKeys = ''	THEN ErrorMsg = 'Null parameter "SigProfKeys" passed to routine. (':Method:')'
IF Signatures = ''	THEN ErrorMsg = 'Null parameter "Signatures" passed to routine. (':Method:')'
IF SigDTMs = ''		THEN ErrorMsg = 'Null parameter "SigDTMs" passed to routine. (':Method:')'


IF ErrorMsg NE '' THEN RETURN

SigCnt = COUNT(SigProfKeys,@VM) + (SigProfKeys NE '')

FOR I = 1 TO SigCnt

	IF SigProfKeys<1,I> = ''	THEN ErrorMsg = 'Null parameter "SigProfKey" passed to routine. (':Method:')'
	
	thisSigDTM = ICONV(SigDTMs<1,I>,'DT') 
	IF thisSigDTM = '' THEN
		*ErrorMsg = 'Invalid SigDTM ':QUOTE(thisSigDTM):' passed to routine. (':Method:')'
	END
	
	IF ErrorMsg NE '' THEN RETURN
	
NEXT I

otParms = 'WO_WFR_WIP':@RM:WfrID
WfrWipRec = obj_Tables('ReadRec',otParms)

IF Get_Status(errCode) THEN
	RETURN
END

ProfileCnt	= COUNT(WfrWipRec<WO_WFR_WIP_SIG_PROFILE$>,@VM) + (WfrWipRec<WO_WFR_WIP_SIG_PROFILE$> NE '')
LastProfSig = WfrWipRec<WO_WFR_WIP_SIG_PROFILE$,ProfileCnt>

LastBoxSigned = 0
WriteFlag = 0

FOR I = 1 TO SigCnt
	SigProfKey	= SigProfKeys<1,I>
	
	
	IF NUM(SigProfKey[1,1]) ELSE
		SigProfKey = WOStep:SigProfKey
	END
	
	LOCATE SigProfKey IN WfrWipRec<WO_WFR_WIP_SIG_PROFILE$> USING @VM SETTING Pos THEN
	
		WfrWipRec<WO_WFR_WIP_SIGNATURE$,Pos> = Signatures<1,I>
		WfrWipRec<WO_WFR_WIP_SIG_DTM$,Pos> = ICONV(SigDTMs<1,I>,'DT')
		
		WriteFlag = 1	
		
	END 
	
NEXT I

IF WriteFlag = 1 THEN
	otParms = FieldStore(otParms,@RM,4,0,WfrWipRec)	;* Put record in 4th field of OtParms
	obj_Tables('WriteRec',otParms)

END ELSE
	obj_Tables('UnlockRec',otParms)
END

RETURN


