UFN_CONSTITUENT_GETRECEIPTPREFERENCE

Returns the receipt preference code for a given constituent.

Return

Return Type
tinyint

Parameters

Parameter Parameter Type Mode Description
@CONSTITUENTID uniqueidentifier IN
@REVENUETYPECODE tinyint IN

Definition

Copy


            CREATE function dbo.UFN_CONSTITUENT_GETRECEIPTPREFERENCE
            (
                @CONSTITUENTID uniqueidentifier,
                @REVENUETYPECODE tinyint = null
            )
            returns tinyint
            with execute as caller
            as begin

                declare @RECEIPTTYPECODE tinyint;
                declare @RETURNCODE tinyint;

                -- check the MAILPREFERENCE table to see if this constituent has overridden the system default mail preferences

                select @RECEIPTTYPECODE = coalesce(RECEIPTTYPECODE,2) from dbo.MAILPREFERENCE where CONSTITUENTID = @CONSTITUENTID and MAILTYPECODE = 5;

                -- use the RECEIPTTYPE from the MAILPREFERENCE table

                if @RECEIPTTYPECODE <> 2
                    set @RETURNCODE = @RECEIPTTYPECODE;
                else

                -- use the RECEIPTTYPE from the system defaults

                begin
                    if @REVENUETYPECODE = 2 -- pledge payment

                        set @RETURNCODE = coalesce((select top 1 PLEDGEPAYMENTPREFERENCECODE from dbo.RECEIPTPREFERENCEINFO), 0);
                    else if @REVENUETYPECODE = 3 -- recurring gift payment

                        set @RETURNCODE = coalesce((select top 1 RECURRINGGIFTPAYMENTPREFERENCECODE from dbo.RECEIPTPREFERENCEINFO), 0);
                    else
                        set @RETURNCODE = 0;
                end

                return @RETURNCODE;
            end