USP_DATAFORMTEMPLATE_EDITLOAD_REVENUEGLDISTRIBUTION

The load procedure used by the edit dataform template "Revenue GL Distribution Edit Form"

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter used to load the fields defined on the form.
@DATALOADED bit INOUT Output parameter indicating whether or not data was actually loaded.
@GLDISTRIBUTION xml INOUT Revenue GL distribution
@REVENUEAMOUNT money INOUT Revenue amount
@DEBITGLPAYMENTMETHODREVENUETYPEMAPPINGID uniqueidentifier INOUT Debit mapping type
@CREDITGLPAYMENTMETHODREVENUETYPEMAPPINGID uniqueidentifier INOUT Credit mapping type
@TSLONG bigint INOUT Output parameter indicating the TSLONG value of the record being edited. This is used to manage multi-user concurrency issues when multiple users access the same record.
@TRANSACTIONCURRENCYID uniqueidentifier INOUT Transaction currency ID

Definition

Copy


                CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_REVENUEGLDISTRIBUTION
                (
                    @ID uniqueidentifier,
                    @DATALOADED bit = 0 output,
                    @GLDISTRIBUTION xml = null output,
                    @REVENUEAMOUNT money = null output,
                    @DEBITGLPAYMENTMETHODREVENUETYPEMAPPINGID uniqueidentifier = null output,
                    @CREDITGLPAYMENTMETHODREVENUETYPEMAPPINGID uniqueidentifier = null output,
                    @TSLONG bigint = 0 output,
                    @TRANSACTIONCURRENCYID uniqueidentifier = null output
                )
                as
                begin                                                
                    set nocount on;

                    set @DATALOADED = 0;
                    set @TSLONG = 0;

                    -- Rename the TRANSACTIONAMOUNT field to AMOUNT.

                    set @GLDISTRIBUTION = (
                        select 
                            GLDISTRIBUTION.GLTRANSACTIONID as ID, 
                            GLDISTRIBUTION.TRANSACTIONTYPECODE, 
                            GLDISTRIBUTION.TRANSACTIONAMOUNT AMOUNT, 
                            GLDISTRIBUTION.GLPAYMENTMETHODREVENUETYPEMAPPINGID, 
                            GLDISTRIBUTION.ACCOUNT, 
                            GLDISTRIBUTION.PROJECT, 
                            GLDISTRIBUTION.REFERENCE, 
                            GLDISTRIBUTION.TRANSACTIONCURRENCYID
                        from 
                            dbo.UFN_REVENUE_GETGLDISTRIBUTION(@ID) GLDISTRIBUTION
                        inner join dbo.GLTRANSACTION T on T.ID = GLDISTRIBUTION.GLTRANSACTIONID
                        where T.SYSTEMDISTRIBUTION = 0
                        for xml raw('ITEM'),type,elements,root('GLDISTRIBUTION'),BINARY BASE64
                    );

                    select 
                        @REVENUEAMOUNT = case FINANCIALTRANSACTION.TYPECODE when 4 then coalesce(PLANNEDGIFTADDITION.TRANSACTIONGIFTAMOUNT, PLANNEDGIFT.TRANSACTIONGIFTAMOUNT) else FINANCIALTRANSACTION.TRANSACTIONAMOUNT end,
                        @TRANSACTIONCURRENCYID = FINANCIALTRANSACTION.TRANSACTIONCURRENCYID
                    from 
                        dbo.FINANCIALTRANSACTION
                        left join dbo.V_PLANNEDGIFTREVENUE_WITHADDITIONS as PLANNEDGIFTREVENUE on FINANCIALTRANSACTION.ID = PLANNEDGIFTREVENUE.REVENUEID
                        left join dbo.PLANNEDGIFTADDITION on PLANNEDGIFTADDITION.ID = PLANNEDGIFTREVENUE.PLANNEDGIFTADDITIONID
                        left outer join dbo.PLANNEDGIFT on PLANNEDGIFT.ID = PLANNEDGIFTREVENUE.PLANNEDGIFTID
                    where 
                        FINANCIALTRANSACTION.ID = @ID

                    select 
                        TOP 1 @DEBITGLPAYMENTMETHODREVENUETYPEMAPPINGID = GLPAYMENTMETHODREVENUETYPEMAPPINGID
                    from 
                        dbo.UFN_REVENUE_GETGLDISTRIBUTION_FROMITEMLISTXML(@GLDISTRIBUTION)
                    where 
                        TRANSACTIONTYPECODE = 0;

                    select 
                        TOP 1 @CREDITGLPAYMENTMETHODREVENUETYPEMAPPINGID = GLPAYMENTMETHODREVENUETYPEMAPPINGID
                    from 
                        dbo.UFN_REVENUE_GETGLDISTRIBUTION_FROMITEMLISTXML(@GLDISTRIBUTION)
                    where 
                        TRANSACTIONTYPECODE = 1;

                    if @REVENUEAMOUNT is not null 
                        begin                          
                            set @DATALOADED = 1                    
                            select @TSLONG = max(tslong) from dbo.REVENUEGLDISTRIBUTION where REVENUEID = @ID
                        end

                    return 0;                    
                end