---
title: Production & Manufacturing
slug: production
status: active
owner: hazem
updated: 2026-06-18
refs:
  - moon-erp-be/Modules/Production/
  - moon-erp/src/app/features/production/
plans:
  - knowledge-base/plans/mfg-mto-flow-plan.html
related: []
---

## Context
The Manufacturing module + its **cost-accounting megaproject** (8 phases 0–7 + Phase A/B/C). Covers work centers, BOM/routing, production orders, WIP/cost roll-up, consignment (Phase C, shipped + merged to main). The factory side has its own nav and screens under `/production` (FE) and `Modules/Production` (BE).

## How it works / current state
- **Production dashboard** — intentionally simple/professional ("داش بورد كويسة للإنتاج لانها بسيطة اوي") + a **per-work-center load board** (`capacity()` / by_center in `ProductionDashboardService`).
- **Factory side menu is collapsible** — nav groups collapse (long menu): `expandedGroups` signal, `toggleGroup`, `isGroupExpanded`, `expandActiveGroup` in `factory-layout.component.{ts,html,scss}`.
- Cost-accounting: Phases 0–7 + Phase A done & pushed; Phase B reverted (redundant); Phase C consignment shipped + merged to `main` (BE `5e692e120` / FE `19b1a1c`).

## Decisions & why
- **Dashboard kept simple on purpose** — the value is at-a-glance load + status, not a wall of charts.
- **Phase C = explicit-borrow design** (consignment) after review fixes.
- There was an **AI feature** in the manufacturing work — check `Modules/Production` + the FE feature for where it lives before re-building.

## Gotchas
- The factory nav was historically much larger than what showed — verify the DB-driven nav matches the screens that exist (test + elmadina installs drifted).

## Make-to-Order customer flow (2026-06-18 analysis)
A customer's desired MTO cycle was analysed against the module (9-agent code-verified sweep). Full doc: **[`plans/mfg-mto-flow-plan.html`](../plans/mfg-mto-flow-plan.html)**.
- **Verdict: ~85–92% of the mechanics already exist** (BOM, routing, 3-leg standard cost, MO state machine, FEFO issue with balanced WIP GL, MfgPegging SO↔MO, OrderCockpit readiness). The customer flow is essentially the documented **pharma-toll** workflow ([`plans/mfg-pharma-toll-fitgap.html`]).
- **Net-new build = a thin layer:** (1) a standard **Production-Request / intake** entity (clone the `MfgTollContract`/`Line` shape — customer + existing/new-product line + qty + polymorphic attachments — but drop `material_ownership='customer'`); (2) **new-product → Development BOM** routing (BOM is born `Active`, no draft→approve, no dept ownership, no "needs-BOM" queue); (3) the **3 Accounting approval gates** — request→Sales-Order, MO **launch** (`ReleaseProductionOrder`), and **additional-material issue** (`IssueMaterials` has no qty cap / no approval today).
- **Key reuse:** Core `ApprovalWorkflow` engine exists but is **unwired** (no production `ApprovalDocumentType` cases, `submitForApproval` only called in tests, approve() doesn't mutate the document). Wiring it = add production doc-types + an `Approvable` event/callback + checks at the 3 points. `Attachment` (polymorphic) already supports product PDFs/formula images — only the **upload UI** is missing.
- **Decision to keep:** do NOT build a parallel readiness/planning service — enhance `OrderCockpit::readiness` (Phase B was reverted for duplicating it).

## Open / next
- **MTO flow:** awaiting owner answers (see §7 of the plan): is "قسم التول" a toll/consignment dept or just sales-intake; SO-then-MO semantics; whether material-availability is a hard gate or advisory; definition of "additional material"; single vs multi-level approver.
- Optional dashboard enhancements (quality CoA strip, `variance_monthly` trend, real late-order ids).
- Confirm the manufacturing DB additions are present on test/elmadina (older installs were missing pieces — see [moonstack-update](moonstack-update.md) seeder gap for why reference data drifts).

## Links
- Detail/state currently also in `MEMORY.md` `mfg-*` notes (project-state, phaseC-borrow-decision, ui-reorg-plan) → consolidate into this file as we touch them.
- (Add HTML plans here under `plans:` when created — e.g. a plan page for a specific production problem.)
