UFN_REVENUEBATCH_GETCURRENCYFORAPPLICATION
Looks up the currency for a given revenue batch application.
Return
Return Type |
---|
uniqueidentifier |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@APPLICATIONID | uniqueidentifier | IN | |
@APPLICATIONTYPECODE | tinyint | IN |
Definition
Copy
CREATE function dbo.UFN_REVENUEBATCH_GETCURRENCYFORAPPLICATION(
@APPLICATIONID uniqueidentifier,
@APPLICATIONTYPECODE tinyint
)
returns uniqueidentifier
as
begin
-- Note that a return value of null means the row's currency should be used.
declare @APPLICATIONCURRENCYID uniqueidentifier;
-- NotAnApplication = 0
-- Sponsorship = 1
-- Membership = 2
-- OrderOrReservation = 3
-- RecurringGift = 4
-- Pledge = 5
-- PlannedGift = 6
-- EventRegistration = 7
-- MatchingGiftClaim = 8
-- GrantAward = 9
-- DonorChallenge = 10
-- UNKNOWN = 999
select @APPLICATIONCURRENCYID =
case
when @APPLICATIONTYPECODE in (4, 6, 8, 9, 10) then
(select TRANSACTIONCURRENCYID from dbo.REVENUE where ID = @APPLICATIONID)
when @APPLICATIONTYPECODE = 5 then
(
select TRANSACTIONCURRENCYID from dbo.REVENUE where ID = @APPLICATIONID
union all
select null from dbo.BATCHREVENUEAPPLICATIONPLEDGE where ID = @APPLICATIONID
)
when @APPLICATIONTYPECODE = 7 then
(
select top 1 BASECURRENCYID from (--prevent bad subquery error
select EVENT.BASECURRENCYID
from dbo.REGISTRANT
inner join dbo.EVENT on REGISTRANT.EVENTID = EVENT.ID
where REGISTRANT.ID = @APPLICATIONID
union all
select EVENT.BASECURRENCYID
from dbo.BATCHREVENUEREGISTRANT
inner join dbo.EVENT on BATCHREVENUEREGISTRANT.EVENTID = EVENT.ID
where BATCHREVENUEREGISTRANT.ID = @APPLICATIONID
) as COMPOSITE
)
else null -- Catch-all for applications that are still single-currency
end;
return @APPLICATIONCURRENCYID;
end