mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-05 09:32:12 +00:00
81 lines
2.6 KiB
C#
81 lines
2.6 KiB
C#
|
|
using Data.SeaHavenIndustries.Enums;
|
|||
|
|
|
|||
|
|
namespace SeaHaven.Services.Helpers
|
|||
|
|
{
|
|||
|
|
public static class WorkOrderDerivedFields
|
|||
|
|
{
|
|||
|
|
private static readonly HashSet<LifecycleStatus?> TerminalStatuses = new()
|
|||
|
|
{
|
|||
|
|
LifecycleStatus.Complete,
|
|||
|
|
LifecycleStatus.Canceled,
|
|||
|
|
LifecycleStatus.Closed
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
public static bool IsPastDue(
|
|||
|
|
DateTime? scheduledDate,
|
|||
|
|
LifecycleStatus? lifecycleStatus,
|
|||
|
|
DateTime? utcNow = null)
|
|||
|
|
{
|
|||
|
|
if (!scheduledDate.HasValue)
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
if (TerminalStatuses.Contains(lifecycleStatus))
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
var today = (utcNow ?? DateTime.UtcNow).Date;
|
|||
|
|
return scheduledDate.Value.Date < today;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static bool IsTerminal(LifecycleStatus? lifecycleStatus)
|
|||
|
|
=> TerminalStatuses.Contains(lifecycleStatus);
|
|||
|
|
|
|||
|
|
public static string? GetDayGroup(DateTime? scheduledDate)
|
|||
|
|
{
|
|||
|
|
if (!scheduledDate.HasValue)
|
|||
|
|
return null;
|
|||
|
|
|
|||
|
|
return scheduledDate.Value.DayOfWeek switch
|
|||
|
|
{
|
|||
|
|
DayOfWeek.Monday => "monday",
|
|||
|
|
DayOfWeek.Tuesday => "tuesday",
|
|||
|
|
DayOfWeek.Wednesday => "wednesday",
|
|||
|
|
DayOfWeek.Thursday => "thursday",
|
|||
|
|
DayOfWeek.Friday => "friday",
|
|||
|
|
_ => null
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string? FormatApptTime(DateTime? start, DateTime? end)
|
|||
|
|
{
|
|||
|
|
if (!start.HasValue)
|
|||
|
|
return null;
|
|||
|
|
|
|||
|
|
if (end.HasValue)
|
|||
|
|
return $"{start.Value:HH:mm} – {end.Value:HH:mm}";
|
|||
|
|
|
|||
|
|
return start.Value.ToString("HH:mm");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string GetLifecycleStatusLabel(LifecycleStatus? status)
|
|||
|
|
{
|
|||
|
|
if (!status.HasValue)
|
|||
|
|
return "";
|
|||
|
|
|
|||
|
|
return status.Value switch
|
|||
|
|
{
|
|||
|
|
LifecycleStatus.Incomplete => "Incomplete",
|
|||
|
|
LifecycleStatus.Scheduled => "Scheduled",
|
|||
|
|
LifecycleStatus.InProgress => "In Progress",
|
|||
|
|
LifecycleStatus.Complete => "Complete",
|
|||
|
|
LifecycleStatus.Canceled => "Canceled",
|
|||
|
|
LifecycleStatus.OnHold => "On Hold",
|
|||
|
|
LifecycleStatus.PendingVendor => "Pending Vendor",
|
|||
|
|
LifecycleStatus.PendingApproval => "Pending Approval",
|
|||
|
|
LifecycleStatus.NeedsReview => "Needs Review",
|
|||
|
|
LifecycleStatus.Closed => "Closed",
|
|||
|
|
_ => status.Value.ToString()
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|