COMPILE FUNCTION obj_WO_LogRR(Method,Parms)
/*
	Methods for the Work Order Log (WO_LOG) Release/Recall methods
    
	04/18/2016 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
	Release				;* Release Cassette based Runs
	Recall				;* Recall
  
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box, Popup, obj_RDS, obj_WO_Mat, Set_Property, obj_Sched
DECLARE FUNCTION obj_Prod_Spec
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, Btree.Extract, ErrMsg, RList, obj_WO_Step, Send_Info, obj_RDS2
DECLARE SUBROUTINE obj_Notes, Msg, obj_WO_Mat, obj_RDS, obj_Post_Log, obj_WO_Mat_Log, obj_WO_Wfr


$INSERT APPCOLORS
$INSERT MSG_EQUATES
$INSERT NOTIFICATION_EQU

$INSERT COMPANY_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQUATES
$INSERT WO_MAT_EQUATES

$INSERT RDS_EQUATES
$INSERT REACT_RUN_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT PRS_LAYER_EQUATES

$INSERT PROD_SPEC_EQUATES
$INSERT EPI_PART_EQUATES
$INSERT CUST_EPI_PART_EQUATES
$INSERT PROD_VER_EQUATES


EQU CRLF$	TO \0D0A\

EQU TARGET_ACTIVELIST$ TO 5

ErrTitle = 'Error in Stored Procedure "obj_WO_LogRR"'
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 = 'Release'		; GOSUB Release
	CASE Method = 'Recall'		; GOSUB Recall
	
	CASE 1
		ErrorMsg = 'Unknown Method ':QUOTE(Method):' passed to routine.'

END CASE

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

RETURN Result



* * * * * * *
Release:
* * * * * * *

WONo		= Parms[1,@RM]
CassNos		= Parms[COL2()+1,@RM]

IF WONo	= ''			THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
IF ErrorMsg NE ''		THEN RETURN


*OrgColor = Set_Property('WO_LOG2.STATUSLINE_FIX','BACKCOLOR',YELLOW$)	;* //////// Messaging  *** Out for development

TableVar = ''
OtParms = 'WO_LOG':@RM:WONo:@RM:TableVar 
*WORec = obj_Tables('ReadRec',OtParms)			;* **** Out for development

WORec = XLATE('WO_LOG',WONo,'','X')				;* Used for testing * * * * * * * * * * 


CustNo		= WORec<WO_LOG_CUST_NO$>
PromiseDt	= WORec<WO_LOG_PROMISE_SHIP_DT$>
WOStepKeys	= WORec<WO_LOG_WO_STEP_KEY$>
ProdVerNo	= WORec<WO_LOG_PROD_VER_NO$>
EPIPartNo	= WORec<WO_LOG_EPI_PART_NO$>
WOMatKeys	= WORec<WO_LOG_WO_MAT_KEY$>


IF ProdVerNo	= '' THEN ErrorMsg = 'Prod Ver No blank on Work Order. WO Not Released. (':Method:')'
IF CustNo		= '' THEN ErrorMsg = 'No Cust Number on Work Order. WO Not Released. (':Method:')'
IF WOStepKeys	= '' THEN ErrorMsg = 'Missing WO Step Keys. WO Not Released. (':Method:')'

IF ErrorMsg NE '' THEN
 	obj_Tables('UnlockRec',OtParms)
 
	RETURN
END

* * *   Lock all the WO_MAT records for updates   * * *

CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')

WOMKeys = ''
FOR K = 1 TO CassCnt
	WOMKeys<1,K> = WONo:'*':CassNos<1,K>
NEXT K

Send_Info('Locking WOMat records for update...')


WOMTableVar = obj_WO_Mat('LockSet',WOMKeys)

IF Get_Status(errCode) THEN
	obj_Tables('UnlockRec',OtParms)		;* Unlock WO_LOG record
	
	Send_Info(STR(' ',60))														;** - Messaging - **
	NewForm = Xlate('APP_INFO', 'NEW_WO_FORM', '', 'X')
    If NewForm then
        Form = 'NDW_WO_LOG'
    end else
        Form = 'WO_LOG2'
    end
	Dummy = Set_Property(Form:'.STATUSLINE_FIX','BACKCOLOR',OrgColor)			;** - Messaging - **
	RETURN
END


* At this point the WO_LOG is locked and the WO_MAT (cassettes) are all locked for update




ReactorType = XLATE('PROD_VER',ProdVerNo,PROD_VER_REACT_TYPE$,'X')

BEGIN CASE
	CASE ReactorType = 'GAN'	; GOSUB RelGaN
	CASE ReactorType = 'EPP'	; GOSUB RelEpiPRO
	CASE ReactorType NE ''		; GOSUB RelASM
	CASE 1
		obj_Tables('UnlockRec',OtParms)
		
	
END CASE

RETURN


* * * * * * *
Recall:
* * * * * * *

RETURN



* * * * * * *
RelGaN:
* * * * * * *

OrderWaferQty	= WORec<WO_LOG_WO_QTY$>
PONo			= WORec<WO_LOG_CUST_PO_NO$>
VisionOrderNo	= WORec<WO_LOG_PROD_ORD_NO$>		;* SAP Production Order Number
VisionLineNos	= ''
WMOLoadQty		= XLATE('CUST_EPI_PART',CustNo:'*':EPIPartNo,CUST_EPI_PART_WMO_LOAD_CNT$,'X')



EpiPN		= WORec<WO_LOG_EPI_PART_NO$>
EpiPartRec	= XLATE('EPI_PART',EpiPN,'','X')

SubSupplyBy	= EpiPartRec<EPI_PART_SUB_SUPP_BY$>

ProdVerRec = XLATE('PROD_VER',ProdVerNo,'','X')

ProcStepNos = ProdVerRec<PROD_VER_PROC_STEP_NO$>
ProcPSNs	= ProdVerRec<PROD_VER_PROC_STEP_PSN$>
ReactorType	= ProdVerRec<PROD_VER_REACT_TYPE$>

WOStepCnt = COUNT(ProcPSNs,@VM) + (ProcPSNs NE '')

TableVar = ''

FOR WOStep = 1 TO WOStepCnt

	WOStepKey = WORec<WO_LOG_WO_STEP_KEY$,WOStep>
	WOStepRec = XLATE('WO_STEP',WOStepKey,'','X')
	
	IF WOStep = WOStepCnt THEN LastStep = 1 ELSE LastStep = 0
	
	ProcPSN			= ProcPSNs<1,WOStep>
	StepProfile 	= obj_Prod_Spec('GetSigProfile',ProcPSN)
	
	SigCnt = COUNT(StepProfile,@VM) + (StepProfile NE '')
	
	CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')		
	
	Def = ""
	Def<MCAPTION$>		= "Releasing Cassettes for WO Step ":WOStep:"..."
	Def<MTYPE$>			= "G"
	Def<MEXTENT$>		= CassCnt
	Def<MTEXTWIDTH$>	= 600
	
	*MsgUp = Msg(@WINDOW, Def)						;* * * * * * * *** Out for development
	
	* * *   This was WM_IN and RDS creation section  * * *
	
	FOR N = 1 TO CassCnt
		CassNo = CassNos<1,N>
		
	
		FOR S = 1 TO SigCnt
			StepSig = StepProfile<1,S>
			IF StepSig[1,2] NE 'RN' THEN
				SigProfile := I:StepProfile<1,N>:@VM
			END
		NEXT S
		
		*Void = Msg(@WINDOW, MsgUp, N, MSGINSTUPDATE$)   ;* * * * * * * Out for development
		
		
		
		
		
	NEXT N
	
	*Msg(@WINDOW, MsgUp) ;* take down the gauge
	
	
NEXT WOStep



RETURN



* * * * * * *
RelASM:
* * * * * * *


RETURN


* * * * * * *
RelEpiPRO:
* * * * * * *



RETURN


************    Original Code    * * * * * * *

/*

* * * * * * *
ReleaseCassettes:
* * * * * * *

WONo		= Parms[1,@RM]
CassNos		= Parms[COL2()+1,@RM]

IF WONo	= ''			THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
IF ErrorMsg NE ''		THEN RETURN

OrgColor = Set_Property('WO_LOG2.STATUSLINE_FIX','BACKCOLOR',YELLOW$)	;* //////// Messaging

TableVar = ''
OtParms = 'WO_LOG':@RM:WONo:@RM:TableVar 
WORec = obj_Tables('ReadRec',OtParms)			;* Locks and reads record for update

IF Get_Status(errCode) THEN Return

* Added 5/21/2015 JCH to check for previous releases on this work order

WOMatKeys = WORec<WO_LOG_WO_MAT_KEY$>






OrderNo		= WORec<WO_LOG_ORDER_NO$>
OrderItems	= WORec<WO_LOG_ORDER_ITEM$>
CustNo		= WORec<WO_LOG_CUST_NO$>
PromiseDt	= WORec<WO_LOG_PROMISE_SHIP_DT$>
WOStepKeys	= WORec<WO_LOG_WO_STEP_KEY$
ProdVerNo	= WORec<WO_LOG_PROD_VER_NO$>
EPIPartNo	= WORec<WO_LOG_EPI_PART_NO$>

IF OrderNo = '' AND ProdVerNo = '' THEN ErrorMsg = 'Both Order No and Prod Ver No blank on Work Order. WO Not Released. (':Method:')'

IF CustNo		= '' THEN ErrorMsg = 'No Cust Number on Work Order. WO Not Released. (':Method:')'
*IF OrderItems	= '' THEN ErrorMsg = 'No Order Items on Work Order. WO Not Released. (':Method:')'
*IF PromiseDt	= '' THEN ErrorMsg = 'No Promise Date on Work Order. WO Not Released. (':Method:')'
IF WOStepKeys	= '' THEN ErrorMsg = 'Missing WO Step Keys. WO Not Released. (':Method:')'

IF ErrorMsg NE '' THEN
 	obj_Tables('UnlockRec',OtParms)
 	
	RETURN
END


* * * * * * * * * * * * * * * * * * * * * * * * * *

IF ProdVerNo NE '' THEN

	ReactorType = XLATE('PROD_VER',ProdVerNo,PROD_VER_REACT_TYPE$,'X')
	
	IF ReactorType NE 'EPP' THEN

		IF WORec<WO_LOG_WO_START_DTM$> = '' THEN
			CurrDTM = ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTHS'),'DT')
			WORec<WO_LOG_WO_START_DTM$> = CurrDTM
		END
	END
END

* * * * * * * * * * * * * * * * * * * * * * * * * * *

Send_Info("Collecting Data for release...")								;* //////// Messaging

IF OrderNo = '' THEN
	OrderWaferQty	= WORec<WO_LOG_WO_QTY$>
	PONo			= WORec<WO_LOG_CUST_PO_NO$>
	VisionOrderNo	= WORec<WO_LOG_PROD_ORD_NO$>		;* SAP Production Order Number
	VisionLineNos	= ''
	WMOLoadQty		= XLATE('CUST_EPI_PART',CustNo:'*':EPIPartNo,CUST_EPI_PART_WMO_LOAD_CNT$,'X')

END ELSE

	OrderRec = XLATE('ORDER',OrderNo,'','X')

	OrderWaferQty	= 0
	

	FOR I = 1 TO COUNT(OrderItems,@VM) + (OrderItems NE '')
		OrderDetRec = XLATE('ORDER_DET',OrderNo:'*':OrderItems<1,I>,'','X')
		IF NOT(INDEX(OrderDetRec<ORDER_DET_EPI_PN$>,'MISC',1)) THEN
			OrderWaferQty = OrderWaferQty + OrderDetRec<ORDER_DET_ITEM_QTY$>
		END
	NEXT I

	PONo			= OrderRec<ORDER_PO_NO$>
	VisionOrderNo	= OrderRec<ORDER_VISION_ORDER_NO$>
	VisionLineNos	= XLATE('ORDER_DET',OrderItems,ORDER_DET_VISION_LINE_NO$,'X')
END

OrdSummary = ''	;* Holds Order Detail Lot Numbers and Associated Order Item Numbers


CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')

WOMKeys = ''
FOR K = 1 TO CassCnt
	WOMKeys<1,K> = WONo:'*':CassNos<1,K>
NEXT K

Send_Info('Locking WOMat records for update...')


WOMTableVar = obj_WO_Mat('LockSet',WOMKeys)

IF Get_Status(errCode) THEN
	obj_Tables('UnlockRec',OtParms)		;* Unlock WO_LOG record
	
	Send_Info(STR(' ',60))														;** - Messaging - **
	Dummy = Set_Property('WO_LOG2.STATUSLINE_FIX','BACKCOLOR',OrgColor)			;** - Messaging - **
	RETURN
END


* At this point the WO_LOG is locked and the WO_MAT (cassettes) are all locked for update


EpiPN		= WORec<WO_LOG_EPI_PART_NO$>
EpiPartRec	= XLATE('EPI_PART',EpiPN,'','X')

SubSupplyBy	= EpiPartRec<EPI_PART_SUB_SUPP_BY$>

ProdVerRec = XLATE('PROD_VER',ProdVerNo,'','X')

ProcStepNos = ProdVerRec<PROD_VER_PROC_STEP_NO$>
ProcPSNs	= ProdVerRec<PROD_VER_PROC_STEP_PSN$>
ReactorType	= ProdVerRec<PROD_VER_REACT_TYPE$>

WOStepCnt = COUNT(ProcPSNs,@VM) + (ProcPSNs NE '')

TableVar = ''

FOR WOStep = 1 TO WOStepCnt

	WOStepKey = WORec<WO_LOG_WO_STEP_KEY$,WOStep>
	WOStepRec = XLATE('WO_STEP',WOStepKey,'','X')
	
	IF WOStep = WOStepCnt THEN LastStep = 1 ELSE LastStep = 0
	
	ProcPSN			= ProcPSNs<1,WOStep>
	
	SubPreClean		= XLATE('PRS_STAGE',ProcPSN:'*PRE',PRS_STAGE_CLEAN_TOOL$,'X')
	SubPostClean	= XLATE('PRS_STAGE',ProcPSN:'*POST',PRS_STAGE_CLEAN_TOOL$,'X')
	
	IF ReactorType = 'EPP' THEN
		
		Send_Info('Creating WM_OUT records for WOStep ':WOStep:'...')						;** - Messaging - **
		
		OutOnlyCassIDS = obj_WM_Out('Create',WONO:@RM:WOStep:@RM:CassNos:@RM:WMOLoadQty)	;* Changed WMOLoadQty 9/14/2012 JCH *********
		
	END ELSE
		OutOnlyCassIDs = ''
	END
	
	StepRDSNos = ''
	
	CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')		
	
	Def = ""
	Def<MCAPTION$>		= "Releasing Cassettes for WO Step ":WOStep:"..."
	Def<MTYPE$>			= "G"
	Def<MEXTENT$>		= CassCnt
	Def<MTEXTWIDTH$>	= 600
	
	MsgUp = Msg(@WINDOW, Def)
	
	ReprocessedRDSNos = ''
	
	FOR N = 1 TO CassCnt
	
		CassNo = CassNos<1,N>
		
		Void = Msg(@WINDOW, MsgUp, N, MSGINSTUPDATE$)
		
		IF ReactorType = 'EPP' THEN
			CassWaferQty = XLATE('WO_MAT',WONo:'*':CassNo,WO_MAT_WAFER_QTY$,'X')
			
			WMIKey = WONo:'*':WOStep:'*':CassNo
			Send_Info('Creating WM_IN record "':WMIKey:'"...')							;** - Messaging - **
			
			obj_WM_IN('Create',WONo:@RM:WOStep:@RM:CassNo:@RM:CassWaferQty)				;* ********************************   EpiPro 5000 Reactor -> create WM_IN records
			
		END ELSE
		
			IF WOStepRec<WO_STEP_RDS_KEY$,CassNo> = '' THEN
				WOMatRec = XLATE('WO_MAT',WoNo:'*':CassNo,'','X')
				
				CassLotNo 		= WOMatRec<WO_MAT_LOT_NO$>
				CassWaferQty	= WOMatRec<WO_MAT_WAFER_QTY$>
				CassCustPartNo	= WOMatRec<WO_MAT_CUST_PART_NO$>
				CassSubPartNo	= WOMatRec<WO_MAT_SUB_PART_NO$>
				CassSubInvID	= ''
				CassOrderItem	= WOMatRec<WO_MAT_ORDER_ITEM$>
				ReprocessedMat	= WOMatRec<WO_MAT_REPROCESSED_MAT$>
				
				IF OrderNo = '' THEN
					QuoteNo = ''
				END ELSE
					QuoteNo	= XLATE('ORDER_DET',OrderNo:'*':CassOrderItem,ORDER_DET_QUOTE_NO$,'X')
				END	
				
				Parms  = WONo:@RM
				Parms := WOStep:@RM
				Parms := LastStep:@RM
				Parms := CassNo:@RM
				Parms := QuoteNo:@RM
				Parms := OrderNo:@RM
				Parms := CassOrderItem:@RM
				Parms := CustNo:@RM
				Parms := PONo:@RM 
				Parms := ProcPSN:@RM
				Parms := SubSupplyBy:@RM
				Parms := SubPreClean:@RM
				Parms := SubPostClean:@RM
				Parms := PromiseDt:@RM 
				Parms := CassLotNo:@RM
				Parms := CassCustPartNo:@RM
				Parms := CassWaferQty:@RM
				Parms := CassSubPartNo:@RM
				Parms := ''					;* QXJ Flag
				
				Send_Info('Creating RDS for Cass No: ':CassNo:'...') 			;** - Messaging - **
				
				NewRDSNo	= obj_RDS('Create',Parms)
				
				StepRDSNos<1,-1> = NewRDSNo
				
				IF Get_Status(errCode) THEN
				
					ErrMsg(errCode)
					
					ErrorMsg = 'RDS Create Failure - Check for missing data on Work Order'
					
					* Modify this to call obj_RDS('Delete' ********************************************
					
					RTParms = 'RDS'
					FOR I = 1 TO COUNT(StepRdsNos,@VM) + (StepRdsNos NE '')
						RdsNo = StepRdsNos<1,I>
						RTParms = FieldStore(RTParms, @RM, 2, 1, RdsNo)
						obj_Tables('DeleteRec',RTParms)
					NEXT I
					Msg(@WINDOW, MsgUp) ;* take down the gauge			
					RETURN		;******************************************************** Check this for WO_LOG being cleared
				END
				
				IF ReprocessedMat THEN
					OrgRDSNo = CassLotNo
					obj_Reprocess('FixUp',OrgRDSNo:@RM:NewRDSNo)	;****************************************************
				END
				
			END		;* End of Check for existing RDS on this WO_Step*CassetteNo 
		END		;* End of check for EpiPRO reactor type
	NEXT N
	Msg(@WINDOW, MsgUp) ;* take down the gauge
NEXT WOStep


Send_Info("Updating WO_Mat Records with release data...")

RelDTM = OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTHS')		;* 12/31/2014 JCH & DKK moved to prevent time incrementing time during release
PtiDTM = OCONV(Date(),'D4/'):' ':OCONV(Time()+5,'MTHS')

FOR N = 1 TO CassCnt
	WOMKey = WOMKeys<1,N>
	CassNo = FIELD(WOMKey,'*',2)
	
	WOMatRec = XLATE('WO_MAT',WOMKey,'','X')			;* We have the lock, so just get the record this way
	
	IF WOMatRec<WO_MAT_REL_DTM$> = '' THEN
		WOMatRec<WO_MAT_REL_DTM$>		=  ICONV(RelDTM,'DT')
		WOMatRec<WO_MAT_REL_BY$>		= @USER4
		WOMatRec<WO_MAT_ORG_COMMIT_DT$>	= PromiseDt
		
		IF SubPreClean = 'No' OR SubPreClean = '' THEN
			WOMatRec<WO_MAT_WMI_CURR_STATUS$> = 'RTU'
		END ELSE
			WOMatRec<WO_MAT_WMI_CURR_STATUS$> = 'PREC'
		END
		
		WOMatRec<WO_MAT_WMO_CURR_STATUS$> = 'RTB'
		
		thisInvDTM = ICONV(RelDTM,'DT')
		
		WHCd		= 'SR'
		LocCd		= 'RB'
		InvAction	= 'REL'
		ScanUserID	= @USER4
		Tag			= ''
		ToolID		= ''
				
		LOCATE thisInvDTM IN WOMatRec<WO_MAT_INV_DTM$> BY 'AR' USING @VM SETTING Pos ELSE
			
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_WH$,Pos,0,WHCd)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_LOCATION$,Pos,0,LocCd)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_ACTION$,Pos,0,InvAction)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_DTM$,Pos,0,thisInvDTM)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_USER$,Pos,0,ScanUserID)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_TAG$,Pos,0,Tag)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_TOOL_ID$,Pos,0,ToolID)
			
		END 
		
		* * *   Added 5/14/2015 by JCH & DKK to "AutoScan" PTI transactions   * * *
		* This section is dead
		WHCd		= '1K'
		LocCd		= 'PTI'
		InvAction	= 'PLACE'
		ScanUserID	= @USER4
		Tag			= ''
		ToolID		= ''
		
		thisPtiDTM = ICONV(PtiDTM,'DT')
		LOCATE thisPtiDTM IN WOMatRec<WO_MAT_INV_DTM$> BY 'AR' USING @VM SETTING Pos ELSE
			
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_WH$,Pos,0,WHCd)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_LOCATION$,Pos,0,LocCd)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_ACTION$,Pos,0,InvAction)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_DTM$,Pos,0,thisPtiDTM)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_USER$,Pos,0,ScanUserID)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_TAG$,Pos,0,Tag)
			WOMatRec = INSERT(WOMatRec,WO_MAT_INV_TOOL_ID$,Pos,0,ToolID)
			
		END 
		* End of dead section
		
		
		
		
		WOMatParms = 'WO_MAT':@RM:WOMKey:@RM:WOMTableVar:@RM:WOMatRec
		obj_Tables('WriteRec',WOMatParms)					;* This writes and unlocks the WO_MAT records
		
		*obj_WO_Wfr('CassRel',WOMKey)						;* Added 3/17/2016 JCH for wafer history ***************************************
		
		
	END
					
	
NEXT N

Send_Info(STR(' ',60))															;** - Messaging - **
Dummy = Set_Property('WO_LOG2.STATUS_LINE_FIX','BACKCOLOR',OrgColor)			;** - Messaging - **


* * * * * *  WO_LOG record write was here

OutOnlyCnt = COUNT(OutOnlyCassIDs,@VM) + (OutOnlyCassIDs NE '')

ExistingWOMatKeys = WORec<WO_LOG_WO_MAT_KEY$>

FOR I = 1 TO OutOnlyCnt
	OutOnlyCassID = OutOnlyCassIDs<1,I>
	LOCATE OutOnlyCassID IN ExistingWOMatKeys BY 'AR' USING @VM SETTING Pos ELSE
		ExistingWOMatKeys = INSERT(ExistingWOMatKeys,1,Pos,0,OutOnlyCassID)
	END
NEXT I

WORec<WO_LOG_WO_MAT_KEY$> = ExistingWOMatKeys	;* Add OutOnly Cassettetes to list inWO_LOG record.

Send_Info('Saving WO_LOG record...')

OtParms = FieldStore(OtParms,@RM,4,1,WORec)

obj_Tables('WriteRec',OtParms)		;* Writes and unlocks the record  It only has one value updated

Send_Info(STR(' ',60))															;** - Messaging - **

* * * * * * * * * * 

ReactNos = obj_Sched('GetReactNos',WONo)		;************************  5/26/2-15 JCH Added schedule ReactNos and check for WO_START_DTM$

rnCnt = COUNT(ReactNos,@VM) + (ReactNos NE '')

IF rnCnt GE 1 THEN

	BEGIN CASE
		CASE rnCnt = 1	
			Message = CassCnt:' Cassettes Released for Reactor No: ':ReactNos
			
		CASE rnCnt = 2
			SWAP @VM WITH ' and ' IN ReactNos
			Message	 = CassCnt:' Cassettes Released for Reactor Nos: ':ReactNos
			
		CASE 1
			LastReact = ReactNos<1,rnCnt>
			RestOfReacts = FIELD(ReactNos,@VM,1,rnCnt - 1)
			SWAP @VM WITH ', ' IN RestOfReacts
			Message = CassCnt:' Cassettes Release for Reactor Nos: ':RestOfReacts:', and ':LastReact
			
	END CASE


	IF WORec<WO_LOG_WO_START_DTM$> NE '' THEN
		Recipients		= XLATE('NOTIFICATION','WO_RELEASE',NOTIFICATION_USER_ID$,'X')
		SentFrom		= @USER4
		Subject			= 'Work Order Release on ':WONo
		
		IF ReactorType = 'EPP' THEN
			AttachWindow = 'WO_PROD_EPI'
		END ELSE
			AttachWindow = 'WO_PROD'
		END

		AttachKey 		= WONo:'*':1

		SendToGroup		= ''   

		Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
		obj_Notes('Create',Parms)

		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END
	END
	
END	;* WO is not on the schedule

* * * * * * * * * *

RETURN

*/




/*

* * * * * * *
RecallWO:
* * * * * * *

WONo = Parms[1,@RM]

IF WONo	= ''			THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
IF ErrorMsg NE ''		THEN RETURN

WORec = XLATE('WO_LOG',WONo,'','X')


CassNos = XLATE('WO_LOG',WONo,'WO_MAT_CASS_NO','X')

CassCnt = COUNT(CassNos,@VM) + (CassNos NE '')

WOMKeys = ''
FOR K = 1 TO CassCnt
	WOMKeys<1,K> = WONo:'*':CassNos<1,K>
NEXT K

WOMTableVar = obj_WO_Mat('LockSet',WOMKeys)			;* Locks all WO_MAT records on the Work Order
IF Get_Status(errCode) THEN RETURN					;* Couldn't lock all of the cassettes


WOMCnt = COUNT(WOMKeys,@VM) + (WOMKeys NE '')

FOR I = 1 TO WOMCnt
	WOMKey = WOMKeys<1,I>

	WOMatRec = XLATE('WO_MAT',WOMKey,'','X')			;* We have the lock, so just get the record this way	
				
	WMIKey = WOMatRec<WO_MAT_WMI_KEY$>
	WMOKey = WOMatRec<WO_MAT_WMO_KEY$>
	
	IF WOMatRec<WO_MAT_REL_DTM$> NE '' THEN

		IF WOMatRec<WO_MAT_RDS_NO$> NE '' THEN
		
			RDSCnt = COUNT(WOMatRec<WO_MAT_RDS_NO$>,@VM) + (WOMatRec<WO_MAT_RDS_NO$> NE '')
			
			FOR N = 1 TO RDSCnt
				Set_Status(0)
				obj_RDS('Delete',WOMatRec<WO_MAT_RDS_NO$,N>)
			NEXT I
		END
		
		IF WMIKey NE '' THEN obj_WM_In('Delete',WMIKey)
		IF WMOKey NE '' THEN obj_WM_Out('Delete',WMOKey)
		
		obj_WO_Wfr('CassDel',WOMKey)			;* Added 3/17/2016 JCH for wafer tracking *********************************
		
		WOMatRec<WO_MAT_REL_DTM$>		= ''
		WOMatRec<WO_MAT_REL_BY$>		= ''
		WOMatRec<WO_MAT_ORG_COMMIT_DT$>	= ''

		WOMatParms = 'WO_MAT':@RM:WOMKey:@RM:WOMTableVar:@RM:WOMatRec
		obj_Tables('WriteRec',WOMatParms)					;* This writes and unlocks the WO_MAT records
			
	END ELSE
		obj_Tables('UnlockRec','WO_MAT':@RM:WOMKey)
		ErrorMsg := " WO_Mat Record ":QUOTE(WOMKey):' has not been released':CRLF$
	END

NEXT I


RETURN


*/






