USP_BANKACCOUNTTRANSACTION_DELETE

Executes the "Bank Account Transaction: 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_BANKACCOUNTTRANSACTION_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as begin
                        declare @TRANSFERADJUSTMENTID uniqueidentifier
                        declare @EXCHANGERATEID uniqueidentifier
                        declare @BASEEXCHANGERATEID uniqueidentifier
                        declare @BASEEXCHANGERATE1ID uniqueidentifier

                        select
                            @TRANSFERADJUSTMENTID = A.TRANSFERADJUSTMENTID
                            ,@EXCHANGERATEID = ISNULL(A.EXCHANGERATEID, A1.EXCHANGERATEID)
                            ,@BASEEXCHANGERATEID = BAT.BASEEXCHANGERATEID
                            ,@BASEEXCHANGERATE1ID = BAT1.BASEEXCHANGERATEID 
                        from
                            BANKACCOUNTADJUSTMENT A
                        inner join dbo.BANKACCOUNTTRANSACTION BAT on BAT.ID = A.ID
                        left outer join dbo.BANKACCOUNTTRANSACTION BAT1 on BAT1.ID = A.TRANSFERADJUSTMENTID
                        left outer join dbo.BANKACCOUNTADJUSTMENT A1 on A1.ID = BAT1.ID
                        where
                            A.ID = @ID

                        begin try
                            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;

                            --delete all the distributions related to these transactions

                            delete from dbo.GLTRANSACTION where ID in (select GLTRANSACTIONID from dbo.BANKACCOUNTTRANSACTIONGLDISTRIBUTION where BANKACCOUNTTRANSACTIONID in (@ID, @TRANSFERADJUSTMENTID));

                            -- use the system generated delete routine to allow proper recording of the deleting agent

                            exec USP_BANKACCOUNTTRANSACTION_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID

                            if not @TRANSFERADJUSTMENTID is null
                                exec USP_BANKACCOUNTTRANSACTION_DELETEBYID_WITHCHANGEAGENTID @TRANSFERADJUSTMENTID, @CHANGEAGENTID

                            --delete spot rates that are being used

                            delete dbo.CURRENCYEXCHANGERATE where TYPECODE = 2 and ID in (@EXCHANGERATEID, @BASEEXCHANGERATEID, @BASEEXCHANGERATE1ID);

                            -- reset CONTEXT_INFO to previous value

                            if not @contextCache is null
                                set CONTEXT_INFO @contextCache
                        end try

                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch

                        return 0;
                    end