# Setup Wizard Design

## Purpose
First-time setup wizard that guides users through essential system configuration when the database is empty/reset. Prevents misconfiguration issues like wrong account mappings, missing warehouses, missing fiscal years.

## Detection & Redirect
- On dashboard load, check if fiscal years exist (API call)
- If none → redirect to `/setup-wizard`
- Setting `system.setup_completed` can override (skip wizard even if data sparse)
- Wizard accessible anytime from Settings nav

## Steps

### Step 1: Fiscal Year (السنة المالية)
- Fields: name, start_date, end_date
- Auto-suggest: current year, Jan 1 - Dec 31
- Creates fiscal year + auto-generates 12 monthly periods
- Service: `FiscalYearService.create()`

### Step 2: Base Currency (العملة الأساسية)
- Fields: code, name, name_ar, symbol
- Pre-filled with QAR (Qatari Riyal) as default
- Service: `CurrencyService.create()`

### Step 3: Treasury / Cash (الخزينة)
- Fields: name (e.g. "الخزينة الرئيسية")
- Auto-creates detail account under parent 1101 (النقد في الصندوق)
- Updates `accounting.default_cash_account` setting to parent
- Service: `AccountService.create()` + `SettingService.update()`

### Step 4: Bank Account (حساب البنك)
- Fields: bank_name, account_number
- Auto-creates detail account under parent 1102 (النقد في البنك)
- Creates bank account record linked to GL account
- Updates `accounting.default_bank_account` setting
- Service: `AccountService.create()` + `BankAccountService.create()` + `SettingService.update()`

### Step 5: Warehouse (المخزن)
- Fields: name, code
- Pre-filled: "المخزن الرئيسي" / "WH-001"
- Type: "main"
- Updates `purchases.default_warehouse_id` and `sales.default_warehouse_id`
- Service: `WarehouseService.create()` + `SettingService.update()`

### Step 6: Default Accounts (حسابات الأستاذ)
- Shows all critical account settings as dropdowns
- Pre-selects correct accounts from chart of accounts
- Groups: Accounting defaults, Sales accounts, Purchases accounts
- Settings updated:
  - accounting: default_cash/bank/check/client/supplier/expense/revenue
  - sales: revenue/cogs/receivable/tax_payable/discount/inventory account_id
  - purchases: inventory/expense/payable/tax_receivable/discount account_id
- Service: `SettingService.update()` (multiple calls)

## UX
- PrimeNG Stepper component at top
- Each step: card with form fields + validation
- "Next" button validates form, calls API, advances on success
- "Previous" button to go back
- "Skip" link for non-critical steps
- Final summary page with checkmarks
- "Start Using System" button sets `system.setup_completed = true` and navigates to dashboard

## Route
- Path: `/setup-wizard`
- Guard: `authGuard` (must be logged in)
- Lazy loaded standalone component

## Files
- `src/app/features/setup-wizard/setup-wizard.component.ts`
- `src/app/features/setup-wizard/setup-wizard.component.html`
- `src/app/features/setup-wizard/setup-wizard.component.scss`
- Route added to `src/app/app.routes.ts`
- Translations in `src/assets/i18n/ar.json` and `en.json`
- Redirect logic in dashboard component
