diff --git a/SeaHaven.DataServices/Helpers/WorkOrderBoardProjection.cs b/SeaHaven.DataServices/Helpers/WorkOrderBoardProjection.cs index 9ccfbd8..3d43fe3 100644 --- a/SeaHaven.DataServices/Helpers/WorkOrderBoardProjection.cs +++ b/SeaHaven.DataServices/Helpers/WorkOrderBoardProjection.cs @@ -72,12 +72,13 @@ namespace SeaHaven.DataServices.Helpers w.PrimaryDispatchId, w.RowVersion, DispatchRowVersion = w.PrimaryDispatch != null ? w.PrimaryDispatch.RowVersion : null, - // SH-188: aggregate Pending uplifts on every dispatch tied to this WO + // SH-188: aggregate Pending uplifts on every live dispatch tied to this WO // (primary WorkOrderId and multi-WO DispatchWorkOrders links). PendingUpliftCount = context.DispatchUpliftRequests.Count(u => u.Status == "Pending" && (u.IsDeleted == null || u.IsDeleted == false) && u.Dispatch != null + && (u.Dispatch.IsDeleted == null || u.Dispatch.IsDeleted == false) && ( u.Dispatch.WorkOrderId == w.Id || u.Dispatch.DispatchWorkOrders!.Any(link => link.WorkOrderId == w.Id))) diff --git a/SeaHaven.Services/Implementation/WorkOrderDetailService.cs b/SeaHaven.Services/Implementation/WorkOrderDetailService.cs index c8f47e7..0bb6eac 100644 --- a/SeaHaven.Services/Implementation/WorkOrderDetailService.cs +++ b/SeaHaven.Services/Implementation/WorkOrderDetailService.cs @@ -128,6 +128,7 @@ namespace SeaHaven.Services.Implementation PrimaryDispatchId = row.PrimaryDispatchId, RowVersion = row.RowVersion, DispatchRowVersion = row.DispatchRowVersion, + PendingUpliftCount = row.PendingUpliftCount, Description = extended?.Description, Trade = extended?.Trade, Problem = extended?.Problem, diff --git a/SeaHavenIndustries.Tests/WorkOrderBoardServiceTests.cs b/SeaHavenIndustries.Tests/WorkOrderBoardServiceTests.cs index bda4319..92c4d36 100644 --- a/SeaHavenIndustries.Tests/WorkOrderBoardServiceTests.cs +++ b/SeaHavenIndustries.Tests/WorkOrderBoardServiceTests.cs @@ -319,6 +319,56 @@ public class WorkOrderBoardPendingUpliftTests Assert.Equal(2, result.ScheduledRows[0].Id); Assert.Equal(1, result.ScheduledRows[0].PendingUpliftCount); } + + [Fact] + public async Task GetBoardRows_PendingUpliftOnSoftDeletedDispatch_DoesNotCount() + { + await using var context = CreateContext(); + var weekStart = new DateOnly(2026, 6, 22); + + context.Vendors.Add(new Vendor { Id = 1, CompanyName = "Acme HVAC" }); + context.Dispatches.Add(new Dispatch + { + Id = 10, + VendorId = 1, + WorkOrderId = 1, + ScheduledDate = new DateTime(2026, 6, 24, 8, 0, 0), + IsDeleted = true + }); + context.workOrders.Add(new WorkOrder + { + Id = 1, + InternalWONumber = "10000000001", + ScheduledDate = new DateTime(2026, 6, 23), + LifecycleStatus = LifecycleStatus.Scheduled, + PrimaryDispatchId = 10, + SiteCode = "BK5" + }); + context.DispatchUpliftRequests.Add(new DispatchUpliftRequest + { + Id = 100, + DispatchId = 10, + RequestedNTE = 1500m, + Status = "Pending", + RequiredTier = 1, + NotificationStatus = "Pending" + }); + await context.SaveChangesAsync(); + + var service = new WorkOrderBoardDataService(context); + var result = await service.GetBoardRowsAsync(new WorkOrderBoardQuery( + weekStart, + weekStart.AddDays(4), + null, + false, + null, + false, + null, + null)); + + Assert.Single(result.ScheduledRows); + Assert.Equal(0, result.ScheduledRows[0].PendingUpliftCount); + } } public class WorkOrderBoardServiceTests diff --git a/SeaHavenIndustries.Tests/WorkOrderPhase6Tests.cs b/SeaHavenIndustries.Tests/WorkOrderPhase6Tests.cs index 8eeb94e..d6bd47e 100644 --- a/SeaHavenIndustries.Tests/WorkOrderPhase6Tests.cs +++ b/SeaHavenIndustries.Tests/WorkOrderPhase6Tests.cs @@ -170,6 +170,46 @@ public class WorkOrderDetailServiceTests Assert.Equal("WeekRolled", detail.Audit[0].Action); } + [Fact] + public async Task GetDetail_SurfacesPendingUpliftCountFromBoardRow() + { + var (context, service) = CreateSut(); + + context.Vendors.Add(new Vendor { Id = 1, CompanyName = "Acme HVAC" }); + context.Dispatches.Add(new Dispatch + { + Id = 10, + VendorId = 1, + WorkOrderId = 1, + ScheduledDate = new DateTime(2026, 6, 24, 8, 0, 0) + }); + context.workOrders.Add(new WorkOrder + { + Id = 1, + InternalWONumber = "10000000001", + LifecycleStatus = LifecycleStatus.Scheduled, + ScheduledDate = DateTime.UtcNow.AddDays(1), + PrimaryDispatchId = 10, + SiteCode = "BK5", + RowVersion = new byte[] { 1, 0, 0, 0, 0, 0, 0, 1 } + }); + context.DispatchUpliftRequests.Add(new DispatchUpliftRequest + { + Id = 100, + DispatchId = 10, + RequestedNTE = 1500m, + Status = "Pending", + RequiredTier = 1, + NotificationStatus = "Pending" + }); + await context.SaveChangesAsync(); + + var detail = await service.GetDetailAsync(1, WorkOrderAccountTestHelpers.OrgWideAdmin()); + + Assert.NotNull(detail); + Assert.Equal(1, detail!.Info.PendingUpliftCount); + } + [Fact] public async Task GetAudit_ResolvesAssignToUserIdsToDisplayNames() {