mega-plant/scripts
David f7ce429c04 Re-link invoice lines whose target asset a seed replaced
`booked_asset` stores an asset record ID, and `npm run seed` deletes and
re-creates every asset — so the id a line was booked against stops existing after
a seed. The line then points at nothing and silently drops out of monthly_income,
which is exactly the reported symptom: booked yesterday, unbooked today, with the
line still carrying the correct code.

The booking step now re-derives the pointer from the register code the line
already carries (`asset_code`, falling back to the machine code) whenever the
stored target is empty or no longer exists. It only ever points a line at the
asset its own code names, so it never invents a match and never clears a
site booking. A line with no matching code stays unbooked exactly as before.

This makes the documented run order self-healing:
`npm run seed && node scripts/book-invoice.mjs` now restores the links, so a
reset cannot silently unbook the register.

Verified by running a full seed and re-booking: 29 pointers were invalidated by the
seed and all 29 were re-linked, giving 45 posted rows and 3 unbooked lines — the
two MPLANT05 containers and one WT02 trailer, which have no matching plant item.
2026-10-09 00:52:52 +02:00
..
audit-auth-mobile.mjs feat: add user access and improve plant dashboard 2026-10-06 04:02:08 +02:00
book-invoice.mjs Re-link invoice lines whose target asset a seed replaced 2026-10-09 00:52:52 +02:00
extract.mjs Round 2 (Parts B-D): asset register restructure, type field, sequential codes, flat sortable table, cost_lines, removed synthetic code, fail loudly 2026-09-12 10:24:26 +02:00
seed.mjs Give external invoices a supplier name; keep them off the sites page 2026-10-08 12:04:42 +02:00
setup-auth.mjs feat: add user access and improve plant dashboard 2026-10-06 04:02:08 +02:00
setup-invoice-collections.mjs Sites: auto-allocate container lines to the container the site hires 2026-10-02 18:32:12 +02:00
setup-site-assignment.mjs Sites: auto-allocate container lines to the container the site hires 2026-10-02 18:32:12 +02:00
verify-auth-routes.mjs Split the invoice register into Internal and External Invoices 2026-10-08 11:49:48 +02:00
verify-cost-reconciliation.mjs Round 4: regressions fixed + mobile standard 2026-09-12 12:05:43 +02:00