diff --git a/services/identity/FlatRender.IdentitySvc/Application/Services/AdminService.cs b/services/identity/FlatRender.IdentitySvc/Application/Services/AdminService.cs index f9ff05f..fe9373b 100644 --- a/services/identity/FlatRender.IdentitySvc/Application/Services/AdminService.cs +++ b/services/identity/FlatRender.IdentitySvc/Application/Services/AdminService.cs @@ -62,16 +62,20 @@ public class AdminService(IdentityDbContext db) public async Task> GetPlanStatisticsAsync(Guid tenantId) { var now = DateTime.UtcNow; - return await db.UserPlans + // Pull flat rows then aggregate in memory — EF can't translate a conditional + // Count(predicate) inside a grouped Select. + var rows = await db.UserPlans .Where(p => p.TenantId == tenantId) - .GroupBy(p => p.PlanName) + .Select(p => new { p.PlanName, p.ExpiresAt, p.CancelledAt, p.PriceMinorPaid }) + .ToListAsync(); + return rows.GroupBy(r => r.PlanName) .Select(g => new PlanStatRow( g.Key, g.Count(), g.Count(x => x.ExpiresAt > now && x.CancelledAt == null), g.Sum(x => x.PriceMinorPaid))) .OrderByDescending(r => r.RevenueMinor) - .ToListAsync(); + .ToList(); } // ── CRM notes / tags ────────────────────────────────────────────────────