USP_OTHERPAYMENTMETHOD_TOGGLEDEPOSITSTATUS

Executes the "Other Payment Method: Toggle Deposit Status" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the update.

Definition

Copy


                CREATE procedure dbo.USP_OTHERPAYMENTMETHOD_TOGGLEDEPOSITSTATUS
                (
                    @ID uniqueidentifier,
                    @CHANGEAGENTID uniqueidentifier
                )
                as begin

                    if exists(select ID from dbo.NONDEPOSITABLEPAYMENTMETHOD
                                where ID = @ID)
                        begin
                        declare @contextCache varbinary(128);
                        declare @e int;

                        -- cache current context information 

                        set @contextCache = CONTEXT_INFO();

                        -- set CONTEXT_INFO to @CHANGEAGENTID 

                        if not @CHANGEAGENTID is null
                            set CONTEXT_INFO @CHANGEAGENTID;

                        delete from dbo.NONDEPOSITABLEPAYMENTMETHOD
                        where ID = @ID;

                        -- reset CONTEXT_INFO to previous value 

                        if not @contextCache is null
                            set CONTEXT_INFO @contextCache;

                        end
                    else
                        begin
                            declare @CURRENTDATE datetime;
                            set @CURRENTDATE = getdate();

                            --Check that no payments of this type are currently deposited in a deposit that holds payments that have not yet been posted

                            if exists (
                                select top(1) 1
                                from dbo.[BANKACCOUNTDEPOSITPAYMENT]
                                inner join dbo.[REVENUE] 
                                    on [BANKACCOUNTDEPOSITPAYMENT].[ID] = [REVENUE].[ID]
                                inner join dbo.[REVENUEPAYMENTMETHOD]
                                    on [REVENUE].[ID] = [REVENUEPAYMENTMETHOD].[REVENUEID]
                                inner join dbo.[OTHERPAYMENTMETHODDETAIL]
                                    on [REVENUEPAYMENTMETHOD].[ID] = [OTHERPAYMENTMETHODDETAIL].[ID]
                                where
                                    (
                                        --[REVENUE].[DONOTPOST] = 1 or

                                        not exists(select 1 from [REVENUEPOSTED] where [ID] = [REVENUE].[ID])
                                    ) and
                                    [OTHERPAYMENTMETHODDETAIL].[OTHERPAYMENTMETHODCODEID] = @ID and
                                    [BANKACCOUNTDEPOSITPAYMENT].[DEPOSITID] is not null
                  and [REVENUE].DONOTPOST <> 1
                            )
                            begin
                                raiserror('BBERR_REMOVINGDEPOSITABLEFROMDEPOSIT',13,1);    
                            end    

                            insert into dbo.NONDEPOSITABLEPAYMENTMETHOD (ID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
                            values (@ID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE);

                        end
                    return 0;

                end