UFN_RECURRINGGIFTELIGIBILITYSTATUS

Gets the tax claim eligibility status code of a recurring gift record.

Return

Return Type
tinyint

Parameters

Parameter Parameter Type Mode Description
@REVENUEID uniqueidentifier IN

Definition

Copy


            /* 
                Status codes:
                    0 - No valid declaration
                    1 - Declaration is not eligible for split
                    2 - Constituent has valid declaration for split
                    3 - Split is covenant gift
            */
            create function dbo.UFN_RECURRINGGIFTELIGIBILITYSTATUS
            (
                @REVENUEID uniqueidentifier
            )
            returns tinyint
            with execute as caller
            as begin
                declare @ELIGIBILITYSTATUSCODE tinyint

                ; with CTE_SPLITANDELIGIBILITYSTATUSCODE as
                (
                    select 
                        dbo.UFN_GIFTAIDREVENUESPLIT_GETTAXCLAIMELIGIBILITYSTATUS(REVENUESPLIT.ID) as STATUSCODE
                    from dbo.REVENUESPLITGIFTAID
                    inner join dbo.REVENUESPLIT on REVENUESPLITGIFTAID.ID = REVENUESPLIT.ID
                    where REVENUESPLIT.REVENUEID = @REVENUEID
                )
                select top 1
                    @ELIGIBILITYSTATUSCODE = STATUSCODE
                from CTE_SPLITANDELIGIBILITYSTATUSCODE
                where
                    STATUSCODE in (1, 2, 3)
                order by
                    case 
                        when STATUSCODE = 2 then 1
                        when STATUSCODE = 3 then 2
                        when STATUSCODE = 1 then 3
                    end

                return coalesce(@ELIGIBILITYSTATUSCODE, 0);
            end