11-- roles=Finance
22-- class=TotalsByFund
33
4+
45DECLARE @ProjectOfMonthFund AS int ;
56DECLARE @RegistrationIncomeFund AS int ;
67
@@ -10,7 +11,7 @@ SET @ProjectOfMonthFund = 25;
1011-- Donations, except Project of the Month
1112SELECT
1213 t .BatchRef AS BatchId,
13- bht .Code as Typ,
14+ COALESCE ( bht .Code , IIF ( c . ContributionTypeId = 6 , ' Ret' , ' Fail' )) as Typ,
1415 CONVERT (VARCHAR , c .ContributionDate , 101 ) AS ContribDate,
1516 CONVERT (VARCHAR , t .Settled , 101 ) as SettleDate,
1617 c .FundId ,
@@ -30,8 +31,18 @@ FROM Contribution AS c
3031WHERE c .FundId <> @ProjectOfMonthFund
3132 AND c .ContributionTypeId <> 99
3233 AND c .ContributionDate >= @StartDate AND c .ContributionDate < dateadd (day , 1 , @EndDate)
33- AND bh .BundleStatusId = 0
34- GROUP BY t .BatchRef , bht .Code , CONVERT (VARCHAR , c .ContributionDate , 101 ), CONVERT (VARCHAR , t .Settled , 101 ), c .FundId , cf .FundName , cf .FundAccountCode , cf .FundIncomeAccount , cf .FundIncomeDept , cf .FundIncomeFund
34+ AND (bh .BundleStatusId = 0 OR c .ContributionTypeId = 6 OR c .ContributionStatusId = 2 )
35+ GROUP BY
36+ t .BatchRef ,
37+ COALESCE (bht .Code , IIF (c .ContributionTypeId = 6 , ' Ret' , ' Fail' )),
38+ CONVERT (VARCHAR , c .ContributionDate , 101 ),
39+ CONVERT (VARCHAR , t .Settled , 101 ),
40+ c .FundId ,
41+ cf .FundName ,
42+ cf .FundAccountCode ,
43+ cf .FundIncomeAccount ,
44+ cf .FundIncomeDept ,
45+ cf .FundIncomeFund
3546
3647UNION ALL
3748
@@ -58,17 +69,18 @@ FROM Contribution AS c
5869 LEFT JOIN BundleHeader AS bh on bd .BundleHeaderId = bh .BundleHeaderId
5970 LEFT JOIN lookup .BundleHeaderTypes AS bht on bht .Id = bh .BundleHeaderTypeId
6071WHERE c .FundId <> @ProjectOfMonthFund
72+ AND c .PeopleId = 33643
6173 AND c .ContributionTypeId = 99
6274 AND c .ContributionDate >= @StartDate AND c .ContributionDate < dateadd (day , 1 , @EndDate)
63- AND bh .BundleStatusId = 0
75+ AND ( bh .BundleStatusId = 0 OR c . ContributionTypeId = 6 OR c . ContributionStatusId = 2 )
6476GROUP BY t .BatchRef , bht .Code , CONVERT (VARCHAR , c .ContributionDate , 101 ), CONVERT (VARCHAR , t .Settled , 101 ), oe .Data , o .OrganizationName
6577
6678UNION ALL
6779
6880-- Project of the Month
6981SELECT
7082 t .BatchRef as BatchId,
71- bht .Code as Typ,
83+ COALESCE ( bht .Code , IIF ( c . ContributionTypeId = 6 , ' Ret' , ' Fail' )) as Typ,
7284 CONVERT (VARCHAR , c .ContributionDate , 101 ) AS ContribDate,
7385 CONVERT (VARCHAR , t .Settled , 101 ) as SettleDate,
7486 c .FundId ,
@@ -86,8 +98,19 @@ FROM Contribution AS c
8698 LEFT JOIN BundleHeader AS bh on bd .BundleHeaderId = bh .BundleHeaderId
8799 LEFT JOIN lookup .BundleHeaderTypes AS bht on bht .Id = bh .BundleHeaderTypeId
88100WHERE c .FundId = @ProjectOfMonthFund
101+ AND c .PeopleId = 33643
89102 AND c .ContributionDate >= @StartDate AND c .ContributionDate < dateadd (day , 1 , @EndDate)
90103 AND bh .BundleStatusId = 0
91- GROUP BY t .BatchRef , bht .Code , CONVERT (VARCHAR , c .ContributionDate , 101 ), CONVERT (VARCHAR , t .Settled , 101 ), c .FundId , FORMAT (c .ContributionDate , ' Y' , ' en-US' ), cf .FundName , cf .FundAccountCode , cf .FundIncomeAccount , cf .FundIncomeDept , cf .FundIncomeFund
104+ GROUP BY
105+ t .BatchRef ,
106+ COALESCE (bht .Code , IIF (c .ContributionTypeId = 6 , ' Ret' , ' Fail' )),
107+ CONVERT (VARCHAR , c .ContributionDate , 101 ),
108+ CONVERT (VARCHAR , t .Settled , 101 ),
109+ c .FundId ,
110+ CONCAT (cf .FundName , ' (' , FORMAT (c .ContributionDate , ' Y' , ' en-US' ), ' )' ),
111+ cf .FundAccountCode ,
112+ cf .FundIncomeAccount ,
113+ cf .FundIncomeDept ,
114+ cf .FundIncomeFund
92115
93116ORDER BY ContribDate ASC , Typ ASC , BatchId ASC , FundId ASC
0 commit comments