# D1 — «إضافة دواء»: the preset entry point (design option ج)

**Repo:** FE only — **backend: zero change** · **Branch:** `hazemdev2` · **Migration:** no

## Approved design

`/home/moonui2/public_html/knowledge-base/plans/drug-entry-form-design.html` — **read it first**, especially §4 (the option ج mockup), §6 (the recommendation) and §8 (the next step). The owner approved option ج **with all its recommendations, all phases**.

## The one thing that makes this succeed or fail

**This is a preset over the existing product dialog — not a second form, not a second entity, not a second save path.** Everything goes through the same `products.component` dialog and the same `POST/PUT /api/core/products`.

The design is explicit that a bare preset ("same form, flag ticked, tab active") is **not enough** — it fixes clarity but not the 50-drug workflow, and the owner would be back asking for a separate form within a month. The three things that actually make 50 drugs fast are an **indivisible bundle**. Ship all three or the package has not landed:

1. **«إضافة دواء» entry button** in the products toolbar, beside the existing new-product and multi-entry buttons. Opens the same dialog with `is_drug` pre-ticked, the دواء tab active, and the barcode field reachable early (a scanner is the pharmacist's input device).
2. **«حفظ + دواء تاني»** — saves, clears the form, and **leaves the dialog open** in the same preset state, so the pharmacist never returns to the list. Precedent to follow: the existing multi-product-entry dialog in the same component.
3. **Sticky fields** — category, manufacturer, storage temperature and tax carry over from the previous entry, marked in the UI as sticky (the mockup uses a ⚲ marker). They are the fields that repeat across a supplier's batch of medicines.

## Field order for the preset (from the mockup)

Grouped for a pharmacist, not for a general trader:
1. **Identity** — name (ar/en), barcode, code
2. **Pharmacology** — active ingredients + per-ingredient strength, dosage form, strength + unit, Rx flag, controlled flag, manufacturer *(sticky)*, category *(sticky)*, storage temperature *(sticky)*
3. **Pack & price** — the same units grid WP8 built (unit · factor · barcode · purchase price · sale price), including the composition helper

Reuse the existing controls and the existing units grid. **Do not fork them.**

## Exact files

- `src/app/features/products/products.component.ts` — the entry point, the preset state, save-and-next, sticky-field carry-over
- `src/app/features/products/products.component.html` — the toolbar button, the preset dialog footer (`حفظ + دواء تاني` / `حفظ وإغلاق` / `إلغاء`), the reordered groups
- `src/app/features/products/products.component.scss` — only if the sticky marker or grouping needs it
- `src/assets/i18n/en.json` + `ar.json` — new keys, **additive, at matching positions in both**

⚠️ **WP7 and WP8 just rewrote parts of these same files** — WP7 added the conditional 5th tab and a bound `[(value)]="activeTab"`; WP8 made the units grid editable and added the composition helper. **Read both before editing. Work around them surgically; do not restructure or reformat.**

## Regression guard — the criterion that matters most

**The ordinary product flow must be untouched.** The existing "منتج جديد" button, the 5-tab dialog, and saving a non-drug product must behave exactly as they do today — no new required field, no reordering for them, no extra request. A user who never touches medicines must not be able to tell this shipped.

Verify it explicitly; do not assert it.

## Acceptance criteria

1. «إضافة دواء» opens the dialog with `is_drug` on and the دواء tab active; the pharmacology fields are grouped and ordered as in the mockup.
2. «حفظ + دواء تاني» saves, clears, and keeps the dialog open in preset state; the saved product appears in the list behind it. Entering three medicines in a row without closing works.
3. Sticky fields (category, manufacturer, storage temperature, tax) carry from one entry to the next, are visibly marked, and are still editable. Closing the dialog resets them.
4. «حفظ وإغلاق» behaves like today's save.
5. **REVISED 2026-08-03 by the owner** — «وكمان تعديل للدواء يكون سهل… علشان الدوا يبقى مهيّأ».
   The preset follows the **record**, not the entry path. Opening a product with `is_drug = true` — from the list, by any route — opens the dialog in the **same** pharmacist preset as «إضافة دواء»: دواء tab active, pharmacology grouped, pack/units reachable.
   Two boundaries: **(a)** «حفظ + دواء تاني» is a *creation* affordance and must NOT appear when editing; edit gets the normal footer. **(b)** Sticky fields apply to consecutive *new* entries only — an existing drug must show its own values. A sticky value leaking into an edit would silently rewrite a saved product.
6. **A non-drug product's create/edit flow is byte-for-byte unchanged.**
7. The payload is identical to what WP6's `StoreProductRequest`/`UpdateProductRequest` accept — **no new keys**. Read those two classes and confirm; a key they do not declare is dropped silently by `validated()`.
8. RTL correct (Arabic is primary).
9. `npx tsc --noEmit` clean and `npx ng build --base-href /app/` green.

## Environment

- FE `/home/moonui2/public_html/moon-erp`, branch `hazemdev2`. **moonui2 ONLY — never touch `/home/moonui`.**
- Build: `npx ng build --base-href /app/` and `npx tsc --noEmit` — pre-authorized.
- **Deploy to `/app` when green** (the owner tests live there): `rm -f /home/moonui2/public_html/app/*.js /home/moonui2/public_html/app/*.css /home/moonui2/public_html/app/*.html /home/moonui2/public_html/app/*.ico` → `\cp -rf dist/moon-erp/browser/* /home/moonui2/public_html/app/` → verify `app/assets/config.json` keeps the moonui2 dev `apiUrl` → `chown -R moonui2:moonui2 /home/moonui2/public_html/app`. Dev deploy only — **no ship, no merge, no push**.
- **Commit is allowed for this package** on `hazemdev2` (the tree is clean and synced with `main`); use a conventional `feat(products): …` message. Do not push and do not merge.
- `chown moonui2:moonui2` after every edit.
- **Never** run `git checkout`, `git restore`, or `git stash` on `src/assets/i18n/ar.json` or `en.json` — they were destroyed that way once. Additive edits only; verify both still parse as valid JSON when done.
- Add a bilingual `[Unreleased]` bullet to `/home/moonui2/moon-erp-be/docs/moonstack/CHANGELOG.md` describing what the pharmacist gets — not the implementation.

## Out of scope

- Any backend change. If you believe one is needed, **report it and stop** — the design says backend is zero change.
- Bulk import from supplier files — the owner confirmed on 2026-08-03 it is a **separate future topic** («هنعمل موضوع الاستيراد الجماعي»). Build no part of it here.
- The multi-product-entry dialog — copy its *pattern*, do not modify it.
- Options أ and ب from the design document.
