FASE 4-5-6: Infraestructura, CRM, Service Orders, Notificaciones, Ahorro, Logistica, API Publica

FASE 4:
- Redis cache de stock con fallback graceful
- Multi-moneda (MXN/USD) con contabilidad en MXN
- Proveedores y ordenes de compra completo
- Meilisearch 1.5M+ partes indexadas
- Metabase KPIs con dashboard auto-generado

FASE 5:
- CRM mejorado: activities, tags, loyalty program, analytics
- Imagenes de partes: upload, resize, thumbnails WebP
- Ordenes de servicio Kanban: received->diagnosis->repair->ready->delivered
- Garantias/RMA, alertas de reorden, multi-sucursal
- Stubs BNPL (APLAZO) y ERP Sync (Aspel/Contpaqi)

FASE 6:
- Notificaciones automaticas: push/WhatsApp/email/in-app
- Reportes de ahorro vs retail_price
- Logistica + tracking: DHL, FedEx, Estafeta, 99min, Uber
- API Publica: API keys, rate limiting, catalog search

Migraciones: v1.9-v3.0
Tests: 93/93 pasando
Backup: nexus_backup_20260427_045859.tar.gz
This commit is contained in:
Nexus Dev
2026-04-27 05:23:30 +00:00
parent b70cb3042b
commit 9ff3dc4c8b
71 changed files with 10939 additions and 420 deletions

View File

@@ -0,0 +1,31 @@
-- v2.8 Savings Reports
-- Add retail_price (MSRP) to inventory for savings calculation
ALTER TABLE inventory ADD COLUMN IF NOT EXISTS retail_price NUMERIC(12,2);
ALTER TABLE inventory ADD COLUMN IF NOT EXISTS reference_price NUMERIC(12,2); -- competitor price or market price
-- Track savings per sale item
ALTER TABLE sale_items ADD COLUMN IF NOT EXISTS retail_price NUMERIC(12,2);
ALTER TABLE sale_items ADD COLUMN IF NOT EXISTS savings_amount NUMERIC(12,2) DEFAULT 0;
-- Savings summary per sale
ALTER TABLE sales ADD COLUMN IF NOT EXISTS total_savings NUMERIC(12,2) DEFAULT 0;
-- Customer savings history (denormalized for quick lookup)
ALTER TABLE customers ADD COLUMN IF NOT EXISTS total_savings NUMERIC(12,2) DEFAULT 0;
-- Savings report view
CREATE OR REPLACE VIEW v_customer_savings AS
SELECT
s.customer_id,
c.name as customer_name,
date_trunc('month', s.created_at) as month,
COUNT(*) as orders_count,
SUM(s.total) as total_spent,
SUM(s.total_savings) as total_saved,
AVG(s.total_savings / NULLIF(s.total, 0) * 100) as avg_savings_pct
FROM sales s
JOIN customers c ON s.customer_id = c.id
WHERE s.status = 'completed' AND s.total_savings > 0
GROUP BY s.customer_id, c.name, date_trunc('month', s.created_at)
ORDER BY month DESC, total_saved DESC;