mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 22:23:12 +00:00
Brings in dev's Phase 5 (PR #17) + vendor PRs (#25/#28/#29) atop the Phase 6/7 + flagColor base (PR #22). Preserves dev Phase 1-5 behavior and PR #22 Phase 6/7 + flagColor behavior. Conflict resolutions (16 files): - Migrations Phase4_SearchIndexes/.Designer + Phase5_DomainEvents/.Designer: take dev (Phase4 incl. SQL Server SiteCode/InternalWONumber index-compat shrink fix; Phase5 identical). ModelSnapshot union: Vendor CompanyId index + Phase7 ServiceNotes/ExternalWorkOrderId index. - ApplicationDbContext: keep dev SiteCode/InternalWONumber MaxLength (Phase1-5 + unguarded model test) + HEAD CompletionDocTemplate/ExternalWorkOrderId. - WorkOrderAuditService: unify on dev async staging API; convert Phase6 CompletionService 2 call sites to await StageFieldChangedAsync (drops HEAD sync duplicate; only callers, no test refs). - Hosted services: take HEAD (retry-on-failure, coherent with Phase7 WorkOrderJobRunStateAccessor/OpsHealth). Program.cs keeps dev vendor DI (ClamAV/VendorDocumentScanWorker/ArgumentExceptionFilter) + HEAD Phase7. - WorkOrderController: keep HEAD Phase6/7 service params + dev doc comment. - VendorController/WorkOrderBoardCreateService/QueryFilters/appsettings: union / dev-correct. - WorkOrderBoardUpdateServiceTests: union of HEAD (Phase6/7+flagColor) and dev (Phase1-5) test methods. Verified WorkOrderType.Other (enum 99) is a legit category, not an overdue sentinel; overdue uses dedicated OperationalFlags.PastDue + IsPastDue, and 'Overdue' is rejected as a WorkOrderType (no PR #23 import needed). Removed dev duplicate Api.Options.WorkOrderJobRunState (HEAD defines it in Services.Implementation alongside the Accessor; Services cannot reference Api).
127 lines
5.2 KiB
C#
127 lines
5.2 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
|
|
namespace SeaHaven.DataServices.Helpers
|
|
{
|
|
public static class WorkOrderBoardProjection
|
|
{
|
|
public static async Task<IReadOnlyList<WorkOrderBoardRawRow>> ProjectRowsAsync(
|
|
IQueryable<WorkOrder> query,
|
|
bool isUnscheduled)
|
|
{
|
|
var rows = await query
|
|
.Select(w => new
|
|
{
|
|
w.Id,
|
|
w.InternalWONumber,
|
|
w.RescheduleCount,
|
|
w.CarriedOver,
|
|
w.WorkOrderType,
|
|
w.SiteCode,
|
|
LocationName = w.Locations != null ? w.Locations.Name : null,
|
|
WoPocName = w.PocName,
|
|
WoPocPhone = w.PocPhone,
|
|
WoPocNotes = w.PocNotes,
|
|
ContactPoc = w.WorkOrderContacts!
|
|
.OrderBy(c => c.Id)
|
|
.Select(c => new
|
|
{
|
|
Name = c.POC != null
|
|
? ((c.POC.FirstName ?? "") + " " + (c.POC.LastName ?? "")).Trim()
|
|
: null,
|
|
PhoneNumber = c.POC != null ? c.POC.PhoneNumber : null,
|
|
c.Notes
|
|
})
|
|
.FirstOrDefault(),
|
|
w.LifecycleStatus,
|
|
w.LegacyStatus,
|
|
w.Status,
|
|
w.AssignTo,
|
|
w.AssignToUser!.FirstName,
|
|
w.AssignToUser!.LastName,
|
|
w.AssignToUser!.Initials,
|
|
w.AssignToUser!.Color,
|
|
w.DueDate,
|
|
w.ScheduledDate,
|
|
w.ScheduledStart,
|
|
w.ScheduledEnd,
|
|
w.TargetWeek,
|
|
w.ScheduleWeekOnly,
|
|
VendorId = w.PrimaryDispatch != null ? (int?)w.PrimaryDispatch.VendorId : null,
|
|
VendorName = w.PrimaryDispatch != null && w.PrimaryDispatch.Vendor != null
|
|
? w.PrimaryDispatch.Vendor.CompanyName
|
|
: null,
|
|
TechName = w.PrimaryDispatch != null && w.PrimaryDispatch.Vendor != null
|
|
? w.PrimaryDispatch.Vendor.ContactName
|
|
: null,
|
|
DispatchTechPhone = w.PrimaryDispatch != null ? w.PrimaryDispatch.TechPhone : null,
|
|
WoTechPhone = w.TechPhone,
|
|
VendorPhone = w.PrimaryDispatch != null && w.PrimaryDispatch.Vendor != null
|
|
? w.PrimaryDispatch.Vendor.Phone
|
|
: null,
|
|
DispatchApptDate = w.PrimaryDispatch != null ? w.PrimaryDispatch.ScheduledDate : null,
|
|
w.Trade,
|
|
w.Problem,
|
|
w.ServiceNotes,
|
|
w.ExtraServices,
|
|
w.DocStatus,
|
|
w.FlagColor,
|
|
w.PrimaryDispatchId,
|
|
w.RowVersion,
|
|
DispatchRowVersion = w.PrimaryDispatch != null ? w.PrimaryDispatch.RowVersion : null
|
|
})
|
|
.ToListAsync();
|
|
|
|
return rows.Select(w =>
|
|
{
|
|
var pocName = !string.IsNullOrWhiteSpace(w.WoPocName) ? w.WoPocName : w.ContactPoc?.Name;
|
|
var pocPhone = !string.IsNullOrWhiteSpace(w.WoPocPhone) ? w.WoPocPhone : w.ContactPoc?.PhoneNumber;
|
|
var pocNotes = !string.IsNullOrWhiteSpace(w.WoPocNotes) ? w.WoPocNotes : w.ContactPoc?.Notes;
|
|
var techPhone = !string.IsNullOrWhiteSpace(w.DispatchTechPhone)
|
|
? w.DispatchTechPhone
|
|
: (!string.IsNullOrWhiteSpace(w.WoTechPhone) ? w.WoTechPhone : w.VendorPhone);
|
|
|
|
return new WorkOrderBoardRawRow(
|
|
w.Id,
|
|
w.InternalWONumber,
|
|
w.RescheduleCount,
|
|
w.CarriedOver,
|
|
w.WorkOrderType,
|
|
w.SiteCode,
|
|
w.LocationName,
|
|
pocName,
|
|
pocPhone,
|
|
pocNotes,
|
|
w.LifecycleStatus,
|
|
w.LegacyStatus ?? w.Status,
|
|
w.AssignTo,
|
|
w.FirstName,
|
|
w.LastName,
|
|
w.Initials,
|
|
w.Color,
|
|
w.DueDate,
|
|
w.ScheduledDate,
|
|
w.ScheduledStart,
|
|
w.ScheduledEnd,
|
|
w.TargetWeek,
|
|
w.ScheduleWeekOnly,
|
|
w.VendorId,
|
|
w.VendorName,
|
|
w.TechName,
|
|
techPhone,
|
|
w.DispatchApptDate,
|
|
w.Trade ?? w.Problem,
|
|
w.Problem,
|
|
w.ServiceNotes,
|
|
w.ExtraServices,
|
|
w.DocStatus,
|
|
w.FlagColor,
|
|
w.PrimaryDispatchId,
|
|
w.RowVersion,
|
|
w.DispatchRowVersion,
|
|
isUnscheduled);
|
|
}).ToList();
|
|
}
|
|
}
|
|
}
|