Batch Status on Process Flow

oee batch process-flow station

Batch-items displayed on station nodes in the Process Flow derive their status from the actual state of the data — not from a stored status column.

Visibility Filter

Before a batch is displayed, it must pass the visibility filter:

---
config:
  layout: dagre
---
flowchart TB
    A["Machine Event + Batch Details"] --> FILTER{"Should this batch be visible?"}

    FILTER --> F1{"me.resolved = true?"}
    F1 -- "yes" --> HIDDEN1["HIDDEN\nBatch journey moved to next station"]
    F1 -- "no" --> F2{"bd.status = aborted?"}
    F2 -- "yes" --> HIDDEN2["HIDDEN\nBatch was aborted"]
    F2 -- "no" --> VISIBLE["VISIBLE\nProceed to derive status"]

Status Derivation

Status is derived from oee_machine_events.end_ts and active oee_time_entries:

---
config:
  layout: dagre
---
flowchart TB
    VISIBLE["Batch is visible"] --> DERIVE{"Derive display status"}

    DERIVE --> D1{"me.end_ts set?"}
    D1 -- "yes" --> COMPLETED["COMPLETED"]
    D1 -- "no" --> D2{"Active time entries\nfor this batch?"}
    D2 -- "yes, someone clocked in" --> RUNNING["RUNNING"]
    D2 -- "no, nobody clocked in" --> IDLE["IDLE"]

An “active time entry” is a row in oee_time_entries where batch_id matches the batch’s oee_batch_details.id and end_ts IS NULL.

StatusConditionStation badgeBatch-item style
RUNNINGend_ts is NULL + active time entries existACTIVE (green)Green RUNNING badge
IDLEend_ts is NULL + no active time entriesIDLE (gray)Gray IDLE badge
COMPLETEDend_ts is setShows routing actionBlue COMPLETED badge

Click Behavior

What happens when an operator clicks a batch-item depends on the derived status:

---
config:
  layout: dagre
---
flowchart TB
    CLICK["Click batch-item on station"] --> STATUS{"Derived status?"}

    STATUS -- "IDLE\n(no time entries without end_ts)" --> IDLE_CHECK{"Has any\noee_time_entries?"}
    IDLE_CHECK -- "No" --> START["Open Start Job modal"]
    IDLE_CHECK -- "Yes" --> IDLE_OPTION["Show option:\nResume (clock in) or Complete"]

    STATUS -- "RUNNING\n(active time entries)" --> COMPLETE["Open Complete Job modal"]

    STATUS -- "COMPLETED\n(has end_ts)" --> RESOLVE_CHECK{"Same batch_number exists\nunresolved on a\ndownstream station?"}
    RESOLVE_CHECK -- "Yes" --> AUTO_RESOLVE["Mark this event resolved\nBatch already exists downstream\nNo modal needed"]
    RESOLVE_CHECK -- "No" --> CONN_CHECK{"How many outgoing\nconnections?"}
    CONN_CHECK -- "1" --> DIRECT_START["Open Start Job modal\non the one connected station\nMark resolved only if they submit"]
    CONN_CHECK -- "2+" --> ROUTE["Open Route Job dialog\nThen Start Job modal on selected station\nMark resolved only if they submit"]

A COMPLETED batch only appears on stations with outgoing connections. Terminal stations (0 connections) auto-resolve in complete_batch() so the user never sees a COMPLETED batch there.

Complete Job Flow

When the Complete Job modal is submitted:

---
config:
  layout: dagre
---
flowchart TB
    COMPLETE["Complete Job submitted"] --> CORE["complete_batch() SQL function"]
    CORE --> C1["Clock everyone out\nSet end_ts on all active time entries"]
    C1 --> C2["Set me.end_ts on machine event"]
    C2 --> C3["Set bd.status = completed"]
    C3 --> TERMINAL{"Station has 0\noutgoing connections?"}
    TERMINAL -- "yes" --> AUTO["Auto-resolve\nme.resolved = TRUE\nBatch disappears"]
    TERMINAL -- "no" --> POST["After modal closes"]
    POST --> DOWN{"Same batch_number\nunresolved downstream?"}
    DOWN -- "yes" --> RESOLVE["Mark resolved\nBatch disappears"]
    DOWN -- "no" --> LEAVE["Leave unresolved\nBatch shows as COMPLETED\nUser clicks to route"]

The resolved Column

oee_machine_events.resolved is a boolean that controls whether a batch-item is visible on its station. Once resolved, the batch disappears from the station node.

Resolved is set automatically in three places:

  1. complete_batch() SQL function — auto-resolves when completing at a terminal station (no outgoing connections)
  2. start_batch() SQL function — auto-resolves previous completed events with the same batch_number when work begins at the next station
  3. Frontend routing flow — marks resolved after the user submits the Start Job modal on the next station

SQL: Status Derivation Query

The schematic query in backend/queries/ops.ts derives batch_status:

CASE
    WHEN me.end_ts IS NOT NULL THEN 'completed'
    WHEN EXISTS (
        SELECT 1 FROM oee_time_entries te
        WHERE te.batch_id = bd.id AND te.end_ts IS NULL
    ) THEN 'running'
    ELSE 'idle'
END AS batch_status

See Also

  • Batches — batch lifecycle, starting and completing
  • Process Flow — schematic builder overview
  • Station — station nodes and configuration
  • Events — all event types