# 31 — Coverage Audit: Pharma Toll-Manufacturing Client Workflow vs Published Analysis

> **Addendum to the Manufacturing × Moon-ERP analysis (reports 00–24).** Source of requirements:
> client interview — a pharmaceutical *contract manufacturing / toll* factory ("تصنيع للغير بالأوردر").
> This file audits EVERY requirement derived from that interview against the published analysis
> (`md/20-mapping.md`, `md/21-gaps.md`, `md/22-contracts.md`, `md/23-roadmap.md`, spec digests `md/00..06`)
> and emits the definitive list of NEW work items the published plan does not yet contain.
>
> **Verdict legend:** ✅ FULLY COVERED (cite where) · 🟡 PARTIALLY COVERED (what exists vs what's missing) ·
> ❌ NOT COVERED (net-new). Requirement IDs **IR-1..IR-9** are derived below.
> **Numbering note (post-review):** this file's derived requirements were renumbered
> **R-01..R-09 → IR-1..IR-9** to end the collision with `md/30`'s authoritative requirement scheme
> (R-01..R-21); its decision rows were re-aligned to the single authoritative register in
> `md/36` §4 (the former "D-23 pre-sales scope" here is now **D-31**).

---

## 0. Derived requirements (IR-1..IR-9)

The interview describes **two business cycles** plus a cross-cutting UI demand. Decomposed:

### Cycle 1 — Exploratory Costing (دورة التكلفة الاستكشافية)
- **IR-1** Customer brings a product + its composition (تركيبته) and requests *exploratory pricing* →
  an intake/request document (a **manufacturing RFQ / costing request**) must exist as a first-class entity.
- **IR-2** R&D department authors a **DRAFT BOM** for that request (recipe not yet productionized).
- **IR-3** Accounting computes a **preliminary / exploratory cost** off that draft BOM and returns a
  **quote (preliminary product cost)** to the customer. This is a *costing-only, pre-order* pass —
  no stock, no GL, no production order.

### Cycle 2 — Production, make-to-order (دورة الإنتاج)
- **IR-4** Every structure/document in this cycle is **tied to the customer order** (order-as-anchor;
  full traceability from sales order → BOM → trial → production order → receipt).
- **IR-5** **TRIAL / sample batch** stage (دورة التجربة): R&D produces a real test batch with **real cost**;
  it needs its own cycle/order type distinct from a normal production order, and the customer evaluates it.
- **IR-6** On customer agreement → **formal order** → R&D **finalizes the BOM** (Draft → Active) →
  **Planning** computes required quantities + checks readiness.
- **IR-7** **DEPOSIT / down-payment gate** (دفعة تحت حساب): because the factory buys raw materials *on
  behalf of the customer*, a customer down-payment must be **received and verified BEFORE** materials are
  reserved/purchased. This is a hard financial gate inserted between "planning OK" and "reserve".
- **IR-8** **Customer-supplied raw materials** that remain **the customer's property** (consignment) may be
  used alongside factory-purchased materials, mixed within the same order.
- **IR-9** (cross-cutting) **Dedicated per-stage workspace SCREENS** (واجهات لكل مرحلة إنتاجية) so the order is
  advanced from stage to stage from those screens — beyond shop-floor operator terminals; these are
  back-office *stage workbenches* (R&D, Planning, Finance-gate, Reserve/Issue, etc.).

After IR-6 the order rejoins the already-mapped chain: finalize BOM → Planning → (deposit gate, IR-7) →
reserve → manufacturing order → issue → manufacture → finish → receive into FG warehouse.

---

## 1. Verdict table (IR-1..IR-9 vs published analysis)

| # | Requirement (client) | Verdict | Where covered / what's missing |
|---|---|---|---|
| **IR-1** | Manufacturing RFQ / exploratory-costing request as a first-class intake document | ❌ **NOT COVERED** | No RFQ/costing-request entity anywhere. Spec digests 00–06 model demand only as a **confirmed `sales_order`** (`md/02` L19,L89,L282; `md/03` L318 pegging `source_orders[]`). `21-gaps.md` does not list a quoting/RFQ gap (grep: no "RFQ/quote/exploratory" token). Mapping's 27 entities start at confirmed demand → MPS/MRP. **The entire pre-sales costing cycle is outside the published scope.** |
| **IR-2** | R&D authors a **Draft BOM** before any order | 🟡 **PARTIAL** | The *data structure* exists: `BomStatus` widened to `{Draft, Active, Inactive, Obsolete}` and lifecycle `Draft → Active → Inactive → Obsolete` is mapped (`20-mapping.md` row 2; `01-spec-masterdata.md` L57,L255; activated in roadmap Phase 0/Phase 1). **What's missing:** (a) **R&D as an actor/owner** of the Draft state — no R&D department/role; permissions are flat `production.*` with no R&D-vs-Planning split; (b) a Draft BOM **detached from a product master** (an exploratory recipe for a not-yet-onboarded customer product) — Moon BOM requires a `product_id` FK (`20-mapping.md` row 2), so a "BOM for a prospect's product" has no home; (c) the **request→Draft-BOM workflow** linking IR-1 to this BOM. |
| **IR-3** | Accounting computes **preliminary/exploratory cost** → quote to customer | 🟡 **PARTIAL** | The **costing engine exists**: `ComputeStandardCost`/`RollUpStandardCost` (BOM roll-up × WC rates), `mfg_standard_costs`, per-item `costing_method` (`20-mapping.md` rows 23–25; `23-roadmap.md` Phase 3; `04-spec-costing.md` §4.1–4.2). **What's missing:** (a) running that roll-up on a **Draft/exploratory BOM** *before* a product/order exists and persisting the result as a **quote** (no quote entity, no quote→customer document); (b) the **Accounting-reviews-then-returns-price** handoff workflow; (c) the cost-roll-up is currently scheduled at **Phase 3** (`23-roadmap.md`) but Cycle-1 quoting is needed at sales time, i.e. **before** Phase 1 execution — a sequencing conflict. No exploratory/preliminary cost mode is specified (costing assumes a *closed order's* actuals/standards). |
| **IR-4** | All Cycle-2 documents anchored to the customer order (full order traceability) | ✅ **FULLY COVERED** | `mfg_peggings (production_order_id, sales_order_id, sales_order_item_id, allocated_quantity)` links every production order to the sales order it serves (`20-mapping.md` row 26; `22-contracts.md` §1 Sales row, §2 events; `mfg_mrp_planned_orders.source_demand_id` carries it through MRP). `production_type=MakeToOrder` drives the order-anchored branch (`02-spec-planning.md` L35). Production-order network (parent/child) walks set→piece→semi-finished orders (`03-spec-execution.md` L70). **Order-as-anchor is the published model.** |
| **IR-5** | **Trial / sample batch** stage with real cost (R&D-run), customer evaluates | ❌ **NOT COVERED** | `order_type ∈ {Standard, Rework, Repair}` only (`03-spec-execution.md` L24,L291; `20-mapping.md` row 13). **There is no `Trial`/`Sample`/`Pilot` order type**, no "produce-for-customer-evaluation → approval gate → convert-to-production" flow. The spec's only sample-ish concept is `routing_type=Inspection` (a routing flavor, not an order lifecycle). A trial batch is "a real process with real cost" → it needs the full Issue/Confirm/Receipt+GL rail (which exists) but **gated as a trial, with an evaluation/approval outcome that either promotes the order to production or stops it** — that gating + the trial→approval→formal-order transition is entirely net-new. Closest published item: `B5 rework flow undefined` and `B13 ECO` — neither is the trial cycle. |
| **IR-6** | On agreement → formal order → R&D finalizes BOM → Planning computes qty + readiness | 🟡 **PARTIAL** | **BOM finalize (Draft→Active):** covered (`20-mapping.md` row 2; lifecycle in `01-spec-masterdata.md` L255). **Planning qty + readiness:** covered by MRP netting + CRP readiness (`20-mapping.md` rows 11–12; `23-roadmap.md` Phase 4; `02-spec-planning.md`). **What's missing:** the **explicit business-process orchestration** "agreement event → R&D hand-off → Planning hand-off" as a tracked, role-routed multi-department workflow; the published plan has the *engines* (BOM lifecycle, MRP, CRP) but not the **staged approval/hand-off pipeline with department ownership** that the client describes (ties to IR-9). |
| **IR-7** | **Deposit / down-payment gate** before reserve/purchase (factory buys RM on customer's behalf) | ❌ **NOT COVERED** | No financial gate exists between Planning and Reservation. Published `ReleaseProductionOrder` (Planned→Released) **reserves stock unconditionally** (`22-contracts.md` §2 `ProductionOrderReleased`; `23-roadmap.md` Phase 1 "Release side-effects: reserve stock"; `03-spec-execution.md` L63). The spec has **no down-payment / advance-payment / customer-deposit concept** (grep: no "deposit/advance/دفعة" in digests). This is a **toll-specific hard gate**: receive + verify a customer deposit (an AR/finance document) → only then allow reserve/PO. Requires (a) a deposit/advance document (Sales/Accounting), (b) a **Release precondition** checking deposit sufficiency, (c) wiring the factory-buys-RM-on-behalf semantics (procurement billed back to the customer). None are in scope. `B18 toll fee invoicing` mentions toll *output* invoicing only — not an *upfront* deposit. |
| **IR-8** | Customer-supplied raw materials remain customer property; mixed with own materials | ✅ **FULLY COVERED** | `production_type=TollManufacturing` + `material_ownership ∈ {Own, Customer}` on order, component, and issue line (`03-spec-execution.md` L27,L107,L128; `20-mapping.md` rows 13,17). Consignment = dedicated `warehouses.is_consignment` rows — held, never valued, never purchasable (`20-mapping.md` row 17; `21-gaps.md` A15; `22-contracts.md` §1 Inventory row; decision **D-15**; `23-roadmap.md` Phase 6). Toll issue = tracking-only movement, **no RM credit at own cost** (`22-contracts.md` §4 toll row; `03-spec-execution.md` L128). **Mixing own + customer materials in one order is exactly the per-line `ownership` model** — fully handled. (Note: this is scheduled at **Phase 6**; if this client is the launch customer, Phase 6 toll/consignment must pull forward — decision **D-07** already anticipates this.) |
| **IR-9** | Dedicated **per-stage workspace screens** to advance the order stage-by-stage | 🟡 **PARTIAL** | **Shop-floor operator terminals** are covered (per-WC touch terminals, Ready queue, Start/Done, supervisor dashboard — `20-mapping.md` §5 `shop-floor/`; `23-roadmap.md` Phase 5; `05-spec-shopfloor.md`). The Angular FE layout (`20-mapping.md` §5) has stage-grouped folders (`planning/`, `execution/`, `costing/`). **What's missing:** the client wants **back-office STAGE WORKBENCHES for the whole order journey** — R&D screen, Planning screen, Finance-deposit-gate screen, Reserve/Issue screen, Trial screen — each owning a stage and providing the "move to next stage" action with role-gated hand-off. The published FE is organized **by functional module** (boms, planning, execution…), not as a **single order-centric stage pipeline / workflow board**. The orchestration UI (one order walking named stages with per-stage ownership) is net-new. |

**Tally:** ✅ 2 fully covered (IR-4, IR-8) · 🟡 4 partial (IR-2, IR-3, IR-6, IR-9) · ❌ 3 not covered (IR-1, IR-5, IR-7).

---

## 2. Root-cause: why the gaps exist

The published analysis is an **execution-grade map of the manufacturing spec**, and the spec itself
**begins at a confirmed customer order** and ends at finished-goods receipt + costing. It models the
*factory floor and its books* superbly. The client's workflow adds a **pre-order commercial/engineering
funnel** the spec never contemplated:

1. **Pre-sales costing funnel** (IR-1→IR-3): request → R&D draft recipe → exploratory price → quote.
   The spec has no quoting, no exploratory/draft-cost mode, no R&D actor — demand is *already confirmed*
   when its model starts. This is the single biggest blind spot and it is **commercial, not manufacturing**.
2. **Trial-batch lifecycle** (IR-5): a real but *provisional* production run whose business outcome is a
   customer go/no-go, not finished-goods stock. The spec's `order_type` enum has no trial state.
3. **Deposit-gated procurement** (IR-7): a toll-business cash-control rule (buy RM only after the customer
   pays) that sits at the Release transition. The spec reserves unconditionally.
4. **Department-staged workflow + per-stage UI** (IR-6 partial, IR-9): the client thinks in *departments
   and stages* (R&D → Accounting → Planning → Finance → Floor); the published plan thinks in *engines and
   modules*. The engines exist; the **staged orchestration layer and its screens** do not.

Everything *downstream of the confirmed formal order* (BOM lifecycle, MRP/CRP, reserve, issue, confirm,
receive, cost, toll consignment, pegging) is already covered — IR-4 and IR-8 are textbook hits, and IR-2/IR-3/IR-6
reuse existing engines with workflow glue missing.

---

## 3. Definitive NEW work items (addendum to roadmap 23)

Each item is sized with the **gap-level** legend from `21-gaps.md` (S ≤ ~3 dev-days · M ≤ ~3 dev-weeks · L > 3 dev-weeks)
and assigned a target phase relative to the published roadmap.

| New ID | Work item | Covers | Type | Size | Target phase |
|---|---|---|---|---|---|
| **C-01** | **Manufacturing RFQ / Costing-Request entity** `mfg_costing_requests` (+ lines): customer, brought-product description/composition, status `{Requested, BomDrafted, Priced, Quoted, Won, Lost}`; links to the draft BOM (C-02) and the quote (C-03). First-class intake; numbered via `SequenceService('production','costing_request')`. | IR-1 | NEW table + Action | M | **New Phase 2.5** (pre-sales; renamed from the provisional "1.5" — needs Phase-2 WC rates, `md/36` §3) |
| **C-02** | **Draft-BOM for prospect products**: allow a BOM in `Draft` whose parent is a *prospective* product. Either (a) make BOM `product_id` nullable with a free-text `prospect_product_name` for exploratory BOMs, or (b) auto-create a `Product` of a new `lifecycle=Prospect` state. Plus **R&D ownership**: new role + permissions `production.rnd.bom.{draft,finalize}`. | IR-2, IR-6 | EXTEND `bill_of_materials` + Core role/perms | M | Phase 1 (BOM v2) + Phase 0 (perms) |
| **C-03** | **Exploratory/Preliminary costing mode + Quote document**: run `RollUpStandardCost` against a Draft BOM with *estimated* material prices, persist as `mfg_cost_estimates`, and emit a customer-facing **quote** (reuse Sales quotation if present, else `mfg_quotes`). Accounting-review step. **Pull cost roll-up forward** from Phase 3 (at least an estimate-only variant). | IR-3 | NEW Action (estimate mode) + NEW table + Sales tie-in | M | Pull part of Phase 3 cost roll-up into **Phase 2.5** (after Phase-2 labor/OH rates land) |
| **C-04** | **R&D actor / department model**: register R&D as a role/department with its own permission slice and as the **owner of Draft-BOM and Trial stages**; extend `PermissionDependencyRegistry` `production` contributor with R&D presets. Distinguish R&D vs Planning vs Finance vs Floor ownership for stage routing (feeds C-08). | IR-2, IR-5, IR-6 | Core perms + role config | S | **Phase 0** (perms layer) |
| **C-05** | **Trial / Sample-batch order type**: add `Trial` (and/or `Sample`,`Pilot`) to `ProductionOrderStatus`/`order_type`; a Trial order runs the **real Issue→Confirm→Receipt+GL rail** but flagged `is_trial`, output routed to a *trial/evaluation* bucket (not sellable FG), and on customer evaluation either **promotes to a formal production order** (carrying the finalized BOM/routing) or closes as Lost. New events `TrialBatchProduced`, `TrialApproved`/`TrialRejected`. | IR-5 | EXTEND `production_orders` enum + Actions/events | M | **New, between Phase 1 and Phase 2** (needs execution rail from P1) |
| **C-06** | **Customer-deposit / down-payment gate**: a deposit document (reuse Sales/Accounting **advance-payment / customer-deposit** if it exists in Moon — VERIFY; else `mfg_order_deposits`) capturing required %, received amount, status; and a **`ReleaseProductionOrder` precondition** that blocks reserve/PO until `deposit_received ≥ deposit_required` (configurable per order/customer). Wire "factory purchases RM on customer's behalf" so MRP-raised POs are tagged billable-to-customer **and are raised ONLY after the deposit gate is satisfied — the gate governs purchasing as well as release/reservation (the client's stated reason for the deposit; planning prepares draft PRs only)**. | IR-7 | EXTEND Release guard + PR gate + Sales/Accounting deposit doc | M | **Phase 2** (gate, per `md/36` §3) + **Phase 4** (MRP billable-PO tag) |
| **C-07** | **Pull Toll/consignment forward** (decision D-07): if this client is the launch customer, move `warehouses.is_consignment`, per-line `material_ownership`, and toll GL branch from **Phase 6 → Phase 1/2**. Already fully designed (IR-8) — this is a *scheduling* change, not new design. | IR-8 (timing) | Roadmap re-sequence | — | Re-sequence Phase 6 → early |
| **C-08** | **Order stage-pipeline + per-stage workbench screens**: a single **order workflow state model** (`Request → DraftBom → Quoted → Trial → Agreed → BomFinal → Planned → DepositGate → Reserved → InProduction → Received`) with a **stage owner** per step, and back-office **stage workbench screens** (R&D, Planning, Finance-gate, Reserve/Issue, Trial-review) each exposing "advance to next stage" with role-gated hand-off and an order-centric **pipeline board**. Distinct from the shop-floor operator terminals (which stay). **Interpretation caveat (OQ-9):** this reads «مرحلة إنتاجية» as *commercial case stages*; if the client means per-MANUFACTURING-stage screens (mixing/granulation/compression/packaging), the answer is per-operation workbenches over routing operations — must be confirmed at the Phase-0 gate. | IR-6, IR-9 | NEW workflow engine + Angular stage screens | L | Board MVP Phase 2 + gate-critical workbenches Phase 2.5; completion Phase 5 (`md/36` §3) |

**New tables introduced by this addendum:** `mfg_costing_requests` (+lines), `mfg_cost_estimates`,
optionally `mfg_quotes` (prefer reuse of Sales quotation), optionally `mfg_order_deposits` (prefer reuse of an
Accounting/Sales advance-payment doc). Net **2–4 new `mfg_*` tables** on top of the published 24, pending
Sales/Accounting reuse verification for quote + deposit.

**New enums / state extensions:** `order_type += Trial` (or new `is_trial` + trial sub-state); BOM
`product_id` nullable / `Product.lifecycle=Prospect`; `mfg_costing_requests.status`; an **order
stage-pipeline** workflow state separate from the financial `ProductionOrderStatus`.

**New actors:** **R&D department/role** (owns Draft-BOM + Trial); explicit **Finance deposit-gate** owner.

---

## 4. Decisions this addendum needs from management (extends D-01..D-22)

> **Authoritative numbering = `md/36` §4.** This table proposed the decisions; the register in
> `md/36` §4 (D-23..D-36 + OQ-9) carries the final numbers and recommendations and supersedes any
> divergence below (e.g. D-24's recommendation here was superseded by the ratified
> `order_type=Trial`).

| # | Decision | Options | Recommendation |
|---|---|---|---|
| **D-31** *(was provisionally "D-23" here)* | Pre-sales costing cycle scope | Build full RFQ→DraftBOM→Quote (C-01..C-03) vs minimal estimate spreadsheet | **Build C-01..C-03** — it is this client's entry point; without it Cycle-1 is unserved |
| **D-24** | Trial-batch modeling | New `order_type=Trial` vs reuse Standard order + flag vs separate trial module | **`is_trial` flag + trial sub-state on production order** (reuses the full P1 rail; lightest) |
| **D-25** | Deposit gate enforcement | Hard block at Release vs advisory warning vs per-customer config | **Hard block, configurable threshold per order/customer**; reuse Moon advance-payment if it exists |
| **D-26** | Draft-BOM for prospect product | Nullable `product_id` vs `Product.lifecycle=Prospect` state | **`Product.lifecycle=Prospect`** (keeps BOM FK integrity; promotes cleanly on Won) |
| **D-27** | Toll/consignment timing for this client | Keep Phase 6 vs pull to Phase 1/2 | **Pull forward** (this is a toll factory — D-07 trigger fired) |
| **D-28** | Stage-pipeline UI scope | Full workflow engine + per-stage screens (C-08, L) vs order-centric pipeline board MVP first | **Pipeline board MVP early; full per-stage workbenches Phase 5** |
| **D-29** | Quote / deposit document ownership | New `mfg_*` tables vs reuse Sales quotation + Accounting advance-payment | **Reuse Sales/Accounting where they exist** (VERIFY in `/home/moonui/moon-erp-be`); `mfg_*` only as fallback |

---

## 5. Bottom line

The published analysis **fully covers the order-anchored, toll/consignment manufacturing core** this client
needs (IR-4, IR-8) — order-to-everything pegging and customer-owned-material handling are textbook hits, only
needing toll/consignment **pulled forward** in time (C-07/D-27). The **engineering and planning engines** for
IR-2/IR-3/IR-6 already exist (BOM lifecycle, standard-cost roll-up, MRP/CRP) but lack the **workflow glue,
R&D actor, exploratory-cost mode, and quote document** to serve the client's *commercial* funnel.

The **three genuine net-new capabilities** are all *outside the manufacturing spec's universe*: the
**exploratory-costing/RFQ cycle** (IR-1, ❌), the **trial-batch order lifecycle** (IR-5, ❌), and the
**customer-deposit gate before reservation** (IR-7, ❌) — plus the **per-stage workbench orchestration UI**
(IR-9, 🟡). These become work items **C-01..C-08** and decisions in the authoritative register
**`md/36` §4 (D-23..D-36 + OQ-9)**, appended to roadmap 23.
None invalidate the published architecture; all are additive and reuse the existing rails.
</content>
</invoke>
