UFN_REVENUESPLITGIFTAID_DISTRIBUTIONCHANGED
Determines if the GL distributions have changed for a given revenue split gift aid record.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@REVENUESPLITGIFTAIDID | uniqueidentifier | IN | |
@DISTRIBUTION | xml | IN |
Definition
Copy
create function dbo.UFN_REVENUESPLITGIFTAID_DISTRIBUTIONCHANGED
(
@REVENUESPLITGIFTAIDID as uniqueidentifier,
@DISTRIBUTION as xml
)
returns bit
with execute as caller
as
begin
declare @DISTRIBUTIONTABLE table
(
ID uniqueidentifier,
AMOUNT money,
TRANSACTIONTYPECODE tinyint,
ACCOUNT nvarchar(100),
PROJECT nvarchar(100)
);
declare @NEWDISTRIBUTIONTABLE table
(
ID uniqueidentifier,
AMOUNT money,
TRANSACTIONTYPECODE tinyint,
ACCOUNT nvarchar(100),
PROJECT nvarchar(100)
);
declare @DISTCOUNT int
declare @CHANGED as bit
set @CHANGED = 0;
if @CHANGED = 0
begin
insert into @NEWDISTRIBUTIONTABLE(ID, AMOUNT, TRANSACTIONTYPECODE, ACCOUNT, PROJECT)
select ID, AMOUNT, TRANSACTIONTYPECODE, ACCOUNT, PROJECT from dbo.UFN_REVENUESPLITGIFTAID_GETGLDISTRIBUTION_FROMITEMLISTXML(@DISTRIBUTION);
insert into @DISTRIBUTIONTABLE(ID, AMOUNT, TRANSACTIONTYPECODE, ACCOUNT, PROJECT)
select ID, AMOUNT, TRANSACTIONTYPECODE, ACCOUNT, PROJECT from dbo.GIFTAIDGLDISTRIBUTION where REVENUESPLITGIFTAIDID = @REVENUESPLITGIFTAIDID;
select @DISTCOUNT = count(ID) from @DISTRIBUTIONTABLE;
if @DISTCOUNT <> (select count(ID) from @NEWDISTRIBUTIONTABLE)
set @CHANGED = 1;
if @CHANGED = 0
begin
select @DISTCOUNT = count([NEW].ID)
from @NEWDISTRIBUTIONTABLE as [NEW]
inner join @DISTRIBUTIONTABLE as [OLD]
on [NEW].AMOUNT = [OLD].AMOUNT
and ([NEW].TRANSACTIONTYPECODE = [OLD].TRANSACTIONTYPECODE or ([NEW].TRANSACTIONTYPECODE is null and [OLD].TRANSACTIONTYPECODE is null))
and ([NEW].ACCOUNT = [OLD].ACCOUNT or ([NEW].ACCOUNT is null and [OLD].ACCOUNT is null))
and ([NEW].PROJECT = [OLD].PROJECT or ([NEW].PROJECT is null and [OLD].PROJECT is null));
if @DISTCOUNT <> (select count(ID) from @NEWDISTRIBUTIONTABLE)
set @CHANGED = 1;
end
end
return @CHANGED
end