spTeamDonations
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@TeamID | int | IN | |
@SortBy | int | IN | |
@SortOrder | int | IN |
Definition
Copy
CREATE PROCEDURE [dbo].[spTeamDonations]
(
@TeamID int,
@SortBy int = 0,
@SortOrder int = 1
)
AS
declare @Temp table([ID] int,
Amount money,
IsOffline bit,
DonationTransactionsID int,
CurrencyType int,
IsAthon bit,
InvoiceDate datetime,
InvoicePaid bit,
PledgeID int,
SolicitorID int,
GiftBackOfficeID int,
IsChangeBucket bit,
DateAdded datetime,
DateProcessed datetime,
IsDeleted bit)
insert into @Temp
SELECT fd.[ID],
fd.Amount,
fd.IsOffline,
fd.DonationTransactionsID,
fd.CurrencyType,
fd.IsAthon,
fd.InvoiceDate,
fd.InvoicePaid,
fd.PledgeID,
fd.SolicitorID,
fd.GiftBackOfficeID,
fd.IsChangeBucket,
dt.DateAdded,
dt.processed_date DateProcessed,
dt.IsDeleted
from dbo.fnFundRaiserTeamSolicitors(@TeamID, 0, 0) frts --sterling parameters 2 and 3 are irrelevant now
inner join dbo.FundRaiserSolicitors frs on frs.ID = frts.SolicitorID
inner join dbo.FundRaiserDonations fd on fd.solicitorid = frs.id
inner join dbo.DonationTransactions dt on dt.status = 1 and dt.DonationTransactionsID = fd.DonationTransactionsID
order by
case
when @SortOrder = 1 then null
when @SortBy = 0 then dt.DateAdded
when @SortBy = 1 then case fd.IsAthon when 0 then fd.Amount else fd.Amount * frs.AthonUnits end
end asc,
case
when @SortOrder = 0 then null
when @SortBy = 0 then dt.DateAdded
when @SortBy = 1 then case fd.IsAthon when 0 then fd.Amount else fd.Amount * frs.AthonUnits end
end desc
delete from @Temp
where exists (select 'null' from dbo.FundRaiserDonations fd where fd.PledgeID = ID)
select * from @Temp
RETURN