USP_PLEDGEPAYMENT_FIXSPLITS

Updates the splits for a pledge payment based on the splits for the pledge.

Parameters

Parameter Parameter Type Mode Description
@PAYMENTID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


            CREATE procedure dbo.USP_PLEDGEPAYMENT_FIXSPLITS
            (
                @PAYMENTID uniqueidentifier,
                @CHANGEAGENTID uniqueidentifier 
            )
            as 
            set nocount on;

            declare @contextCache varbinary(128);
            declare @CURRENTDATE datetime;
            declare @PAYMENTAMOUNT money;

            set @CURRENTDATE = getdate(); 

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

            --Delete all the splits for this pledge payment and add the new ones.

            --Can come back and be more intelligent about updating vs. deleting at

            --the expense of complexity and speed


            set @contextCache = CONTEXT_INFO();

            if not @CHANGEAGENTID is null
                set CONTEXT_INFO @CHANGEAGENTID;

            delete from dbo.REVENUESPLIT where REVENUEID = @PAYMENTID;

            if not @contextCache is null
                set CONTEXT_INFO @contextCache

            select @PAYMENTAMOUNT = AMOUNT from dbo.REVENUE where ID = @PAYMENTID

            insert into dbo.REVENUESPLIT(ID, REVENUEID, TYPECODE, APPLICATIONCODE, DESIGNATIONID, AMOUNT,ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
                select
                    newid(),
                    @PAYMENTID
                    TYPECODE, 
                    APPLICATIONCODE,
                    DESIGNATIONID,
                    AMOUNT,
                    @CHANGEAGENTID,
                    @CHANGEAGENTID,
                    @CURRENTDATE,
                    @CURRENTDATE
                from dbo.UFN_PLEDGE_GETSPLITSFORPAYMENT(dbo.UFN_PLEDGE_GETPLEDGEFROMPAYMENT(@PAYMENTID), @PAYMENTAMOUNT); 

            return 0;