USP_DATAFORMTEMPLATE_EDIT_REVENUEDETAIL_2

The save procedure used by the edit dataform template "Revenue Detail Edit Form 2".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@AMOUNT money IN Revenue amount
@RECEIPTAMOUNT money IN Receipt amount
@SPLITS xml IN Designations
@SOURCECODE nvarchar(50) IN Source code
@APPEALID uniqueidentifier IN Appeal
@BENEFITS xml IN Benefits
@BENEFITSWAIVED bit IN Benefits waived
@MAILINGID uniqueidentifier IN Mailing
@CHANNELCODEID uniqueidentifier IN Channel
@DONOTACKNOWLEDGE bit IN Do not acknowledge
@CATEGORYCODEID uniqueidentifier IN Revenue category

Definition

Copy


                    CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_REVENUEDETAIL_2
                    (
                        @ID uniqueidentifier,
                        @CURRENTAPPUSERID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier,
                        @AMOUNT money,                    
                        @RECEIPTAMOUNT money,
                        @SPLITS xml,
                        @SOURCECODE nvarchar(50),
                        @APPEALID uniqueidentifier,
                        @BENEFITS xml,
                        @BENEFITSWAIVED bit,
                        @MAILINGID uniqueidentifier,
                        @CHANNELCODEID uniqueidentifier,
                        @DONOTACKNOWLEDGE bit,
                        @CATEGORYCODEID uniqueidentifier
                    )
                    as
                    set nocount on;

                    declare @CHANGEDATE datetime;
                    declare @TYPECODE tinyint;

                    begin try

                        set @CHANGEDATE = getdate();

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

                        /* Validate payment information */

                        --IS THE REVENUE POSTED?

                        if exists (select 1 from dbo.REVENUEPOSTED where ID = @ID)
                            raiserror('You cannot edit a posted gift.', 13, 1)

                        select @TYPECODE = TRANSACTIONTYPECODE
                        from dbo.REVENUE
                        where ID = @ID;

                        declare @REVENUEPAYMENTMETHODID uniqueidentifier
                        select @REVENUEPAYMENTMETHODID = ID
                        from dbo.REVENUEPAYMENTMETHOD
                        where REVENUEID = @ID

                        declare @CLEARGLDISTRIBUTION bit;
                        set @CLEARGLDISTRIBUTION = 0;

                        declare @OLDCATEGORYCODEID uniqueidentifier
                        select top 1 @OLDCATEGORYCODEID = REVENUECATEGORY.GLREVENUECATEGORYMAPPINGID
                        from dbo.REVENUECATEGORY
                        inner join dbo.REVENUESPLIT on REVENUECATEGORY.ID = REVENUESPLIT.ID
                        where REVENUESPLIT.REVENUEID = @ID

                        -- check to see if amount or revenue category has changed

                        if (
                            select count(REVENUE.ID) from dbo.REVENUE 
                            where REVENUE.ID = @ID and AMOUNT = @AMOUNT
                        ) = 0 or not ((@CATEGORYCODEID is null and @OLDCATEGORYCODEID is null) and @CATEGORYCODEID = @OLDCATEGORYCODEID)
                            set @CLEARGLDISTRIBUTION = 1;

                        -- check to see if designations have changed

                        if @CLEARGLDISTRIBUTION = 0
                            if dbo.UFN_CHECKDETAIL_SPLITSCHANGED(@ID, @SPLITS) = 1
                                set @CLEARGLDISTRIBUTION = 1;

                        exec dbo.USP_REVENUEDETAIL_EDIT_2 @ID, @CURRENTAPPUSERID, @CHANGEAGENTID, @TYPECODE
                            @AMOUNT, @RECEIPTAMOUNT, @SPLITS, @SOURCECODE, @APPEALID, @BENEFITS, @BENEFITSWAIVED
                            @MAILINGID, @CHANNELCODEID, @DONOTACKNOWLEDGE, @CHANGEDATE, @CATEGORYCODEID;

                        -- clear the user-defined gl distributions

                        if @CLEARGLDISTRIBUTION = 1
                        begin                            
                            --Clear GL

                            --Cache CONTEXT INFO

                            declare @contextCache varbinary(128);
                            set @contextCache = CONTEXT_INFO();

                            if not @CHANGEAGENTID is null
                                set CONTEXT_INFO @CHANGEAGENTID;

                            delete from dbo.REVENUEGLDISTRIBUTION where REVENUEID = @ID and OUTDATED = 0;    
                            delete from dbo.STOCKDETAILGLDISTRIBUTION where STOCKDETAILID = @REVENUEPAYMENTMETHODID and OUTDATED = 0;
                            delete from dbo.PROPERTYDETAILGLDISTRIBUTION where PROPERTYDETAILID = @REVENUEPAYMENTMETHODID and OUTDATED = 0;

                            --Restore CONTEXT_INFO

                            if not @contextCache is null
                                set CONTEXT_INFO @contextCache;

                            -- Add new GL distributions

                            exec dbo.USP_SAVE_REVENUEGLDISTRIBUTION @ID;

                            -- Add new stock detail GL distributions

                            exec dbo.USP_SAVE_STOCKDETAILGLDISTRIBUTION @ID;

                            -- Add new property detail GL distributions

                            exec dbo.USP_SAVE_PROPERTYDETAILGLDISTRIBUTION @ID;
                        end
                    end try

                    begin catch
                        exec dbo.USP_RAISE_ERROR;
                    end catch
                    return 0;