COMPILE FUNCTION obj_React_Maint(Method,Parms)
/*
	Methods for REACT_MAINT table
    
	09/10/2013 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    Convert(ReactNo,ProbCat,ReactItemType,ReactItemID							;* Reactor
   
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Dialog_Box
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, Btree.Extract, ErrMsg
DECLARE SUBROUTINE  obj_Notes, Send_Info

$INSERT MSG_EQUATES
$INSERT REACT_EVENT_EQUATES
$INSERT REACTOR_LOG_EQUATES

ErrTitle = 'Error in Stored Procedure "obj_React_Event"'
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 = 'Convert'			; GOSUB Convert
	CASE Method = 'Create'			; GOSUB Create
	CASE Method = 'Post'			; GOSUB Post
	
	
	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



* * * * * * *
Convert:
* * * * * * *

RLID	= Parms[1,@RM]
RLRec	= Parms[COL2()+1,@RM]

IF RLID = '' THEN RETURN

IF RLRec = '' THEN
	RLRec = XLATE('REACTOR_LOG',RLID,'','X')
END

IF RLRec<REACTOR_LOG_CATEGORY$> NE 'M' THEN RETURN 	;* Not maintenance

ProbCats = RLRec<REACTOR_LOG_REACT_PROB_CAT_ID$>
ServIDs	= RLRec<REACTOR_LOG_REACT_SERV_ID$>

CatCnt = COUNT(ProbCats,@VM) + (ProbCats NE '')

EQU COL$PROB_CAT	TO 1
EQU COL$SERV_IDS	TO 2
EQU COL$TUBE_ID		TO 3
EQU COL$GR_NOS		TO 4

Result = ''

FOR I = 1 TO CatCnt

	ProbCat = ProbCats<1,I>
	
	IF ProbCat NE '' THEN
		LOCATE ProbCat IN Result<COL$PROB_CAT> BY 'AR' SETTING CPos ELSE
			Result = INSERT(Result,COL$PROB_CAT,CPos,0,ProbCat)
		END
	END
	
	ServID	= ServIDs<1,I>
	
	IF ServID NE '' THEN
		LOCATE ServID IN Result<COL$SERV_IDS> BY 'AR' USING @VM SETTING SPos ELSE
			Result = INSERT(Result,COL$SERV_IDS,SPos,0,ServID)
		END
	END
NEXT I

ItemCnt = COUNT(RLRec<REACTOR_LOG_REACT_ITEM_IDS$>,@VM) + (RLRec<REACTOR_LOG_REACT_ITEM_IDS$> NE '')
GraphNos = ''

OPEN 'DICT.GRAPHITE' TO DictGraphiteTable ELSE
	ErrMsg("Unable to open 'DICT.GRAPHITE' IN obj_React_Maint('Convert'")
	RETURN
END

FOR N = 1 TO ItemCnt
	SerialNo	= RLRec<REACTOR_LOG_REACT_ITEM_IDS$,N>
	Search		= 'SERIAL':@VM:SerialNo:@FM
	Option		= ''
	Flag		= ''
	GraphNo 	= ''
	
	Set_Status(0)
	
	Btree.Extract(Search,'GRAPHITE',DictGraphiteTable,GraphNo,Option,Key)
	
	IF Get_Status(errCode) THEN
		DEBUG
	END
	
	IF GraphNo = '' THEN
		IF RowExists('TUBE',SerialNo) THEN
			Result<COL$TUBE_ID> = SerialNo
		END
	END ELSE
	
		IF RowExists('GRAPHITE',GraphNo) THEN
			GraphNos<1,-1> = GraphNo
		END
	END
	IF GraphNos NE '' THEN Result<COL$GR_NOS> = GraphNos
	
NEXT N


RETURN

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

ReactNo		= Parms[1,@RM]
EventDTM	= Parms[COL2()+1,@RM]
EventType	= Parms[COL2()+1,@RM]
LoggedBy	= Parms[COL2()+1,@RM]
Mode		= Parms[COL2()+1,@RM]
Comment		= Parms[COL2()+1,@RM]
	
DEBUG

IF ReactNo = ''		THEN ErrorMsg = 'Null parameter "ReactNo" passed to routine. (':Method:')'
IF EventDTM = ''	THEN ErrorMsg = 'Null parameter "EventDTM" passed to routine. (':Method:')'
IF EventType = ''	THEN ErrorMsg = 'Null parameter "EventType" passed to routine. (':Method:')'

IF LoggedBy = '' THEN LoggedBy = @USER4

thisEventDTM = ICONV(EventDTM,'DT')

IF thisEventDTM = '' THEN
	ErrorMsg = 'Ivalid Data ':QUOTE(EventDTM):' passed in "EventDTM" parameter. (':Method:')'
END


IF ErrorMsg NE '' THEN RETURN

ReactEventKey = ReactNo:'*':thisEventDTM

OtParms = 'REACT_EVENT':@RM:ReactEventKey
ReactEventRec = obj_Tables('ReadRec',OtParms)	;* Temporary for conversion

IF Get_Status(errCode) THEN DEBUG


ReactEventRec<REACT_EVENT_LOGGED_BY$>	= LoggedBy
ReactEventRec<REACT_EVENT_EVENT_TYPE$>	= EventType
ReactEventRec<REACT_EVENT_REACT_MODE$>	= Mode
ReactEventRec<REACT_EVENT_COMMENT$>		= Comment

*OtParms = 'REACT_EVENT':@RM:ReactEventKey:@RM:@RM:ReactEventRec
*obj_Tables('WriteRec',OtParms)


RETURN



* * * * * * *
Post:
* * * * * * * 

* Called from Post event handler on the REACTOR_LOG (existing) OR the REACT_MAINT windows

ReactorNo		= Parms[1,@RM]
InstDTM			= Parms[COL2()+1]
ReactLogID		= Parms[COL2()+1]
ItemIDs			= Parms[COL2()+1]	;* Edit table column contents (
ItemTypes		= Parms[COL2()+1]	;* Edit table column contents (SN Req)
ReactHrs		= Parms[COL2()+1]
ReactWfrCnt		= Parms[COL2()+1]





RETURN



