mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 12:43:24 +00:00
26 lines
1,020 B
TypeScript
26 lines
1,020 B
TypeScript
|
|
import type { CompDocSaveStatus } from "@/domain/work-orders/types/completion-doc";
|
||
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||
|
|
import {
|
||
|
|
getClosabilityGaps,
|
||
|
|
tableRowToClosabilityInput,
|
||
|
|
} from "@/domain/work-orders/utils/wo-closability";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* SH-115 / SH-341: completion is manual with confirmation, except that generating the
|
||
|
|
* completion document completes the WO — but only when the SH-114 closability gate passes
|
||
|
|
* on the persisted row. Not-required (NN) and drafts never complete; Past Due rows must be
|
||
|
|
* rescheduled before any status change, so they are left for the dispatcher.
|
||
|
|
*/
|
||
|
|
export function shouldCompleteAfterCompletionDoc(
|
||
|
|
status: CompDocSaveStatus,
|
||
|
|
row: WorkOrderTableRow,
|
||
|
|
): boolean {
|
||
|
|
if (status !== "Yes" || row.docStatus !== "Yes") {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (row.status === "Completed" || row.status === "Canceled" || row.isPastDue) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return getClosabilityGaps(tableRowToClosabilityInput(row)).length === 0;
|
||
|
|
}
|