@@ -53,17 +53,24 @@ public class FinanceDashboardService : IFinanceDashboardService
|
||||
DateOnly? from, DateOnly? to, int? ministryId, int? categoryGroupId)
|
||||
{
|
||||
var q = PaidApproved(from, to);
|
||||
if (ministryId.HasValue) q = q.Where(e => e.MinistryId == ministryId.Value);
|
||||
if (categoryGroupId.HasValue) q = q.Where(e => e.CategoryGroupId == categoryGroupId.Value);
|
||||
if (ministryId.HasValue) q = q.Where(e => e.MinistryId == ministryId.Value);
|
||||
|
||||
// Group by the deepest level whose parent id is supplied.
|
||||
// Lines belonging to the scoped (Paid+Approved, optionally ministry-filtered) expenses.
|
||||
var scopedLines = from l in _db.ExpenseLines
|
||||
join e in q on l.ExpenseId equals e.Id
|
||||
select l;
|
||||
|
||||
// Group by the deepest level whose parent id is supplied. Category levels aggregate
|
||||
// over LINES (line amounts); the ministry level uses the header total to avoid
|
||||
// double-counting a multi-line expense across its lines.
|
||||
List<(int Id, decimal Amount)> grouped;
|
||||
if (categoryGroupId.HasValue)
|
||||
grouped = (await q.GroupBy(e => e.SubCategoryId)
|
||||
grouped = (await scopedLines.Where(l => l.CategoryGroupId == categoryGroupId.Value)
|
||||
.GroupBy(l => l.SubCategoryId)
|
||||
.Select(g => new { Id = g.Key, Amount = g.Sum(x => x.Amount) }).ToListAsync())
|
||||
.Select(x => (x.Id, x.Amount)).ToList();
|
||||
else if (ministryId.HasValue)
|
||||
grouped = (await q.GroupBy(e => e.CategoryGroupId)
|
||||
grouped = (await scopedLines.GroupBy(l => l.CategoryGroupId)
|
||||
.Select(g => new { Id = g.Key, Amount = g.Sum(x => x.Amount) }).ToListAsync())
|
||||
.Select(x => (x.Id, x.Amount)).ToList();
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user