USP_MAPPINGERROR_BANKACCOUNTDEPOSIT_RECREATEDISTRIBUTION

Recreate the distribution for payments linked to a bank account deposit.

Parameters

Parameter Parameter Type Mode Description
@DEPOSITID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN
@CURRENTDATE datetime IN
@PROCESSID uniqueidentifier IN

Definition

Copy


CREATE procedure dbo.USP_MAPPINGERROR_BANKACCOUNTDEPOSIT_RECREATEDISTRIBUTION
(
    @DEPOSITID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @CURRENTDATE datetime = null,
    @PROCESSID uniqueidentifier = null
) as 
begin

    if @CHANGEAGENTID is null
        exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

    if @CURRENTDATE is null
        set @CURRENTDATE = getdate();

    declare @DEFAULTGLACCOUNTID uniqueidentifier;
    select @DEFAULTGLACCOUNTID = S.DEFAULTGLACCOUNTID
    from dbo.PDACCOUNTSYSTEM S
    inner join dbo.BANKACCOUNT BA on S.ID = BA.PDACCOUNTSYSTEMID
    inner join dbo.BANKACCOUNTTRANSACTION BAT on BAT.BANKACCOUNTID = BA.ID
    where BAT.ID = @DEPOSITID;

    if @DEFAULTGLACCOUNTID is not null and exists(select 1 
        from dbo.DEPOSITGLDISTRIBUTIONLINK D
        inner join dbo.GLTRANSACTION T on D.ID = T.ID
        where D.DEPOSITID = @DEPOSITID and T.GLACCOUNTID = @DEFAULTGLACCOUNTID)
    begin
        declare @REVENUEID uniqueidentifier;

        declare revenueCursor cursor local fast_forward for
        select R.ID from dbo.BANKACCOUNTDEPOSITPAYMENT R where R.DEPOSITID = @DEPOSITID;

        open revenueCursor;
        fetch next from revenueCursor into @REVENUEID;
        while @@FETCH_STATUS = 0
        begin
            exec dbo.USP_MAPPINGERROR_REVENUE_RECREATEDISTRIBUTION @REVENUEID, @CHANGEAGENTID, @CURRENTDATE
            fetch next from revenueCursor into @REVENUEID;
        end
        close revenueCursor;
        deallocate revenueCursor;
    end

    if exists(select 1 from dbo.GLACCOUNTMAPPINGERROR where TRANSACTIONID = @DEPOSITID and DELETED = 0
        and ERRORMESSAGE in (select E.ERRORMESSAGE from dbo.GLACCOUNTMAPPINGERROR E where E.TRANSACTIONID = @DEPOSITID and E.GLACCOUNTMAPPINGERRORUPDATEPROCESSID = @PROCESSID))
        return 0
    else
        return 1
end