Function RDS_Events(CtrlEntId, Event, @PARAMS)
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Infineon.

    Name        :   RDS_Events

    Description :   This function acts as a commuter module for all events related to this window.

    Notes       :   Commuter Modules are automatically called from the Promoted_Events function which is called by the
                    application-specific promoted event handler. This makes it possible to add QuickEvents that need to
                    execute Basic+ logic without having use the Form Designer to make the association, although this is
                    limited to the events which are currently promoted.

                    If the form needs to call the commuter module directly then the QuickEvent parameters should be
                    formatted like this:

                        '@SELF','@EVENT',['@PARAM1','@PARAMx']

    Parameters  :
        CtrlEntId   [in] -- The fully qualified name of the control calling the promoted event
        Event       [in] -- The event being executed. See the Notes section regarding "PRE" events
        Param1-15   [in] -- Additional event parameter holders
        EventFlow  [out] -- Set to 1 or 0 so the calling event knows whether or not to chain forward. See comments in
                            EVENT_SETUP insert

    History     :   (Date, Initials, Notes)
        07/26/18    djs     Created initial commuter module.
        08/06/18    djs     Added ROTR Sign-off requirements to the SIGN.CLICK event.
        09/14/23	djm		Add blocker for Wafers In after load signature is complete.
        06/13/24	djm		Add new stage-specific supplement system.

***********************************************************************************************************************/

#pragma precomp SRP_PreCompiler
#Window RDS

$insert APP_INSERTS
$insert EVENT_SETUP
$insert MSG_EQUATES
$insert RDS_EQUATES
$insert LSL_USERS_EQUATES
$insert PROD_SPEC_EQUATES
$insert WO_MAT_EQUATES
$insert SURFACE_SCAN_EQUATES
$insert REACTOR_EQUATES
$insert PRS_STAGE_EQUATES
$insert COMPANY_EQUATES
$insert WO_MAT_QA_EQUATES
$insert REACT_STATUS_EQUATES
$insert SUPPL_INFO_ARRAY_EQU
$insert CLEAN_INSP_EQUATES
$insert OVERRIDE_LOG_EQUATES
$insert REACT_LL_EQUATES
$Insert REACT_MODE_NG_EQUATES
$Insert REACTOR_MODES_EQUATES

Equ COL$LOG_FILE        to 1
Equ COL$LOG_DTM         to 2
Equ COL$ACTION          to 3
Equ COL$WH_CD           to 4
Equ COL$LOC_CD          to 5
Equ COL$WO_NOS          to 6
Equ COL$CASS_NOS        to 7
Equ COL$USER_ID         to 8
Equ COL$TAGS            to 9
Equ COL$TOOL_ID         to 10

Equ COL$MET_TEST        to 1    ; // QA Metrology control on RDS_UNLOAD & RDS_POST_EPI windows
Equ COL$MET_TEST_DESC   to 2
Equ COL$MET_SLOT        to 3
Equ COL$MET_SLOT_DESC   to 4
Equ COL$MET_WFR_QTY     to 5
Equ COL$MET_MIN         to 6
Equ COL$MET_MAX         to 7
Equ COL$MET_RESULT      to 8
Equ COL$MET_STD_MAX     to 9
Equ COL$MET_STD_RESULT  to 10
Equ COL$MET_SIG         to 11
Equ COL$MET_SIG_DTM     to 12

Equ MSG_WIDTH$			to 600

EQU READONLY_GREEN$ TO 192 + (220*256) + (192*65536)

Declare subroutine ErrMsg, Set_Status, obj_WO_Mat, obj_WO_Mat_Log, obj_RDS, Set_Property, Send_Event, Database_Services
Declare subroutine Dialog_Box, Qa_Services, Obj_React_Ll, Start_Window, obj_React_Status, Reactor_Services, Rds_Services
Declare subroutine Lot_Event_Services, Override_Log_Services
Declare function   Dialog_Box, Msg, MemberOf, obj_WO_Mat, Database_Services, Get_Property, obj_React_Status, Get_Status
Declare function   QA_Services, Database_Services, Rds_Services, Obj_Calendar, Override_Log_Services, Max, Supplement_Services
Declare function   Datetime, Test_Run_Services

SubclassInfo    = Form_Services('FindSubclassControl')
Subclass        = SubclassInfo<1>

// Update the arguments so that the OpenInsight OLE event will treate the ActiveX event as a native event handler.
If Event EQ 'OLE' then
    Transfer Event to OIEvent
    Transfer Param1 to Event
    Transfer Param2 to Param1
    Transfer Param3 to Param2
    *    Transfer Param4 to Param3
    *    Transfer Param5 to Param4
    *    Transfer Param6 to Param5
    *    Transfer Param7 to Param6
    *    Transfer Param8 to Param7
end

GoToEvent Event for CtrlEntID

Return EventFlow else EVENT_CONTINUE$


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Events
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Event WINDOW.CREATE(CreateParam)
    
    GoSub Setup_OLE_Controls
    
    SRP_Show_Window(@Window, '', 'C', 'C', 1, '', False$, False$)
    
end event


Event WINDOW.READ()
    GoSub OLE_LL_Status
    LoadSig = Get_Property(@WINDOW:'.OP_IN', 'DEFPROP')
    Reactor = Get_Property(@WINDOW:'.REACTOR','DEFPROP')
    PickPlaceFlag = XLATE('REACTOR',Reactor,REACTOR_PICK_PLACE$,'X')        
    IF PickPlaceFlag AND LoadSig EQ '' THEN
        Set_Property(@WINDOW:'.ASM_LOAD_LOCK','ENABLED',1)         
    END ELSE
        Set_Property(@WINDOW:'.ASM_LOAD_LOCK','ENABLED',0)
    END
    // Disable Wafers In edit line control if the RDS has been loaded and signed.
    RDSNo = Get_Property(@Window:'.RDS_NO', 'TEXT')
    If RDSNo NE '' then
        WaferLoadSig = Xlate('RDS', RDSNo, 'OPERATOR_IN', 'X')
        If WaferLoadSig NE '' then
            Set_Property(@Window:'.WAFERS_IN', 'ENABLED', False$)
            Set_Property(@Window:'.WAFERS_IN', 'BACKCOLOR', READONLY_GREEN$)
        end else
            Set_Property(@Window:'.WAFERS_IN', 'ENABLED', True$)
            Set_Property(@Window:'.WAFERS_IN', 'BACKCOLOR', '')
        end
    end
    
end event


Event WINDOW.CLOSE(CancelFlag)
    
end event


Event WINDOW.CLEAR(bSaveKey, bSuppressWarning, bMaintainFocus, CtrlIDFocus)
    
end event


Event SUPPL_BUTTON.CLICK()
    
    RDSNo = Get_Property(@Window:'.RDS_NO', 'TEXT')
    Dialog_Box('NDW_RDS_SUPP_SIG', @Window, RDSNo :@FM: 'LOAD' :@FM: FALSE$)
    
end event


Event PUB_SIGN.CLICK()
    
    RDSNo		= Get_Property(@WINDOW:'.RDS_NO','TEXT')
    ReactorType = Get_Property(@WINDOW:'.REACTOR_TYPE','TEXT')
    LoadLockVal = Get_Property(@WINDOW:'.LOAD_LOCK_SIDE_HIDDEN','TEXT')
    TWAllSigned = Get_Property(@WINDOW:'.TW_ALL_SIGNED','INVALUE')
    WONo		= Get_Property(@WINDOW:'.WO','TEXT')
    RunOrderNo 	= Get_Property(@WINDOW:'.RUN_ORDER_NUM','TEXT')
    Reactor		= Get_Property(@WINDOW:'.REACTOR','TEXT')
    WOStep		= Get_Property(@WINDOW:'.WO_STEP','DEFPROP')
    CassNo		= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
    LSIDArray	= Get_Property(@WINDOW:'.RDS_LS_ID','ARRAY')
    Preauthenticated = FALSE$
    SignEventType = Get_Property(CtrlEntID, 'TEXT')
    
    Begin Case
        
        Case SignEventType EQ 'Sign'            
            
            RDSNo  = Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
            WfrQty = Get_Property(@WINDOW:'.WAFERS_IN','TEXT')
            LLSide = Get_Property(@Window:'.LOAD_LOCK_SIDE', 'DEFPROP')
            
            Reactor     = Get_Property(@Window:'.REACTOR', 'TEXT')
            ReactorRec  = Database_Services('ReadDataRow', 'REACTOR', Reactor)
            ReactorType = ReactorRec<REACTOR_REACT_TYPE$>
            ROTREnabled = Xlate('REACTOR', Reactor, 'ENABLE_ROTR', 'X')
            
            // Don't allow tracking in on down reactor
            ReactorCurrModeKey = Xlate('REACTOR_CHILD_KEY_IDS_NG', Reactor, 1, 'X')
            ReactCurrModeRec = Database_Services('ReadDataRow','REACT_MODE_NG', ReactorCurrModeKey, '','','')
            CurrReactMode = ReactCurrModeRec<REACT_MODE_NG_MODE$>
            CurrE10State = Xlate('REACTOR_MODES', CurrReactMode, REACTOR_MODES_E10_STATE$, 'X')
            
            Override = False$
            UserVerification = ''
            OverrideGroups = 'LEAD':@VM:'SUPERVISOR':@VM:'ENGINEERING':@VM:'ENG_TECH':@VM:'ROTR_OVERRIDE'
            
            ReactorIsDown = CurrE10State _NEC 'PRODUCTIVE'
            If	(ReactorIsDown EQ True$) then
                // Allow override during prove in
                If ReactorType EQ 'EPP' then
                    If RDS_Services('IsEpiProTestRun', RDSNo) then Override = True$
                end
                
                If Override EQ False$ then 
                    UserMsg = "Reactor down. Override required from a lead or supervisor."
                    UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
                    Override = UserVerification<1>
                end
            end
            
            If (ReactorIsDown NE True$) OR (Override EQ True$) then
                If (ReactorType EQ 'ASM+' OR ReactorType EQ 'HTR' OR ReactorType EQ 'ASM') AND (ROTREnabled EQ True$) then
                    ROTRStatus = ReactorRec<REACTOR_ROTR_STATUS$>        
                    If ROTRStatus EQ 'F' then
                        FailReason = ReactorRec<REACTOR_ROTR_STATUS_REASON$>
                        Message    = 'Unable to load reactor.' : CRLF$ : FailReason
                        RotrOverrideCount = ReactorRec<REACTOR_ROTR_OVERRIDE_COUNT$>
                        If RotrOverrideCount EQ '' then RotrOverrideCount = 0
                        Message := CRLF$ : RotrOverrideCount : ' override(s) were performed since the ROTR block was originally set.'
                        Message    := CRLF$ : 'A lead or supervisor must override to clear ROTR status.'
                        
                        Response = Msg(@Window, '', 'RDS_ROTR_OVERRIDE', '', Message)
                        
                        Begin Case
                            Case Response EQ 1
                                Response = True$        ; // User Clicked Override
                            Case Response EQ 2
                                Response = False$       ; // User Clicked Cancel
                            Case Response EQ char(27)
                                Response = False$       ; // User Pressed Escape Key
                        End Case            
                        
                        If Response EQ True$ then
                            If UserVerification EQ '' then
                                UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups)
                            end
                            Valid = UserVerification<1>
                            If Valid EQ True$ then
                                // Prompt user for a comment
                                ResponseComment = Dialog_Box('NDW_ADD_COMMENT', @WINDOW)
                                
                                IF ResponseComment<2> NE '' THEN
                                    // Clear ROTR reactor load block.
                                    overrideLogTable = 'RDS':@VM:'REACTOR'
                                    overrideLogKey = RDSNo:@VM:Reactor
                                    overrideLogUser = Response<2>
                                    overrideLogComment = ResponseComment<2>
                                    overrideLogCategory = 'ROTR_BLOCK'
                                    overrideLogCause = FailReason
                                    orKey = Override_Log_Services('Create', overrideLogTable, overrideLogKey, overrideLogUser, overrideLogComment, overrideLogCategory, overrideLogCause)
                                    
                                    //Add override key to RDS
                                    RDSRec = Xlate('RDS', RDSNo, '', 'X')
                                    RDSRec = Insert(RDSRec, RDS_OVERRIDE_KEYS$, 1, 0, orKey)
                                    
                                    ReactorRec<REACTOR_ROTR_STATUS$>        = 'P'
                                    
                                    rotrStatusReason = ReactorRec<REACTOR_ROTR_STATUS_REASON$>
                                    ReactorRec<REACTOR_PREVIOUS_ROTR_STATUS_REASON$> = rotrStatusReason
                                    ReactorRec<REACTOR_ROTR_STATUS_REASON$> = ''
                                    
                                    ReactorRec<REACTOR_PREVIOUS_ROTR_OVERRIDE_RDS$> = RDSNo
                                    
                                    rotrOverrideCount = ReactorRec<REACTOR_ROTR_OVERRIDE_COUNT$>
                                    ReactorRec<REACTOR_ROTR_OVERRIDE_COUNT$> = rotrOverrideCount + 1
                                    
                                    Database_Services('WriteDataRow', 'REACTOR', Reactor, ReactorRec, True$, False$, True$)
                                    Database_Services('WriteDataRow', 'RDS', RDSNo, RDSRec, True$, False$, True$)
                                    
                                end else
                                    //No Comment added. Block Load Signaure
                                    Msg(@Window, 'A comment is required to perform an ROTR Block Override', '', '', '')
                                    return
                                end
                            end else
                                // ROTR override not verified. Block load signature.
                                return
                            end
                        end else
                            // Block load signature
                            return
                        end                                          
                    end
                end
                
                SupplAckReq = Supplement_Services('UnacknowledgedSupplementCheck', 'RDS', RDSNo, 'LOAD')
                IF (SupplAckReq NE FALSE$) then
                    Response = Dialog_Box('NDW_RDS_SUPP_SIG', @Window, RDSNo :@FM: 'LOAD' :@FM: FALSE$)
                    If Response EQ False$ then
                        return
                    end else
                        PreAuthenticated = TRUE$
                    end
                end
                
                
                RDSLayerAckReq = Xlate('RDS', RDSNo, 'RDS_LAYER_ACK_REQ', 'X')
                If RDSLayerAckReq EQ True$ then
                    ErrorMessage = 'RDS layer parameters must be reviewed for accuracy and acknowledged before the load operation can be signed.'
                    ErrMsg(ErrorMessage)
                    LayerKeys = Xlate('RDS', RDSNo, 'RDS_LAYER_KEYS', 'X')
                    // Just display the first layer
                    RDSLSID = LayerKeys<0, 1>
                    Dialog_Box('RDS_LAYER', @Window, RDSLSID)
                    
                    RDSLayerAck = Xlate('RDS', RDSNo, 'RDS_LAYER_ACK', 'X')
                    If ( (RDSLayerAck EQ False$) or (RDSLayerAck EQ '') ) then
                        ErrorMessage = 'RDS layer parameters were not acknowledged. Sign load stage event aborting.'
                        ErrMsg(ErrorMessage)
                        return
                    end
                end
                
                FWIInstAckReq  = Xlate('RDS', RDSNo, 'FWI_INST_ACK_REQ', 'X')
                If (FWIInstAckReq EQ True$) then
                    Response = RDS_Services('RDSVerifyInst', RDSNo, 'FWI')
                    If Response EQ False$ then return
                end
                
                LoadInstAckReq  = Xlate('RDS', RDSNo, 'LOAD_INST_ACK_REQ', 'X')
                If (LoadInstAckReq EQ True$) then
                    Response = RDS_Services('RDSVerifyInst', RDSNo, 'LOAD')
                    If Response EQ False$ then return  
                end
                
                SupplAckReq = Xlate('RDS', RDSNo, 'SUPPL_ACK_REQ', 'X')
                IF (SupplAckReq EQ True$) then
                    Response = Dialog_Box('NDW_RDS_SUPP_SIG', @Window, RDSNo)
                    If Response EQ False$ then return
                end
                //Check if TW Required
                if XLATE('APP_INFO', 'NEW_TW_SYSTEM_ACTIVE_SWITCH', 1, 'X') EQ True$ AND (ReactorType EQ 'HTR' OR ReactorType EQ 'ASM' OR ReactorType 'ASM+') then
                    UsingTestWafers          = False$
                    IsTWReqd                 = RDS_Services('IsTWLoggingReqd', RDSNo)
                    ExistingTestWafersLogged = Test_Run_Services('GetTestRunKeysByRDS', RdsNo)
                    If ExistingTestWafersLogged NE True$ then
                        If Not(IsTWReqd) then
                            //Test wafer logging is NOT required here.
                            If ReactorType NE 'EPP' then
								UsingTestWafers = Msg(@Window, '', 'YESNO', '', 'Test Wafer Usage logging is not required on this load.':@FM:'Are any test wafers loaded?')
								If UsingTestWafers EQ True$ then
									TWLogResult = Dialog_Box('NDW_LOG_TEST_WAFER_USAGE', @Window, RDSNo : @VM : 'STANDARD' : @VM : 'REACTOR' : @VM :  Reactor)
									If TWLogResult NE True$ then
										ContinueSign = Msg(@Window, '', 'YESNO', '', 'Continue?':@FM:'Test wafer logging was cancelled. Do you wish to continue signing?')
										If Not(ContinueSign) then return
									end
								end
                            end                        
                        end else
                            //Test wafer logging is Required here.
                            Begin Case
                                Case ReactorType EQ 'ASM' OR ReactorType EQ 'HTR'
                                    UsingTestWafers = Msg(@Window, '', 'YESNO', '', 'A test wafer is required to be ran with this load for metrology on this run':@FM:'Are any test wafers loaded?')
                                Case ReactorType EQ 'ASM+'
                                    UsingTestWafers = Msg(@Window, '', 'YESNO', '', 'A test wafer is required to be ran with this load for metrology on the next run.':@FM:'Are any test wafers loaded?')
                            End Case
                            If UsingTestWafers EQ True$ then
                                //User has stated that they are using test wafers
                                TWLogResult = Dialog_Box('NDW_LOG_TEST_WAFER_USAGE', @Window, RDSNo : @VM : 'STANDARD' : @VM : 'REACTOR' : @VM :  Reactor)
                                If TWLogResult NE True$ then
                                    //User exited the the TW log prompt answering that they are not using any test wafers.
                                    UserMsg          = "Unable to sign load because test wafer logging is required on this run. A supervisor or lead may override."
                                    OverrideGroups   = 'LEAD':@VM:'SUPERVISOR':@VM:'ENGINEERING':@VM:'ENG_TECH'
                                    UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
                                    Override         = UserVerification<1>
                                    OverrideUser	 = UserVerification<2>
                                    If Override then
                                    	Override_log_services('Create', 'RDS', RDSNo, OverrideUser, '', 'TW_USAGE', '')
                                    end else
                                    	return
                                    end
                                end
                            end else
                                //User has stated that they are NOT using test wafers
                                UserMsg          = "Unable to sign load because test wafer logging is required on this run. A supervisor or lead may override."
                                OverrideGroups   = 'LEAD':@VM:'SUPERVISOR':@VM:'ENGINEERING':@VM:'ENG_TECH'
                                UserVerification = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups:@FM:'':@FM:UserMsg)
                                Override         = UserVerification<1>
								OverrideUser	 = UserVerification<2>
								If Override then
									Override_log_services('Create', 'RDS', RDSNo, OverrideUser, '', 'TW_USAGE', '')
								end else
									return
								end
                            end
                        end
                    end
                end
                
                ReadyToSign = QA_Services('LoadSignatureReady', RDSNo, @User4, WfrQty, LLSide)
                If ReadyToSign EQ True$ then
                    If PreAuthenticated EQ FALSE$ then
                        initParams    = ''
                        initParams<4> = 'Sign Load'
                        Response      = Dialog_Box('NDW_VERIFY_USER', @WINDOW, initParams)
                        Valid         = Response<1>
                        If (Valid EQ True$) then
                            QA_Services('SignLoadStage', RDSNo, @USER4, WfrQty, LLSide)
                        end
                    end else
                        QA_Services('SignLoadStage', RDSNo, @USER4, WfrQty, LLSide)
                    end
                end
                If Error_Services('HasError') then
                    ErrorMsg = Error_Services('GetMessage')
                    ErrMsg(ErrorMsg)
                end
            end else
                Msg(@Window, "Reactor load signature not allowed on a down reactor.")
            end
            
            GoSub OLE_LL_Status
            Set_Property(@Window, 'SAVEWARN', False$)
            Send_Event(@Window, 'READ')
            
        Case SignEventType EQ 'Unsign'
            // 1. Check if on hold. If so, then block event and inform user
            WOMatKey = WONo:'*':CassNo
            WOMatCurrStatus = obj_WO_Mat('CurrStatus',WOMatKey)
            IF WOMatCurrStatus = 'HOLD' THEN
                ErrorMessage  = 'Process Error':@SVM:'Cassette is on Hold and may not have the signature removed.':CRLF$:CRLF$
                ErrMsg(ErrorMessage)
                RETURN 0
            END                      
            // 2.
            //   a. For Non-EPP - Check if LWII, LWIS, or FQA has been signed. If so, then block event and inform user           
            //   b. For EPP - Check Clean_Insp actions to see if an inspection or surfscan has been completed
            //           Also check the FQA signature (MO_QA)
            UnloadSig   = Xlate('RDS', RDSNo, 'OPERATOR_OUT', 'X')
            ReactorType = Xlate('RDS', RDSNo, 'REACTOR_TYPE','X')
            CISigs      = Xlate('RDS', RDSNo, 'LWI_CI_SIG', 'X')
            Convert @VM to '' in CISigs
            IF ReactorType NE 'EPP' THEN               
                FQASig = Xlate('RDS', RDSNo, 'SUP_VER_SIG', 'X')                
            END ELSE
                WMOutKey = Xlate('RDS', RDSNo, 'WM_OUT_KEY', 'X')
                FQASig   = Xlate('WM_OUT', WMOutKey, 'SUP_VER_SIG', 'X')
            END
            If ( (UnloadSig NE '') or (CISigs NE '') or (FQASig NE '') ) then
                // UNLOAD, LWII, LWIS, or FQA already signed. Block unload unsign event.
                ErrorMessage  = 'Process Error':@SVM:'UNLOAD, LWII, LWIS, or FQA already signed. Cannot unsign unload event.' |
                : CRLF$ : CRLF$
                ErrMsg(ErrorMessage)
                Return 0
            end
            
            // 3. Lead/Supervisor/Engineer/EngTech override
            Response     = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4 : @FM : 'LEAD' : @VM : 'SUPERVISOR':@VM:'ENGINEER':@VM:'ENG_TECH')
            Valid        = Response<1>
            OverrideUser = Response<2>
            
            If Valid then
                Lot_Event_Services('CreateLotEvent', RDSNo, Datetime(), 'UNSIGN_LOAD', 'Load stage unsigned', 'Reactor', @User4, True$, 'RDS')
                
                // 4. Remove WO_MAT Unload signature, date, and time
                WOMatRec = Database_Services('ReadDataRow', 'WO_MAT', WOMatKey)
                SigProf  = WOMatRec<WO_MAT_SIG_PROFILE$>
                Sigs     = WOMatRec<WO_MAT_SIGNATURE$>
                SigDTMs  = WOMatRec<WO_MAT_SIG_DTM$>
                Locate '1LOAD' in SigProf using @VM setting vPos then
                    Sigs<1, vPos>    = ''
                    SigDTMs<1, vPos> = ''
                    WOMatRec<WO_MAT_SIGNATURE$> = Sigs
                    WOMatRec<WO_MAT_SIG_DTM$>   = SigDTMs
                    obj_React_Status('HandleLoadUnsign',Reactor:@RM:WONo:@RM:CassNo:@RM:RDSNo:@RM:OverrideUser)
                end
                
                // 5. Remove '1LOAD' material log entry (i.e. WO_MAT<INV...> columns)
                InvActions = WOMatRec<WO_MAT_INV_ACTION$>
                Locate '1LOAD' in InvActions using @VM setting vPos then
                    WOMatRec<WO_MAT_INV_WH$>         = Delete(WOMatRec<WO_MAT_INV_WH$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_LOCATION$>   = Delete(WOMatRec<WO_MAT_INV_LOCATION$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_ACTION$>     = Delete(WOMatRec<WO_MAT_INV_ACTION$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_DTM$>        = Delete(WOMatRec<WO_MAT_INV_DTM$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_USER$>       = Delete(WOMatRec<WO_MAT_INV_USER$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_TAG$>        = Delete(WOMatRec<WO_MAT_INV_TAG$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_TOOL_ID$>    = Delete(WOMatRec<WO_MAT_INV_TOOL_ID$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_LOC$>        = Delete(WOMatRec<WO_MAT_INV_LOC$>, 0, vPos, 0)
                    WOMatRec<WO_MAT_INV_SCAN_ENTRY$> = Delete(WOMatRec<WO_MAT_INV_SCAN_ENTRY$>, 0, vPos, 0)
                end
                Database_Services('WriteDataRow', 'WO_MAT', WOMatKey, WOMatRec, True$, False$, True$)
                
                // 6. Remove RDS Unload signature, date, and time
                // NOTE: This needs to occur before item #5 to avoid RDS_ACTIONS restoring the load signature
                Set_Property(@Window:'.OP_IN', 'TEXT', '')
                Set_Property(@Window:'.OP_IN_NAME', 'TEXT', '')
                Set_Property(@Window:'.OP_IN_DATE', 'TEXT', '')
                Set_Property(@Window:'.OP_IN_TIME', 'TEXT', '')
                IOOptions = Get_Property(@Window, 'IOOPTIONS')
                IOOptions<6> = True$
                Set_Property(@Window, 'IOOPTIONS', IOOptions)
                Send_Event(@Window, 'WRITE')
                IOOptions<6> = False$
                Set_Property(@Window, 'IOOPTIONS', IOOptions)				
                
                Reactor     = Get_Property(@Window:'.REACTOR', 'TEXT')
                Rds_Services('AddComment', RDSNo, 'Load Stage Unsigned from Reactor ' : Reactor)
                ReactorRec  = Database_Services('ReadDataRow', 'REACTOR', Reactor)
                PreviousRotrOverrideRds = ReactorRec<REACTOR_PREVIOUS_ROTR_OVERRIDE_RDS$>
                
                // Check if ROTR override was preformed when signing this load
                If (PreviousRotrOverrideRds EQ RDSNo) then
                    // Reset the override flag
                    ReactorRec<REACTOR_ROTR_STATUS$> = 'F'
                    PreviousRotrStatusReason = ReactorRec<REACTOR_PREVIOUS_ROTR_STATUS_REASON$>
                    ReactorRec<REACTOR_ROTR_STATUS_REASON$> = PreviousRotrStatusReason
                    RotrOverrideCount = ReactorRec<REACTOR_ROTR_OVERRIDE_COUNT$>
                    ReactorRec<REACTOR_ROTR_OVERRIDE_COUNT$> = Max(0, (RotrOverrideCount - 1))
                end
                Database_Services('WriteDataRow', 'REACTOR', Reactor, ReactorRec, True$, False$, True$)
                If ReactorType EQ 'EPP' then
                    Reactor_Services('DecrementWfrMetrics', RDSNo)
                end
                Set_Property(@Window:'.PUB_SIGN', 'TEXT', 'Sign')
                
            end else
                Return 0               
            end          
            
    End Case
    Post_Event(@Window, 'READ')
    
end event


Event LL_L_STATUS.OnClick()
    
    MsgStruct = "" 
    MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
    
    ReactNo				= Get_Property(@Window:'.REACTOR','DEFPROP')
    ActiveReactLLKey	= XLATE('REACTOR', ReactNo, REACTOR_ACTIVE_LL_DISABLED$,'X')
    ReactLL				= XLATE('REACT_LL', ActiveReactLLKey, REACT_LL_DISABLED$, 'X')
    StatusSide = 'L'
    
    GoSub ChangeLLStatus
    Set_Property(@Window, 'SAVEWARN', False$)
    Gosub OLE_LL_Status
    
end event


Event LL_R_STATUS.OnClick()
    
    MsgStruct = "" 
    MsgStruct<MTEXTWIDTH$> = MSG_WIDTH$
    
    ReactNo				= Get_Property(@Window:'.REACTOR','DEFPROP')
    ActiveReactLLKey	= XLATE('REACTOR', ReactNo, REACTOR_ACTIVE_LL_DISABLED$,'X')
    ReactLL				= XLATE('REACT_LL', ActiveReactLLKey, REACT_LL_DISABLED$, 'X')
    StatusSide = 'R'
    
    GoSub ChangeLLStatus
    
    Set_Property(@Window, 'SAVEWARN', False$)
    Gosub OLE_LL_Status
    
end event


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal GoSubs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Setup_OLE_Controls:
    
return

ChangeLLStatus:
	
    If ReactNo EQ '' then
        return
    end
    If ActiveReactLLKey EQ '' then
        return
    end
    If ReactLL EQ '' OR ReactLL NE StatusSide then
        return
    end
    RDSNo = Get_Property(@Window:'.RDS_NO', 'DEFPROP')
    CurrUser = @USER4
    CurrDTM = obj_Calendar('CurrDTM')
    
    ActiveStartDTM = OCONV(ActiveReactLLKey[-1,'B*'],'DT4/^HS')
    
    orlParms  = ReactNo:@RM
    orlParms := ActiveReactLLKey:@RM
    orlParms := @USER4:@RM		;* Current user
    orlParms := ReactLL:@RM		;* 'L' or 'R' for LL side
    orlParms := CurrDTM
    
    OverrideGroups = 'LEAD':@VM:'SUPERVISOR':@VM:'ENGINEER':@VM:'ENG_TECH'
    Response = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:OverrideGroups)
    
    Valid    = Response<1>
    IF Valid then
        Obj_React_Ll('SetQual', orlParms)
        Message = 'Qual-Mode sucessfully toggled!'
        Msg(@Window, Message)
        overrideLogTable = 'RDS':@VM:'REACTOR'
        overrideLogKey = RDSNo:@VM:ReactNo
        overrideLogUser = Response<2>
        overrideLogComment = 'Performed Load-Lock qual override'
        overirdeLogCategory = 'LOAD_LOCK'
        orKey = Override_Log_Services('Create', overrideLogTable, overrideLogKey, overrideLogUser, overrideLogComment, overrideLogCategory)
    end else
        Message = 'User is not authorized to put load-lock into qual mode.'
        Msg(@Window, MsgStruct, 'PROCESS_ERROR', '', Message)
    end       
    
    
return


OLE_LL_Status:
	
    IF @Window EQ 'RDS' then
        
        RedNormal =  "Vertical(Gradient(Red L=90, Red L=80, 30%), Gradient(Red L=75, Red L=80), Border(Red))"
        RedHover  =  "Vertical(Gradient(Red L=90, Red L=80, 90%), Gradient(Red L=75, Red L=80), Border(Red))"
        RedPushed =  "Vertical(Gradient(Red L=90, Red L=80, 5%), Gradient(Red L=75, Red L=80), Border(Red))"
        
        OrangeNormal = "Vertical(Gradient(Orange L=90, Orange L=80, 30%), Gradient(Orange L=75, Orange L=80), Border(Orange))"
        OrangeHover  = "Vertical(Gradient(Orange L=90, Orange L=80, 90%), Gradient(Orange L=75, Orange L=80), Border(Orange))"
        OrangePushed = "Vertical(Gradient(Orange L=90, Orange L=80, 5%), Gradient(Orange L=75, Orange L=80), Border(Orange))"
        
        GreenNormal =  "Vertical(Gradient(Green L=90, Green L=80, 30%), Gradient(Green L=75, Green L=80), Border(Green))"
        
        bgUp = ''
        bgUp<1> = GreenNormal
        bgUp<2> = GreenNormal
        bgUp<3> = GreenNormal
        bgUp<4> = GreenNormal
        bgUp<5> = GreenNormal
        
        bgDown = ''
        bgDown<1> = RedNormal
        bgDown<2> = RedHover
        bgDown<3> = RedPushed
        bgDown<4> = RedHover
        bgDown<5> = RedNormal
        
        bgQual = ''
        bgQual<1> = OrangeNormal
        bgQual<2> = OrangeHover
        bgQual<3> = OrangePushed
        bgQual<4> = OrangeHover
        bgQual<5> = OrangeNormal
        
        Reactor = Get_Property(@WINDOW:'.REACTOR','DEFPROP')
        LoadSig = Get_Property(@Window:'.OP_IN', 'DEFPROP')
        
        Set_Property(@Window:".LL_L_STATUS", "OLE.Caption", 'EN')
        Set_Property(@Window:".LL_R_STATUS", "OLE.Caption", 'EN')
        Set_Property(@Window:".LL_L_STATUS", "OLE.Background", bgUp)
        Set_Property(@Window:".LL_R_STATUS", "OLE.Background", bgUp)
        Set_Property(@Window:".LL_L_STATUS", "ENABLED", 0)
        Set_Property(@Window:".LL_R_STATUS", "ENABLED", 0)
        
        
        IF Reactor NE '' then
            
            LLDisabled = XLATE('REACTOR', Reactor, REACTOR_ACTIVE_LL_DISABLED$, 'X')
            IF LLDisabled NE '' then
                ReactLLRec = Database_Services('ReadDataRow', 'REACT_LL', LLDisabled)
                SideDisabled = ReactLLRec<REACT_LL_DISABLED$>
                QualMode = ReactLLRec<REACT_LL_QUAL_MODE$>
                //LL Left Status
                Ctrl = @Window : '.LL_L_STATUS'
                Set_Property(Ctrl, 'OLE.STYLE', 'STD')
                Set_Property(Ctrl, 'OLE.Font', 'Segoe UI' : @SVM : '9')
                
                
                IF SideDisabled EQ 'L' then
                    If LoadSig EQ '' then
                        Set_Property(@Window:".LL_L_STATUS", "ENABLED", 1)
                    end
                    IF QualMode then
                        Set_Property(Ctrl, "OLE.Caption", 'QUAL')
                        Set_Property(Ctrl, "OLE.Background", bgQual)
                        Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnClick', 1)
                        
                    end else
                        Set_Property(Ctrl, "OLE.Caption", 'DIS')
                        Set_Property(Ctrl, "OLE.Background", bgDown)
                        Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnClick', 1)
                        
                    end
                end
                //LL Right Status
                Ctrl = @Window : '.LL_R_STATUS'
                Set_Property(Ctrl, 'OLE.STYLE', 'STD')
                Set_Property(Ctrl, 'OLE.Font', 'Segoe UI' : @SVM : '9')
                Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnClick', 1)
                
                IF SideDisabled EQ 'R'  then
                    If LoadSig EQ '' then
                        Set_Property(@Window:".LL_R_STATUS", "ENABLED", 1)
                    end
                    
                    IF QualMode then
                        Set_Property(Ctrl, "OLE.Caption", 'QUAL')
                        Set_Property(Ctrl, "OLE.Background", bgQual)
                        Send_Message(Ctrl, 'OLE.OnClick', 1)
                        
                    end else
                        Set_Property(Ctrl, "OLE.Caption", 'DIS')
                        Set_Property(Ctrl, "OLE.Background", bgDown)
                        Send_Message(Ctrl, 'QUALIFY_EVENT', 'OLE.OnClick', 1)
                    end
                end
            end
        end
    end
    
return


