# Stock-balances screen fixes — B1→B8 execution tracker

> Executes Fable's ranked plan from [stock-balances-lots-consignment-review.html](stock-balances-lots-consignment-review.html) (full B1–B8 specs + mockups are IN that HTML — agents read the relevant B-section there). Branch **hazemdev2**, push periodically, **NO merge to main**. Each chunk: implement → **Fable UX review** → deploy → push. code-reviewer for BE correctness. Root artisan → chown storage bootstrap/cache. FE = `/home/moonui2/public_html/moon-erp`, BE = `/home/moonui2/moon-erp-be`. Deploy FE: build → copy dist to `/home/moonui2/public_html/app`.

## Steps (Fable's ranked order)
- **B1** (FE, CRITICAL) ⬜ compound on-hand cell «105 +45 🤝» + value column → `owned_value` (BE already returns it on StockBalanceResource). **Closes the value leak on this screen.**
- **B2** (FE + small BE, CRITICAL) ⬜ row dataKey include product_variant_id; `productLots` scope lots + reconcile by variant.
- **B3** (BE+FE, HIGH) ⬜ list-level owner lens: BE `owner` param on `index` + a `lot-owners` endpoint; FE lens + violet banner + URL sync (port the reports' shipped pattern/i18n).
- **B4** (FE, HIGH) ⬜ harden lot expansion: error state (not blank/"no lots"), stale `lotsCache` after refresh, chevron only on batch-tracked rows.
- **B5** (BE, HIGH) ⬜ nearest-expiry map rebased on `inventory_lot_balances` (owner-attributed) instead of serials→genealogy→movements; owner hint on the badge.
- **B6** (BE+FE) ⬜ server-side `meta.totals` (whole-company owned/consignment, not page-only) + a violet consignment stat card.
- **B7** (FE) ⬜ counting/جرد entry point from the screen (the "أكّد بجرد" hint has no affordance).
- **B8** (FE) ⬜ per-lot value column · show-depleted toggle · batch-collision ⚠ detector · «رد للعميل» group action · fix LEGACY hardcoded tag · main-table RTL dir=ltr gaps.

## Ledger
- 2026-07-11 — plan received (Fable review). Starting B1+B2 (CRITICALs).
- 2026-07-11 — **B1+B2+B4 ✅ DONE** (BE `77eba8194` · FE `83d790589`, deployed). Value leak closed on the list (owned_value + «+N 🤝» compound cell), variant dataKey + productLots variant scoping, error/cache/chevron hardening, +makeLot→allocMakeLot suite-collision fix. 34 tests. Fable UX review deferred to ONE final review of the completed screen (after B8).
- 2026-07-11 — **B3+B5+B6 ✅ DONE** (BE `4c198380b` · FE `c5a62d6ac`, deployed). Owner lens + lot-owners endpoint · nearest-expiry from lot ledger + 🤝 owner attribution · whole-company meta.totals + consignment card. 8 new tests.
- 2026-07-11 — **BUGFIX (user-reported):** consignment «استلام أمانة» form stuck loading — `listAll()` fired ~686 requests over a 17k-product catalog. Fixed: products now server-side searchable (first 100 + onProductSearch). Deployed in `c5a62d6ac`.
- 2026-07-11 — **B7+B8 ✅ DONE** (FE `7ffa0ed39`, deployed). Count entry (3 gates → inventory-counts pre-fill) + lot value column · show-depleted · batch-collision ⚠ · «رد للعميل» · LEGACY key · RTL/token audit. **ALL B1→B8 SHIPPED.**
- 2026-07-11 — **FINAL Fable review: SHIP-with-tweaks** — 4 sign-off fixes applied (consignment-card passive · customer-lens expansion/cards coherence · recon-mismatch magnitude) + 2 optional (list-error state, count-link arrow). FE `a3842a66b`, deployed. **✅✅ PLAN COMPLETE — all B1→B8 shipped, Fable-signed-off.** Not merged to main.
- Deferred (low): optional (b) — move numeric-cell `dir="ltr"` from `<td>` to inner span (needs live visual check).
