feat: add invoice builder with line detail, address, and person picker.

Enrich invoice line items and previews, migrate several CRM surfaces to Ant, and wire shared money/picker helpers.
This commit is contained in:
2026-11-30 14:34:47 +03:30
parent f1bcb232ee
commit 33c95d72a8
64 changed files with 5813 additions and 2737 deletions
@@ -0,0 +1,101 @@
# PersonPicker — Design Spec
**Date:** 2026-11-29
**Status:** Approved in conversation (layout A, scope 2, create-via-modal)
## Problem
«افزودن شخص جدید» alongside person select is duplicated and visually awkward (link button under select). Activity and Deal copy the same search + modal logic; Invoice uses a different label and navigates away instead of creating inline.
## Goals
1. One Ant Design Vue component for person select + create.
2. Cleaner UX: create action lives in the select dropdown footer.
3. Create always opens embedded `PersonFormView` in a modal; after save, select that person without leaving the parent form.
4. Wire into Activity form, Deal form, and Invoice form. Treasury stays out of scope.
## Non-goals
- Refactoring `TreasuryPartySelect` (multi-kind party: person/company/user/other).
- Migrating unrelated form chrome or legacy `Ui*` kits beyond what this component needs for its own modal.
- Shared company picker.
## Approach
**Full `PersonPicker` component** that owns:
- `a-select` with server search (`GET /people?q=&limit=30`, 300ms debounce)
- Dropdown footer: divider + link button (`UserAddOutlined` + configurable label)
- Modal with embedded `PersonFormView`
- Optional seed list so parents can keep already-loaded people visible
Parents keep only `v-model` (person id) and optional side effects on `created` / `change`.
## API
**File:** `apps/web/src/components/PersonPicker.vue`
| Prop / model | Type | Default | Notes |
|---|---|---|---|
| `modelValue` (`v-model`) | `string` | `''` | Selected person id |
| `placeholder` | `string` | `'جستجو و انتخاب شخص'` | |
| `allowClear` | `boolean` | `true` | |
| `disabled` | `boolean` | `false` | |
| `addLabel` | `string` | `'افزودن شخص جدید'` | Invoice may pass `'افزودن مشتری جدید'` |
| `seedPeople` | `PersonDto[]` | `[]` | Initial / remembered options |
| `modalNest` | `boolean` | `false` | Forward `nest` to modal when parent is already nested |
| Emit | Payload | When |
|---|---|---|
| `update:modelValue` | `string` | Selection cleared or changed |
| `change` | `PersonDto \| null` | Resolved person object when known; `null` on clear |
| `created` | `PersonDto` | After successful create in modal (also selects that person) |
## UI / design rules
- Ant-only controls; no raw HTML buttons/inputs; no new scoped look CSS.
- No manual `size` on Ant controls (theme `controlHeight: 36`).
- Dropdown footer: `a-divider` + `a-button type="link"` with icon; stop mousedown so select does not steal focus/close incorrectly (same pattern as `TreasuryPartySelect`).
- Modal: prefer `a-modal` if the surrounding page is Ant-migrated and does not already depend on `UiModal` for this flow; if nesting/`UiModal` is required for Activity’s existing nest behavior, match current Activity/Deal nesting so z-index/stacking does not regress.
- Pass `:initial-query` from the current search string into `PersonFormView` when opening create.
## Parent integration
### ActivityFormView
- Replace select + link + person-search watchers + create modal with `<PersonPicker v-model="personId" :seed-people="people" @change="…" @created="…" />`.
- On `change`/`created`, call existing `rememberPerson` / deal-link side effects as today.
- Remove duplicated `personQuery` / `personResults` / `newPersonOpen` / modal block when fully owned by the picker (seed via `people` ref still updated from `change`).
### DealFormView
- Same as Activity.
- On `created` / person pick: keep `contactKind = 'person'` and company auto-fill from `person.company` (existing `pickPerson` behavior).
### InvoiceFormView
- Replace select + `RouterLink` «افزودن مشتری جدید» with `PersonPicker` (`add-label` optional).
- Switch from client-only filter over loaded `people` to server search inside the picker; pass current `people` as `seedPeople`.
- On create/select, ensure parent `people` list still has the chosen person for any labels/downstream logic.
## Behavior details
- Empty query: show seed / remembered options (not a forced empty list).
- Clear: emit `''` and `change(null)`.
- Create cancel: close modal only.
- Create save: close modal, merge person into internal options, set `modelValue`, emit `created` then selection updates.
- Loading: select `loading` while search in flight.
- Errors: failed search → empty options for that query (silent or message consistent with Activity today).
## Governance
- Shared component under `apps/web/src/components/` (not `components/ui`).
- Touch only the three views listed for replacement; no drive-by refactors.
- Ant strict rules: no new chrome CSS, no `size` props.
## Success criteria
- One shared component used in Activity, Deal, Invoice.
- No standalone «افزودن شخص جدید» link under the select in those three views.
- Create stays in-modal; Invoice no longer navigates away to create.
- `npm run build -w @mento/web` passes.
@@ -0,0 +1,89 @@
# Invoice Preview Templates — Design Spec
**Date:** 2026-11-30
**Status:** Approved in conversation (preview-only selection; approach C; 5 distinct moods)
## Problem
Current `InvoiceDocPreview` looks cluttered: repeated doc-type labels, a dense 6-field metadata grid, weak hierarchy, and a generic “wireframe” look. Users need multiple luxurious, professional invoice looks they can switch in preview/print.
## Goals
1. Five visually distinct invoice templates available in the preview modal.
2. Template choice applies to both on-screen preview and print HTML.
3. Reduce clutter: fewer competing labels, clearer hierarchy, calmer table/totals.
4. Keep Ant Design Vue governance for modal chrome (segmented, buttons); sheet itself is print-oriented HTML/CSS.
## Non-goals
- Org-level default template persistence (settings / API) — later.
- Per-invoice template stored on Invoice model — later.
- Changing invoice data model, builder grid, or totals logic.
- Migrating other pages or legacy print paths outside `InvoiceDocPreview`.
## Approach
**Shared skeleton + distinct layouts/themes (approach C):**
- One data/render pipeline (props → line rows → totals).
- Three layout families reused across five moods:
- Wide colored header band
- Dark sidebar + light body
- Minimal / editorial / modern header variants
- Five named themes with different color, typography weight, and chrome — not five fully forked HTML trees.
## Templates
| Id | Label (FA) | Mood | Accent | Layout family |
|----|------------|------|--------|---------------|
| `emerald` | کلاسیک زمردی | Brand / professional | Emerald green | Wide header band |
| `noir` | اجرایی تیره | Luxury corporate | Navy + soft gold | Dark sidebar |
| `pearl` | مرواریدی | Luxury minimal | Near-black on white | Minimal lines only |
| `sand` | ادیتوریال شنی | Editorial / magazine | Warm beige + brown | Soft top wash + asymmetric meta |
| `slate` | مدرن اسلیت | Modern technical | Slate + teal accent | Two-column header + chip meta |
**Default:** `emerald`
### Shared content rules (all templates)
- Show doc type **once** (no duplicate “فاکتور فروش” in header corners).
- Primary meta in header: customer, issue date, due/valid, title (max 4). Status and currency move to compact chips or footer strip — not a 6-cell dense grid.
- Table: calm header, generous row padding, amount column emphasized; optional unit/discount/tax columns only when data needs them (existing logic).
- Totals: one clear block (bottom-start in RTL); notes opposite side when present.
- Paper sizes A4 / A5 remain; template scales typography slightly for A5.
### Per-template chrome (summary)
1. **Emerald:** thin emerald top bar; soft emerald table header; totals box with emerald payable.
2. **Noir:** ~18% navy sidebar (org + doc type); navy table header / white text; gold payable; notes with thin gold rule.
3. **Pearl:** oversized org name; no color bars; thick rule under column headers; totals as typography only (no bordered card).
4. **Sand:** soft beige top third; editorial title; muted brown labels; warm beige totals column.
5. **Slate:** aligned two-column header; meta as chips; slate table header; payable in teal strip / soft card.
## UX (preview modal)
- Header/footer chrome stays Ant: `a-segmented` for **template** (5 short FA labels) + existing A4/A5 segmented + print/close.
- Selected template drives both preview sheet and `printSheet()` CSS/HTML.
- No persistence beyond the open modal session (reset to `emerald` when modal opens is acceptable; optionally remember last choice in `sessionStorage` — nice-to-have, not required).
## Implementation touchpoints
| Area | Change |
|------|--------|
| `apps/web/src/components/InvoiceDocPreview.vue` | Template state, preview markup per layout/theme, print HTML/CSS parity |
| Call sites | No prop API change required unless we later expose `defaultTemplate` |
Prefer extracting shared helpers (escape, money, row HTML, col visibility) inside the same file or a small colocated module if the SFC grows too large — avoid premature split.
## Success criteria
- User can switch among 5 looks in preview without leaving the modal.
- Print matches the selected look (colors with `print-color-adjust: exact`).
- Preview feels less cluttered than current (no duplicate titles; meta ≤ 4 primary fields).
- `npm run build -w @mento/web` passes; Ant control rules on modal chrome unchanged (no manual `size`).
## Out of scope follow-ups
- Org setting “default invoice template”
- Persist template on invoice record
- PDF generation service (server-side)