# Changelog — productionrules

> All notable changes to the **productionrules** module are documented here.
> Format: grouped by version/date, newest first.

---

## v0.4.1 — 2026-03-25
### Fixes
- Placeholder fix (minor internal adjustment)

---

## v0.4.0 — 2026-03-23 / 2026-03-24
### Material Pack input — x-notation parser
- Added `NNNNxQTY` format support in material pack input (e.g. `62133x5`)
- x-notation parser: job required + auto-suggest based on input
- Removed redundant `fg_qty` field from rule form
- Fixed material packs showing `Array` instead of formatted text in BOM note (downstream)

---

## v0.3.0 — 2026-03-18
### Layout / Input alignment
- Fixed label column width to 170px — consistent input box alignment across all rule forms
- Fixed `pr-right` panel overflow: box-sizing, removed explicit width, corrected input widths

---

## v0.2.0 — 2026-03-17
### BOM Generation
- Redirect to BOM list after successful **CONFIRM GENERATE BOM**
- Generate BOM as Draft (`status=0`) instead of Enabled
- FG BOM now includes all routing service ops (edge op + self-routing steps)
- Fixed FG service resolution via workstation label; added `fk_default_workstation` to all service BOM lines
- Fixed `buildServiceMap` wrong column name (`type` → `fk_product_type`)
- Added routing service BOM lines on Generate BOM (SF=forming, FG=edge op)
- Fixed missing `FROM` in `fetch()`, added transaction to `delete_ruleset`
- Fixed infinite loop in `computeRequirements` — pre-load all rules (no N+1 queries)
- Prepend edge stage to FG routing lines in downstream BOM notes
- Fixed routing stage in BOM notes — SF uses root stage 10, FG uses edge stage
- Added editable root stage 10 (operation/workstation) to ruleset — prepended in BOM routing
- Fixed shifted BOM routing stage mapping

### Flow diagram / Layout
- SF node clickable — loads Root rule form on right panel on click
- SF node uses `data-href` from PHP for reliable click navigation
- Fixed SF node click: `stopImmediatePropagation` + guard on FG handler
- Added tooltip to SF node showing root rule (stage, op, ws, mfg efficiency)
- SF tooltip format aligned with FG tooltip style
- Separated columns with CSS grid — Flow position no longer affected by right panel height
- Fixed Flow section jump when Edit rule panel is taller than Root rule form
- Fixed layout jump: removed sessionStorage scroll save/restore approach
- Fixed extra `<br>` appearing when Root rule form is shown (shorter form)
- Fixed `min-height` on `pr-right` so Flow pins to constant bottom position

### Root rule form
- Root rule form on right panel: mfg efficiency + stage dropdown + op + workstation
- Expanded Root rule form to 7 rows (added Ref / Description / Status) — matches Edit rule height
- Reordered fields, renamed Stage→Step order, added autocomplete datalists
- Fixed missing closing braces after Root rule form
- Fixed CSRF: `show_add=1` param instead of `action=add_form` for GET link
- Fixed CSRF on ADD RULE link — guard add handler to POST only

### SAVE NEXT RULE workflow
- Added fast add-next-rule action from edit panel
- SAVE NEXT RULE: saves current rule then navigates to add form
- SAVE NEXT RULE: copies all edit fields to add form (without saving)
- Fixed PRG pattern — redirect after rule create

### Rule / Ruleset management
- Added delete action for selected rule
- Merged DELETE RULE button into same row as UPDATE / CANCEL / SAVE NEXT RULE
- DELETE RULESET button inline with Flow title (`morehtmlright`)
- Fixed `load_fiche_titre` param order for DELETE button
- Show root node and prefill `from_ref` on empty ruleset
- Create editable SF root rule on ruleset add
- Swapped CANCEL and SAVE NEXT RULE button order
- Fixed ADD RULE button size in Root rule form
- Fixed note field overflow in add rule form

---

## v0.1.1 — 2026-03-12
### BOM generation foundation
- CONFIRM GENERATE BOM button moved to modal footer, preserved button color
- Use `status+update` instead of `validate` for SF BOM (preserves PROV ref)
- Use Dolibarr automatic BOM numbering instead of manual ref
- Use standard BOM refs; apply manufacturing efficiency to all generated BOM lines
- Fixed BOM generation status; apply manufacturing efficiency to BOM lines
- Added `.gitattributes` to enforce LF line endings in repo

---

## v0.1.0 — initial
### Module scaffold
- Module descriptor (`modProductionrules.class.php`)
- Integrated into MRP menu section — `MRP → Production rules`
- Correct `fk_menu` logic for left menu
- Icon support via `$this->picto` prefix (consistent with MRP/MO style)
- Initial rule card (`productionrules_card.php`) and list (`productionrules_list.php`)
- SQL table for rules (`llx_productionrules`, `llx_productionrules_ruleset`)
- Admin setup page (`admin/setup.php`)

---

## Backlog
- Revision support per rule + per BOM
- Automatic MO creation from BOM
- Warnings for inconsistent rules
- Batch processing for multi-job BOM generation
- Filtering and grouping rules in UI
- Multi-stage BOM visualization
- Logging + audit trail for manufacturing traceability
- Rule import/export
- Rule preview & validation
- Unit tests & code coverage


---

## v0.1.0 – Module foundation
### Module bootstrap
- Created custom Dolibarr module under `/htdocs/custom/productionrules`
- Implemented module descriptor `modProductionRules.class.php`
- Added metadata: module id, version, dependencies, subversion flags
- Implemented proper init/remove methods aligned with Dolibarr module lifecycle

### Core functionality
- Implemented SQL table for storing production rules
  - Columns for from_ref, to_ref, operation, qty_per_from, workstation, step_order, flags
  - Support for multi-output from a single input
  - Support for revision and job-specific BOM logic
- Added rule persistence:
  - Insert rule
  - Delete rule
  - Delete all rules
  - List rules

### UI integration
- Created custom UI page `productionrules_rules.php`
  - Rule add form
  - Rule listing table
  - Rule deletion controls
- Added backend logic for validation and sanitize user input

### BOM generator core
- Implemented rule engine to compute:
  - Consumption matrix
  - Multi-step transformations (material→SF→FG)
- Implemented BOM generator using Dolibarr BOM API:
  - Generated BOMs inherit job number in reference
  - Designed to avoid product duplication

### Infrastructure
- Support for multi-line operations
- Stateless UI workflow (no JS dependencies)
- Standardized function/class naming aligned with Dolibarr architecture
