Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(scheduling): only a Hard or Soft Deadline can be late

naveenkash5ee90f27efd9
diff --git a/.claude/rules/scheduling-data-structures.md b/.claude/rules/scheduling-data-structures.md
index ae0cfc65fe..3d6c313bfd 100644
--- a/.claude/rules/scheduling-data-structures.md
+++ b/.claude/rules/scheduling-data-structures.md
@@ -459,7 +459,10 @@ only; its output is read by nothing in the placement path (spec
placed end, the forecast finish) while clearing
`scheduleOutdatedReason`/`scheduleOutdatedAt` for each job. The engine's `buildWrites` also computes the
**newly-late** flag (was on-time-or-unforecast before, now projected past `dueDate`
- on the location calendar) for the wave's digest.
+ on the location calendar) for the wave's digest. Every due-date judgement — need-by
+ targets, lateness conflicts, newly-late, the behind-target sentence — reads
+ `committedDueDate` (`priority-calculator.ts`): only a Hard or Soft Deadline job has
+ one; the date left on an ASAP or No Deadline job (the job form hides it) is ignored.
- **Behind-target attribution (informational only):** when the JOB's verdict is late,
`getCause()` appends `composeBehindTarget` (`conflict-messages.ts`) — "First behind
target: {op} (due X, projected Y)", the first op in topological order whose
diff --git a/apps/erp/app/modules/production/AGENTS.md b/apps/erp/app/modules/production/AGENTS.md
index e421bf6618..131d988e98 100644
--- a/apps/erp/app/modules/production/AGENTS.md
+++ b/apps/erp/app/modules/production/AGENTS.md
@@ -143,7 +143,7 @@ pnpm --filter erp test
- `getProductionPlanning` — MRP-driven production planning (RPC `get_production_planning_grid`, latest migration `20261006205037`: wraps `get_production_planning` and adds the item group, the planning-horizon fence date, the first negative week, the latest order date and `orderQuantity` — the open Make actions inside the fence, which the default sort uses (the Order / Make button shows the quantity; there is no Qty to Order column), not the base RPC's `quantityToOrder`; `asOf` is the location's today, and `actionTypes` / `actionAssignees` filter on OPEN planning actions inside each item's fence, in the database)
- `nextJobPriority(siblings, deadlineType)` — pure: a job's fractional priority among the jobs already on its date, by deadline type; `calculateJobPriority` reads the siblings and calls it, the planning date apply places a batch with it. `deadlineTypeForPlanningDate(deadlineType)` — the type a job carries once planning gives it a date (No Deadline → Soft Deadline)
- **Job status** (`production.server.ts`, all published except `planDraftJob`) — the job header's buttons post to `x+/job+/$jobId.status.tsx`, which maps the status to one operation: Planned → `planDraftJob` (Draft only), Paused → `pauseJob` (from Ready / In Progress), Ready → `resumeJob` (from Paused; refuses blocked manufacturing and the Make to Asset rules, then recalculates and runs MRP), Draft / In Progress → `reopenJob` (Cancelled → Draft, Completed → In Progress), Closed → `closeJob` (from Completed, then `service.closeJob` writes the remaining WIP off as production variance), Cancelled → `cancelJob`. Each flip is guarded on its from-statuses (`moveJobStatus`). Complete is `completeJob` (`x+/job+/$jobId.complete.tsx`): `complete_job_to_inventory`, then the picked-material return (a failure there is a `warning`).
-- **Job edits** (`production.server.ts`, published) — `updateJobDetails` (the details form), `configureJob`, `createJob` (`x+/job+/new.tsx`: the records must be the company's, refused for an item an unreleased change notice holds and for a Make to Asset item that cannot complete to an asset; the route shows those two on the item field), `createJobs` (`x+/job+/bulk.new.tsx`), `insertJob` (the API's and workflows' create: Draft or Planned only), `createSalesOrderLineJob` (unpublished, `x+/sales-order+/$orderId.$lineId.job.tsx`; the line must be on the order) and `convertSalesOrderLinesToJobs` (`$orderId.lines.jobs.tsx`). Every job creation goes through `jobCreationRefusal` (the records are the company's, no unreleased change notice holds the item, the Make to Asset rule); `orderPlannedJobs` skips an item a change notice holds. `deleteJobs` and the property panel's / jobs table's field writes through `x+/job+/update.tsx` — `setJobItem` (re-pulls the method), `setJobDeadline` (re-ranks priority, one read and one write for all jobs), `setJobQuantity` (recalculates), `setJobSalesOrderLine`, `setJobFields` — and `updateJobDetails` and `configureJob` refuse a locked job (`readUnlockedJobs` / `requireJob`).
+- **Job edits** (`production.server.ts`, published) — `updateJobDetails` (the details form), `configureJob`, `createJob` (`x+/job+/new.tsx`: the records must be the company's, refused for an item an unreleased change notice holds and for a Make to Asset item that cannot complete to an asset; the route shows those two on the item field), `createJobs` (`x+/job+/bulk.new.tsx`), `insertJob` (the API's and workflows' create: Draft or Planned only), `createSalesOrderLineJob` (unpublished, `x+/sales-order+/$orderId.$lineId.job.tsx`; the line must be on the order) and `convertSalesOrderLinesToJobs` (`$orderId.lines.jobs.tsx`). Every job creation goes through `jobCreationRefusal` (the records are the company's, no unreleased change notice holds the item, the Make to Asset rule); `orderPlannedJobs` skips an item a change notice holds. `deleteJobs` and the property panel's / jobs table's field writes through `x+/job+/update.tsx` — `setJobItem` (re-pulls the method), `setJobDeadline` (re-ranks priority, one read and one write for all jobs; `nextJobDeadline` keeps date and type in step — ASAP / No Deadline clear the date, a date on a No Deadline job makes it Soft), `setJobQuantity` (recalculates), `setJobSalesOrderLine`, `setJobFields` — and `updateJobDetails` and `configureJob` refuse a locked job (`readUnlockedJobs` / `requireJob`).
- **Job method** (`production.server.ts`, published) — Get Method is `copyMethodToJob` (`upsertJobMethod`, then the job's requirements and dependencies) and `copyMethodToMaterial`; `createJobMaterial` / `updateJobMaterial` / `deleteJobMaterial` / `deleteJobMaterials` and `createJobOperation` / `updateJobOperation` / `deleteJobOperation` / `deleteJobOperations` (the plural two are unpublished: Delete Selected, one recalculation) / `reorderJobOperations` / `setJobOperationStatus` (a Done operation returns its unconsumed picks) / `setJobOperationDueDate` / `syncJobOperationProcedure` back the bill of material and bill of process routes under `x+/job+/methods+/`; Get Method and the material, operation and procedure writes refuse a locked job (`requireJob`). Save Method (`x+/job+/methods+/save.tsx`) is `upsertMakeMethodFromJob` / `upsertMakeMethodFromJobMethod`: parts update and the target method's revision lock, as the items' Save Method. `completeOperation` (published) reports a good quantity on an untracked operation: it records it, backflushes (`issue`), and at the target sets the operation Done, posts its ended events and returns its picks. `createProductionEvent` / `updateProductionEvent` save a production event and post an ended one to the GL (`post-production-event`; a skipped posting is returned as `postingError`). `createProductionQuantity` records a production quantity (refuses a locked job, keeps a scrap reason only on Scrap); `updateProductionQuantity` corrects one and needs accounting update, so it is not published. The procedure properties panel posts to `setProcedureFields`. The bare row writes (`upsertJobMaterial`, `upsertJobOperation`, `upsertJobMethod`, `upsertProductionEvent`, `updateJob`) are building blocks in `production.service.ts` and are never tools.
- `cancelJob` (`production.server.ts`, published as `production_cancelJob`) — the one cancel path, used by the job page's Cancel (`x+/job+/$jobId.cancel.tsx`), the status route and planning's Cancel action: refuses another company's job (`notFound`), sets Cancelled and clears the assignee only while the job is in `fromStatuses` (default `CANCELLABLE_JOB_STATUSES`; a refusal is a `conflict` and changes nothing), then returns its unconsumed picked material (`post-picking` `returnJobRemainders`, which sweeps only a Completed or Cancelled job) and cancels its open picking-list lines; a failure of either is a `warning`, the job stays Cancelled. Pinned by `test/database/cancel-job.test.ts`. Planning edits a job only while `isJobEditableFromPlanning` (`production.models.ts`: Draft / Planned)
- `getPlanningActions` / `getPlanningActionsByIds` — the persisted MRP worklist (`planningAction`, written by `generatePlanningActions` in `@carbon/planning` after every MRP run; statuses `Open` / `Dismissed` / `Actioned`). `dismissPlanningActions` / `reopenDismissedPlanningActions` (Dismissed ↔ Open; both return the ids they changed, which the routes report), `markPlanningActionsActioned` (the conditional Open → Actioned claim that is the apply path's lock — an empty result means another apply got there first; it returns the row's suggested quantity and date, which Apply writes instead of the page's possibly stale read) and `reopenPlanningActions` (its rollback, Actioned → Open), `assignPlanningActions` (sets the assignee and marks it overridden so the next MRP run keeps it; Open and Dismissed rows only, returning the ids it changed). `settleNewSupplyPlanningActions` is the page's Order button's settle: the suggested orders it submits carry no action id, so after the PO lines (`Order`) or jobs (`Make`) are created it flips the Open / Dismissed action of each ordered (item, week) pair at the location to Actioned — otherwise the suggestion stayed on the page beside its order until the next MRP run. An Apply reads its actions (`getPlanningActionsByIds`) and their jobs / PO lines in one statement each (Kysely, the ids as parameters — never a PostgREST URL), then applies set-based: `applyProductionPlanningDateActions(db, …)` moves every Expedite / Defer in one transaction (the claim, the jobs, the jobs already on the target dates, one UPDATE of due date + deadline type + priority via the pure `nextJobPriority` — a "No Deadline" job becomes `Soft Deadline`, `deadlineTypeForPlanningDate`, since the job form hides the due date for No Deadline), and the route sends one `schedule-inputs-changed` event for the batch; Increase / Decrease / Cancel call postings with their own transactions, so they run per job, three jobs at a time, each claimed right before its change. The transaction-scoped claim and release live in `planning-action-claims.ts` (`claimPlanningActions` / `releasePlanningActionClaims`), shared with purchasing's `applyPurchasingPlanningActions`. Bad input to either planning route answers 400, a failed read or write 500. `releasePlanningActionClaim` gives a failed per-job apply's claim back (deleting it instead when MRP has already written an Open row for the same need), and `updatePlanningJob` is planning's single-job write (the drawer's inline edit, and Increase / Decrease), guarded on Draft / Planned in the UPDATE itself; a quantity change restates `scrapQuantity` from the item's scrap rate. `planDraftJob` (`production.server.ts`) is the drawer's Plan on a Draft job (`planJob` intent), in `releaseJobs`' order: the requirements recalculation (a failure leaves the job Draft), the guarded Draft → Planned flip, then MRP, so the job counts as supply. It sends no scheduler notice — the scheduler places only released jobs. `replanAfterItemChange` (`production.server.ts`) runs MRP after an item's planning or manufacturing settings are saved, so the planning pages follow them at once. `planningAction` is read-only through the API; its writers use the service role. Applied from `x+/production+/planning.update.tsx` (one service-function call per `action`: `order` (`orderPlannedJobs`), `updateJob` (`updatePlannedJob`), `planJob` (`planJobFromPlanning`), `apply` and its typed aliases (`applyPlanningActions`), `dismiss` (`dismissProductionPlanningActions`), `reopen` (`reopenProductionPlanningActions`), `assign` (`assignProductionPlanningActions`); a dismiss / reopen / assign that changes nothing is a `conflict`) and `x+/purchasing+/planning.update.tsx`; `usePlanningActions` reads both routes' answers; UI in `ui/Planning/`: `ProductionPlanningTable` + `ProductionPlanningOrderDrawer`, `planningColumns.tsx` (the column set shared with purchasing: the Stock Availability week strip via `PlanningWeekStrip` + `planning-week-geometry.ts`, `LatestOrderDate`, `PlanningFence` + `planning-fence.ts`), `PlanningActionLines` (the expanded row), `PlanningOrderGrids` + `PlanningDrawerParts` (the drawer's suggested / open-order grids, `periodIdFor`, the "N More After" button), `usePlanningActions` (the dismiss / reopen / assign / apply fetcher), and `planning-action-scope.ts` (`resolvePlanningActionScope`, `actionsOfTypes`, `PLANNING_ACTIONS_COLUMN`, `PLANNING_ASSIGNEE_COLUMN`, `PLANNING_DRAWER_PARAM` — pure, re-exported from `production.models.ts` so vitest can import it), `planned-orders-from-actions.ts` (pure: the drawer's suggested orders, the row's Order / Make quantity and a bulk order are the item's open Order / Make actions — `openNewSupplyActions`, `plannedOrdersFromActions`, `productionOrdersFromActions`, `supplierConversionFactor` — never sized again on screen, so a shortfall MRP folded into an Increase is not offered twice), `planning-increase.ts` (pure: `chartedOrderQuantity` charts an order at its open Increase), and `planning-review.ts` (pure: `planningActionNeedsReview` — Review vs Apply from the order's LIVE status, `purchaseOrderStatus` / `jobStatus` from `getPlanningActions`, not MRP's run-time `requiresManualAction` stamp, so a PO reopened since applies at once; a date move on a supplier-promised line stays Review — and `purchaseOrderPlanningMenu`, which order commands a row's ⋯ offers; `PlanningActionHandlers.purchaseOrderMenuItems` carries them, purchasing only). Both planning grids put the open order drawer's item in the address (`?item=<itemId>`, `useLinkedDrawerItem` in `~/hooks/useDrawerItem`), so a link reopens it; the loader reads that row on its own (`drawerItem`) when it is not on the page. Tests: `apps/erp/test/apply-production-planning-date-actions.test.ts` (`nextJobPriority`, `planJobDateMoves`), `planning-action-scope.test.ts`, `planning-fence.test.ts`, `planning-increase.test.ts`, `planning-review.test.ts`, `planned-orders-from-actions.test.ts`, `planning-week-geometry.test.ts`
diff --git a/apps/erp/app/modules/production/production.server.ts b/apps/erp/app/modules/production/production.server.ts
index 894e695e02..2e43fd981c 100644
--- a/apps/erp/app/modules/production/production.server.ts
+++ b/apps/erp/app/modules/production/production.server.ts
@@ -1596,7 +1596,9 @@ export const setJobItem = defineServiceFn({
* Refused when any job is locked. Each job's priority is recalculated among
* the jobs at its location on the new date (`nextJobPriority`), in one read
* and one write for every job. A field left out keeps the job's current
- * value; a `dueDate` of null clears it.
+ * value; a `dueDate` of null clears it. The two stay in step
+ * (`nextJobDeadline`): ASAP and No Deadline clear the date, and a date given
+ * to a No Deadline job makes it a Soft Deadline.
*
* @mcp
*/
@@ -1617,8 +1619,7 @@ export const setJobDeadline = defineServiceFn({
const moves = jobs.map((job) => ({
id: job.id,
locationId: job.locationId,
- dueDate: dueDate !== undefined ? dueDate || null : job.dueDate,
- deadlineType: deadlineType ?? job.deadlineType
+ ...service.nextJobDeadline(job, { dueDate, deadlineType })
}));
// The jobs already on each new date at each location, in one read: a
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index 11e818e310..cf110c85e6 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -678,6 +678,36 @@ export function deadlineTypeForDueDate(
: deadlineType;
}
+/**
+ * A job's due date and deadline type after a change to either, kept in step:
+ * a type that takes no date (ASAP, No Deadline) clears the date, which the
+ * job form hides for those; a date set on its own follows
+ * `deadlineTypeForDueDate`.
+ */
+export function nextJobDeadline(
+ job: { dueDate: string | null; deadlineType: DeadlineType },
+ change: { dueDate?: string | null; deadlineType?: DeadlineType }
+): { dueDate: string | null; deadlineType: DeadlineType } {
+ const dueDate =
+ change.dueDate !== undefined ? change.dueDate || null : job.dueDate;
+ if (change.deadlineType !== undefined) {
+ const takesDate =
+ change.deadlineType === "Hard Deadline" ||
+ change.deadlineType === "Soft Deadline";
+ return {
+ dueDate: takesDate ? dueDate : null,
+ deadlineType: change.deadlineType
+ };
+ }
+ return {
+ dueDate,
+ deadlineType:
+ change.dueDate !== undefined
+ ? deadlineTypeForDueDate(job.deadlineType, dueDate)
+ : job.deadlineType
+ };
+}
+
/**
* The priority of a job placed among `siblings` — the jobs that share its due
* date (or lack of one) at its location, in priority order. Fractional
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
index 23a2218212..5daca5bc61 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobHeader.tsx
@@ -94,7 +94,11 @@ import type { action as statusAction } from "~/routes/x+/job+/$jobId.status";
import { useSuppliers } from "~/stores";
import { generateBomIds } from "~/utils/bom";
import { path } from "~/utils/path";
-import { isJobLocked, jobCompleteValidator } from "../../production.models";
+import {
+ deadlineRequiresDueDate,
+ isJobLocked,
+ jobCompleteValidator
+} from "../../production.models";
import { getJobMethodTree } from "../../production.utils";
import type { Job } from "../../types";
import JobStatus from "./JobStatus";
@@ -215,7 +219,10 @@ const JobHeader = () => {
// Forecast slack: calendar days between the projected completion (forward-ASAP
// finish) and the promised due date. Positive = late, negative = early.
const projectedCompletionAt = routeData?.job?.projectedCompletionAt;
- const jobDueDate = routeData?.job?.dueDate;
+ // Only a Hard or Soft Deadline promises a date; the form hides the rest.
+ const jobDueDate = deadlineRequiresDueDate(routeData?.job?.deadlineType)
+ ? routeData?.job?.dueDate
+ : null;
const slack = useMemo(() => {
if (!projectedCompletionAt || !jobDueDate) return null;
const days = parseDate(projectedCompletionAt.slice(0, 10)).compare(
@@ -308,14 +315,12 @@ const JobHeader = () => {
routeData?.job?.status ?? ""
) && (
<>
- {routeData?.job?.dueDate &&
- isSameDay(parseDate(routeData?.job?.dueDate), todaysDate) && (
- <JobStatus status="Due Today" />
- )}
- {routeData?.job?.dueDate &&
- parseDate(routeData?.job?.dueDate) < todaysDate && (
- <JobStatus status="Overdue" />
- )}
+ {jobDueDate && isSameDay(parseDate(jobDueDate), todaysDate) && (
+ <JobStatus status="Due Today" />
+ )}
+ {jobDueDate && parseDate(jobDueDate) < todaysDate && (
+ <JobStatus status="Overdue" />
+ )}
{slack && (
<Status
color={slack.late ? "red" : "green"}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx b/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx
index 85d42c2ed9..9f87a0e217 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobProperties.tsx
@@ -537,10 +537,8 @@ const JobProperties = () => {
onChange={(value) => {
const next = value?.value ?? "";
setDeadlineType(next);
+ // One post: the server clears the date a type takes none of.
onUpdate("deadlineType", next || null);
- if (!deadlineRequiresDueDate(next)) {
- onUpdate("dueDate", null);
- }
}}
/>
</ValidatedForm>
diff --git a/apps/erp/test/schedule-moves.test.ts b/apps/erp/test/schedule-moves.test.ts
index 1a56dfd8f3..07300507a9 100644
--- a/apps/erp/test/schedule-moves.test.ts
+++ b/apps/erp/test/schedule-moves.test.ts
@@ -15,7 +15,10 @@ import {
moveScheduleJob,
reorderScheduleOperations
} from "../app/modules/production/production.server";
-import { deadlineTypeForDueDate } from "../app/modules/production/production.service";
+import {
+ deadlineTypeForDueDate,
+ nextJobDeadline
+} from "../app/modules/production/production.service";
import { createServiceContext } from "@carbon/api/service-fn.server";
type Answer = { data: unknown; error: { message: string } | null };
@@ -223,6 +226,45 @@ describe("deadlineTypeForDueDate", () => {
});
});
+describe("nextJobDeadline", () => {
+ const soft = { dueDate: "2026-10-24", deadlineType: "Soft Deadline" } as const;
+ const undated = { dueDate: null, deadlineType: "No Deadline" } as const;
+
+ it.each([
+ ["ASAP clears the date", soft, { deadlineType: "ASAP" }, null, "ASAP"],
+ [
+ "No Deadline clears the date",
+ soft,
+ { deadlineType: "No Deadline" },
+ null,
+ "No Deadline"
+ ],
+ [
+ "Hard Deadline keeps it",
+ soft,
+ { deadlineType: "Hard Deadline" },
+ "2026-10-24",
+ "Hard Deadline"
+ ],
+ [
+ "a date makes a No Deadline job Soft",
+ undated,
+ { dueDate: "2026-10-30" },
+ "2026-10-30",
+ "Soft Deadline"
+ ],
+ [
+ "clearing the date makes a Soft job No Deadline",
+ soft,
+ { dueDate: null },
+ null,
+ "No Deadline"
+ ]
+ ] as const)("%s", (_, job, change, dueDate, deadlineType) => {
+ expect(nextJobDeadline(job, change)).toEqual({ dueDate, deadlineType });
+ });
+});
+
describe("moveScheduleJob keeps the deadline type in step with the date", () => {
const move = (deadlineType: string, columnId: string) => {
const caller = callerWith({
diff --git a/packages/planning/src/scheduling/priority-calculator.test.ts b/packages/planning/src/scheduling/priority-calculator.test.ts
index 68eea574bb..680668ef1b 100644
--- a/packages/planning/src/scheduling/priority-calculator.test.ts
+++ b/packages/planning/src/scheduling/priority-calculator.test.ts
@@ -3,7 +3,10 @@
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { describe, expect, it } from "vitest";
-import { sortOperationsByPriority } from "./priority-calculator.ts";
+import {
+ committedDueDate,
+ sortOperationsByPriority
+} from "./priority-calculator.ts";
import type { OperationWithJobInfo } from "./types.ts";
const op = (
@@ -35,3 +38,17 @@ describe("sortOperationsByPriority", () => {
).toEqual(expected);
});
});
+
+describe("committedDueDate", () => {
+ // The job form hides the date of ASAP and No Deadline jobs, so it is never late.
+ it.each([
+ ["Hard Deadline", "2026-10-24"],
+ ["Soft Deadline", "2026-10-24"],
+ ["ASAP", null],
+ ["No Deadline", null]
+ ] as const)("a %s job dated 24 Oct is due %s", (deadlineType, expected) => {
+ expect(committedDueDate({ deadlineType, dueDate: "2026-10-24" })).toBe(
+ expected
+ );
+ });
+});
diff --git a/packages/planning/src/scheduling/priority-calculator.ts b/packages/planning/src/scheduling/priority-calculator.ts
index adaac47c4e..67f08bc8b7 100644
--- a/packages/planning/src/scheduling/priority-calculator.ts
+++ b/packages/planning/src/scheduling/priority-calculator.ts
@@ -20,6 +20,22 @@ const DEADLINE_PRIORITY: Record<string, number> = {
"No Deadline": 3
};
+/**
+ * The date a job is promised for, or null. Only a Hard or Soft Deadline holds
+ * one: the job form hides the due date of an ASAP or No Deadline job, so a
+ * date left on one is a promise nobody can see. Need-by targets, lateness
+ * conflicts and newly-late notices all read this.
+ */
+export function committedDueDate(job: {
+ deadlineType?: DeadlineType | string | null;
+ dueDate?: string | null;
+}): string | null {
+ return job.deadlineType === "Hard Deadline" ||
+ job.deadlineType === "Soft Deadline"
+ ? (job.dueDate ?? null)
+ : null;
+}
+
/**
* Get deadline priority value (for sorting)
*/
diff --git a/packages/planning/src/scheduling/scheduling-engine.ts b/packages/planning/src/scheduling/scheduling-engine.ts
index e709b15666..47753cf49a 100644
--- a/packages/planning/src/scheduling/scheduling-engine.ts
+++ b/packages/planning/src/scheduling/scheduling-engine.ts
@@ -43,6 +43,7 @@ import { calendarAdapters, computeNeedByDates } from "./need-by-calculator.ts";
import {
applyPriorities,
calculatePrioritiesByWorkCenter,
+ committedDueDate,
toOperationWithJobInfo
} from "./priority-calculator.ts";
import {
@@ -525,7 +526,7 @@ export class SchedulingEngine {
this.needByByOperation = computeNeedByDates({
operations,
graph,
- jobDueDate: this.job?.dueDate ?? null,
+ jobDueDate: this.job ? committedDueDate(this.job) : null,
calendarHoursPerDay,
workingDayTest
});
@@ -575,7 +576,7 @@ export class SchedulingEngine {
const operations = Array.from(this.scheduledOperations.values());
const selections =
await this.workCenterSelector.selectWorkCentersForOperations(operations, {
- jobDueDate: this.job?.dueDate ?? null,
+ jobDueDate: this.job ? committedDueDate(this.job) : null,
batchPlacements: this.batchPlacements
});
@@ -803,7 +804,7 @@ export class SchedulingEngine {
// business day now exceeds the due date. Edge-triggered by construction, so
// a second identical regen produces no entry. Jobs with no due date are
// never late. Computed on the FACTORY calendar (location tz).
- const dueDate = this.job?.dueDate ?? null;
+ const dueDate = this.job ? committedDueDate(this.job) : null;
const tz = this.job?.timezone ?? "UTC";
if (dueDate && this.projectedCompletionAt) {
const priorProjected = this.job?.projectedCompletionAt ?? null;
@@ -887,7 +888,7 @@ export class SchedulingEngine {
* per-op conflicts (targets are outputs, not constraints).
*/
private composeBehindTargetSentence(): string | null {
- const dueDate = this.job?.dueDate ?? null;
+ const dueDate = this.job ? committedDueDate(this.job) : null;
if (!dueDate || !this.projectedCompletionAt) return null;
const tz = this.job?.timezone ?? "UTC";
if (businessDay(this.projectedCompletionAt, tz) <= dueDate) return null;