# WP1 — Column show/hide (⚙ gear) on stock-issue + stock-receipt grids

## Goal
Give the «تعديل إذن الصرف» and «تعديل إذن الإضافة» line grids a ⚙ gear popover that toggles each column's visibility, driven by the existing `DocConfigService` (company-wide `core.document_settings`, gated by `core.settings`). Register every grid column in `DOC_CONFIG_REGISTRY` so the toggles exist and each `<th>`/`<td>` is guarded by `fieldVisible`. Locked columns (product, quantity) always stay visible. Display-only — no change to save/approval/posting.

## Exact files (FE `/home/moonui2/public_html/moon-erp`)
1. `src/app/core/services/doc-config.service.ts` — extend the registry entries `inventory.issue` (currently ~line 103, only 3 fields) and `inventory.receipt` (~line 91, 4 fields) to register ALL toggleable line columns. Use the `LINE(key, labelKey, {opts})` helper (defined ~line 10). Keep existing entries; ADD the missing ones.
   - **issue** line fields to have registered (area 'line'): `product_id`(locked, exists), `product_variant_id`, `stock`, `unit_id`(exists), `quantity`(locked, exists — this is «المطلوب»), `issued_quantity`, `warehouse_id`, `owner_partner_id`, `batch_number`.
   - **receipt** line fields: `product_id`(locked, exists), `product_variant_id`, `stock`, `unit_id`(exists), `quantity`(locked, exists), `unit_cost`(exists), `total_cost`, `batch_number`.
   - Field `key` MUST equal the string the template passes to `fieldVisible(docKey, key, 'line')`. For form-backed columns use the formControlName (`product_variant_id`, `issued_quantity`, `warehouse_id`, `owner_partner_id`, `batch_number`, `unit_cost`). For display-only columns use logical keys `stock` and `total_cost`.
   - labelKeys: reuse existing i18n (`INVENTORY.PRODUCT`, `PRODUCTS.VARIANTS`, `INVENTORY.STOCK`, `INVENTORY.UNIT`, `INVENTORY.REQUESTED`/`INVENTORY.QUANTITY`, `INVENTORY.ISSUED_QTY`, `INVENTORY.LINE_WAREHOUSE`, `INVENTORY.LINE_CONSIGNOR`, `INVENTORY.BATCH_NUMBER`, `INVENTORY.UNIT_COST`, `INVENTORY.TOTAL_COST`). All already exist.
2. `src/app/features/stock-issues/stock-issues.component.ts` + `.html` — add gear button + popover; guard every currently-unguarded `<th>`/matching `<td>` with `@if (docConfig.fieldVisible(docKey, '<key>', 'line'))`. docKey already = `'inventory.issue'` (ts:81). `unit_id` already guarded — leave it.
3. `src/app/features/stock-receipts/stock-receipts.component.ts` + `.html` — same. docKey = `'inventory.receipt'` (ts:78). `unit_id` + `unit_cost` already guarded — leave them.
4. `src/assets/i18n/ar.json` + `en.json` — add only if a needed label key is missing (most exist). Add e.g. `INVENTORY.COLUMNS` ("الأعمدة" / "Columns") for the gear tooltip.

## Reference pattern — invoice gear (copy the shape, adapt to LINE area)
`invoices.component.html:329-406`: a `pi pi-cog` `p-button` toggles a `fieldSettingsVisible` signal; a `field-settings-panel` renders `@for` over a list of `{key,label}`, each a `<p-toggleSwitch [ngModel]="isFieldVisible(f.key)" (ngModelChange)="toggleField(f.key)">`. For the stock grids, the toggle list is the docKey's registry LINE fields where NOT locked; bind to `docConfig.fieldVisible(docKey, key, 'line')` and on change call `docConfig.setField(docKey, key, 'line', 'visible', newVal)`.
- Only render the gear button when `permissions.hasPermission('core.settings')` (inject `PermissionService`). If no permission → no gear, columns render at their default/persisted visibility (read-only).
- Build the toggle list from `docConfig.registry.find(d=>d.key===docKey)?.fields.filter(f=>f.area==='line' && !f.locked)` — do NOT hardcode.

## DocConfigService API (already exists — just call it)
- `fieldVisible(docKey, fieldKey, area): boolean` (:227) — locked→true; else override else registry default.
- `setField(docKey, fieldKey, area, aspect, val)` (:256) — persists to `core.document_settings` company-wide.
- `docConfig.registry` (:192) — the DOC_CONFIG_REGISTRY array (for building the toggle list).
- `LINE(key,label,{locked?,defaultVisible?})` (:10) — registry field helper.

## Interfaces (consumed by WP2)
- After WP1 the registry lists the FULL ordered column set per docKey. WP2 will read `docConfig.registry.find(...).fields` (line area) as the canonical column list to drive order/width. Keep field `key`s stable and equal to the template guard keys.

## Acceptance criteria
- [ ] A `core.settings` user sees a ⚙ gear on both edit dialogs; toggling a column hides/shows its `<th>` AND its `<td>` together (no orphaned header/cell).
- [ ] product & quantity toggles are absent or disabled (locked → always visible).
- [ ] Hiding then reopening the dialog (or reloading) keeps the choice (persisted company-wide via `core.document_settings`).
- [ ] A user WITHOUT `core.settings` sees no gear and the persisted layout applies read-only.
- [ ] Bespoke cells still work: consignor still only shows when its column is visible AND `lineShowsConsignor(i)`; on-hand badge, serial/lot chips, barcode unaffected.
- [ ] `ng build` green. No change to onSave payload / approval / posting.

## Tests
- No FE runner. Gate = `ng build` green + opus review + manual acceptance on /app.

## Flags
- NOT [FIN] (display-only). No migration.

## Out of scope
- Reorder & resize (that's WP2). Read-only detail-view tables. Any save/approval/posting logic. Invoices/other docs.
