USP_DATAFORMTEMPLATE_ADD_PAYMENT

Stored procedure used to save on the payment add form.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT
@CHANGEAGENTID uniqueidentifier IN
@CONSTITUENTID uniqueidentifier IN
@DATE datetime IN
@AMOUNT money IN
@PAYMENTMETHODCODE tinyint IN
@CHECKDATE UDT_FUZZYDATE IN
@CHECKNUMBER nvarchar(20) IN
@REFERENCEDATE UDT_FUZZYDATE IN
@REFERENCENUMBER nvarchar(20) IN
@CARDHOLDERNAME nvarchar(255) IN
@CREDITCARDNUMBER nvarchar(4) IN
@CREDITTYPECODEID uniqueidentifier IN
@AUTHORIZATIONCODE nvarchar(20) IN
@EXPIRESON UDT_FUZZYDATE IN
@ISSUER nvarchar(100) IN
@NUMBEROFUNITS decimal(20, 3) IN
@SYMBOL nvarchar(25) IN
@MEDIANPRICE decimal(19, 4) IN
@GIFTINKINDSUBTYPECODEID uniqueidentifier IN
@PROPERTYSUBTYPECODEID uniqueidentifier IN
@RECEIPTAMOUNT money IN
@CONSTITUENTACCOUNTID uniqueidentifier IN
@REVENUESTREAMS xml IN
@POSTSTATUSCODE tinyint IN
@POSTDATE datetime IN
@FINDERNUMBER bigint IN
@SOURCECODE nvarchar(50) IN
@APPEALID uniqueidentifier IN
@TRIBUTEID uniqueidentifier IN
@BENEFITS xml IN
@BENEFITSWAIVED bit IN
@GIVENANONYMOUSLY bit IN
@MAILINGID uniqueidentifier IN
@LETTERCODEID uniqueidentifier IN
@CHANNELCODEID uniqueidentifier IN
@DONOTACKNOWLEDGE bit IN
@DONOTRECEIPT bit IN
@OTHERPAYMENTMETHODCODEID uniqueidentifier IN
@REFERENCE nvarchar(255) IN
@DIRECTDEBITRESULTCODE nvarchar(10) IN
@LOWPRICE decimal(19, 4) IN
@HIGHPRICE decimal(19, 4) IN
@GIFTINKINDITEMNAME nvarchar(100) IN
@GIFTINKINDDISPOSITIONCODE tinyint IN
@GIFTINKINDNUMBEROFUNITS int IN
@GIFTINKINDFAIRMARKETVALUE money IN
@PERCENTAGEBENEFITS xml IN
@PDACCOUNTSYSTEMID uniqueidentifier IN
@TRANSACTIONCURRENCYID uniqueidentifier IN
@BASEEXCHANGERATEID uniqueidentifier IN
@EXCHANGERATE decimal(20, 8) IN
@CURRENTAPPUSERID uniqueidentifier IN
@BATCHNUMBER nvarchar(100) IN
@SEPAMANDATEID uniqueidentifier IN
@TRANSACTIONID uniqueidentifier IN
@MERCHANTACCOUNTID uniqueidentifier IN
@VENDORID nvarchar(50) IN

Definition

Copy


            CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_PAYMENT
            (
                @ID uniqueidentifier = null output,
                @CHANGEAGENTID uniqueidentifier,
                @CONSTITUENTID uniqueidentifier,                    
                @DATE datetime,
                @AMOUNT money = 0,
                @PAYMENTMETHODCODE tinyint = 1,
                @CHECKDATE dbo.UDT_FUZZYDATE = '00000000',
                @CHECKNUMBER nvarchar(20) = '',
                @REFERENCEDATE dbo.UDT_FUZZYDATE = '00000000',
                @REFERENCENUMBER nvarchar(20) = '',
                @CARDHOLDERNAME nvarchar(255) = '',
                @CREDITCARDNUMBER nvarchar(4) = '',
                @CREDITTYPECODEID uniqueidentifier = null,
                @AUTHORIZATIONCODE nvarchar(20) = '',
                @EXPIRESON dbo.UDT_FUZZYDATE = '00000000',
                @ISSUER nvarchar(100) = '',
                @NUMBEROFUNITS decimal(20,3) = 0,
                @SYMBOL nvarchar(25) = '',
                @MEDIANPRICE decimal(19,4) = 0,
                @GIFTINKINDSUBTYPECODEID uniqueidentifier = null,
                @PROPERTYSUBTYPECODEID uniqueidentifier = null,
                @RECEIPTAMOUNT money = 0,
                @CONSTITUENTACCOUNTID uniqueidentifier = null,
                @REVENUESTREAMS xml = null,
                @POSTSTATUSCODE tinyint = 1,
                @POSTDATE datetime = null,
                @FINDERNUMBER bigint = null,
                @SOURCECODE nvarchar(50) = null,
                @APPEALID uniqueidentifier = null,
                @TRIBUTEID uniqueidentifier = null,
                @BENEFITS xml = null,
                @BENEFITSWAIVED bit = 0,
                @GIVENANONYMOUSLY bit = null,
                @MAILINGID uniqueidentifier = null,
                @LETTERCODEID uniqueidentifier = null,
                @CHANNELCODEID uniqueidentifier = null,
                @DONOTACKNOWLEDGE bit = 0,
                @DONOTRECEIPT bit = 0,
                @OTHERPAYMENTMETHODCODEID uniqueidentifier = null,
                @REFERENCE nvarchar(255) = null,
                @DIRECTDEBITRESULTCODE nvarchar(10) = '',
                @LOWPRICE decimal(19,4) = 0,
                @HIGHPRICE decimal(19,4) = 0,
                @GIFTINKINDITEMNAME nvarchar(100) = '',
                @GIFTINKINDDISPOSITIONCODE tinyint = 0,
                @GIFTINKINDNUMBEROFUNITS int = 0,
                @GIFTINKINDFAIRMARKETVALUE money = 0,
                @PERCENTAGEBENEFITS xml = null,
                @PDACCOUNTSYSTEMID uniqueidentifier = null,
                @TRANSACTIONCURRENCYID uniqueidentifier = null,
                @BASEEXCHANGERATEID uniqueidentifier = null,
                @EXCHANGERATE decimal(20,8) = null,
                @CURRENTAPPUSERID uniqueidentifier = null,
                @BATCHNUMBER nvarchar(100) = '',
                @SEPAMANDATEID uniqueidentifier = null,
                @TRANSACTIONID uniqueidentifier = null,
                @MERCHANTACCOUNTID uniqueidentifier = null,
                @VENDORID nvarchar(50) = ''
            )
            as
            set nocount on;

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

            declare @CURRENTDATE datetime;

            if @ID is null
                set @ID = newid();

            set @CURRENTDATE = GetDate();

            begin try
                set @POSTDATE = @DATE;

                --if we have a finder number make sure the constituent has been added to the tables

                if isnull(@FINDERNUMBER, 0) > 0
                    exec dbo.USP_DATAFORMTEMPLATE_ADD_ACQUISITIONLISTMEMBER @CONSTITUENTID, @CHANGEAGENTID, @FINDERNUMBER;

                if @PDACCOUNTSYSTEMID is null
                    set @PDACCOUNTSYSTEMID = '4B121C2C-CCE6-440D-894C-EA0DEF80D50B';

                -- Check GL business rule for this account system and set to 'Do not post' if needed.

                -- ####

                declare @ALLOWGLDISTRIBUTIONS bit;
                set @ALLOWGLDISTRIBUTIONS = dbo.UFN_PDACCOUNTSYSTEM_ALLOWGLDISTRIBUTIONS(@PDACCOUNTSYSTEMID)
                if @ALLOWGLDISTRIBUTIONS = 0
                    begin
                        set @POSTSTATUSCODE = 2        -- Do not post

                        set @POSTDATE = null
                    end
                -- ####                                


                --Set currency parameters for backwards compatibility

                if @TRANSACTIONCURRENCYID is null
                    set @TRANSACTIONCURRENCYID = dbo.UFN_CURRENCY_GETORGANIZATIONCURRENCY();

                --Multicurrency - Retrieve base currency from the account system's currency set.

                declare @CURRENCYSETID uniqueidentifier;
                select @CURRENCYSETID = CURRENCYSETID from dbo.PDACCOUNTSYSTEM where ID = @PDACCOUNTSYSTEMID;

                declare @BASECURRENCYID uniqueidentifier;
                select 
                    @BASECURRENCYID = BASECURRENCYID
                from 
                    dbo.CURRENCYSET
                where 
                    ID = coalesce(@CURRENCYSETID,dbo.UFN_CURRENCYSET_GETAPPUSERDEFAULTCURRENCYSET());

                -- Ensure that we can add a payment of this transaction currency to the account system.

                if not exists(
                    select 1
                    from 
                        dbo.CURRENCYSETTRANSACTIONCURRENCY
                        inner join dbo.PDACCOUNTSYSTEM on PDACCOUNTSYSTEM.CURRENCYSETID = CURRENCYSETTRANSACTIONCURRENCY.CURRENCYSETID
                    where 
                        PDACCOUNTSYSTEM.ID = @PDACCOUNTSYSTEMID
                        and CURRENCYSETTRANSACTIONCURRENCY.CURRENCYID = @TRANSACTIONCURRENCYID
                )
                begin
                    raiserror('TRANSACTIONCURRENCYINVALIDFORACCOUNTSYSTEM',13,1);
                end

                if @PAYMENTMETHODCODE = 2 --Direct Debit

                begin
                    if @SEPAMANDATEID is not null --Trying to add/use a SEPA mandate

                    begin
                        --Make sure that the mandate is getting added to an account that is tied to a financial institution that

                        --has a SEPA banking system

                        if not exists
                        (
                            select 1 
                            from 
                                dbo.CONSTITUENTACCOUNT
                                inner join dbo.FINANCIALINSTITUTION on FINANCIALINSTITUTION.ID = CONSTITUENTACCOUNT.FINANCIALINSTITUTIONID
                                inner join dbo.BANKINGSYSTEM on BANKINGSYSTEM.ID = FINANCIALINSTITUTION.BANKINGSYSTEMID
                            where 
                                CONSTITUENTACCOUNT.ID = @CONSTITUENTACCOUNTID
                                and BANKINGSYSTEM.CONDITIONSETTINGNAME = 'BankingSystem-SEPA'
                        )
                        begin
                            raiserror('BBERR_SEPAMANDATE_SEPABANKINGSYSTEMREQUIREDFORACCOUNT', 13, 1);
                        end
                    end
                end

                if @BATCHNUMBER is null
                set @BATCHNUMBER = ''

                exec dbo.USP_PAYMENT_ADD @ID output, @CHANGEAGENTID, @CURRENTDATE, @CONSTITUENTID,
                                        @DATE, @AMOUNT, @PAYMENTMETHODCODE, @CHECKDATE, @CHECKNUMBER,
                                        @REFERENCEDATE, @REFERENCENUMBER, @CARDHOLDERNAME, @CREDITCARDNUMBER,
                                        @CREDITTYPECODEID, @AUTHORIZATIONCODE, @EXPIRESON, @ISSUER,
                                        @NUMBEROFUNITS, @SYMBOL, @MEDIANPRICE, @GIFTINKINDSUBTYPECODEID,
                                        @PROPERTYSUBTYPECODEID, @RECEIPTAMOUNT, @CONSTITUENTACCOUNTID,
                                        @REVENUESTREAMS, @POSTSTATUSCODE, @POSTDATE, @FINDERNUMBER,
                                        @SOURCECODE, @APPEALID, @BENEFITS, @BENEFITSWAIVED, @GIVENANONYMOUSLY
                                        @MAILINGID, @CHANNELCODEID, @DONOTACKNOWLEDGE,@DONOTRECEIPT,
                                        @BATCHNUMBER, @OTHERPAYMENTMETHODCODEID, @REFERENCE, @TRIBUTEID, @LETTERCODEID,
                                        @DIRECTDEBITRESULTCODE, @LOWPRICE, @HIGHPRICE, @GIFTINKINDITEMNAME
                                        @GIFTINKINDDISPOSITIONCODE, @GIFTINKINDNUMBEROFUNITS
                                        @GIFTINKINDFAIRMARKETVALUE, @PERCENTAGEBENEFITS, @PDACCOUNTSYSTEMID,
                                        @TRANSACTIONCURRENCYID, @BASECURRENCYID, @BASEEXCHANGERATEID, @EXCHANGERATE, @CURRENTAPPUSERID,
                                        @SEPAMANDATEID, @TRANSACTIONID, @MERCHANTACCOUNTID, @VENDORID;
            end try

            begin catch
                exec dbo.USP_RAISE_ERROR;

                return 1;
            end catch

            return 0;