Add customer management and billing reports for organized client tracking

Introduced a new `customers` table with CRUD operations for customer management and a new `/api/reports/customer-billing` endpoint for customer-centric billing reports, replacing site-based reporting.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/kHMnjKS
This commit is contained in:
marco370 2025-10-23 08:27:49 +00:00
parent 18aa847dab
commit 7b102a1a1c

View File

@ -73,6 +73,26 @@ The database includes core tables for `users`, `guards`, `certifications`, `site
- **Contract Management**: Sites now include contract fields: `contractReference` (codice contratto), `contractStartDate`, `contractEndDate` (date validità contratto in formato YYYY-MM-DD)
- Sites now reference service types via `serviceTypeId` foreign key; `shiftType` is optional and can be derived from service type
- **Multi-Location Support**: Added `location` field (enum: roccapiemonte, milano, roma) to `sites`, `guards`, and `vehicles` tables for complete multi-sede resource isolation
- **Customer Management (October 23, 2025)**: Added `customers` table with `sites.customerId` foreign key for customer-centric organization. Customers include: name, business name, VAT/fiscal code, address, city, province, ZIP, phone, email, PEC, contact person, notes, active status.
**Recent Features (October 23, 2025)**:
- **Customer Management (Anagrafica Clienti)**: New `/customers` page with full CRUD operations:
- Comprehensive customer form: name, business name, VAT/fiscal code, address, contacts (phone/email/PEC), referent, notes
- Customer status toggle (active/inactive)
- Delete confirmation with cascade considerations
- Sidebar menu entry for admin/coordinator roles
- Backend: Full CRUD routes with validation
- **Reports per Cliente**: New customer-centric billing reports replacing site-based approach:
- Backend endpoint `/api/reports/customer-billing` aggregating by customer → sites → service types
- Separate counters based on service type:
* Presidio Fisso → Hours worked
* Pattuglia/Ronda → Number of passages (from `serviceType.patrolPassages`)
* Ispezione → Number of inspections counted
* Pronto Intervento → Number of interventions counted
- Frontend: "Report Clienti" tab with 5 KPI cards (customers, hours, passages, inspections, interventions)
- Hierarchical display: Customer header → Sites list → Service type details with conditional badges
- CSV export with 8 columns: Cliente, Sito, Tipologia Servizio, Ore, Turni, Passaggi, Ispezioni, Interventi
- Maintains existing "Report Guardie" and "Report Siti" tabs for compatibility
**Recent Features (October 17-18, 2025)**:
- **Multi-Sede Operational Planning**: Redesigned operational planning workflow with location-first approach: