diff --git a/Marco.Pms.Services/Controllers/DashboardController.cs b/Marco.Pms.Services/Controllers/DashboardController.cs index 901027b..4cf27de 100644 --- a/Marco.Pms.Services/Controllers/DashboardController.cs +++ b/Marco.Pms.Services/Controllers/DashboardController.cs @@ -618,9 +618,6 @@ namespace Marco.Pms.Services.Controllers [HttpGet("expense/monthly")] public async Task GetExpenseReportByProjectsAsync([FromQuery] Guid? projectId, [FromQuery] Guid? categoryId, [FromQuery] int months) { - months = 0 - months; - var end = DateTime.UtcNow.Date; - var start = end.AddMonths(months); // inclusive EOD try { @@ -630,15 +627,22 @@ namespace Marco.Pms.Services.Controllers .Where(e => e.TenantId == tenantId && e.IsActive - && e.StatusId != Draft - && e.TransactionDate >= start - && e.TransactionDate <= end); // [Server Filters] + && e.StatusId != Draft); // [Server Filters] + + if (months != 0) + { + months = 0 - months; + var end = DateTime.UtcNow.Date; + var start = end.AddMonths(months); // inclusive EOD + baseQuery = baseQuery.Where(e => e.TransactionDate >= start + && e.TransactionDate <= end); + } if (projectId.HasValue) - baseQuery.Where(e => e.ProjectId == projectId); + baseQuery = baseQuery.Where(e => e.ProjectId == projectId); if (categoryId.HasValue) - baseQuery.Where(e => e.ExpensesTypeId == categoryId); + baseQuery = baseQuery.Where(e => e.ExpensesTypeId == categoryId); // Single server-side group/aggregate by project var report = await baseQuery