# WP4 — Stock card: the «المصدر المباشر» column

**Repo:** FE (`/home/moonui2/public_html/moon-erp`) · **Branch:** `hazemdev2` · **Depends on WP3** · **BE change:** none

## Goal — this is the heart of the owner's request

> «لو حصل صرف على تاج تشغيل يظهر الاسم بتاعه ويدوب عليه مباشر، مش على إذن الصرف … علشان أعرف الخامة
> دي اتصرفت على أنهي أمر إنتاج أو أمر تشغيل»

Today the stock card's SOURCE column shows the **document** (`GDN-000014`) and navigates to the
stock-issues screen. Proved from live data: product **17139** has 7 issue movements and **all 7 are
production-order issues** — so the screen shows 7 delivery notes where the truth is 7 production orders.

WP3 added a server-side resolver that returns the real source per movement. **Render it.**

## Settled decision — additive, not a replacement

**Add a NEW column «المصدر المباشر»; the existing document column stays.** (Owner decision §9 Q2.)
The issue number is what's printed on the paper — losing it would be a downgrade. Do not remove or
repurpose the existing column, and do not change `referenceRouteMap`.

## Read first

- `../tasks/WP3-report.md` — it contains **the exact JSON shape** of the `source` object. Build against
  that, not against a guess. If the shape there and the live API disagree, the API wins and you say so.
- `src/app/features/stock-card/stock-card.component.{ts,html}` — the screen. The existing SOURCE
  column is at `html:448-452`, `getSourceRoute()` at `ts:492-497`, `navigateToSource()` at `ts:500-505`,
  `referenceRouteMap` at `ts:56-66`.
- `src/app/core/models/inventory.model.ts` — `StockCardEntry` (line ~410) needs the new field typed.

## What to build

1. Type the new `source` field on `StockCardEntry`, matching WP3's shape exactly.
2. Render a new column that shows **the source kind as a badge + the name/number**:
   - production order → the order badge + `order_number`, linking to the order
   - job tag → a **visually distinct** badge + the tag's **name**, linking to the tags screen
   - consignment → the **partner's name**, and **no document link** (WP3 returns none — do not invent one)
   - everything else → its label + number, linking where WP3 gives a target
   - nothing resolvable → «—», never a broken link
3. **Use a real `routerLink`,** not a click handler. The existing column is a bare `<a (click)=…>`
   (`html:448-452`) — so it cannot be middle-clicked or copied. The new one must be a proper link:
   the owner asked to "get to" the order, and opening it in a new tab while keeping the card open is
   the normal way to do that.
4. Follow the app's existing deep-link convention for opening a record on a list screen
   (`queryParams: { viewId }`) — check how `navigateToSource()` and `GlobalSearchService` do it and
   match. Do not invent a new URL scheme.
5. Bilingual labels — reuse existing keys where they exist; any new key goes into **both**
   `src/assets/i18n/ar.json` and `en.json`.

## Acceptance criteria

1. On product 17139's card, the 7 production issues show **أمر إنتاج + MO-number**, and the link opens
   that order. (This is the owner's own example — verify against it.)
2. A job-tagged issue shows the **tag's name** with a badge that is clearly not the production-order
   badge, and never reads as an order.
3. A consignment movement shows the **partner name** with **no** document link.
4. A movement with no resolvable source shows «—» and is not clickable.
5. The **existing** document column is unchanged and still navigates as before.
6. Links are real `routerLink`s — middle-click/open-in-new-tab works.
7. RTL layout intact; the table does not overflow its container (it may scroll horizontally).
8. `npx ng build --base-href /app/` green; `npx tsc --noEmit` no new errors.

## Environment / rules

- ⛔ **NEVER** `git checkout` / `restore` / `stash` on `src/assets/i18n/ar.json` or `en.json`.
  Additive edits only; a new key goes in BOTH files.
- Builds are pre-authorized. **Do NOT deploy to `/app`** — the orchestrator deploys.
- `chown moonui2:moonui2` every edited file. Commit on `hazemdev2`, conventional. **No push, no merge.**
- moonui2 ONLY — never `/home/moonui`. Never print a git remote URL.

## Out of scope

Printing (WP6) · the stock-balances screen (WP5) · changing the backend resolver (WP3 owns it — if it
is wrong, report it, don't patch around it in the template).
