From 4de73ff7991467269e465e41466939898a48154a Mon Sep 17 00:00:00 2001 From: Tom Karasch Date: Tue, 27 Jan 2026 22:34:26 -0500 Subject: [PATCH 1/6] Events reports page Updates the Events reports page by renaming the report options and adding a reporting repository. This change improves clarity and functionality. --- FMS/Pages/Reporting/Events/Index.cshtml | 30 +++++++++++----------- FMS/Pages/Reporting/Events/Index.cshtml.cs | 8 ++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/FMS/Pages/Reporting/Events/Index.cshtml b/FMS/Pages/Reporting/Events/Index.cshtml index 00bb6d8e..3ca7ca55 100644 --- a/FMS/Pages/Reporting/Events/Index.cshtml +++ b/FMS/Pages/Reporting/Events/Index.cshtml @@ -10,38 +10,38 @@

Select a Report from the list

- - Assignment Report By CO + Pending Report
- - Assignment Report By County + Completed Report
- - Assignment Report By HSI + Compliance Report
- - Assignment Report By Site Name + Completed Outstanding Report
- - Assignment Report By Unit + Overdue Report
\ No newline at end of file diff --git a/FMS/Pages/Reporting/Events/Index.cshtml.cs b/FMS/Pages/Reporting/Events/Index.cshtml.cs index bc477566..8bb16a77 100644 --- a/FMS/Pages/Reporting/Events/Index.cshtml.cs +++ b/FMS/Pages/Reporting/Events/Index.cshtml.cs @@ -1,3 +1,4 @@ +using FMS.Domain.Repositories; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -5,8 +6,15 @@ namespace FMS.Pages.Reporting.Events { public class IndexModel : PageModel { + private readonly IReportingRepository _repository; + + public IndexModel(IReportingRepository repository) => _repository = repository; + public void OnGet() { + // Method intentionally left empty. } + + } } From cc27ba31ca69ef581fe060c9295f62b748ba399d Mon Sep 17 00:00:00 2001 From: Tom Karasch Date: Wed, 28 Jan 2026 08:50:32 -0500 Subject: [PATCH 2/6] Adds Events reports DTOs and repository method Adds several DTOs to support different event reports, including pending, completed, overdue, and compliance. Also, the changes include adding a repository method to retrieve pending events. Moves some of the DTO's to the correct folder. --- FMS.Domain/Dto/Event/EventReportDto.cs | 13 +++++ .../Dto/Reports/DelistedReportByDateDto.cs | 2 +- .../Reports/DelistedReportByDateRangeDto.cs | 2 +- .../EventsCompletedOutstandingReportDto.cs | 12 +++++ .../Dto/Reports/EventsCompletedReportDto.cs | 12 +++++ .../Dto/Reports/EventsComplianceReportDto.cs | 12 +++++ .../Dto/Reports/EventsOverdueReportDto.cs | 12 +++++ .../Dto/Reports/EventsPendingReportDto.cs | 51 +++++++++++++++++++ .../Repositories/IReportingRepository.cs | 3 +- .../Repositories/ReportingRepository.cs | 20 ++++++-- FMS/Helpers/ExportHelper.cs | 4 ++ FMS/Pages/Reporting/Delisted/Index.cshtml.cs | 1 - FMS/Pages/Reporting/Events/Index.cshtml.cs | 15 ++++++ 13 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 FMS.Domain/Dto/Event/EventReportDto.cs create mode 100644 FMS.Domain/Dto/Reports/EventsCompletedOutstandingReportDto.cs create mode 100644 FMS.Domain/Dto/Reports/EventsCompletedReportDto.cs create mode 100644 FMS.Domain/Dto/Reports/EventsComplianceReportDto.cs create mode 100644 FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs create mode 100644 FMS.Domain/Dto/Reports/EventsPendingReportDto.cs diff --git a/FMS.Domain/Dto/Event/EventReportDto.cs b/FMS.Domain/Dto/Event/EventReportDto.cs new file mode 100644 index 00000000..2599fb48 --- /dev/null +++ b/FMS.Domain/Dto/Event/EventReportDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public class EventReportDto + { + + } +} diff --git a/FMS.Domain/Dto/Reports/DelistedReportByDateDto.cs b/FMS.Domain/Dto/Reports/DelistedReportByDateDto.cs index 72796627..eb27c5b6 100644 --- a/FMS.Domain/Dto/Reports/DelistedReportByDateDto.cs +++ b/FMS.Domain/Dto/Reports/DelistedReportByDateDto.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace FMS.Domain.Dto.Reports +namespace FMS.Domain.Dto { public class DelistedReportByDateDto { diff --git a/FMS.Domain/Dto/Reports/DelistedReportByDateRangeDto.cs b/FMS.Domain/Dto/Reports/DelistedReportByDateRangeDto.cs index 20fca53a..d876f6a5 100644 --- a/FMS.Domain/Dto/Reports/DelistedReportByDateRangeDto.cs +++ b/FMS.Domain/Dto/Reports/DelistedReportByDateRangeDto.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace FMS.Domain.Dto.Reports +namespace FMS.Domain.Dto { public class DelistedReportByDateRangeDto { diff --git a/FMS.Domain/Dto/Reports/EventsCompletedOutstandingReportDto.cs b/FMS.Domain/Dto/Reports/EventsCompletedOutstandingReportDto.cs new file mode 100644 index 00000000..c059c82e --- /dev/null +++ b/FMS.Domain/Dto/Reports/EventsCompletedOutstandingReportDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public class EventsCompletedOutstandingReportDto + { + } +} diff --git a/FMS.Domain/Dto/Reports/EventsCompletedReportDto.cs b/FMS.Domain/Dto/Reports/EventsCompletedReportDto.cs new file mode 100644 index 00000000..b33c433b --- /dev/null +++ b/FMS.Domain/Dto/Reports/EventsCompletedReportDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public class EventsCompletedReportDto + { + } +} diff --git a/FMS.Domain/Dto/Reports/EventsComplianceReportDto.cs b/FMS.Domain/Dto/Reports/EventsComplianceReportDto.cs new file mode 100644 index 00000000..ffe0aa42 --- /dev/null +++ b/FMS.Domain/Dto/Reports/EventsComplianceReportDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public class EventsComplianceReportDto + { + } +} diff --git a/FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs b/FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs new file mode 100644 index 00000000..35d39f6f --- /dev/null +++ b/FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public class EventsOverdueReportDto + { + } +} diff --git a/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs b/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs new file mode 100644 index 00000000..78b54350 --- /dev/null +++ b/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs @@ -0,0 +1,51 @@ +using ClosedXML.Attributes; +using FMS.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public class EventsPendingReportDto + { + public EventsPendingReportDto() { } + + public EventsPendingReportDto(EventSummaryDto reportEvent, string hsiid, string facilityName, string unitName) + { + HSIID = hsiid; + FacilityName = facilityName; + EventTypeName = reportEvent.EventType.Name; + EventStartDate = reportEvent.StartDate; + EventDueDate = reportEvent.DueDate; + ComplianceOfficerName = reportEvent.ComplianceOfficer.Name; + UnitName = unitName; + ActivityComment = reportEvent.Comment; + } + + [XLColumn(Header = "HSI ID")] + public string HSIID { get; set; } + + [XLColumn(Header = "Facility Name")] + public string FacilityName { get; set; } + + [XLColumn(Header = "Event Type")] + public string EventTypeName { get; set; } + + [XLColumn(Header = "Event Start Date")] + public DateOnly? EventStartDate { get; set; } + + [XLColumn(Header = "Event Due Date")] + public DateOnly? EventDueDate { get; set; } + + [XLColumn(Header = "Compliance Officer")] + public string ComplianceOfficerName { get; set; } + + [XLColumn(Header = "Unit")] + public string UnitName { get; set; } + + [XLColumn(Header = "Activity Comment")] + public string ActivityComment { get; set; } + } +} diff --git a/FMS.Domain/Repositories/IReportingRepository.cs b/FMS.Domain/Repositories/IReportingRepository.cs index 75840ee2..c8bebe48 100644 --- a/FMS.Domain/Repositories/IReportingRepository.cs +++ b/FMS.Domain/Repositories/IReportingRepository.cs @@ -1,5 +1,4 @@ using FMS.Domain.Dto; -using FMS.Domain.Dto.Reports; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -30,6 +29,8 @@ public interface IReportingRepository : IDisposable #region Events Reports + Task> GetEventsPendingAsync(); + #endregion } } diff --git a/FMS.Infrastructure/Repositories/ReportingRepository.cs b/FMS.Infrastructure/Repositories/ReportingRepository.cs index 42bdd42a..6d2560d6 100644 --- a/FMS.Infrastructure/Repositories/ReportingRepository.cs +++ b/FMS.Infrastructure/Repositories/ReportingRepository.cs @@ -1,10 +1,12 @@ -using FMS.Domain.Dto; -using FMS.Domain.Dto.Reports; +using DocumentFormat.OpenXml.Office2010.Excel; +using FMS.Domain.Dto; +using FMS.Domain.Entities; using FMS.Domain.Repositories; using FMS.Infrastructure.Contexts; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -174,11 +176,23 @@ public async Task> GetDelistedByDate return reportDto; } - #endregion #region Events Reports + public async Task> GetEventsPendingAsync() + { + return await _context.Facilities.AsNoTracking() + .Include(e => e.FacilityType) + .Include(e => e.Events) + .Include(e => e.ComplianceOfficer) + .Include(e => e.OrganizationalUnit) + .OrderBy(e => e.ComplianceOfficer) + .Where(e => (e.FacilityType.Name == "HSI" || e.FacilityType.Name == "VRP")) + .SelectMany(e => e.Events.Where(ev => ev.Active && ev.CompletionDate == null).Select(ev => new EventSummaryDto(ev))) + .ToListAsync(); + } + #endregion #region IDisposable Support diff --git a/FMS/Helpers/ExportHelper.cs b/FMS/Helpers/ExportHelper.cs index 25106f46..5bf7bda0 100644 --- a/FMS/Helpers/ExportHelper.cs +++ b/FMS/Helpers/ExportHelper.cs @@ -72,6 +72,10 @@ public static byte[] ExportExcelAsByteArray(this IEnumerable list, ReportT table.ShowTotalsRow = true; table.Field("Acres").TotalsRowFunction = XLTotalsRowFunction.Sum; } + if (reportType == ReportType.Event) + { + + } wb.SaveAs(ms); diff --git a/FMS/Pages/Reporting/Delisted/Index.cshtml.cs b/FMS/Pages/Reporting/Delisted/Index.cshtml.cs index 52c3db68..408afa30 100644 --- a/FMS/Pages/Reporting/Delisted/Index.cshtml.cs +++ b/FMS/Pages/Reporting/Delisted/Index.cshtml.cs @@ -1,5 +1,4 @@ using FMS.Domain.Dto; -using FMS.Domain.Dto.Reports; using FMS.Domain.Repositories; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; diff --git a/FMS/Pages/Reporting/Events/Index.cshtml.cs b/FMS/Pages/Reporting/Events/Index.cshtml.cs index 8bb16a77..c3790e1b 100644 --- a/FMS/Pages/Reporting/Events/Index.cshtml.cs +++ b/FMS/Pages/Reporting/Events/Index.cshtml.cs @@ -1,6 +1,11 @@ +using DocumentFormat.OpenXml.Wordprocessing; +using FMS.Domain.Dto; using FMS.Domain.Repositories; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace FMS.Pages.Reporting.Events { @@ -15,6 +20,16 @@ public void OnGet() // Method intentionally left empty. } + public async Task OnPostPendingAsync() + { + var fileName = $"Events_Pending_{DateTime.Now:yyyy-MM-dd-HH-mm-ss.FFF}.xlsx"; + + // "delistedByDateRangeReportList" Detailed Facility List to go to a report + IReadOnlyList eventsPendingSummaryList = await _repository.GetEventsPendingAsync(); + + + return File(eventsPendingSummaryList.ExportExcelAsByteArray(ExportHelper.ReportType.Event), "application/vnd.ms-excel", fileName); + } } } From 2758a4c70a068f8d0fc84c19e1418aa8c2916117 Mon Sep 17 00:00:00 2001 From: Tom Karasch Date: Wed, 28 Jan 2026 16:16:12 -0500 Subject: [PATCH 3/6] Sets default end date for delisted report Sets the default end date for the delisted report to the current date. Also, it adds a required field indicator for the "End Date" field on the delisted report page. Commented out events reporting, as it's not part of the current requirements. Relates to 961-add-events-reports --- FMS/Pages/Reporting/Delisted/Index.cshtml | 3 ++- FMS/Pages/Reporting/Delisted/Index.cshtml.cs | 4 +++- FMS/Pages/Reporting/Index.cshtml | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/FMS/Pages/Reporting/Delisted/Index.cshtml b/FMS/Pages/Reporting/Delisted/Index.cshtml index b11c8814..56202e14 100644 --- a/FMS/Pages/Reporting/Delisted/Index.cshtml +++ b/FMS/Pages/Reporting/Delisted/Index.cshtml @@ -36,9 +36,10 @@
- +
+

* denotes required field

\ No newline at end of file diff --git a/FMS/Pages/Reporting/Delisted/Index.cshtml.cs b/FMS/Pages/Reporting/Delisted/Index.cshtml.cs index 408afa30..723be00b 100644 --- a/FMS/Pages/Reporting/Delisted/Index.cshtml.cs +++ b/FMS/Pages/Reporting/Delisted/Index.cshtml.cs @@ -2,6 +2,8 @@ using FMS.Domain.Repositories; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Graph.Drives.Item.Items.Item.Workbook.Functions.Today; +using Microsoft.Kiota.Abstractions; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -21,7 +23,7 @@ public class IndexModel : PageModel [Display(Name = "End Date")] [BindProperty] - public DateOnly? EndDate { get; set; } = null; + public DateOnly? EndDate { get; set; } = DateOnly.FromDateTime(DateTime.Now); public void OnGet() { diff --git a/FMS/Pages/Reporting/Index.cshtml b/FMS/Pages/Reporting/Index.cshtml index 6e8d8ef8..9d2519e2 100644 --- a/FMS/Pages/Reporting/Index.cshtml +++ b/FMS/Pages/Reporting/Index.cshtml @@ -15,7 +15,7 @@
  • @ReportingOptions.Delisted
  • -
  • + @*
  • @ReportingOptions.Events
  • @@ -23,5 +23,5 @@
  • @ReportingOptions.PAF -
  • + *@ \ No newline at end of file From 5c772b2f1d5ec92b8e84d8e0ad804b947cf680ec Mon Sep 17 00:00:00 2001 From: Tom Karasch Date: Wed, 28 Jan 2026 16:21:31 -0500 Subject: [PATCH 4/6] Updates delisted report filename Renames the delisted report filename to more accurately reflect the data included (date range). --- FMS/Pages/Reporting/Delisted/Index.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FMS/Pages/Reporting/Delisted/Index.cshtml.cs b/FMS/Pages/Reporting/Delisted/Index.cshtml.cs index 723be00b..88d5e030 100644 --- a/FMS/Pages/Reporting/Delisted/Index.cshtml.cs +++ b/FMS/Pages/Reporting/Delisted/Index.cshtml.cs @@ -42,7 +42,7 @@ public async Task OnPostByDateAsync() public async Task OnPostByDateRangeAsync() { - var fileName = $"Delisted_by_Date_and_CO_{DateTime.Now:yyyy-MM-dd-HH-mm-ss.FFF}.xlsx"; + var fileName = $"Delisted_by_Date_Range_{DateTime.Now:yyyy-MM-dd-HH-mm-ss.FFF}.xlsx"; // "delistedByDateRangeReportList" Detailed Facility List to go to a report IReadOnlyList delistedByDateRangeReportList = await _repository.GetDelistedByDateRangeAsync(StartDate, EndDate); From fca692d56ceaaef7ffed709c99ea13f55854a244 Mon Sep 17 00:00:00 2001 From: Tom Karasch Date: Wed, 28 Jan 2026 16:28:47 -0500 Subject: [PATCH 5/6] Enables events reports Corrects the display of the events reports link and disables the site summary report for now. Related to 961-add-events-reports --- FMS/Pages/Reporting/Index.cshtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FMS/Pages/Reporting/Index.cshtml b/FMS/Pages/Reporting/Index.cshtml index 9d2519e2..610672e9 100644 --- a/FMS/Pages/Reporting/Index.cshtml +++ b/FMS/Pages/Reporting/Index.cshtml @@ -15,10 +15,10 @@
  • @ReportingOptions.Delisted
  • - @*
  • +
  • @ReportingOptions.Events
  • -
  • + @*
  • @ReportingOptions.SiteSummary
  • From 13d0268727eabff14684a5ad20e23f8caa42e27a Mon Sep 17 00:00:00 2001 From: Tom Karasch Date: Sun, 1 Feb 2026 18:57:47 -0500 Subject: [PATCH 6/6] Adds event reports functionality. Adds functionality to retrieve and display event reports based on different types such as pending, compliance, completed, etc. Also introduces sorting for the event reports. --- FMS.Domain/Dto/Event/EventReportDto.cs | 50 +++++++++++++- FMS.Domain/Dto/Event/EventReportSort.cs | 17 +++++ ...> EventsActivityCompletedByCOReportDto.cs} | 2 +- .../Dto/Reports/EventsPendingReportDto.cs | 14 ++-- .../Repositories/IReportingRepository.cs | 2 +- .../Repositories/ReportingRepository.cs | 38 +++++++++-- FMS/Helpers/EventSortHelper.cs | 66 +++++++++++++++++++ 7 files changed, 175 insertions(+), 14 deletions(-) create mode 100644 FMS.Domain/Dto/Event/EventReportSort.cs rename FMS.Domain/Dto/Reports/{EventsOverdueReportDto.cs => EventsActivityCompletedByCOReportDto.cs} (74%) diff --git a/FMS.Domain/Dto/Event/EventReportDto.cs b/FMS.Domain/Dto/Event/EventReportDto.cs index 2599fb48..5df6244e 100644 --- a/FMS.Domain/Dto/Event/EventReportDto.cs +++ b/FMS.Domain/Dto/Event/EventReportDto.cs @@ -1,5 +1,8 @@ -using System; +using DocumentFormat.OpenXml.Office.Y2022.FeaturePropertyBag; +using FMS.Domain.Entities; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,6 +11,51 @@ namespace FMS.Domain.Dto { public class EventReportDto { + public EventReportDto(Event eventNew) + { + Id = eventNew.Id; + FacilityId = eventNew.FacilityId; + ParentId = eventNew.ParentId; + EventType = eventNew.EventType; + ActionTaken = eventNew.ActionTaken; + StartDate = eventNew.StartDate; + DueDate = eventNew.DueDate; + CompletionDate = eventNew.CompletionDate; + ComplianceOfficer = eventNew.ComplianceOfficer; + EventAmount = eventNew.EventAmount; + EventContractor = eventNew.EventContractor; + Comment = eventNew.Comment; + } + public Guid Id { get; set; } + + public Guid FacilityId { get; set; } + + public Guid? ParentId { get; set; } + + public string FacilityNumber { get; set; } + + public string FacilityName { get; set; } + + public EventType EventType { get; set; } + + public ActionTaken ActionTaken { get; set; } + + public DateOnly? StartDate { get; set; } + + public DateOnly? DueDate { get; set; } + + public DateOnly? CompletionDate { get; set; } + + public ComplianceOfficer ComplianceOfficer { get; set; } + + public OrganizationalUnit OrganizationalUnit { get; set; } + + [DataType(DataType.Currency)] + public decimal? EventAmount { get; set; } + + public EventContractor EventContractor { get; set; } + + public string Comment { get; set; } } } diff --git a/FMS.Domain/Dto/Event/EventReportSort.cs b/FMS.Domain/Dto/Event/EventReportSort.cs new file mode 100644 index 00000000..f1303029 --- /dev/null +++ b/FMS.Domain/Dto/Event/EventReportSort.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FMS.Domain.Dto +{ + public enum EventReportType + { + Pending, + Compliance, + Completed, + CompletedOutstanding, + CompletedByCO, + } +} diff --git a/FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs b/FMS.Domain/Dto/Reports/EventsActivityCompletedByCOReportDto.cs similarity index 74% rename from FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs rename to FMS.Domain/Dto/Reports/EventsActivityCompletedByCOReportDto.cs index 35d39f6f..df0ac410 100644 --- a/FMS.Domain/Dto/Reports/EventsOverdueReportDto.cs +++ b/FMS.Domain/Dto/Reports/EventsActivityCompletedByCOReportDto.cs @@ -6,7 +6,7 @@ namespace FMS.Domain.Dto { - public class EventsOverdueReportDto + public class EventsActivityCompletedByCOReportDto { } } diff --git a/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs b/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs index 78b54350..9d1d3489 100644 --- a/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs +++ b/FMS.Domain/Dto/Reports/EventsPendingReportDto.cs @@ -10,17 +10,17 @@ namespace FMS.Domain.Dto { public class EventsPendingReportDto { - public EventsPendingReportDto() { } + public EventsPendingReportDto() {} - public EventsPendingReportDto(EventSummaryDto reportEvent, string hsiid, string facilityName, string unitName) + public EventsPendingReportDto(EventReportDto reportEvent) { - HSIID = hsiid; - FacilityName = facilityName; - EventTypeName = reportEvent.EventType.Name; + HSIID = reportEvent.FacilityNumber; + FacilityName = reportEvent.FacilityName; + EventTypeName = reportEvent.EventType?.Name; EventStartDate = reportEvent.StartDate; EventDueDate = reportEvent.DueDate; - ComplianceOfficerName = reportEvent.ComplianceOfficer.Name; - UnitName = unitName; + ComplianceOfficerName = reportEvent.ComplianceOfficer?.Name; + UnitName = reportEvent.OrganizationalUnit?.Name; ActivityComment = reportEvent.Comment; } diff --git a/FMS.Domain/Repositories/IReportingRepository.cs b/FMS.Domain/Repositories/IReportingRepository.cs index c8bebe48..5d399fad 100644 --- a/FMS.Domain/Repositories/IReportingRepository.cs +++ b/FMS.Domain/Repositories/IReportingRepository.cs @@ -29,7 +29,7 @@ public interface IReportingRepository : IDisposable #region Events Reports - Task> GetEventsPendingAsync(); + Task> GetEventsReportsAsync(EventReportType eventReportType); #endregion } diff --git a/FMS.Infrastructure/Repositories/ReportingRepository.cs b/FMS.Infrastructure/Repositories/ReportingRepository.cs index 6d2560d6..87a974e2 100644 --- a/FMS.Infrastructure/Repositories/ReportingRepository.cs +++ b/FMS.Infrastructure/Repositories/ReportingRepository.cs @@ -180,17 +180,47 @@ public async Task> GetDelistedByDate #region Events Reports - public async Task> GetEventsPendingAsync() + public async Task> GetEventsReportsAsync(EventReportType eventReportType) { - return await _context.Facilities.AsNoTracking() + List facilityList = await _context.Facilities.AsNoTracking() + .Include(e => e.County) + .Include(e => e.FacilityStatus) + .Include(e => e.HsrpFacilityProperties) + .Include(e => e.HsrpFacilityProperties.ComplianceOfficer) .Include(e => e.FacilityType) .Include(e => e.Events) .Include(e => e.ComplianceOfficer) .Include(e => e.OrganizationalUnit) - .OrderBy(e => e.ComplianceOfficer) .Where(e => (e.FacilityType.Name == "HSI" || e.FacilityType.Name == "VRP")) - .SelectMany(e => e.Events.Where(ev => ev.Active && ev.CompletionDate == null).Select(ev => new EventSummaryDto(ev))) + .SelectMany(e => e.Events.Where(ev => ev.Active) + .Select(ev => new EventReportDto(ev))) .ToListAsync(); + + List reportDto; + + switch (eventReportType) + { + case EventReportType.Pending: + reportDto = facilityList.Where(e => e.Status == "Pending").ToList(); + break; + case EventReportType.Compliance: + reportDto = facilityList.Where(e => e.Status == "Compliance").ToList(); + break; + case EventReportType.Completed: + reportDto = facilityList.Where(e => e.Status == "Completed").ToList(); + break; + case EventReportType.CompletedOutstanding: + reportDto = facilityList.Where(e => e.Status == "CompletedOutstanding").ToList(); + break; + case EventReportType.CompletedByCO: + reportDto = facilityList.Where(e => e.Status == "CompletedByCO").ToList(); + break; + default: + reportDto = facilityList; + break; + } + + return reportDto; } #endregion diff --git a/FMS/Helpers/EventSortHelper.cs b/FMS/Helpers/EventSortHelper.cs index 1e5eaf38..ac3600de 100644 --- a/FMS/Helpers/EventSortHelper.cs +++ b/FMS/Helpers/EventSortHelper.cs @@ -71,5 +71,71 @@ public static IEnumerable OrderEventQuery( _ => events.OrderBy(e => e.StartDate) .ThenByDescending(e => e.DueDate) }; + + + public static IList SortReportEvents(IList events, EventSort sortBy) + { + var sortedList = new List(); + + // Get top-level parents + var topLevelParents = events.Where(e => e.ParentId == Guid.Empty || e.ParentId == null).OrderReportEventQuery(sortBy); + + foreach (var parent in topLevelParents) + { + sortedList.Add(parent); + AddReportChildrenRecursively(parent, events, sortedList, sortBy); + } + + return sortedList; + } + + private static void AddReportChildrenRecursively(EventReportDto parent, IList allEvents, List sortedList, EventSort sortBy) + { + var children = allEvents.Where(c => c.ParentId == parent.Id).OrderReportEventQuery(sortBy); + foreach (var child in children) + { + sortedList.Add(child); + AddReportChildrenRecursively(child, allEvents, sortedList, sortBy); + } + } + + public static IEnumerable OrderReportEventQuery( + this IEnumerable events, EventSort sortBy) => + sortBy switch + { + EventSort.EventType => events.OrderBy(e => e.EventType.Name) + .ThenByDescending(e => e.StartDate), + EventSort.EventTypeDesc => events.OrderByDescending(e => e.EventType.Name) + .ThenByDescending(e => e.StartDate), + EventSort.ActionTaken => events.OrderBy(e => e.ActionTaken.Name) + .ThenBy(e => e.StartDate), + EventSort.ActionTakenDesc => events.OrderByDescending(e => e.ActionTaken.Name) + .ThenByDescending(e => e.StartDate), + EventSort.StartDateDesc => events.OrderByDescending(e => e.StartDate) + .ThenByDescending(e => e.DueDate), + EventSort.DueDate => events.OrderBy(e => e.DueDate) + .ThenBy(e => e.StartDate), + EventSort.DueDateDesc => events.OrderByDescending(e => e.DueDate) + .ThenBy(e => e.StartDate), + EventSort.CompletionDate => events.OrderByDescending(e => e.CompletionDate) + .ThenBy(e => e.EventType.Name), + EventSort.CompletionDateDesc => events.OrderBy(e => e.CompletionDate) + .ThenBy(e => e.EventType.Name), + EventSort.ComplianceOfficer => events.OrderBy(e => e.ComplianceOfficer.Name) + .ThenBy(e => e.EventType.Name), + EventSort.ComplianceOfficerDesc => events.OrderByDescending(e => e.ComplianceOfficer.Name) + .ThenBy(e => e.EventType.Name), + EventSort.EventAmount => events.OrderBy(e => e.EventAmount) + .ThenBy(e => e.EventType.Name), + EventSort.EventAmountDesc => events.OrderByDescending(e => e.EventAmount) + .ThenByDescending(e => e.EventType.Name), + EventSort.EventContractor => events.OrderByDescending(e => e.EventContractor?.Name) + .ThenBy(e => e.EventType.Name), + EventSort.EventContractorDesc => events.OrderBy(e => e.EventContractor?.Name) + .ThenBy(e => e.EventType.Name), + // EventSort.StartDate + _ => events.OrderBy(e => e.StartDate) + .ThenByDescending(e => e.DueDate) + }; } }