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:
82
pos/migrations/v2.2_alerts_warranty.sql
Normal file
82
pos/migrations/v2.2_alerts_warranty.sql
Normal file
@@ -0,0 +1,82 @@
|
||||
-- v2.2_alerts_warranty.sql
|
||||
-- Mejora #7: Alertas de Reorden mejoradas
|
||||
-- Mejora #10: Garantías / RMA
|
||||
-- Mejora #1: Multi-sucursal sync helpers
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- ALERTAS DE REORDER
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
-- Add reorder columns to inventory
|
||||
ALTER TABLE inventory
|
||||
ADD COLUMN IF NOT EXISTS reorder_point INTEGER,
|
||||
ADD COLUMN IF NOT EXISTS reorder_qty INTEGER;
|
||||
|
||||
-- Table to track generated reorder alerts (prevents duplicate notifications)
|
||||
CREATE TABLE IF NOT EXISTS reorder_alerts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
inventory_id INTEGER NOT NULL REFERENCES inventory(id) ON DELETE CASCADE,
|
||||
branch_id INTEGER REFERENCES branches(id),
|
||||
alert_type VARCHAR(20) NOT NULL, -- 'zero', 'low', 'over'
|
||||
stock_at_alert INTEGER NOT NULL,
|
||||
threshold INTEGER,
|
||||
status VARCHAR(20) DEFAULT 'open', -- open, acknowledged, resolved
|
||||
po_id INTEGER REFERENCES purchase_orders(id),
|
||||
employee_id INTEGER REFERENCES employees(id),
|
||||
notes TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
resolved_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_reorder_alerts_inventory ON reorder_alerts(inventory_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_reorder_alerts_status ON reorder_alerts(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_reorder_alerts_created ON reorder_alerts(created_at DESC);
|
||||
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
-- GARANTÍAS / RMA
|
||||
-- ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
-- Warranty registry attached to sale_items
|
||||
CREATE TABLE IF NOT EXISTS warranties (
|
||||
id SERIAL PRIMARY KEY,
|
||||
sale_id INTEGER REFERENCES sales(id) ON DELETE SET NULL,
|
||||
sale_item_id INTEGER REFERENCES sale_items(id) ON DELETE SET NULL,
|
||||
inventory_id INTEGER REFERENCES inventory(id) ON DELETE SET NULL,
|
||||
customer_id INTEGER REFERENCES customers(id),
|
||||
supplier_id INTEGER REFERENCES suppliers(id),
|
||||
part_number VARCHAR(100),
|
||||
name VARCHAR(300),
|
||||
warranty_months INTEGER DEFAULT 0,
|
||||
start_date DATE NOT NULL,
|
||||
end_date DATE NOT NULL,
|
||||
status VARCHAR(20) DEFAULT 'active', -- active, claimed, expired, void
|
||||
notes TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_warranties_sale ON warranties(sale_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_warranties_customer ON warranties(customer_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_warranties_status ON warranties(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_warranties_end_date ON warranties(end_date);
|
||||
|
||||
-- Warranty claims (RMA process)
|
||||
CREATE TABLE IF NOT EXISTS warranty_claims (
|
||||
id SERIAL PRIMARY KEY,
|
||||
warranty_id INTEGER NOT NULL REFERENCES warranties(id) ON DELETE CASCADE,
|
||||
claim_date DATE NOT NULL DEFAULT CURRENT_DATE,
|
||||
reason TEXT NOT NULL,
|
||||
diagnosis TEXT,
|
||||
resolution VARCHAR(20), -- approved, rejected, repaired, replaced, refunded
|
||||
replacement_inventory_id INTEGER REFERENCES inventory(id),
|
||||
refund_amount NUMERIC(12,2),
|
||||
labor_cost NUMERIC(12,2),
|
||||
status VARCHAR(20) DEFAULT 'open', -- open, in_review, resolved, closed
|
||||
employee_id INTEGER REFERENCES employees(id),
|
||||
supplier_rma_number VARCHAR(100),
|
||||
notes TEXT,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
resolved_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_warranty_claims_warranty ON warranty_claims(warranty_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_warranty_claims_status ON warranty_claims(status);
|
||||
Reference in New Issue
Block a user