# Settings Module — Implementation Plan

বর্তমান `/settings` page-টি basic (static inputs)। এটাকে complete tab-based Settings Module-এ rebuild করব, যেটা existing `business_settings` table (key/value) ব্যবহার করে সব config persist করবে এবং পুরো ERP জুড়ে real-time sync হবে।

## Scope (Phase 1 — এই delivery)

13টি settings category, একটি tabbed UI-এ:

1. **Company** — name, logo, banner, mobile, email, address, website, trade license, VAT/TIN
2. **Invoice** — prefix, auto-number, size (POS/A4), header/footer text, print logo toggle, barcode/QR toggle, terms & conditions
3. **Currency & Financial** — symbol (৳ default), decimal places, default VAT %, discount type (flat/percent), profit calc method (FIFO/avg)
4. **User & Permission** — links to existing `/admin`, `/staff`, plus password min length, session timeout (minutes), max login attempts
5. **Branch & Godown** — default branch, default godown, transfer approval required toggle
6. **Product** — SKU auto-generate, barcode prefix, multi-unit enable, multi-price enable, low stock alert threshold
7. **Customer** — customer ID auto-generate, referral system toggle, wallet system toggle, default due limit, link to segments
8. **Payment Methods** — toggle each: cash, bank, bKash, Nagad, Rocket, cheque, online; plus account numbers
9. **Notification** — SMS/WhatsApp/Email toggles, low stock alert, due alert (links to existing `/sms`)
10. **Backup** — link to existing `/backups`, schedule dropdown (daily/weekly/monthly), auto-backup toggle
11. **System** — language (BN/EN), timezone, date format, theme (light/dark — UI toggle), dashboard layout placeholder
12. **Security** — login logs link, activity logs placeholder, 2FA placeholder (future), IP whitelist text
13. **Advanced** — SMTP settings, payment gateway keys (placeholder), API access toggle

## Architecture

**Storage:** All settings → `business_settings` table (existing `setting_key` / `setting_value` pattern, already used by company logo)। কোনো নতুন column-based table নয় — JSON values for grouped settings।

**Server functions** (`src/lib/settings.functions.ts`):
- `getAllSettings()` — returns all key/value pairs as a flat object
- `updateSettings({ updates: Record<string, any> })` — admin-only, bulk upsert
- `uploadCompanyAsset({ type: 'logo' | 'banner', file })` — uploads to existing `brand-logos` bucket

**UI** (`src/routes/_authenticated/settings.tsx`):
- Replace current static page with `<Tabs>` (13 tabs, vertical on desktop / horizontal scroll on mobile)
- Each tab = one form section with its own `useMutation` save button
- Admin-only edit; non-admins see read-only
- Toast on save; React Query invalidate on success so consumers (logo hook, invoice, POS) auto-refresh
- BN/EN labels via existing `useLanguage`

**Consumers** that already read settings keep working unchanged (e.g., `useCompanyLogo` reads `company_logo_url`). New keys are additive।

## What's NOT in this phase (future)
- 2FA enforcement, device tracking, IP-restriction actual enforcement (UI only stored)
- SMTP actual mail sending wiring
- Payment gateway live integration
- Multi-company / SaaS mode
- Dashboard layout customization engine

## Files

- **New:** `src/lib/settings.functions.ts`
- **Rewrite:** `src/routes/_authenticated/settings.tsx`
- **No DB migration needed** — `business_settings` table already exists with key/value shape

Approve করলে implement শুরু করব।
