# LEDGER — ISS-2026-9165: "issued to a production order" report (warehouse reports)

**Date:** 2026-07-19 · hazemdev2 both repos · dev DB moonui2_dev_be (forward-only) · **Implementer = Codex (codex:codex-rescue); Opus organizes + reviews + deploys.**
**Source:** Portal ISS-9165 analysis + client scope_freeze step 4577 «أخذ بالتوصية + لازم يكون فيه صلاحية لإخفاء التكلفة».

**Owner/client acceptance:** In warehouse reports (تقارير المخازن), the storekeeper picks a production order (+ optional date range) and sees, per material, how much was issued to it — quantity + unit + planned-vs-issued, with إذن-صرف numbers/dates and totals. Cost columns are shown ONLY to users holding a cost-visibility permission; others see the report without cost.

## Frozen decisions
- Single production order with per-material detail (client took rec) + date filter.
- Show cost + quantities, BUT cost gated by a NEW permission (client: «صلاحية لإخفاء التكلفة») — holders see cost, others don't (BE strips cost fields when the user lacks it; FE hides the columns).
- Show planned vs issued (client took rec).
- Lives as a new tab in the existing inventory-reports screen (`/core/inventory-reports`, perm `inventory.reports.view`). Excel/PDF export like the other tabs.

## Data source (confirmed)
- `MfgMaterialIssue` (production_order_id, inventory_issue_id, issued_at, issued_by) + `MfgMaterialIssueLine` (product_id, quantity, unit_id, unit_cost). Aggregate per product for the order.
- Join `inventory_issues` (issue_number = إذن الصرف number) + `production_order_materials` (planned_quantity, consumed_quantity).
- Company-scoped via `auth()->user()->company_id`.

## WP table
| WP | Scope | Repo | Depends | Implementer | Review | Migration? | Status | Commits |
|----|-------|------|---------|-------------|--------|-----------|--------|---------|
| WP1 | BE: report endpoint + cost permission. | BE | — | opus sub-agent (Codex env-blocked at the time) | code-reviewer(opus) | permission seed only | ✅ done | `78880d6da` · 19 tests pass (5 new + 14 baseline) · pint clean · local-deploy + RolePermissionSeeder run on dev; permission granted to owner/manager/accountant/production_cost_accountant (verified). Codex blocker later solved (drive via companion `task --cwd <repo>` — see memory); WP2 will use Codex. |
| WP2 | FE: report tab + service + picker + cost-gated columns + export. | FE | WP1 | opus sub-agent | code-reviewer(opus) | — | ✅ done | `91d750c5e` · new 'Production Order Issues' tab in inventory-reports + productionOrderIssues() service + PO picker + cost cols gated on can_view_cost + Excel/PDF export + i18n · ng build green |

## Serialization
WP1 (BE) → WP2 (FE). One writer per repo. Codex implements each; Opus reviews + deploys /app + publishes ISS-9165 verification.

## Notes
[FIN]-light (reads costs, no GL posting). Opus owns the ledger + review gates + deploy. Decisions/comms via the ticket ([[decisions-via-ticket-not-chat]]). No merge/main (owner /fullpush).

## WP1 review (code-reviewer opus) — APPROVE
0 crit/high/medium. Company isolation + cost-permission gating both correct (no cross-tenant/cost leak). 4 LOW (deferred, non-blocking test-hardening):
- weighted-average cost test uses equal unit_costs → doesn't truly exercise total_cost/qty; add mixed-cost product.
- no test for zero-issues order (materials:[], totals 0) or missing production_order_id → 422.
- seeder-level assertion that storekeeper role LACKS inventory.reports.production_issue_cost.
- productionOrderIssues() ~100 lines (>50 guideline) — extract per-material mapping closure.

## WP2 review (code-reviewer opus) — APPROVE
0 crit/high/medium. Cost gating airtight — all 5 cost render/export sites guarded on poCanViewCost (no leak). Load-guard, tab isolation, picker/data flow, export, i18n parity all clean. 2 LOW (deferred): roster listAll() fires on every ngOnInit (lazy-load on tab-5 entry instead); no planned-qty grand total in footer (deliberate).

## STATUS: ✅ COMPLETE — both WPs done+reviewed(APPROVE). Deployed /app main-2BCW4LJR.js. CHANGELOG bilingual bullet present (ISS-9165). Awaiting owner /fullpush + client test. Codex could not run here (cPanel/CageFS) → opus implemented both WPs.
