Skip to content

Commit 968ff74

Browse files
Refactors dashboard queries for accuracy (#920) (#921)
1 parent 112898d commit 968ff74

20 files changed

Lines changed: 69 additions & 755 deletions

src/Application/Features/Dashboard/Queries/GetEducationAndTrainings.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public async Task<Result<EducationAndTrainingDto>> Handle(Query request, Cancell
2323
var query = from mi in context.EducationPayments
2424
join ap in context.Activities on mi.ActivityId equals ap.Id
2525
join l in context.Locations on mi.LocationId equals l.Id
26-
where mi.ActivityApproved >= request.StartDate &&
27-
mi.ActivityApproved <= request.EndDate
26+
where mi.PaymentPeriod >= request.StartDate &&
27+
mi.PaymentPeriod <= request.EndDate
28+
&& mi.EligibleForPayment
2829
select new { mi, ap, l };
2930

3031
// Checks and applies filter based on UserId or TenantId else throws exception
@@ -45,7 +46,6 @@ group x.mi by x.l into grp
4546
select new LocationDetail(
4647
grp.Key.Name,
4748
grp.Key.LocationType,
48-
grp.Count(mi => mi.EligibleForPayment),
4949
grp.Count()
5050
);
5151

@@ -63,24 +63,18 @@ public EducationAndTrainingDto(LocationDetail[] details)
6363
{
6464
Details = details;
6565

66-
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.TotalCount);
67-
CustodyPayable = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
68-
69-
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.TotalCount);
70-
CommunityPayable = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
71-
66+
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
67+
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
68+
7269
}
7370

7471
public LocationDetail[] Details { get; }
7572

7673
public int Custody { get; }
77-
public int CustodyPayable { get; }
78-
7974
public int Community { get; }
80-
public int CommunityPayable { get; }
81-
75+
8276
}
8377

84-
public record LocationDetail(string LocationName, LocationType LocationType, int Payable, int TotalCount);
78+
public record LocationDetail(string LocationName, LocationType LocationType, int Payable);
8579

8680
}

src/Application/Features/Dashboard/Queries/GetEmployments.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public async Task<Result<EmploymentsDto>> Handle(Query request, CancellationToke
2323
var query = from mi in context.EmploymentPayments
2424
join ap in context.Activities on mi.ActivityId equals ap.Id
2525
join l in context.Locations on mi.LocationId equals l.Id
26-
where mi.ActivityApproved >= request.StartDate &&
27-
mi.ActivityApproved <= request.EndDate
26+
where mi.PaymentPeriod >= request.StartDate &&
27+
mi.PaymentPeriod <= request.EndDate
28+
&& mi.EligibleForPayment
2829
select new { mi, ap, l };
2930

3031
// Checks and applies filter based on UserId or TenantId else throws exception
@@ -45,7 +46,6 @@ group x.mi by x.l into grp
4546
select new LocationDetail(
4647
grp.Key.Name,
4748
grp.Key.LocationType,
48-
grp.Count(mi => mi.EligibleForPayment),
4949
grp.Count()
5050
);
5151

@@ -62,25 +62,16 @@ public record EmploymentsDto
6262
public EmploymentsDto(LocationDetail[] details)
6363
{
6464
Details = details;
65-
66-
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.TotalCount);
67-
CustodyPayable = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
68-
69-
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.TotalCount);
70-
CommunityPayable = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
71-
65+
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
66+
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
7267
}
7368

7469
public LocationDetail[] Details { get; }
7570

7671
public int Custody { get; }
77-
public int CustodyPayable { get; }
78-
7972
public int Community { get; }
80-
public int CommunityPayable { get; }
81-
8273
}
8374

84-
public record LocationDetail(string LocationName, LocationType LocationType, int Payable, int TotalCount);
75+
public record LocationDetail(string LocationName, LocationType LocationType, int Payable);
8576

8677
}

src/Application/Features/Dashboard/Queries/GetInductions.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public async Task<Result<InductionsDto>> Handle(Query request, CancellationToken
2222
var context = unitOfWork.DbContext;
2323

2424
var baseQuery = context.InductionPayments
25-
.Where(mi => mi.Approved >= request.StartDate &&
26-
mi.Approved <= request.EndDate);
25+
.Where(mi => mi.PaymentPeriod >= request.StartDate &&
26+
mi.PaymentPeriod <= request.EndDate)
27+
.Where(mi => mi.EligibleForPayment);
2728

2829
// Checks and applies filter based on UserId or TenantId else throws exception
2930
baseQuery = request switch
@@ -42,10 +43,9 @@ join l in context.Locations on mi.LocationId equals l.Id
4243
group mi by l into grp
4344
orderby grp.Key.Name, grp.Key.LocationType
4445
select new LocationDetail(
45-
grp.Key.Name,
46-
grp.Key.LocationType,
47-
grp.Count(mi => mi.EligibleForPayment),
48-
grp.Count()
46+
LocationName: grp.Key.Name,
47+
LocationType: grp.Key.LocationType,
48+
Payable: grp.Count()
4949
);
5050

5151
var results = await query
@@ -61,25 +61,15 @@ public record InductionsDto
6161
public InductionsDto(LocationDetail[] details)
6262
{
6363
Details = details;
64-
65-
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.TotalCount);
66-
CustodyPayable = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
67-
68-
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.TotalCount);
69-
CommunityPayable = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
70-
64+
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
65+
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
7166
}
7267

7368
public LocationDetail[] Details { get; }
74-
7569
public int Custody { get; }
76-
public int CustodyPayable { get; }
77-
7870
public int Community { get; }
79-
public int CommunityPayable { get; }
80-
8171
}
8272

83-
public record LocationDetail(string LocationName, LocationType LocationType, int Payable, int TotalCount);
73+
public record LocationDetail(string LocationName, LocationType LocationType, int Payable);
8474

8575
}

src/Application/Features/Dashboard/Queries/GetPaidActivitiesPerSupportWorker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public async Task<Result<PaidActivitiesDto>> Handle(Query request, CancellationT
2323
join ap in context.Activities on mi.ActivityId equals ap.Id
2424
join l in context.Locations on mi.LocationId equals l.Id
2525
where mi.EligibleForPayment &&
26-
mi.ActivityApproved >= request.StartDate &&
27-
mi.ActivityApproved <= request.EndDate
26+
mi.PaymentPeriod >= request.StartDate &&
27+
mi.PaymentPeriod <= request.EndDate
2828
select new { mi, ap, l };
2929

3030
// Checks and applies filter based on UserId or TenantId else throws exception

src/Application/Features/Dashboard/Queries/GetReassessments.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public async Task<Result<ReassessmentsDto>> Handle(Query request, CancellationTo
2222
var context = unitOfWork.DbContext;
2323

2424
var baseQuery = context.ReassessmentPayments
25-
.Where(mi => mi.AssessmentCompleted >= request.StartDate &&
26-
mi.AssessmentCompleted < request.EndDate.AddDays(1).Date);
25+
.Where(mi => mi.PaymentPeriod >= request.StartDate &&
26+
mi.PaymentPeriod < request.EndDate.AddDays(1).Date)
27+
.Where(mi => mi.EligibleForPayment);
2728

2829
// Checks and applies filter based on UserId or TenantId else throws exception
2930
baseQuery = request switch
@@ -41,10 +42,9 @@ public async Task<Result<ReassessmentsDto>> Handle(Query request, CancellationTo
4142
join l in context.Locations on mi.LocationId equals l.Id
4243
group mi by l into grp
4344
orderby grp.Key.Name, grp.Key.LocationType
44-
select new Details(
45+
select new LocationDetails(
4546
grp.Key.Name,
4647
grp.Key.LocationType,
47-
grp.Count(mi => mi.EligibleForPayment),
4848
grp.Count()
4949
);
5050

@@ -58,27 +58,22 @@ group mi by l into grp
5858

5959
public record ReassessmentsDto
6060
{
61-
public ReassessmentsDto(Details[] details)
61+
public ReassessmentsDto(LocationDetails[] details)
6262
{
6363
Details = details;
6464

65-
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.TotalCount);
66-
CustodyPayable = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
67-
68-
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.TotalCount);
69-
CommunityPayable = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
65+
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
66+
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
7067
}
7168

72-
public Details[] Details { get; }
69+
public LocationDetails[] Details { get; }
7370

7471
public int Custody { get; }
75-
public int CustodyPayable { get; }
7672

7773
public int Community { get; }
78-
public int CommunityPayable { get; }
7974

8075
}
8176

82-
public record Details(string LocationName, LocationType LocationType, int Payable, int TotalCount);
77+
public record LocationDetails(string LocationName, LocationType LocationType, int Payable);
8378

8479
}

src/Application/Features/Dashboard/Queries/GetSupportReferrals.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public async Task<Result<SupportAndReferralDto>> Handle(Query request, Cancellat
2222
var context = unitOfWork.DbContext;
2323

2424
var baseQuery = context.SupportAndReferralPayments
25-
.Where(mi => mi.Approved >= request.StartDate &&
26-
mi.Approved <= request.EndDate);
25+
.Where(mi => mi.PaymentPeriod >= request.StartDate &&
26+
mi.PaymentPeriod <= request.EndDate)
27+
.Where(mi => mi.EligibleForPayment);
2728

2829
// Checks and applies filter based on UserId or TenantId else throws exception
2930
baseQuery = request switch
@@ -50,7 +51,6 @@ join l in context.Locations on mi.LocationId equals l.Id
5051
g.Key.Name,
5152
g.Key.LocationType,
5253
g.Key.SupportType,
53-
g.Count(mi => mi.EligibleForPayment),
5454
g.Count()
5555
);
5656

@@ -69,8 +69,8 @@ public SupportAndReferralDto(LocationDetail[] details)
6969
{
7070
Details = details;
7171

72-
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.TotalCount);
73-
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.TotalCount);
72+
Custody = details.Where(d => d.LocationType.IsCustody).Sum(d => d.Payable);
73+
Community = details.Where(d => d.LocationType.IsCommunity).Sum(d => d.Payable);
7474
}
7575

7676
public LocationDetail[] Details { get; }
@@ -82,6 +82,5 @@ public record LocationDetail(
8282
string LocationName,
8383
LocationType LocationType,
8484
string SupportType,
85-
int Payable,
86-
int TotalCount);
85+
int Payable);
8786
}

src/Server.UI/Components/Dashboard/ApprovedActivityDashboardComponent.razor

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)