USP_BANKACCOUNTDEPOSIT_DELETE

Executes the "Bank Account Deposit: Delete" record operation.

Parameters

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

Definition

Copy


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

                        declare @EXCHANGERATEIDS table (ID uniqueidentifier)

                        insert into @EXCHANGERATEIDS (ID)
                        select BASEEXCHANGERATEID from dbo.BANKACCOUNTDEPOSITCORRECTION where DEPOSITID = @ID
                        union all
                        select TRANSACTIONEXCHANGERATEID from dbo.BANKACCOUNTDEPOSIT where ID = @ID
                        union all
                        select BASEEXCHANGERATEID from dbo.BANKACCOUNTTRANSACTION where ID = @ID

                        begin try
                            if exists(select ID from dbo.BANKACCOUNTDEPOSITPAYMENT where DEPOSITID = @ID)
                                raiserror('ERR_UNLINK_ALL_PAYMENTS', 13, 1);

                            declare @contextCache varbinary(128);
                            -- cache current context information 

                            set @contextCache = CONTEXT_INFO();

                            -- set CONTEXT_INFO to @CHANGEAGENTID 

                            if not @CHANGEAGENTID is null
                                set CONTEXT_INFO @CHANGEAGENTID;

                            update dbo.BANKACCOUNTDEPOSIT set STATUSCODE = 1 where ID = @ID;

                            delete dbo.GLTRANSACTION 
                                where ID in (select GLTRANSACTIONID 
                                    from dbo.BANKACCOUNTDEPOSITCORRECTIONGLDISTRIBUTION D
                                    inner join dbo.BANKACCOUNTDEPOSITCORRECTION C on C.ID = D.BANKACCOUNTDEPOSITCORRECTIONID
                                    where C.DEPOSITID = @ID);

                            delete from dbo.FINANCIALTRANSACTION
                            where PARENTID = @ID and TYPECODE in (24, 25);

                            -- reset CONTEXT_INFO to previous value

                            if not @contextCache is null
                                set CONTEXT_INFO @contextCache

                            exec USP_BANKACCOUNTTRANSACTION_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID

                            --delete spot rates that are being used

                            delete dbo.CURRENCYEXCHANGERATE where TYPECODE = 2 and ID in (select ID from @EXCHANGERATEIDS);

                        end try

                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch

                        return 0;
                    end