COMPILE FUNCTION obj_Maint_Item(Method,Parms)

/*
	Methods for MAINT_ITEM table
    
	11/22/2013 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    *Install(GraphNo,ReactNo,DTM,ReactHrs,ReactWfrs,RL_Id)				;* Adds Reactor Installation line item to record
	*Remove(GraphNo,ReactNo,DTM,ReactHrs,ReactWfrs,RL_Id,RDSWfrCnt)		;* Adds Removal information to Reactor Installation line item
	
*/


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

$INSERT MSG_EQUATES
$INSERT REACTOR_LOG_EQUATES
$INSERT MAINT_ITEM_EQUATES


EQU CRLF$	TO \0D0A\
EQU TAB$	TO CHAR(9)


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

END CASE

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

RETURN Result



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

DEBUG

RLId = Parms[1,@RM]

IF RLId = '' THEN RETURN

OPEN 'MAINT_ITEM' TO MaintItemTable ELSE
	ErrorMsg = 'Unable to open "MAINT_ITEM" for conversion.'
	RETURN
END


RLRec = XLATE('REACTOR_LOG',RLId,'','X')

ProbCatIDs	= RLRec<REACTOR_LOG_REACT_PROB_CAT_ID$>

pcCnt = COUNT(ProbCatIDs,@VM) + (ProbCatIds NE '')

FOR I = 1 TO pcCnt
	ProbCatID = ProbCatIDs<1,I>
	
	MaintItemKey = RLId:'*':ProbCatID
	
	READ MaintItemRec FROM MaintItemTable,MaintItemKey ELSE
		MaintItemRec = ''
	END
	
	MaintItemRec<MAINT_ITEM_ENTER_BY$>		= RLRec<REACTOR_LOG_ENTRY_ID$
	MaintItemRec<MAINT_ITEM_ENTER_DTM$>		= ICONV(OCONV(RLRec<REACTOR_LOG_START_DATE$>,'D4/'):' ':OCONV(RLRec<REACTOR_LOG_START_TIME$>,'MT'),'DT')
	MaintItemRec<MAINT_ITEM_REACT_SERV_ID$>	= RLRec<REACTOR_LOG_REACT_SERV_ID$>
	MaintItemRec<MAINT_ITEM_ITEM_SERIAL$>	= RLRec<REACTOR_LOG_REACT_ITEM_IDS$>
	MaintItemREc<MAINT_ITEM_SCHED$>			= RLRec<REACTOR_LOG_SCHEDULED$>
	MaintItemRec<MAINT_ITEM_COMP_BY$>		= RLRec<REACTOR_LOG_TECH_SIG$
	MaintItemRec<MAINT_ITEM_COMP_DTM$>		= ICONV(OCONV(RLRec<REACTOR_LOG_END_DATE$>,'D4/'):' ':OCONV(RLRec<REACTOR_LOG_END_TIME$>,'MT'),'DT')
	
	*WRITE MaintItemRec ON MaintItemTable,MaintItemKey THEN
	
	
	*END
	
NEXT I











RETURN
