# Changelog — openorderbook

> All notable changes to the **openorderbook** module are documented here.
> Newest first.

---

## v0.9.0 — 2026-03-25
### Admin & TODO view
- Added `admin/setup.php` with Show TODO module option
- Added TODO menu entry linking to `arrears_plan.php`
- `arrears_plan.php`: renders `TODO.Arrears.EN.md` inside Dolibarr layout
- Fixed `config_page_url` to use full `/custom/openorderbook/` path (consistent with planning/scrap modules)

### Scrap query fix
- Scrap qty now uses `job_number` via `llx_mrp_mo_extrafields` (direct `fk_mo` was unreliable)
- Fixed unclosed brace in scrap bulk query block
- Added scrapped qty to MO tooltip in order lines

---

## v0.8.0 — 2026-03-24
### Arrears view
- Implemented arrears page with produced / scrapped qty and date filters
- Added BY column showing creator initials
- Reordered arrears columns: Our Part first, then Customer PN, Customer, Order#
- Fixed gap after title using `fichecenter` wrapper

### Order list UI
- Split Action column into separate Action and Delete columns
- Center-aligned ACTION and DELETE column headers
- Added currency symbol prefix to PRICE/EA input and SOLD VALUE column
- Added currency symbol to Create SO modal (price and total)
- Added radio-like checkboxes for Contract month and Delivery date in Create SO modal
- Added delivery date checkbox with blocking logic to Create SO modal

### MO / Qty produced fix
- `qty_produced` now uses only MAX op_rank from optracking to avoid double-counting
- Resolved MO via `fk_soc_line → element_element` fallback (same as paper_work)

### Dashboard
- Added Open Orders by Customer pie chart
- Fixed wider customer pie chart to prevent legend truncation
- Matched Order Lines pie chart size to customer chart (500×200)

### Delete modals
- Delete order modal with SO-aware options (list view)
- Delete line modal with SO-aware options
- Made Linked SO links visible inside delete modals
- Moved modal CSS to `openorderbook.css` (fixed modal visible on DRAFT-only orders)

### SO workflow
- OPEN SO button + `ORDER_DELETE` trigger
- Renamed `predicted_date` → `delivery_date` + updated all UI labels

---

## v0.7.0 — 2026-03-23
### SO column
- Replaced SO br-list with compact dropdown button in list view
- Added Sales Order links column in paper order list view
- Cached `SHOW COLUMNS` result in session for performance

---

## v0.6.0 — 2026-03-19 (major quality sprint)
### Security
- Replaced `db->escape()` on column names with explicit whitelist in `oob_subcon_set_status()`
- Gated Create SO on `commande->creer` permission
- Added read/write permissions with access guards throughout
- Fixed CSRF on Create SO confirm modal (POST form, token)

### Performance
- Removed `SHOW TABLES` check (tables guaranteed by module install)
- Added LIMIT 500 to customer dropdown
- JOIN societe in detail SELECT to remove extra query
- Fixed N+1 queries in list views (`paper_work` + `completed`)

### Refactoring
- Removed 24 `console.log()` debug calls from `paper_work.js`
- Removed orphaned `.oob-ws-badge` CSS (MACHINE column restructured)
- Removed unused `fk_soc` parameter from autocomplete
- Replaced `value[]` input with span (not submitted); removed dead `applyAutocompleteSelection()`
- Cleaned up orphaned console.log object literal that broke autocomplete JS
- Removed 3 unused table definitions; added `DROP TABLE IF EXISTS` migration

### Fixes
- `contracted_month` changed from `VARCHAR(16)` to `DATE`
- Moved delete POST forms outside outer forms (invalid nesting)
- Replaced GET delete links with hidden POST forms
- Fixed broken JS selectors for row auto-append and numbering
- Fixed create SO redirect on missing `commande` permission
- Fixed `save_all` showing SQL errors instead of always redirecting
- Unified `step=0.01` for qty/price; replaced `PHP_SELF` with `dol_buildpath()`
- Removed `$tables_exist` guard on `save_header` action

### UI
- Rich user tooltip on initials (Dolibarr standard)
- Author full name in Paper Work page title
- SO replace Create SO confirm page with productionrules-style modal

---

## v0.5.0 — 2026-03-18
### MO / MACHINE / JOB columns
- MACHINE column: styled workstation badge (orange pill + gear icon), click navigates to MO card
- MACHINE column: rich routing tooltip with per-step optracking status
- Merged MACHINE + MO-STATUS into single MO column: status badge + ws badge + rich tooltip + bulk produced qty
- MO column: removed ws badge, kept status badge only
- JOB column: link to `mo_card.php` + tooltip (MO ref, status, qty)
- Tooltip: overrode Dolibarr `min-width:550px` forcing extra empty space; fixed to auto-fit content

### Docs
- Added `ANALYSIS.md` — module audit findings and fix plan

---

## v0.4.0 — 2026-03-09
### MO traceability
- Added `fk_mo` column to `llx_openorderbook_paperline`
- Added `MRP_MO_VALIDATE` trigger for OOB paperline → MO traceability
- Fixed trigger: removed duplicate `onMoValidate` body causing parse error
- Fixed duplicate tooltips; rendered proper MO status badge
- Resolved MO dynamically from SO link in Paper Work
- Showed produced quantity in MO tooltip
- Fixed produced qty: filter `role='produced'`, use final MO product only

### Subcon
- SUBCON data model + OOB paperline → SO line link
- Show subcon status in Paper Work order lines

### UI
- Compact order lines layout, ellipsis description, improved MO tooltip
- Used standard Dolibarr colored status badges for MO status column
- Added product tooltip for OUR PART column
- Added creator initials column to Open Orders with Dolibarr user tooltip
- MACHINE badge: click navigates to MO card
- Renamed WORK STATION column to MACHINE
- Used `dol_buildpath()` in Paper Work display of MO job_number, working_station, ref, status

### CSS fixes
- `table-layout:fixed` + overflow on description to prevent header reflow
- Reduced number input min-width; added `width:100%` to fit column
- Nowrap on DESCRIPTION, OUR PART, column headers
- Reduced QTY/PRICE/SOLD VALUE column widths to fit viewport
- SO persist planned delivery date from `contracted_month`

### Chore
- Added `.gitattributes`; normalized all files to LF line endings
- Fixed SQL `ALTER TABLE`: removed `IF NOT EXISTS` from ADD INDEX/COLUMN

---

## v0.3.0 — Customer PN Autocomplete
- Autocomplete via product extrafield `customer_pn`
- Removed FG search; custom JS dropdown (cross-browser)
- Immediate apply on selection

## v0.2.0 — Line Editing
- Dynamic line grid; Save All logic
- Insert and update lines
- Prevent empty line creation

## v0.1.0 — Initial scaffold
- Module created; DB tables: `llx_openorderbook_paper` + `llx_openorderbook_paperline`
- Basic header form + save header logic
- ACTION dropdown (OPEN / CLOSE / CANCEL)
- CSS moved to dedicated file; JS centralized

