# Knowledge Base — INDEX

> The map of every topic. Read [`README.md`](README.md) first (how the KB works). كل موضوع وسطر وصف ولينك.
> ✅ = ملف مكتوب · 🟡 = موجود جزئيًا/يحتاج تكميل · ⬜ = مخطّط (نكتبه أول ما نشتغل عليه)

## 🏭 Production & Manufacturing
- ✅ [Production module](topics/production.md) — manufacturing dashboard + per-work-center load board + collapsible factory nav; cost-accounting megaproject context; **Make-to-Order customer-flow analysis** ([plan](plans/mfg-mto-flow-plan.html)) — module ~90% built, net-new = intake entity + new-product→Development + 3 accounting approval gates.

## 🔬 LIS (Laboratory)
- 🔐 [**LIS Permissions Overhaul — MASTER**](topics/lis-permissions-overhaul.md) — **اقرأه أول حاجة لأي شغل صلاحيات معمل.** يربط 3 مسارات: (1) **Authority Limits** (حدّ خصم رقمي per-role/user — SHIPPED main، topic [[authority-limits]]) · (2) **محرّر «حسب الشاشة» + `LisScreenCatalog`** (٤٦ شاشة/٨ مجموعات، اعتماد خفي مُشتق من الكود ومُتحقَّق بـ**Pest gate** — الطبقة الحتمية «المنتج»؛ hazemdev+/app) · (3) **مساعد AI** (دراسة، اختياري فوق الحتمي). المشكلة الجذرية (٩٨٧ صلاحية بلا وصف + أعطال حيّة: board→sections.view, invoices→invoices.post, critical-alerts guard-mismatch) + حكم Fable «AI الواجهة، الكتالوج المُتحقَّق المنتج» + الروادماب. دراسات: `authority-limits-analysis` · `menu-driven-permissions-study` · `ai-permission-builder-study` · `lab-roles-editor-prototype`.
- ✅ [Analyzer middleware](topics/middleware.md) — on-prem Python middleware (Maglumi/VITROS/Dymind/Udichem), source-of-truth/deploy loop, drivers, ASTM/HL7, SSH access, VITROS onboarding.
- ✅ [Client PC access — reverse SSH tunnel](topics/client-pc-tunnel.md) — **read when the tunnel drops.** How we reach the analyzer's Windows box (`ssh -4 -p 2222 hp@127.0.0.1`, reverse tunnel the client dials out), why it drops, and the fix (free port 2222 on our server: `kill -9` the zombie sshd → user re-runs the tunnel). scp/PowerShell/python toolkit + paths.
- ✅ [Sample generation & the barcode gate](topics/lis-sample-generation.md) — **✅ BARCODE UNIFIED (2026-06-27, elmadina LR-2026-00006):** all barcode printing now flows through ONE source (`LisBarcodeBuilderService`) — panel prints as a single label (members hidden), specimen names English-only (no Arabic mojibake), no extra/unrequested tubes; + BE data-heal migrations (align panel-member specimen/section to its panel · merge duplicate `SPT-*` shadow specimen types, both history-guarded/transactional) + aliquot safeguard + `store()` panelMembers load. Shipped hazemdev+main+`/app`; ⏳ elmadina via MoonStack update (migrations A+C together). Owner report `lab-barcode-bug-analysis.html`. — **🔴 sample tubes are NOT created by the BE at request creation**; the FE generates them in a separate fire-and-forget step (`onOrderSuccess` → `POST /lis/samples auto_split` → `aliquot`) after save → if it doesn't complete the request stays `pending` with 0 samples and barcode print warns "No collected samples". [Investigation report](plans/lab-barcode-no-samples-investigation.html). Fix = move generation to the BE (transactional). **✅ FIXED (2026-06-25):** calculated (`formula`) tests (e.g. eAG in panel HBA1C602) used to spawn a **spurious extra tube/barcode** (and silently broke the formula's own value) — now a formula rides its inputs' section/tube (validation + aliquot safeguard + catalog align); full writeup at top of the topic.
- ✅ [Reference ranges — model, data-loss fix, override feature](topics/lis-reference-ranges.md) — ranges show from a **per-result SNAPSHOT** (taken at first entry; stale if added later) not live; **🔴→✅ DATA-LOSS FIXED (2026-06-25):** saving a test/panel with an empty array used to **wipe all ranges/panel-members** (no soft-delete) — now empty=no-change, wipe needs an explicit clear flag; + **new feature:** edit a result's range inline in Worklist/Validation with who/when audit (`POST /lis/results/{id}/range`). Study: [`lis-reference-range-study.html`](https://moonui.elbaset.com/lis-reference-range-study.html).
- ✅ [8-point batch — portals, report comments, culture catalog](topics/lis-portal-and-culture-fixes.md) — **2026-06-26** (BE `1b85a9278`/FE `0258c1a`): P1 password eye · P2 B2B prints request invoice (buyer=client lab, IDOR-scoped) · P3 internal/process comments (retest/Auto-calc/Auto-verify) stop printing — writer-level + lossless cleanup migration · P4 portals honor report settings via shared `BuildsPortalReportConfig` trait · P5 sample-reasons seeder (reject+result) · P6 portal A4 invoice Arabic via `printHtmlA4` (jsPDF can't shape Arabic) · P7 barcode panel = already fixed · **P8 culture: 32 C&S tests retyped→`culture` in catalog + idempotent corrective migration (history-guarded) + `LabAntibioticSeeder`**. [Plan](https://moonui.elbaset.com/lab-8-fixes-plan.html). 🔴 2 data migrations run on the client via update, not moonui_dev_be.
- ✅ [Antibiotics management screen](plans/antibiotics-management/RESUME.md) — **DONE (2026-07-15، بانتظار /fullpush):** شاشة إدارة كتالوج المضادات الحيوية (`/lab/antibiotics`) — بحث/إضافة/تعديل/تعطيل الـ312 مضاد المستخدمين في جدول المزرعة والحساسية (AST). **الباك كان جاهز 100%** (CRUD+صلاحيات+خدمة FE) فالشغل = شاشة FE (نمط specimen-types) + كود فريد per-company + منح الصلاحية لدور مدير المعمل. FE `8731fad` · BE `7cd96cb25`. Pest 5 pass. [الخطة](https://moonui.elbaset.com/his-analysis/antibiotics-management-plan.html).
- ✅ [Histopathology result entry — reopen-empty fix](topics/lis-histopath-result-entry.md) — **2026-07-14 (بلاغ زبون):** بعد submit/saveDraft، إعادة فتح نتيجة histopath في نفس الجلسة كانت تعرض فورم فاضي — **الداتا سليمة** (محفوظة في `lab_histopath_results` والباك بيعمل eager-load ويرجّعها؛ Refresh كامل كان يداري البق). السبب FE بحت: حدث `changed` مكانش بيحمل الـhistopath فالأب مكانش بيحدّث `item.result.histopath` → reopen يقرأ null → `hydrate()` تقف. **الإصلاح (WP1، FE):** الخلية تُضمّن الـhistopath في `changed` من submit+saveDraft، الأب يكتبه back (حارس `!== undefined`). FE `293f3e9`/BE `74e05e817`/`main-NXJE4DH3.js`، بانتظار /fullpush. ⏸️ **مؤجّل WP2:** لغم split-brain في `POST .../enter` (يكتب في `result_payload` بلا صف histopath — مش بيضرب حاليًا، صفر يتيم). [تقرير](https://moonui.elbaset.com/his-analysis/histopath-edit-empty-investigation.html).
- ✅ [On-screen report preview (Validation)](topics/lis-report-preview.md) — `/lab/validation` got a **Preview** button rendering the EXACT report (PDF/HTML) in an in-app iframe dialog, reusing the canonical print engine so **rich types (culture/histopath/narrative/file) render right** — fixing the orphaned, divergent old `LisResultPreviewComponent`. Pure FE (reaches all labs via update). New `LisPrintReportService.previewRequest()` + `LisHtmlReportService.buildReportHtml()`; `includeDraft=true` (DRAFT watermark) so you preview before release. FE `1339b3b`.
- ✅ [Patient-portal report-access tracking](topics/lis-patient-portal-tracking.md) — Validation/result-entry worklist cards show whether the patient **viewed**/**downloaded** their report on the public portal (badges + date tooltip), so staff know before editing a released result. New `lab_patient_portal_access_logs` table + `POST /lis/portal/requests/{id}/track` (ownership-checked, token hashed once, company-scoped, best-effort). Shipped hazemdev+main (BE `f8061545b`+`3fa81e9fa`/FE `ddb24c5`); **migration RUN on moonui** (caught + fixed a MySQL 64-char index-name overflow — name composite indexes explicitly). Caveat: raw browser Ctrl+P can't be tracked.
- ✅ [Formula-test dependencies (portability) + result decimals](topics/lis-formula-dependencies.md) — **2026-07-01:** onboarded installs carried each formula test's input links as SOURCE-install IDs (not portable) → editing ANY formula test (MCH/MCV/LDL) 422'd («مش بعرف أعدّله»). Fix = **derive deps from the formula's codes** (matched-only, in `prepareForValidation`) + repair migration + import 3rd pass + catalog LDL `TC`→`CHOL`. Codex(read-only, WORKS now)+native reviewed. **⚠️ elmadina LDL alias needs its formula edited `TC`→`CHOL`.** + per-test **decimal_places** now consistent (dp>0=exact, dp=0=as-entered, cap 4→6, display-only) across worklist/validation/report.
- ✅ [LIS first-run Setup wizard](topics/lis-setup-screen.md) — the **Lab Setup** screen (`/lab-setup`, 7 steps: identity · locale & main branch · reference data · **investigations import** [current curated catalog / NAFIS 1,666 / CSV] · pricing · accounting + lab accounts), shipped on hazemdev. Locale writes the company source (single truth, no `lis.currency` dup); installer seeder-gap fix; **full architecture map + how-to-extend + bugs/fixes** ([plan](plans/lis-setup-screen-plan.html)).
- ⬜ LIS flow & rebuild — worklist-centric flow, kanban/validation, external labs, the rebuild plan. (content currently in MEMORY.md `lis-*` notes → consolidate here)
- ✅ [LIS discount system](topics/lis-discount.md) — price-list / insurance / package / **manual whole-request discount**. **✅ FIXED 2026-06-27:** wizard discount was silently dropped; now whole request+invoice with %/fixed toggle, VAT after, blocked w/ insurance. **+ 2026-06-28:** B2B claim **split by price list** (per-lab `claim_split_mode`, shipped 4.0.26) · discount now shows in the **B2B client portal** (request detail + statement; +100%-discount no-invoice fallback — 4.0.28+[Unreleased]). Reports `lab-discount-report.html` · `lab-invoice-discount-display-study.html` · `b2b-claim-split-plan.html`.
- 📋 [LIS permission granularity (cost/pricing + external-lab features)](topics/lis-permissions-granularity.md) — **PLAN (2026-06-28, analysis only):** split Investigations cost/pricing into their own perms (now merged in view/update → margin leak) + give each External-Lab feature its own perm (🔴 found `price-lists sync` ungated WRITE). [HTML](https://moonui.elbaset.com/lis-permissions-granularity-plan.html).
- 📋 [Smart Report (التقرير الذكي)](topics/lis-smart-report.md) — **PLANNED + owner-approved direction (2026-06-30):** rich visual lab report (Dr-Sulaiman-Al-Habib style: cards + severity gradient bar + trend charts) + **AI severity assessment via DeepSeek** (reusing the existing AI infra). 🔑 visual layer = NO AI; AI only **words** a rule-computed severity. 5 caveats (rules-decide / anonymize PHI / best-effort no-hang / disclaimer / cache). **Owner chose 🆎 PHASED → start Phase 1 = the AI assessment box.** Analysis: `smart-report-analysis.html`. Sample ref: `1777288186381.pdf`.
- ⬜ Lab accounting & invoicing — LIS GL settings, VAT, customer invoice printing, payments/cashier.

## 🏥 HIS (Hospital Information System)
- 🔴🔒 [**خطة تنفيذ الكلينك — المراحل الملزمة + سجل التقدم الحي**](topics/clinic-execution-phases.md) — **THE EXECUTION PLAN (2026-07-02، في انتظار اعتماد المالك):** 12 مرحلة م0-م11 بتتابع صارم (لا انتقال قبل إتمام + اعتماد المالك بتسته)، كل مرحلة: الهدف + «اللي هيطلع منها» + شيك ليست تست المالك (م1 مثال المالك: الخدمة CRUD كاملة). ~28-36 يوم. **سجل تقدم حي أول الملف يتحدث مع كل خطوة** (session-proof). Opus ينفذ/Fable أدفايزور. [HTML](https://moonui.elbaset.com/his-analysis/clinic-execution-phases.html).
- ✅ [خطة تظبيط الكلينك — رحلة المريض (v2)](topics/clinic-tightening-plan.md) — **NEWEST (2026-07-02), الأولوية الحاكمة، ⛔ تخطيط فقط (لا تنفيذ قبل اعتماد المالك).** 11 محطة على فلو المريض (أرضية→تسجيل→طابور→كشف→تنفيذ→كاشير→معمل/أشعة→تأمين→خروج→نهاية اليوم)، كل محطة: فلو مستهدف + «من الجينا» + الفورمات بالاسم + «اللي هتشوفه». مبنية على 3 تدقيقات opus — **4 CRITICAL فلوس مثبتة على dev data** + 10 routes بلا guard + history per-encounter. ملاحق: تدقيق الفلوس الكامل + جرد الشاشات. [HTML](https://moonui.elbaset.com/his-analysis/clinic-tightening-plan.html). عند التنفيذ: Opus ينفذ، Fable الأدفايزور.
- ✅ [سيناريوهات تست المالك + الاعتمادات وموجات التسليم](topics/clinic-test-scenarios.md) — 10 سيناريوهات (م0-م9) / 81 خطوة عملية يمشيها المالك بنفسه، كل واحد بعلامات نجاح + «جرّب تكسرها» (متتبعة لمعرفات التدقيق C/H/M) + جدول اعتمادات + قائمة التوازي + **8 موجات تسليم** + DoD. ⚠️ قرار مفتوح: مصدر مطابقة م9 («الدفاتر» = GL/Z-report/تصدير؟).
- ✅ [مبادئ المالك الحاكمة للكلينك](topics/clinic-principles.md) — **ملزمة لكل تصميم:** نماذج البيع (±LIS standalone) · الأدوية (±مشتريات، الصرف منفصل دائمًا) · تصنيف الخدمات 3 أنواع (كشف بـ3 احتمالات إسناد تترتب عليها الحسابات / تحاليل / أشعة) · سرعة الروشتة «كله اختيارات» · عقيدة «الدكتور يختار مش يكتب» (تحاليل/أشعة/شكوى/تشخيص) · الكور واحد (عيادة→مركز→مستشفى) · حقول إكلينيكية ديناميكية · أطباء بأقسام (فلترة 1000 طبيب) · الخدمة=العمود الفقري + الإعدادات بترتّب الدنيا.
- ✅ [الخدمة والإعدادات — ربط الدنيا ببعض](topics/clinic-service-settings.md) — تشريح `clinic_services` من الكود (service_type=4 قيم؛ **جسر LIS/الأشعة غير مستهلك**؛ تصنيف المالك: احتمال (أ) دكتور-بعينه-بساعاته **ناقص**=F9، (ب)+(ج) موجودان) + شبكة الترابط (تسعير→عقود→حجز→بند→تغطية→مطالبة→تقسيم→تقارير) + «اللوجيك المستهدف» لإضافة خدمة تشغّل كل حاجة تلقائيًا + **مخطط الإعدادات الشامل** (4 معرفة + 2 بلا تعريف مقابل ~15 مخططة في 6 مجموعات؛ الشاشة definition-driven) + بنية خدمات الجينا (الإعادة=صف أرخص → `parent_service_id`).
- 📐 [ملف المريض وملف الدكتور — حقول الجينا + إظهار/إخفاء لكل عميل](topics/clinic-profiles-fields.md) — **DESIGN (م1+م9):** جرد الجينا (~41 حقل مريض بحزمة الزوج/الزوجة الـ10 + NID→ميلاد + مسودة + فحص تكرار 5 محاور) مقابل Moon (~16 على الفورم) + جدول فجوات + التوصية الهجينة: سجل حقول core بإعداد ظهور/إلزام per-company (`clinic.patient/doctor_form_fields` — hidden≠required بالـ validation) + الحقول الإضافية على محرك الحقول (scope=patient/category=profile) + presets تخصصية. ≈4-6 أيام؛ إتمام شاشة الأطباء دين مسبق.
- 📐 [محرك الحقول الإكلينيكية الديناميكية — تصميم](topics/clinic-dynamic-fields.md) — **DESIGN (م3):** التوصية = **تمديد محرك history_questions الموجود** (stack كامل: CRUD+validation+HistoryInputType+renderer+seeder-presets) بأعمدة unit/scope/category/danger-ranges/is_computed + توحيد التخزين (تعميم patient_history_answers) + fold الـ vitals كتعريفات (النطاقات من VITAL_FIELDS الثابتة حاليًا FE) + جدول القيم الموحد + compat shim مؤقت. BMI يظل server-computed. ≈5-7 أيام، مخاطرة منخفضة.
- ✅ [مرجع الجينا القديم (OBGY)](topics/gyna-reference.md) — «أساسي في التقييم»: مقارنة 8 أبعاد + حكم الـ history (شكوى المالك مثبتة 100%) + **ميكانيكا الروشتة السريعة** (~نقرتين/دواء، عقد 8 بنود) + **ميكانيكا «يختار مش يكتب»** (شبكة 5 أعمدة ~270 تحليل مرئي + حدد-الفئة + favorites + inline-add يترسّخ للأبد؛ الأشعة فئة بنفس الشبكة؛ التشخيص select2 بخيار Add السحري — **عقد 10 بنود: يُبنى مكوّن مشترك واحد**) + top-10 اقتباسات بمحطاتها. [HTML](https://moonui.elbaset.com/his-analysis/gyna-reference.html).
- ✅ [HIS / Clinic module — analysis · approved design · implementation plan](topics/his.md) — **ACTIVE (2026-06-22)** building a Clinic/HIS module on Moon ERP. **Analysis v2** (29-section report + adversarial-review corrections) ✅ · **UI design APPROVED by owner** (`clinic-his-form-design.html` — clinical workstation, IBM Plex+teal, 5 screens, dense single-page) ✅ · **full build-ready implementation plan** in `his-analysis/clinic-impl/` (`00-master-plan.md` + 8 phase files P0–P7, ~217KB, WPs with file:line+migrations+API+tests) ✅. Binding decisions: Clinic owns money / `source=clinic` / canonical enums / reuse=refactors-with-migrations / patient=shim. **▶️ NEXT: build P0 on `hazemdev` with the per-part review gate (Codex + Claude reviewer + KB log).** Read the topic's 🟢 RESUME block. (LIS = the proven clinical template; Phase-0 HIS-readiness already in LIS.)

## 🛒 WebStore (المتجر الإلكتروني)
- 📋 [واجهة المتجر الإلكتروني — Storefront](topics/webstore-storefront.md) — **PLAN (2026-07-18، Phase-1 تحليل فقط، بانتظار اعتماد المالك):** الباك-إند (موديول `WebStore`) **جاهز وناضج ومختبَر** (٤٤ كوميت `STORE-001..066`، ~٧٥ endpoint، ٤٦ ملف Pest/~٣٦٣ تأكيد، مبني ليطابق عقد تطبيق موبايل)؛ الثيم «صيدليتي» (٢٩ صفحة Tailwind+RTL) **تصميم كامل بربط API = صفر**. **قرارات محسومة:** Angular مستقل بنفس تصميم الثيم · يوصل كابديت MoonStack عادي (يُبنى عند الإصدار ويُشحن مبني — مفيش build عند العميل، حد LVE PMEM) على `/store/` · **الريبو = تطبيق ثانٍ داخل `moon-erp-angular` مش ريبو جديد** (ريبو تالت = بيئات [[parallel-dev]] عمياء عنه). ٧ WPs (WP0 أساس → WP1 MVP → … → WP6 دمج التوزيع). **🔴 ٤ بنود إطلاق:** الثيم بيوعد بدفع بطاقة/InstaPay/محفظة و`place-order` بيعمل Pending بس (**مفيش بوابة دفع**) · `otp_bypass_enabled` مفتوح افتراضيًا بكود `123456` · الـOTP بيتسجّل بلا SMS (فـ«نسيت كلمة السر» مش شغال) · تسريب كوبونات عبر الشركات (`StoreCouponController::index` بلا tenancy trait). المتجر يبيع **منتجات Inventory فقط** — لا تحاليل LIS ولا خدمات عيادة. [التحليل](https://moonui4.elbaset.com/his-analysis/webstore-storefront-analysis.html).

## 🗂️ Session logs / misc
- ✅ [Session fixes 2026-07-14/15](topics/session-2026-07-fixes.md) — أشياء الجلسة اللي مالهاش topic مخصّص: تاب «سير العمل» (self-verification toggle في lab-info، FE `cab0fe4`) · 🧨 **لغم config.json** (كان متتبّع بـapiUrl بيئة خطأ → gitignore + `.example`، FE `df0ae67`) · موقف «الداتا راحت» (تبديل شركة، صفر فقد) · اللغم المتكرّر قطع-نسخة CHANGELOG · [[moonui3-environment]].

## 🧪 Testing / QA
- ✅ [System Tests screen v2 (groups + selective run + drill-down)](plans/e2e-screen-v2/RESUME.md) — **batch 1 DONE (2026-07-15، بانتظار /fullpush):** شاشة `/core/e2e-tests` بقت تجمّع الاختبارات حسب الموديول (أقسام قابلة للطي + عدّاد لكل قسم) + تشغيل الكل/مجموعة/واحد (Playwright tags+`--grep`) + drill-down (وصف+خطوات) + virtual scroll لمئات الحالات. WP1 وسم specs · WP2 رنر filter (migration `e2e_runs.filter`) · WP4 إعادة تصميم + BE parser يبعت group/description/steps. FE `b6189a4`+`6bab294` · BE `9a7e2b693`+`11e5e04af`. **مؤجّل batch 2 (WP3):** بثّ حيّ حالة-بحالة + صور الفشل. [الخطة](https://moonui.elbaset.com/his-analysis/e2e-tests-screen-v2-plan.html).
- ✅ [UI E2E Automation — owner-only "System Tests" screen](plans/ui-e2e-automation/RESUME.md) — **WP1 DONE (2026-07-15، بانتظار /fullpush + تفعيل owner):** شاشة `/core/e2e-tests` (owner-only) بزر Run تشغّل سيناريوهات Playwright على `/app` المنشور وتعرض أخضر/أحمر لكل سيناريو + polling حي. أول سيناريو LIS حقيقي (لوجين→مريض→طلب→تأكيد ظهوره). **الرنر:** موديول `Modules/E2eRunner` — `POST /api/e2e/run` (env-off افتراضيًا + owner + single-flight + detached process لأن مفيش queue worker) + `GET /api/e2e/runs/latest` + `e2e:run {id}`. **أمان:** شركة تست معزولة id 8، injection-safe (int بس للـshell)، Chromium 147 نظامي (browsers root-owned). FE `152d0bb`+`fc6e994` · BE `bdda8b78b`+`9a49fd7d4`. مبني بـimplement-plan (LEDGER + 4 WPs). [الخطة](https://moonui.elbaset.com/his-analysis/ui-e2e-automation-plan.html). مؤجّل WP2-4 (سيناريوهات أكتر · تشغيل انتقائي+تاريخ · UI-drive+data-testid).

## 🚀 Distribution & Updates (MoonStack)
- ✅ [Staging / Mirror environment](topics/staging-mirror.md) — **NEW (2026-06-28):** test a MoonStack update on a data-identical mirror BEFORE live. **elmadina staging LIVE** = `s-elmadina.elbaset.com` (cPanel `selmadina`, DB `selmadina_stg`) + a token'd **Refresh-from-live** PHP link (DATA only, no shell) + red STAGING banner. ⚠️ refresh ≠ code update. Generic-feature plan inside.
- ✅ [Dev & release branch workflow](topics/dev-workflow.md) — **read before cutting a release.** Branches (`hazemdev` work branch → `main` release source), the release page + CLI, **prerequisites + ALL env vars + gotchas so ANY dev env/user can release correctly.**
- ✅ [Parallel development (2nd Claude / fatamadev)](topics/parallel-dev.md) — running a second Claude instance in parallel on its own branch (`fatamadev`), each on a different module, merging to `main`. **Must be separate per instance: DB + URL/deploy + working dir** (🔴 never let the 2nd touch `moonui_dev_be` — not binlogged). Partition by module. [Visual guide](https://moonui.elbaset.com/parallel-claude-fatamadev.html).

## 🛠️ Tooling & Workflow Automation (custom skills/commands — project-local)
- ✅ [Workflow automation — /fullpush + implement-research + implement-plan (+ problem-investigation)](topics/workflow-automation.md) — **الأدوات المخصّصة للـinstall ده (نطوّر عليها):** 🔬 **implement-research** (Fable) = Phase-1 «ابحث أولًا» (KB-first → فحص Opus → HTML gap-analysis 8 أقسام + **معاينة UI متوقّعة** → قف للاعتماد) · 🕵️ **problem-investigation** (Fable) = تحقيق RCA لمشكلة (أسباب جذرية + ليه حصلت + حلول بكل أبعادها → HTML يتغذّى منه implement-plan) · 🏗️ **implement-plan** (Fable) = Phase-2 تنفيذ الخطة المعتمدة WP-by-WP بـledger على القرص (pause/resume) + مراجعة/تست/CHANGELOG لكل إمكانية · 🚀 **/fullpush** = توحيد الفرع↔main (BE+FE) + migrate/seed dev + بناء/نشر `/app`. **ولا واحدة تنشر لوحدها — المالك يشغّل /fullpush.** المصدر canonical = ملفات `.claude/`.
- ✅ [MoonStack update & changelog](topics/moonstack-update.md) — fast/crash-safe self-host updates, the what's-new/changelog process, the **seeder gap** (updates don't seed new definitions), release flow, per-client gotchas, **🔴 docroot-ready packaging fix** ([plan](plans/moonstack-docroot-ready-plan.html)) — the zip extracts as raw Laravel (public/ subfolder → fresh-install 404 + insecure); fix = inject a root `.htaccess` rewrite→`public/`.
- ⬜ Self-hosted distribution plan — the separate WordPress-style installer direction (do NOT touch Ahmed's Moon Central). (in MEMORY.md `self-hosted-distribution-plan`)

## 🎤 Sales & Presentations
- ✅ [Sales presentation & deck visuals](topics/presentation.md) — the EN/AR lab decks (web root, 19 slides, design system), real-screenshot capture recipe, **AI image-gen playbook** (Gemini "Nano Banana" / OpenAI / WaveSpeed) + **🔐 secure key handling (keys never in repo/chat)**.

## 🧩 Core / Platform
- ✅ [Authority Limits (الصلاحيات ذات القيمة)](topics/authority-limits.md) — **NEW (2026-07-04, SHIPPED hazemdev+/app):** a general layer for **numeric per-role/per-user ceilings** over boolean Spatie perms (no new table — reuses the settings store like nav_config). First case: **max manual discount % on a lab request** (enforced on the effective %, both modes, remove-test bypass closed, grandfathering, default=unlimited so upgrades are no-ops). Resolution = «user wins; else most-generous role; else default»; owner/admin unlimited. **Add a new limit = 1 registry entry + 1 `assertWithin` call.** Fable-ruled + native review (2 HIGH+3 MED fixed); 25 Pest green. Analysis `authority-limits-analysis.html`.
- ✅ [Audit / Activity Log (سجل التحركات)](topics/audit-activity-log.md) — **who changed what (before→after) when.** spatie/activitylog auto-logs every BaseModel create/update/delete; the endpoint excluded LIS (fixed → +16 LIS/+5 core subjects), machine-heartbeat noise muted (~57%), and a **new `/core/activity-log` screen** (3-agent design: filter table + git-style diff). BE `4f3e0c6e1` / FE `0f936f3`. Reports: `system-audit-log-report.html` · `activity-log-feature-plan.html`.
- 🔬 [Transaction-document-form + product-search unification](topics/document-form-unification.md) — **DEEP ANALYSIS (2026-06-20, manager-grade)** — one common product-search widget everywhere + a unified `<transaction-document-form>` (header+lines+totals, config-driven) across ALL 11+ line-item editors (sales/purchases/inventory) + **backend-driven** field-visibility (generalize `sales.invoice_visible_fields`) & branch-routed treasury. [HTML plan](https://moonui.elbaset.com/document-form-unification-plan.html), Codex-reviewed. 5-agent code sweep.
- 🔬 [Multi-Branch system (الفروع)](topics/branches.md) — **ANALYSIS PHASE (2026-06-20)** — generalize branches across Core/Accounting/Purchases/Inventory/Sales (+ fix HR/Manufacturing): each branch has warehouses + treasuries + employees (employee can be multi-branch), a main branch/warehouse/treasury, and **transactions default the branch's warehouse + treasury from the logged-in user's branch** instead of picking per-invoice. Big problem: **purchase bill has no warehouse at all.** Reuse the existing **LIS cash-routing-by-`primaryBranch()`** pattern. 3-agent code sweep → HTML study + plan; Codex verifies.
- ✅ [Default Accounts — master inventory & /setup plan](topics/default-accounts/INDEX.md) — **every GL-default-account setting across ALL modules** (de-duped ~52 keys), the 28 missing from the first-run `/setup` page (Lab 10 / Manufacturing 8 / HR 10), the **setup page writes 7 INERT legacy keys nothing reads**, the setting-definition schema, and the extension plan. Per-area topics in [`topics/default-accounts/`](topics/default-accounts/). ⚠️ AR-header trap.
- 🟡 [Setup wizard — module operational settings](topics/setup-wizard-settings.md) — **study (plan-first, 2026-06-19)** of Sales/Purchases/Inventory/Accounting operational settings for the `/setup` wizard: which are **LIVE vs SCAFFOLDED**, each one's effect (file:line) + recommended default, the **2 default-mismatches** (`purchases.grn_mode` seeded `grn` vs code-assumed `direct` → the moontest no-stock bug; `sales.auto_approve_stock_issue_on_invoice` `true`-but-inert), and **4 proposed wizard steps** (definition-driven, after Default-Accounts). [HTML study](https://moonui.elbaset.com/setup-wizard-settings-study.html) · [purchase-bill report](https://moonui.elbaset.com/purchase-bill-no-stock-report.html). ⏳ owner decision: grn_mode default + show/hide scaffolded.
- 🔄 [Owner / Super-Admin account](topics/super-admin-owner.md) — **IN PROGRESS (2026-06-20)** — a sealed "program owner" account baked into every install that does **precise** module on/off (BE 404 + strip perms + nav hide) and caps **users/companies/branches** via a tamper-resistant **signed `entitlement.json`** (reuses `PackageSigner::verify`). Owner ABOVE the tenant `owner` role; isolated from Ahmed's Moon Central. **7-phase roadmap + progress in the topic.** ✅ Phase 1 (EntitlementService 3-state fail-safe + `moonstack:entitlement`) + owner account (seeded every install, in-app password change sticks) DONE+tested+LIVE (login `owner@moonerp.app`). 🔄 Phase 2 FE owner-only gating. ⏳ Phase 3-7 (BE module/limit enforcement, owner screen, mgmt flow). [HTML plan](https://moonui.elbaset.com/super-admin-owner-plan.html).
- ⬜ API conventions — auth (`X-Authorization`), pagination (25 cap / `listAll`), dates/money/soft-deletes, envelope.
- ⬜ Deploy & environments — build/deploy to moonui `/app`, the dev-vs-prod BE targets, `.htaccess`, suexec/chown.

---

### How to extend this index
Add your topic under the right section as `- ✅ [Title](topics/<slug>.md) — hook`. Keep it to one line. See [`README.md`](README.md) §3–4.
