COMPILE FUNCTION obj_React_Status(Method,Parms)
/*
	Methods for the Reactor Mode (REACT_STATUS) table
    
	10/02/2006 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
    SetOutOfProdDTM(React,OutOfProdDTM)			;* Create new React Mode record 	
 	SetUnloadDTM(React,UnloadDTM)
 	CassLoad(ReactNo,WONo,CassNo,LoadDTM)		;* Cass Load signoff button pressed
 												;* Loads may overlap in time (operators sign off BEFORE doing the work.
 												;* This returns a Date-Time for the PrevReactUnloadDTM
 										
 	CassUnload(ReactNo,WONo,CassNo,UnloadDTM)	;* Cass Unload signoff button pressed.  Removes load WONo & CassNo & Resets UnoadDTM
	
*/
#pragma precomp SRP_PreCompiler

DECLARE FUNCTION   Get_Status, Msg, Utility, obj_Tables, Dialog_Box,NextKey, Popup, Get_Property, Database_Services
DECLARE FUNCTION   Error_Services, Environment_Services, Logging_Services, Override_Log_Services, GetTickCount
DECLARE SUBROUTINE Set_Status, Msg, obj_Tables, Send_Dyn, Btree.Extract, ErrMsg, Database_Services, Rlist
DECLARE SUBROUTINE Logging_Services, Mona_Services

$INSERT LOGICAL
$INSERT MSG_EQUATES
$INSERT REACT_STATUS_EQUATES
$INSERT REACTOR_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT RLIST_EQUATES
$INSERT OVERRIDE_LOG_EQUATES

EQU CRLF$  TO  \0D0A\
EQU Comma$ to ','

LogDate           = Oconv(Date(), 'D4/')
LogTime           = Oconv(Time(), 'MTS')
LoggingDTM        = LogDate : ' ' : LogTime
LogPath           = Environment_Services('GetApplicationRootPath') : '\LogFiles\ReactStatus'
LogFilename       = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' React Status.csv'
Headers           = 'Logging DTM' : @FM : 'User' : @FM : 'CassNo' : @FM : 'RDSNo' : @FM : 'Load DTM' : @FM : 'Service' : @FM : 'Notes'
objReactStatusLog = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, Comma$, Headers, '', False$, False$)

IsProd = Environment_Services('IsProd')
If IsProd EQ True$ then
	MonaResource = 'GRP_OPENINSIGHT_MES_OP_FE_OBJREACTSTATUS'
end else
	MonaResource = 'GRP_OPENINSIGHT_MES_OP_FE_DEV_OBJREACTSTATUS'
end

ErrTitle = 'Error in Stored Procedure "obj_React_Status"'
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 = 'SetOutOfProdDTM'			; GOSUB SetOutOfProdDTM
	CASE Method = 'CassLoad'				; GOSUB CassLoad
	CASE Method = 'CassUnload'				; GOSUB CassUnload
	CASE Method = 'ReactorLoad'				; GOSUB ReactorLoad
	CASE Method = 'ReactorUnload'			; GOSUB ReactorUnload
	CASE Method = 'CleanHouse'				; GOSUB CleanHouse
	CASE Method = 'HandleLoadUnsign'        ; GOSUB HandleLoadUnsign
	CASE Method = 'HandleUnloadUnsign'      ; GOSUB HandleUnloadUnsign
	
	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


* * * * * * *
SetOutOfProdDTM:
* * * * * * *

    ReactNo		= Parms[1,@RM]
    OutOfProdDTM	= Parms[COL2()+1,@RM]

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

    IF ErrorMsg NE '' THEN RETURN

    thisOutOfProdDTM = ICONV(OutOfProdDTM,'DT')
    IF thisOutOfProdDTM = '' THEN
        ErrorMsg = 'Invalid value ':QUOTE(OutOfProdDTM):' passed for parameter OutOfProdDTM (':Method:').'
        RETURN
    END

    Test = XLATE('REACTOR',ReactNo,'','X')
    IF Test = '' THEN
        ErrorMsg = 'Invalid Reactor Number ':QUOTE(ReactNo):' passed to routine (':Method:').'
        RETURN
    END

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    IF Get_Status(errCode) or Error_Services('HasError') THEN
    	ErrorMsg = 'Unable to read REACT_STATUS record ':ReactNo:' for update (':Method:').'
        RETURN
    END

    ReactStatRec<REACT_STATUS_OUT_OF_PROD_DTM$>		= thisOutOfProdDTM

    Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)

    If Error_Services('HasError') then
        ErrorMsg = Error_Services('GetMessage')
    end

RETURN


* * * * * * *
CassLoad:
* * * * * * *

    StartTick = GetTickCount()
    MetricName = 'CassLoad'
    
    ReactNo = Parms[1,@RM]
    WONo    = Parms[COL2()+1,@RM]
    CassNo  = Parms[COL2()+1,@RM]
    LoadDTM = Parms[COL2()+1,@RM]
    RDSNo   = Parms[COL2()+1,@RM] 
    
    IF ReactNo = ''	THEN ErrorMsg = 'Null parameter ReactNo passed to routine (':Method:').'
    IF WONo    = ''	THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
    IF CassNo  = ''	THEN ErrorMsg = 'Null parameter CassNo passed to routine (':Method:').'
    IF LoadDTM = '' THEN ErrorMsg = 'Null parameter LoadDTM passed to routine (':Method:').'
    IF RDSNo   = '' THEN ErrorMsg = 'Null parameter RDSNo passed to routine(':Method:').'

    IF ErrorMsg NE '' THEN RETURN
    
    thisLoadDTM = ICONV(LoadDTM,'DT')
    IF thisLoadDTM = '' THEN
        ErrorMsg = 'Invalid value ':QUOTE(LoadDTM):' passed for parameter LoadDTM (':Method:').'
        RETURN
    END

    ReactRec = XLATE('REACTOR',ReactNo,'','X')

    IF ReactRec = '' THEN
        ErrorMsg = 'Invalid Reactor Number ':QUOTE(ReactNo):' passed to routine (':Method:').'
        RETURN
    END

    IF ReactRec<REACTOR_REACT_TYPE$> = 'EPP' THEN RETURN		;* CassLoad is for non EpiPro	

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    IF Get_Status(errCode) or Error_Services('HasError') THEN
        ErrorMsg = 'Unable to read REACT_STATUS record ':ReactNo:' for update (':Method:').'
        RETURN
    END

    CassID = WONo:'*':CassNo

*    PrevLoadedCassCnt                            = COUNT(ReactStatRec<REACT_STATUS_LOAD_CASS_ID$>,@VM) + (ReactStatRec<REACT_STATUS_LOAD_CASS_ID$> NE '')
    PrevLoadedCassCnt                            = DCount(ReactStatRec<REACT_STATUS_LOAD_RDS$>, @VM)
    ReactStatRec                                 = INSERT(ReactStatRec,REACT_STATUS_LOAD_CASS_ID$,PrevLoadedCassCnt+1,0,CassID)
    ReactStatRec                                 = INSERT(ReactStatRec,REACT_STATUS_LOAD_DTM$,PrevLoadedCassCnt+1,0,thisLoadDTM)
    ReactStatRec<REACT_STATUS_LOAD_RDS$, -1>     = RDSNo
    ReactStatRec<REACT_STATUS_LOAD_RDS_DTM$, -1> = thisLoadDTM
        
    Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)

    If Error_Services('HasError') then
        ErrorMsg = Error_Services('GetMessage')       
        LogData    = ''
        LogData<1> = LoggingDTM
        LogData<2> = @User4
        LogData<3> = CassNo
        LogData<4> = RDSNo
        LogData<5> = LoadDTM
        LogData<6> = 'obj_React_Status'
        LogData<7> = ErrorMsg
        Logging_Services('AppendLog', objReactStatusLog, LogData, @RM, @FM) 
    end

    IF ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$> = '' THEN
        UnloadDTM = thisLoadDTM
    END ELSE
        UnloadDTM = ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$,1>
    END

    IF PrevLoadedCassCnt > 0 THEN
        IdleTime = 0
    END ELSE
        IdleTime = thisLoadDTM - UnloadDTM
    END

    IF IdleTime < 0 THEN IdleTime = 0

    IdleTime  = OCONV(ICONV(IdleTime*24,'MD2'),'MD2,')

    Result = IdleTime
    
    EndTick = GetTickCount()
    Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)

RETURN


* * * * * * *
CassUnload:
* * * * * * *
	StartTick = GetTickCount()
    MetricName = 'CassUnload'
	
    ReactNo   = Parms[1,@RM]
    WONo      = Parms[COL2()+1,@RM]
    CassNo    = Parms[COL2()+1,@RM]
    UnloadDTM = Parms[COL2()+1,@RM]
    RDSNo     = Parms[COL2()+1,@RM]

    IF ReactNo	 = '' THEN ErrorMsg = 'Null parameter ReactNo passed to routine (':Method:').'
    IF WONo      = '' THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
    IF CassNo    = '' THEN ErrorMsg = 'Null parameter CassNo passed to routine (':Method:').'
    IF UnloadDTM = '' THEN ErrorMsg = 'Null parameter UnloadDTM passed to routine (':Method:').'
    IF RDSNo     = '' THEN ErrorMsg = 'Null parameter RDSNo passed to routine (':Method:').'

    IF ErrorMsg NE '' THEN RETURN

    thisUnloadDTM = ICONV(UnloadDTM,'DT')
    IF thisUnloadDTM = '' THEN
        ErrorMsg = 'Invalid value ':QUOTE(UnloadDTM):' passed for parameter UnloadDTM (':Method:').'
        RETURN
    END

    ReactRec = XLATE('REACTOR',ReactNo,'','X')
    IF ReactRec = '' THEN
        ErrorMsg = 'Invalid Reactor Number ':QUOTE(ReactNo):' passed to routine (':Method:').'
        RETURN
    END

    IF ReactRec<REACTOR_REACT_TYPE$> = 'EPP' THEN RETURN		;* CassUnload is for non EpiPro	

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    IF Get_Status(errCode) or Error_Services('HasError') THEN
        ErrorMsg = 'Unable to read REACT_STATUS record ':ReactNo:' for update (':Method:').'
        RETURN
    END

    CassID = WONo:'*':CassNo

    LoadedCass = ReactStatRec<REACT_STATUS_LOAD_CASS_ID$>

    Locate CassID in LoadedCass using @VM setting vPos then
        ReactStatRec = DELETE(ReactStatRec,REACT_STATUS_LOAD_CASS_ID$,vPos,0)
        ReactStatRec = DELETE(ReactStatRec,REACT_STATUS_LOAD_DTM$,vPos,0)
    end

    LoadedRDS = ReactStatRec<REACT_STATUS_LOAD_RDS$>
    Locate RDSNo in LoadedRDS using @VM setting vPos then
        ReactStatRec = Delete(ReactStatRec, REACT_STATUS_LOAD_RDS$, vPos, 0)
        ReactStatRec = Delete(ReactStatRec, REACT_STATUS_LOAD_RDS_DTM$, vPos, 0)
    end

    ReactStatRec<REACT_STATUS_UNLOAD_DTM$>		= thisUnloadDTM
    ReactStatRec<REACT_STATUS_UNLOAD_CASS_ID$>	= CassID				;* Added 11/14/2008 JCH
    
    ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$> = thisUnloadDTM
    ReactStatRec<REACT_STATUS_UNLOAD_RDS$>     = RDSNo

    Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)
    If Error_Services('HasError') then
        ErrorMsg = Error_Services('GetMessage')
    end
    
    EndTick = GetTickCount()
    Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)

RETURN


* * * * * * *
ReactorLoad:
* * * * * * *
	StartTick = GetTickCount()
    MetricName = 'ReactorLoad'
	
    * EpiPro Reactor Load

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

    IF ReactNo = ''	THEN ErrorMsg = 'Null parameter ReactNo passed to routine (':Method:').'
    IF WONo    = ''	THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
    IF CassNos = ''	THEN ErrorMsg = 'Null parameter CassNos passed to routine (':Method:').'
    IF LoadDTM = ''	THEN ErrorMsg = 'Null parameter LoadDTM passed to routine (':Method:').'
    IF RDSNos  = ''	THEN ErrorMsg = 'Null parameter RDSNos passed to routine (':Method:').'

    IF ErrorMsg NE '' THEN RETURN

    thisLoadDTM = ICONV(LoadDTM,'DT')
    IF thisLoadDTM = '' THEN
        ErrorMsg = 'Invalid value ':QUOTE(LoadDTM):' passed for parameter LoadDTM (':Method:').'
        RETURN
    END

    ReactRec = XLATE('REACTOR',ReactNo,'','X')
    IF ReactRec = '' THEN
        ErrorMsg = 'Invalid Reactor Number ':QUOTE(ReactNo):' passed to routine (':Method:').'			;* Check for valid reactor number
        RETURN	
    END ELSE
        IF ReactRec<REACTOR_REACT_TYPE$> NE 'EPP' THEN
            ErrorMsg = 'Invalid reactor type ':ReactRec<REACTOR_REACT_TYPE$>:' passed to routine.'		;* Not an EpiPro reactor
            RETURN
        END
    END

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    If Error_Services('NoError') then

*        PrevLoadCnt = COUNT(ReactStatRec<REACT_STATUS_LOAD_CASS_ID$>,@VM) + (ReactStatRec<REACT_STATUS_LOAD_CASS_ID$> NE '')

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

        FOR I = 1 TO CassCnt
            ReactStatRec<REACT_STATUS_LOAD_CASS_ID$,I>	= WONo:'*':CassNos<1,I>
            ReactStatRec<REACT_STATUS_LOAD_DTM$,I>		= thisLoadDTM
        NEXT I
        
        PrevLoadCnt = DCount(ReactStatRec<REACT_STATUS_LOAD_RDS$>, @VM)
        For each RDSNo in RDSNos using @VM
            ReactStatRec<REACT_STATUS_LOAD_RDS$, -1>     = RDSNo
            ReactStatRec<REACT_STATUS_LOAD_RDS_DTM$, -1> = thisLoadDTM
        Next RDSNo

        Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)
        
        If Error_Services('HasError') then
            ErrorMsg = Error_Services('GetMessage')
        end

*        IF ReactStatRec<REACT_STATUS_UNLOAD_DTM$,1> = '' THEN
*            UnloadDTM = thisLoadDTM
*        END ELSE
*            UnloadDTM = ReactStatRec<REACT_STATUS_UNLOAD_DTM$,1>
*        END
        
        If ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$, 1> EQ '' then
            UnloadDTM = thisLoadDTM
        end else
            UnloadDTM = ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$, 1>
        end

        IF PrevLoadCnt > 0 THEN
            IdleTime = 0			;* There were already a cassette on the reactor (HTR reactors)
        END ELSE
            IdleTime = thisLoadDTM - UnloadDTM
        END

        IF IdleTime < 0 THEN IdleTime = 0
        IdleTime  = OCONV(ICONV(IdleTime*24,'MD2'),'MD2,')
        Result = IdleTime
    end else
        ErrorMsg = 'Unable to read REACT_STATUS record ':ReactNo:' for update (':Method:').'
    end
    
    EndTick = GetTickCount()
    Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)

RETURN

* * * * * * *
ReactorUnload:
* * * * * * *
	StartTick = GetTickCount()
    MetricName = 'ReactorUnload'
	
* EpiPro Reactor Unload

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

    IF ReactNo	 = '' THEN ErrorMsg = 'Null parameter ReactNo passed to routine (':Method:').'
    IF WONo      = '' THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
    IF CassNos   = '' THEN ErrorMsg = 'Null parameter CassNos passed to routine (':Method:').'
    IF UnloadDTM = '' THEN ErrorMsg = 'Null parameter UnloadDTM passed to routine (':Method:').'
    IF RDSNos    = '' THEN ErrorMsg = 'Null parameter RDSNos passed to routine (':Method:').'

    IF ErrorMsg NE '' THEN RETURN

    thisUnloadDTM = ICONV(UnloadDTM,'DT')
    IF thisUnloadDTM = '' THEN
        ErrorMsg = 'Invalid value ':QUOTE(UnloadDTM):' passed for parameter UnloadDTM (':Method:').'
        RETURN
    END

    ReactRec = XLATE('REACTOR',ReactNo,'','X')
    IF ReactRec = '' THEN
        ErrorMsg = 'Invalid Reactor Number ':QUOTE(ReactNo):' passed to routine (':Method:').'
        RETURN
    END ELSE
        IF ReactRec<REACTOR_REACT_TYPE$> NE 'EPP' THEN
            ErrorMsg = 'Invalid reactor type ':ReactRec<REACTOR_REACT_TYPE$>:' passed to routine.'
            RETURN
        END
    END

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    If Error_Services('NoError') then

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

        FOR I = 1 TO CassCnt
            ReactStatRec<REACT_STATUS_UNLOAD_CASS_ID$,I> = WONo:'*':CassNos<1,I>	;* Set Unload CassID(s)
            ReactStatRec<REACT_STATUS_UNLOAD_DTM$,I>	= thisUnloadDTM				;* Set Unload DTM(s)
        NEXT I

        For each RDSNo in RDSNos using @VM setting vPos
            ReactStatRec<REACT_STATUS_UNLOAD_RDS$, vPos>     = RDSNo
            ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$, vPos> = thisUnloadDTM
        Next RDSNo
        
        ReactStatRec<REACT_STATUS_LOAD_CASS_ID$> = ''								;* Clear Load CassID(s)
        ReactStatRec<REACT_STATUS_LOAD_DTM$> = ''									;* Clear Load DTM(s)
        
        ReactStatRec<REACT_STATUS_LOAD_RDS$>     =  ''
        ReactStatRec<REACT_STATUS_LOAD_RDS_DTM$> = ''

        Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)
        If Error_Services('HasError') then
            ErrorMsg = Error_Services('GetMessage')
        end
    end else
        ErrorMsg = Error_Services('GetMessage')
    end
    
    EndTick = GetTickCount()
    Mona_Services('QueueLatencyAndCountMetrics', MonaResource, MetricName, StartTick, EndTick)

RETURN


* * * * * * *
HandleLoadUnsign:
* * * * * * *

    ReactNo      = Parms[1,@RM]
    WONo         = Parms[COL2()+1,@RM]
    CassNo       = Parms[COL2()+1,@RM]
    RDSNo        = Parms[COL2()+1,@RM]
    OverrideUser = Parms[COL2()+1,@RM]
    Extra        = Parms[COL2()+1,@RM]
    
    IF ReactNo      = '' THEN ErrorMsg = 'Null parameter ReactNo passed to routine (':Method:').'
    IF WONo         = '' THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
    IF CassNo       = '' THEN ErrorMsg = 'Null parameter CassNo passed to routine (':Method:').'
    IF RDSNo        = '' THEN ErrorMsg = 'Null parameter RDSNo passed to routine(':Method:').'
    IF OverrideUser = '' THEN ErrorMsg = 'Null parameter OverrideUser passed to routine(':Method:').'
    If Extra		= '' then Extra = 0
    
    CassID = WONo:'*':CassNo

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    IF Get_Status(errCode) or Error_Services('HasError') THEN
        ErrorMsg = 'Unable to read REACT_STATUS record ':ReactNo:' for update (':Method:').'
        RETURN
    END
    WOMatRec         = Database_Services('ReadDataRow', 'WO_MAT', CassID)   
    LoadedRDS = ReactStatRec<REACT_STATUS_LOAD_RDS$>
    Locate RDSNo in LoadedRDS using @VM setting vPos then
        ReactStatRec<REACT_STATUS_LOAD_CASS_ID$> = Delete(ReactStatRec<REACT_STATUS_LOAD_CASS_ID$>, 0, vPos, 0)
        ReactStatRec<REACT_STATUS_LOAD_DTM$>     = Delete(ReactStatRec<REACT_STATUS_LOAD_DTM$>, 0, vPos, 0)
        ReactStatRec<REACT_STATUS_LOAD_RDS$>     = Delete(ReactStatRec<REACT_STATUS_LOAD_RDS$>, 0, vPos, 0)
        ReactStatRec<REACT_STATUS_LOAD_RDS_DTM$> = Delete(ReactStatRec<REACT_STATUS_LOAD_RDS_DTM$>, 0, vPos, 0)
    end
    Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)

    If Error_Services('HasError') then
        ErrorMsg = Error_Services('GetMessage')
        return
    end else
        overrideLogTable    = 'RDS':@VM:'REACTOR' 
        overrideLogKey      = RDSNo:@VM:ReactNo 
        overrideLogUser     = OverrideUser
        If Extra then
        	overrideLogComment  = 'UNSIGN-LOAD-EXTRA'
        end else
        	overrideLogComment  = 'UNSIGN-LOAD'
        end
        overrideLogCategory = 'UNSIGN' 
        orKey               = Override_Log_Services('Create', overrideLogTable, overrideLogKey, overrideLogUser, overrideLogComment, overrideLogCategory)
    end
    
Return


* * * * * * *
HandleUnloadUnsign:
* * * * * * *
    ReactNo      = Parms[1,@RM]
    WONo         = Parms[COL2()+1,@RM]
    CassNo       = Parms[COL2()+1,@RM]
    RDSNo        = Parms[COL2()+1,@RM]
    OverrideUser = Parms[COL2()+1,@RM]
    Extra        = Parms[COL2()+1,@RM]; *This variable is used to determine whether or not this came from a regular unload signature or an unload
    
    IF ReactNo      = '' THEN ErrorMsg = 'Null parameter ReactNo passed to routine (':Method:').'
    IF WONo         = '' THEN ErrorMsg = 'Null parameter WONo passed to routine (':Method:').'
    IF CassNo       = '' THEN ErrorMsg = 'Null parameter CassNo passed to routine (':Method:').'
    IF RDSNo        = '' THEN ErrorMsg = 'Null parameter RDSNo passed to routine(':Method:').'
    IF OverrideUser = '' THEN ErrorMsg = 'Null parameter OverrideUser passed to routine(':Method:').'
    If Extra		= '' then Extra = 0
    	
    
    CassID = WONo:'*':CassNo

    ReactStatRec = Database_Services('ReadDataRow', 'REACT_STATUS', ReactNo)

    IF Get_Status(errCode) or Error_Services('HasError') THEN
        ErrorMsg = 'Unable to read REACT_STATUS record ':ReactNo:' for update (':Method:').'
        RETURN
    END
    OriginalLoadTime = ''
    WOMatRec         = Database_Services('ReadDataRow', 'WO_MAT', CassID)
    
    // Get the original load event DTM to reload
    OriginalLoadTime = Xlate('RDS', RDSNo, 'DTM_IN', 'X')
    If OriginalLoadTime NE '' then
        // Restore the loaded cassette information
        PrevLoadedCassCnt                            = DCount(ReactStatRec<REACT_STATUS_LOAD_RDS$>, @VM)
        ReactStatRec<REACT_STATUS_LOAD_RDS$, -1>     = RDSNo
        ReactStatRec<REACT_STATUS_LOAD_RDS_DTM$, -1> = OriginalLoadTime

        PrevUnloadRDS    = ''
        PrevRDSUnloadDTM = ''
        PrevUnloadCassID = ''
        ErrCode          = ''
        Query            = 'SELECT RDS WITH WO EQ ':WONo:' AND WITH REACTOR EQ ':ReactNo:' BY-DSND DATE_OUT BY-DSND TIME_OUT'
        Rlist(Query, TARGET_ACTIVELIST$, '', '', '')
        If Not(Get_Status(ErrCode)) then
            ReadNext PrevUnloadRDS else Null
            PrevRDSUnloadDTM = Xlate('RDS', PrevUnloadRDS, 'DTM_OUT', 'X')
        end
        
        ReactStatRec<REACT_STATUS_UNLOAD_RDS_DTM$> = PrevRDSUnloadDTM
        ReactStatRec<REACT_STATUS_UNLOAD_RDS$>     = PrevUnloadRDS
        
        Database_Services('WriteDataRow', 'REACT_STATUS', ReactNo, ReactStatRec, True$, False$, True$)

        If Error_Services('HasError') then
            ErrorMsg = Error_Services('GetMessage')
            return
        end else
            overrideLogTable    = 'RDS':@VM:'REACTOR' 
            overrideLogKey      = RDSNo:@VM:ReactNo 
            overrideLogUser     = OverrideUser
            overrideLogComment  = 'UNSIGN-UNLOAD'
            overrideLogCategory = 'UNSIGN' 
            orKey = Override_Log_Services('Create', overrideLogTable, overrideLogKey, overrideLogUser, overrideLogComment, overrideLogCategory)
        end
    end
    
Return


* * * * * * *
CleanHouse:
* * * * * * *

OPEN 'REACT_STATUS' TO FileIn ELSE
	RETURN
END

SELECT FileIn

Done = 0
LOOP
	READNEXT ReactNo ELSE Done =1
UNTIL DONE
	READ ReactStatRec FROM FileIn,ReactNo THEN	
		ReactStatRec<REACT_STATUS_LOAD_DTM$> = ''
		ReactStatRec<REACT_STATUS_LOAD_CASS_ID$> = ''
		WRITE ReactStatRec ON FileIn,ReactNo
		
	END	;* End of record read
REPEAT

RETURN


