feat: Phase 2F — customer CRM

Backend:
- New model: Customer (customers table) — name, nickname, phone, email, notes, is_active
- Order model: add customer_id nullable FK → customers
- New router: /api/customers/ — list (with ?search=), create, get, update, soft-delete,
  GET /{id}/orders (visit history with totals)
- Each CustomerOut includes visit_count + total_spent (computed from closed/paid orders)
- PUT /api/orders/{id}/customer — assign or unassign a customer; manager-only;
  validates customer is active; broadcasts order_updated SSE event
- GET /api/orders/{id} now returns customer_id, customer_name (with nickname), customer_phone
- Migration: CREATE TABLE customers + ALTER TABLE orders ADD COLUMN customer_id

Frontend:
- CustomersPage (/customers): searchable list (name/nickname/phone), avatar initials,
  visit count + total_spent on each row; click → detail panel slides in showing stats
  (visits, total spent, avg ticket), contact info, notes, full visit history
- OrderDetailPage: new Πελάτης card — shows assigned customer in blue if set;
  for open orders shows "+ Ανάθεση πελάτη" button → inline search dropdown → assign;
  Αφαίρεση button to unassign
- Sidebar: Users icon for Πελάτες (between Επαφές and Ρυθμίσεις)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 02:59:53 +03:00
co-authored by Claude Sonnet 4.6
parent d39382e8dd
commit e9bdf61a4d
10 changed files with 648 additions and 1 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
import { NavLink } from 'react-router-dom'
import { useState, useEffect, useRef } from 'react'
import { BarChart2, LayoutGrid, ClipboardList, Package, Settings, ChevronRight, ChevronLeft, ShoppingBag, NotebookPen, Receipt, BookUser } from 'lucide-react'
import { BarChart2, LayoutGrid, ClipboardList, Package, Settings, ChevronRight, ChevronLeft, ShoppingBag, NotebookPen, Receipt, BookUser, Users } from 'lucide-react'
import { getIncomingOrders } from '../api/client'
export default function Sidebar() {
@@ -29,6 +29,7 @@ export default function Sidebar() {
{ to: '/notes', icon: NotebookPen, label: 'Σημειώσεις' },
{ to: '/expenses', icon: Receipt, label: 'Έξοδα' },
{ to: '/contacts', icon: BookUser, label: 'Επαφές' },
{ to: '/customers', icon: Users, label: 'Πελάτες' },
{ to: '/settings', icon: Settings, label: 'Ρυθμίσεις' },
]