Compile function NDW_RDS_SUPP_SIG_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 SRP Computer Solutions, Inc.

    Name        :   NDW_RDS_SUPP_SIG_EVENTS

    Description :   Handler program for all Scan services.

    Notes       :   

    Parameters  :
        Service         [in] -- Name of the service being requested
        Param1-10   [in/out] -- Additional request parameter holders
        Response       [out] -- Response to be sent back to the Controller (MCP) or requesting procedure

    Metadata    :

    History     :   (Date, Initials, Notes)
        6/6/2024    djm     Adapted from old form to use new stage specific supplements.

***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler
#window NDW_RDS_SUPP_SIG

$Insert APP_INSERTS
$insert EVENT_SETUP
$Insert SUPPLEMENTS_EQUATES
$Insert MSG_EQUATES

Declare Subroutine End_Dialog, Database_Services, Set_Property, Supplement_Services
Declare Function   Time, Date, Get_Property, Supplement_Services, SRP_Datetime, Rds_Services

// 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$

//-----------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------


Event WINDOW.CREATE(Param1)

    RDSNo    = Param1<1>
    StageSel = ''
    ReadOnly = False$
    If Param1<2> NE '' then
    	StageSel = Param1<2>
    end
    If Param1<3> EQ True$ then
    	ReadOnly = True$
    end
    Set_Property(@Window, '@RDS', RDSNo)
    Database_Services('ActivateRecord', 'RDS', RDSNo)

	GoSub PopulateDropdown
    
    FormSize = '' 
    SRP_Show_Window(@Window, '', 'C', 'C', 1, '', False$, False$, FormSize)
    If ReadOnly EQ True$ then
		Set_Property(@Window:'.PUB_SIGN', 'ENABLED', False$)
    end
    
End Event


Event WINDOW.CLOSE(CancelFlag)

	Response = False$
    End_Dialog(@Window, Response)
    
end event


Event PUB_CLOSE.CLICK()
    
	Response = False$
    End_Dialog(@Window, Response)
    
end event


Event PUB_SIGN.CLICK()
    
    Response = Dialog_Box('NDW_VERIFY_USER', @WINDOW, @USER4:@FM:'SUPERVISOR':@VM:'DATA_ENTRY')
    Valid    = Response<1>
    If Valid EQ True$ then
        SupplSig     = @User4
        SigName      = OConv(SupplSig, '[XLATE_CONV,LSL_USERS*FIRST_LAST]')
        SupplSigDate = Date()
        SupplSigTime = Time()
        Set_Property(@Window:'.EDL_OP_SIG', 'TEXT', SupplSig)
        Set_Property(@Window:'.EDL_OP_SIG_NAME', 'TEXT', SigName)
        Set_Property(@Window:'.EDL_OP_SIG_DATE', 'TEXT', OConv(SupplSigDate, 'D2/') )
        Set_Property(@Window:'.EDL_OP_SIG_TIME', 'TEXT', OConv(SupplSigTime, 'MTH') )
        RDSNo        = Get_Property(@Window, '@RDS')
        StageSel     = Get_Property(@Window : '.CMB_STAGE', 'TEXT')
		SuppID       = Supplement_Services('GetSupplementsForLot', 'RDS', RDSNo, StageSel)
		Supplement_Services('AcknowledgeSupplement', SuppID, SupplSig)
        Set_Property(@Window:'.PUB_SIGN', 'ENABLED', False$)
        Response     = True$
        End_Dialog(@Window, Response)
    end else
    	Message           = 'Invalid password or operation has been canceled by the user. Please try again.'
        MsgStruct         = ''
        MsgStruct<MTEXT$> = Message
        MsgStruct<MTYPE$> = 'BO'
        Response          = FALSE$
        Prompt            = Msg(@Window, MsgStruct)
    end
    
end event

Event CMB_STAGE.CHANGED()
	
	Gosub GetSupplement
	
end event

GetSupplement:
	
	RDSNo      = Get_Property(@Window, '@RDS')
	SuppText   = ''
	StageSel   = Get_Property(@Window : '.CMB_STAGE', 'TEXT')
	SuppID     = Supplement_Services('GetSupplementsForLot', 'RDS', RDSNo, StageSel)
	OldSuppRec = Xlate('SUPPLEMENTS', SuppID, '', 'X', '')

    SupplInst      = OldSuppRec<SUPPLEMENTS_SUPPL_TEXT$>
    SupplEntryID   = OldSuppRec<SUPPLEMENTS_ENTRY_USER$>
    EntryName      = OConv(SupplEntryID, '[XLATE_CONV,LSL_USERS*FIRST_LAST]')
	EntryDateTime  = OldSuppRec<SUPPLEMENTS_ENTRY_DATETIME$>
    SupplEntryDate = SRP_Datetime('Date', EntryDateTime)
    SupplEntryTime = SRP_Datetime('Time', EntryDateTime)
    SupplSig       = OldSuppRec<SUPPLEMENTS_ACK_USER$>
    SigName        = OConv(SupplSig, '[XLATE_CONV,LSL_USERS*FIRST_LAST]')
    AckDateTime    = OldSuppRec<SUPPLEMENTS_ACK_DTM$>
    SupplSigDate   = SRP_Datetime('Date', AckDateTime)
    SupplSigTime   = SRP_Datetime('Time', AckDateTime)
    SupplAck       = OldSuppRec<SUPPLEMENTS_SUPPL_ACK$>
    Set_Property(@Window:'.EDL_ENTRY_ID', 'TEXT', SupplEntryID)
    Set_Property(@Window:'.EDL_ENTRY_NAME', 'TEXT', EntryName)
    Set_Property(@Window:'.EDL_ENTRY_DATE', 'TEXT', OConv(SupplEntryDate, 'D2/') )
    Set_Property(@Window:'.EDL_ENTRY_TIME', 'TEXT', OConv(SupplEntryTime, 'MTH') )
    Set_Property(@Window:'.EDB_SUPPL_INST', 'TEXT', SupplInst)
    Set_Property(@Window:'.EDL_OP_SIG', 'TEXT', SupplSig)
    Set_Property(@Window:'.EDL_OP_SIG_NAME', 'TEXT', SigName)
    Set_Property(@Window:'.EDL_OP_SIG_DATE', 'TEXT', OConv(SupplSigDate, 'D2/') )
    Set_Property(@Window:'.EDL_OP_SIG_TIME', 'TEXT', OConv(SupplSigTime, 'MTH') )
   	CurrStage      = Rds_Services('GetCurrentStage', RDSNo)
	
    If SupplAck EQ True$ OR CurrStage NE StageSel then
        Set_Property(@Window:'.PUB_SIGN', 'ENABLED', False$)
    end else
    	Set_Property(@Window:'.PUB_SIGN', 'ENABLED', True$)
    end


return


PopulateDropdown:
	
	StageArray = ''
	RDSNo      = Get_Property(@Window, '@RDS')
	LotSupps   = Supplement_Services('GetSupplementsForLot', 'RDS', RDSNo, '')
	LotCount   = Dcount(LotSupps, @FM)
	For I = 1 to LotCount
		Stage          = Xlate('SUPPLEMENTS', LotSupps<I>, SUPPLEMENTS_STAGE$, 'X', '')
		StageArray<-1> = Stage
	Next I
	Set_Property(@Window : '.CMB_STAGE', 'LIST', StageArray)
	Set_Property(@Window : '.CMB_STAGE', 'SELPOS', 1)
	If StageSel NE '' then
		Locate StageSel in StageArray using @FM Setting StagePos then
			Set_Property(@Window : '.CMB_STAGE', 'SELPOS', StagePos)
		end
	end
	Gosub GetSupplement
	
return



