mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-02 15:33:21 +00:00
55 lines
No EOL
1.9 KiB
C#
55 lines
No EOL
1.9 KiB
C#
using Data.SeaHavenIndustries;
|
|
|
|
using Data.SeaHavenIndustries.Enums;
|
|
|
|
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
|
|
{
|
|
|
|
public static class WorkOrderDerivedFields
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Past due overlay — never a WorkOrderType. Matches SHOC board design.
|
|
|
|
/// </summary>
|
|
|
|
public static bool IsPastDue(WorkOrder workOrder, DateOnly? asOf = null)
|
|
|
|
{
|
|
|
|
var today = asOf ?? DateOnly.FromDateTime(DateTime.UtcNow);
|
|
|
|
if (workOrder.ScheduledDate == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (LifecycleStatusMapper.IsTerminal(workOrder.LifecycleStatus))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return DateOnly.FromDateTime(workOrder.ScheduledDate.Value.Date) < today;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets initial lifecycle on create. New WOs start Incomplete unless auto-scheduled.
|
|
|
|
/// </summary>
|
|
|
|
public static void SetInitialLifecycleStatus(WorkOrder workOrder)
|
|
|
|
{
|
|
|
|
workOrder.LifecycleStatus ??= LifecycleStatus.Incomplete;
|
|
|
|
ApplyAutoScheduleIfEligible(workOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// SHOC rule: specific scheduled date + assignee + Incomplete → Scheduled.
|
|
|
|
/// Week-only targets do not auto-schedule.
|
|
|
|
/// </summary>
|
|
|
|
public static bool ApplyAutoScheduleIfEligible(WorkOrder workOrder)
|
|
|
|
{
|
|
|
|
if (workOrder.LifecycleStatus != LifecycleStatus.Incomplete)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (workOrder.ScheduleWeekOnly == true)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (workOrder.ScheduledDate == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(workOrder.AssignTo))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
workOrder.LifecycleStatus = LifecycleStatus.Scheduled;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|