# eTailorz Admin Panel — Project Status (as of this session)

## Stack
Laravel 10/11, MySQL (XAMPP), Blade + Tailwind CDN (dev only — production needs npm build),
vanilla JS + fetch() for AJAX (no framework), SortableJS CDN for drag-reorder.

## Design theme
Kanchipuram silk jewel tones — magenta `#C2185B`, saffron `#F57C00`, teal `#00897B`,
indigo `#5E35B1`, cream bg `#FFF9F0`. Fonts: Sora (headings) + Inter (body).
Signature motif: dashed "stitch line" dividers on order pipeline / stat cards.

---

## 1. Auth & Roles
- `users` table extended: `type_id` (1=Super Admin, 2=Shop Owner, 3=Staff), `shop_id`, `role_id`, `is_active`
- Dedicated `admin` guard (separate from any future customer-facing auth)
- `LoginController` — one login form, redirects by `type_id`
- `CheckRole` middleware — gates routes by `type_id`
- Seeded test logins (password `password123` for all):
  - superadmin@etailorz.com
  - owner@maduraishop.com
  - staff@maduraishop.com

## 2. Shops (Super Admin)
- `shops` table: name, owner_name, email, phone, address, city, gst_number, logo, is_active
- Full CRUD at `/superadmin/shops`

## 3. Custom Roles & Permissions (Shop Owner)
- `permissions` — master list (orders.*, measurements.*, customers.*, payments.*, products.*, staff.*)
- `roles` — shop-scoped, shop owner creates their own (e.g. "Cutter", "Cashier")
- `permission_role` pivot, `users.role_id`
- `RoleController` at `/shop/roles` — create role, tick permissions
- `User::hasPermission($key)` helper (added manually via USER_MODEL_ADDITIONS.txt since User.php is pre-existing)
- `CheckPermission` middleware (`->middleware('permission:orders.create')`) — ready to use, not yet applied to routes

## 4. Staff Management (Shop Owner)
- `StaffController` at `/shop/staff` — add/edit staff, assign a role from dropdown
- Staff login → sees only their shop's data, permission-gated by role (once middleware applied)

## 5. Dynamic Garment & Measurement Builder — the original core feature
- `garment_types` — master list (Shirt, Pant, Blouse, Chudithar, Panel Maxi, Frock, Nighty, Kurti, Saree Blouse)
- `measurement_fields` — master catalog, 22 seeded fields (Chest, Waist, Shoulder, Sleeve Length, etc.)
- Both tables have `name_ta` — **bilingual Tamil + English** display everywhere
- `shop_garments` — shop owner toggles which garments their shop offers
- `shop_garment_fields` — the actual builder: pick fields, **custom label**, **drag-to-reorder** (SortableJS), required flag
- Shop owner can also **create a brand-new field on the fly** (not just pick from master list) — adds to master catalog with optional Tamil name
- Pages: `/shop/garments` (toggle list) → `/shop/garments/{type}/builder` (the builder)

## 6. Order Management
- `customers` table — simple shop-scoped customer list
- `orders` table extended: `customer_id`, `discount`, `advance_amount`, `delivery_date`, `notes`, existing `stage`/`total_amount`/`balance_amount`
- `order_items` — one row per garment in an order (garment_type_id, age_type, measurements JSON, qty, unit_price, addon_total, total_amount)
- `OrderController` at `/orders` (shared between Shop Owner + Staff):
  - Customer search (AJAX) + quick-add customer (AJAX)
  - Garment select → **measurement fields load dynamically** from that shop's builder config (AJAX)
  - Cart-style table — add multiple garments before submitting
  - Discount / advance / balance auto-calculated
  - **Server-side price recalculation** — never trusts client-sent totals, prevents tampering

## 7. Addons (Shop Owner) — garment-specific
- `addons` table — shop-scoped, bilingual name + price
- `addon_garment_type` pivot — **each addon applies to specific garments only** (e.g. "Embroidery" → Blouse + Chudithar)
- `order_item_addon` pivot — **price snapshot** at order time (future price changes don't affect old orders)
- `AddonController` at `/shop/addons` — CRUD with garment-type checkboxes
- Order create page — addon checkboxes **filter dynamically** based on selected garment (AJAX to `/orders/garments/{id}/addons`)

---

## Known gotchas hit & fixed this session
- SQLite → switched to MySQL (XAMPP MySQL wasn't running at first)
- Bcrypt hash prefix: `$2b$` (Python) isn't reliably recognized by PHP on Windows — must use `$2y$` prefix
- Sessions table missing when using `SESSION_DRIVER=database` — switched to `file` driver for local dev
- Stale Blade view cache causing "undefined variable" errors after file replacements — fix: `php artisan view:clear` + manually clear `storage/framework/views/`
- Tailwind CDN shows a production warning — harmless for dev, real fix is npm/Vite build (steps given, not yet done)

## Not yet built / next candidates
- Apply `CheckPermission` middleware to actual routes (currently built but unused)
- Payments tracking / history (separate from the advance/balance fields already on Order)
- Customer list/edit page (currently customers only created inline during order entry)
- Orders list page — stage change (Received → Cutting → Stitching → Finishing → Ready → Delivered)
- Move Tailwind from CDN to proper npm/Vite build for production
- Image upload for orders (from your old blade file — not yet ported)
- Clone-measurements-from-previous-order (from your old blade file — not yet ported)
