# 05 — Shop Floor Control (SFC) Layer

> Real-time tracking. Cross-cuts Execution. Answers "where is each order right now?" Provides per-department terminals where workers close an operation and the order advances automatically to the next stage. Inherits all rules from `00`.

---

## 5.1 Purpose & Positioning

SFC sits **between Planning and Execution**, connecting them in real time:
```
Planning (CRP schedules tentatively)
   ↕
SFC: terminals + operation status + auto-advance + live dashboard
   ↕  reads Routing (the defined sequence)
   ↕  writes Confirmation (actual completion)
Execution (Confirmation, GR — the engine)
```

**Key clarification:** SFC is NOT the Routing. Routing is the *defined* sequence (static master data). SFC is the *real-time execution* of that sequence — it uses Routing to know "what's the next operation" and dispatches the order to that department's terminal.

The execution engine already exists (Confirmation, Routing, Order_Operation status). What SFC adds is the **real-time interface + automatic advance between terminals + live monitoring.**

---

## 5.2 The Core Mechanism

```
Each department = a Work Center Terminal (a screen).
Worker closes a stage = Operation Confirmation (engine exists).
Order moves to next stage = Routing Step Advance (auto).
Everyone sees status live = Real-time Shop Floor Monitoring.
```

### Walkthrough
```
WO-001 routing: Press → Deflash → Sand → Grade

[Press terminal] incoming: WO-001
  worker taps [Start] → operation[10].status = InProgress, actual_start = now
  worker taps [Done]  → record qty; operation[10].status = Completed
       system reads Routing → next op = Deflash
       operation[20].status = Ready ; notify Deflash terminal
[Deflash terminal] WO-001 appears automatically ← the "advance"
  ... and so on to Grading (last op) → order Completed → ready for GR
```

The "advance" = on `Done`, system consults **Routing** for the next operation and dispatches the order to the responsible department's terminal automatically.

---

## 5.3 Key Entity — Operation Status (live)

This already exists on `Order_Operation` (file 03); SFC activates its real-time tracking.
```
Order_Operation:
  - order_no, operation_no, work_center_id, tool_id
  - status ∈ { Waiting, Ready, InProgress, Completed }
  - actual_start_time, actual_end_time
  - confirmed_by, quantity_completed
```

### Advance logic
```
on tap "Done" for operation N:
  operation[N].status = Completed
  operation[N].end_time = now
  record confirmation (qty, grades, scrap) → calls Execution engine (file 03)
  next_op = routing.get_next(N)          # ← reads Routing
  if next_op:
      operation[next_op].status = Ready
      notify(next_op.work_center)        # appears on that terminal
  else:
      order.status = Completed           # last op → ready for GR
```

`routing.get_next(N)` is the bridge: Routing answers "what's next?"; Operation Status records "where we are."

---

## 5.4 Terminal UI (per department)

Minimal worker-facing screen per Work Center:
```
- Incoming orders queue (status Ready), sorted by priority/schedule
- For the active order: [Start] / [Done] buttons
- On Done: prompt for quantity, grade distribution, scrap + reason_code
- Shows: order no, product, target qty, this operation only
- Sequence enforcement: an operation appears only after the prior one Completed
```

Design for floor use: large touch targets, minimal typing, offline-tolerant if possible (sync when connected).

---

## 5.5 Real-time Dashboard (supervisor)

```
Live board:
  WO-001: Sanding (Op 30) — 60% done
  WO-002: Pressing (Op 10) — just started
  WO-003: Waiting for press (mold busy)
Live bottleneck detection: many orders Waiting before a resource → that resource is the live constraint (links to CRP, but real-time).
```

---

## 5.6 What SFC Affects (5 impacts)

1. **Real-time visibility** — management knows exactly where each order is, no asking workers.
2. **Auto-feeds Confirmation** — each "Done" creates an immediate confirmation (qty + time), making cost data live & accurate (no end-of-day manual entry).
3. **Live bottleneck detection** — many "Waiting" before a resource exposes the current constraint.
4. **Actual operation times** — start/end per operation feeds OEE, routing-time refinement, time variances (actual vs planned).
5. **Sequence enforcement** — an operation can't appear before its predecessor completes → quality & process integrity.

---

## 5.7 Build Note

~80% of the logic pre-exists (Routing defined, Order_Operation status present, Confirmation engine ready). The build is the **real-time interface + automatic terminal-to-terminal advance + live dashboard** — a layer ON TOP of execution, not a rebuild.

This is the MES-level functionality. Optional integrations for a fuller MES: machine data capture (IoT), OEE computation, barcode/RFID scanning.
