# MATRIZ DE MAPEO: ERP-CORE → RETAIL

**Fecha:** 2025-12-18
**Fase:** 1 - Planeacion
**Objetivo:** Mapear componentes del core hacia requerimientos de retail

---

## 1. MAPEO MODULO A MODULO

### 1.1 Herencia Directa (100%)

| Modulo Retail | Modulo Core | Tipo | Accion |
|---------------|-------------|------|--------|
| RT-001 Fundamentos | MGN-001 Auth | HEREDAR | Import directo |
| RT-001 Fundamentos | MGN-002 Users | HEREDAR | Import directo |
| RT-001 Fundamentos | MGN-003 Roles | HEREDAR | Import directo |
| RT-001 Fundamentos | MGN-004 Tenants | HEREDAR | Import directo |

### 1.2 Herencia con Extension

| Modulo Retail | Modulo Core | % Herencia | Extensiones Requeridas |
|---------------|-------------|------------|------------------------|
| RT-003 Inventario | MGN-011 Inventory | 60% | Stock por sucursal, transferencias |
| RT-004 Compras | MGN-012 Purchasing | 80% | Distribucion a sucursales |
| RT-005 Clientes | MGN-014 CRM | 40% | Programa de lealtad, puntos |
| RT-006 Precios | MGN-013 Sales (pricing) | 30% | Promociones complejas, cupones |
| RT-008 Reportes | MGN-009 Reports | 70% | Dashboard POS, metricas ventas |
| RT-010 Facturacion | MGN-010 Financial | 60% | CFDI 4.0, timbrado PAC |

### 1.3 Componentes Nuevos (Sin herencia directa)

| Modulo Retail | % Herencia | Componentes Nuevos |
|---------------|------------|-------------------|
| RT-002 POS | 20% | Terminal POS, offline, hardware |
| RT-007 Caja | 10% | Arqueos, cortes, denominaciones |
| RT-009 E-commerce | 20% | Tienda online, carrito, checkout |

---

## 2. MAPEO DE TABLAS DDL

### 2.1 Tablas Heredadas de Core

| Schema Core | Tablas | Uso en Retail |
|-------------|--------|---------------|
| auth.users | 26 tablas | Autenticacion completa |
| auth.tenants | | Multi-tenancy |
| auth.roles | | Roles (cajero, supervisor, gerente) |
| auth.permissions | | Permisos granulares |
| core.partners | 12 tablas | Clientes y proveedores |
| core.countries | | Paises |
| core.currencies | | Monedas |
| financial.accounts | 15 tablas | Contabilidad basica |
| financial.invoices | | Facturas base para CFDI |
| financial.payments | | Pagos |
| inventory.products | 20 tablas | Productos base |
| inventory.warehouses | | Almacenes (sucursales) |
| inventory.locations | | Ubicaciones |
| inventory.stock_moves | | Movimientos de stock |
| sales.orders | 10 tablas | Ordenes de venta base |
| sales.pricelists | | Listas de precios |

### 2.2 Tablas Nuevas de Retail

| Tabla Retail | Schema | Relaciona Con Core |
|--------------|--------|-------------------|
| retail.branches | retail | auth.tenants, inventory.warehouses |
| retail.cash_registers | retail | retail.branches |
| retail.pos_sessions | retail | auth.users, retail.cash_registers |
| retail.pos_orders | retail | core.partners, retail.pos_sessions |
| retail.pos_order_lines | retail | inventory.products |
| retail.pos_payments | retail | retail.pos_orders |
| retail.cash_movements | retail | retail.pos_sessions |
| retail.branch_stock | retail | retail.branches, inventory.products |
| retail.stock_transfers | retail | retail.branches |
| retail.stock_transfer_lines | retail | inventory.products |
| retail.product_barcodes | retail | inventory.products |
| retail.promotions | retail | auth.tenants |
| retail.promotion_products | retail | inventory.products |
| retail.loyalty_programs | retail | auth.tenants |
| retail.loyalty_cards | retail | core.partners |
| retail.loyalty_transactions | retail | retail.loyalty_cards |

---

## 3. MAPEO DE SERVICIOS BACKEND

### 3.1 Servicios a Heredar (Import)

| Servicio Retail | Servicio Core | Metodo |
|-----------------|---------------|--------|
| AuthService | auth.service.ts | Import directo |
| UsersService | users.service.ts | Import directo |
| RolesService | roles.service.ts | Import directo |
| TenantsService | tenants.service.ts | Import directo |
| CountriesService | countries.service.ts | Import directo |
| CurrenciesService | currencies.service.ts | Import directo |

### 3.2 Servicios a Extender (class extends)

| Servicio Retail | Servicio Core Base | Extensiones |
|-----------------|-------------------|-------------|
| RetailProductsService | products.service.ts | + barcodes, + promotions |
| RetailInventoryService | inventory.service.ts | + branch_stock, + transfers |
| RetailSalesService | orders.service.ts | + pos_orders, + payments |
| RetailPricelistService | pricelists.service.ts | + promotions, + cupones |
| RetailInvoiceService | invoices.service.ts | + CFDI 4.0, + timbrado |
| RetailCustomersService | partners.service.ts | + loyalty, + points |

### 3.3 Servicios Nuevos (Crear)

| Servicio | Modulo | Descripcion |
|----------|--------|-------------|
| POSSessionService | RT-002 | Sesiones de caja |
| POSOrderService | RT-002 | Ventas POS |
| CashRegisterService | RT-007 | Gestion de cajas |
| CashMovementService | RT-007 | Movimientos efectivo |
| CashClosingService | RT-007 | Cortes de caja |
| BranchService | RT-003 | Gestion sucursales |
| BranchStockService | RT-003 | Stock por sucursal |
| TransferService | RT-003 | Transferencias |
| PromotionService | RT-006 | Promociones |
| LoyaltyService | RT-005 | Programa puntos |
| EcommerceCartService | RT-009 | Carrito compras |
| EcommerceCheckoutService | RT-009 | Checkout |
| CFDIService | RT-010 | Timbrado CFDI |

---

## 4. MAPEO DE ENTIDADES TYPEORM

### 4.1 Entidades Heredadas

| Entidad Core | Uso en Retail |
|--------------|---------------|
| User | Usuarios y cajeros |
| Tenant | Empresas retail |
| Company | Companias |
| Role | Roles (cajero, supervisor) |
| Permission | Permisos |
| Partner | Clientes y proveedores |
| Product | Productos base |
| ProductVariant | Variantes |
| Warehouse | Almacenes (por sucursal) |
| Location | Ubicaciones |
| Invoice | Facturas base |
| Payment | Pagos |
| Pricelist | Listas de precios |

### 4.2 Entidades Nuevas de Retail

| Entidad | Relaciones |
|---------|-----------|
| Branch | → Tenant, → Warehouse |
| CashRegister | → Branch |
| POSSession | → CashRegister, → User |
| POSOrder | → POSSession, → Partner |
| POSOrderLine | → POSOrder, → Product |
| POSPayment | → POSOrder |
| CashMovement | → POSSession |
| BranchStock | → Branch, → Product |
| StockTransfer | → Branch (source), → Branch (dest) |
| StockTransferLine | → StockTransfer, → Product |
| ProductBarcode | → Product |
| Promotion | → Tenant |
| PromotionProduct | → Promotion, → Product |
| LoyaltyProgram | → Tenant |
| LoyaltyCard | → LoyaltyProgram, → Partner |
| LoyaltyTransaction | → LoyaltyCard |

---

## 5. MAPEO DE ESPECIFICACIONES TRANSVERSALES

### 5.1 SPECs Aplicables

| SPEC Core | Modulo Retail | Aplicacion |
|-----------|---------------|------------|
| SPEC-PRICING-RULES | RT-006 | Motor de precios y promociones |
| SPEC-INVENTARIOS-CICLICOS | RT-003 | Conteos de inventario |
| SPEC-TRAZABILIDAD-LOTES-SERIES | RT-003 | Productos con caducidad |
| SPEC-VALORACION-INVENTARIO | RT-003 | Costeo de productos |
| SPEC-SISTEMA-SECUENCIAS | RT-002, RT-010 | Foliado tickets, facturas |
| SPEC-REPORTES-FINANCIEROS | RT-008 | Reportes de caja |

### 5.2 SPECs No Aplicables

| SPEC Core | Razon |
|-----------|-------|
| SPEC-INTEGRACION-CALENDAR | No requiere calendario |
| SPEC-PROYECTOS-DEPENDENCIAS | No hay proyectos largos |
| SPEC-FIRMA-ELECTRONICA-NOM151 | Solo CFDI, no NOM 151 |

---

## 6. MAPEO DE ENDPOINTS API

### 6.1 Endpoints Heredados

| Endpoint Core | Uso en Retail |
|---------------|---------------|
| POST /auth/login | Login cajeros |
| POST /auth/logout | Logout |
| GET /users | Listado usuarios |
| GET /products | Productos |
| GET /partners | Clientes |
| GET /pricelists | Listas de precios |

### 6.2 Endpoints Nuevos

| Endpoint | Metodo | Descripcion |
|----------|--------|-------------|
| /pos/sessions | GET, POST | Sesiones de caja |
| /pos/sessions/:id/close | POST | Cerrar sesion |
| /pos/orders | GET, POST | Ventas POS |
| /pos/orders/:id/pay | POST | Pagar orden |
| /cash/movements | GET, POST | Movimientos efectivo |
| /cash/closings | GET, POST | Cortes de caja |
| /branches | GET, POST, PUT | Sucursales |
| /branches/:id/stock | GET | Stock sucursal |
| /transfers | GET, POST | Transferencias |
| /promotions | GET, POST, PUT | Promociones |
| /loyalty/cards | GET, POST | Tarjetas lealtad |
| /loyalty/transactions | GET, POST | Movimientos puntos |
| /cfdi/timbrar | POST | Timbrar factura |
| /cfdi/cancelar | POST | Cancelar CFDI |

---

## 7. MATRIZ DE DEPENDENCIAS CRUZADAS

### 7.1 Core → Retail

```
MGN-001 Auth ───────► RT-001 Fundamentos (100%)
MGN-002 Users ──────► RT-001 Fundamentos (100%)
MGN-003 Roles ──────► RT-001 Fundamentos (100%)
MGN-004 Tenants ────► RT-001 Fundamentos (100%)
MGN-010 Financial ──► RT-010 Facturacion (60%)
MGN-011 Inventory ──► RT-003 Inventario (60%)
MGN-012 Purchasing ─► RT-004 Compras (80%)
MGN-013 Sales ──────► RT-006 Precios (30%)
MGN-014 CRM ────────► RT-005 Clientes (40%)
MGN-009 Reports ────► RT-008 Reportes (70%)
```

### 7.2 Retail Interno

```
RT-001 ──► RT-002 (base auth)
RT-001 ──► RT-003 (base auth)
RT-001 ──► RT-004 (base auth)
RT-001 ──► RT-005 (base auth)
RT-001 ──► RT-006 (base auth)
RT-001 ──► RT-007 (base auth)
RT-001 ──► RT-008 (base auth)
RT-001 ──► RT-009 (base auth)
RT-001 ──► RT-010 (base auth)

RT-006 ──► RT-002 (precios en POS)
RT-003 ──► RT-002 (stock en POS)
RT-005 ──► RT-002 (clientes en POS)

RT-003 ◄──► RT-004 (inventario y compras)

RT-002 ──► RT-007 (ventas → caja)
RT-002 ──► RT-010 (ventas → factura)

RT-003 ──► RT-009 (stock en ecommerce)
RT-005 ──► RT-009 (clientes en ecommerce)
RT-006 ──► RT-009 (precios en ecommerce)

RT-002, RT-003, RT-005, RT-006, RT-007 ──► RT-008 (reportes)
```

---

## 8. RESUMEN DE ACCIONES

### 8.1 Por Tipo de Integracion

| Tipo | Cantidad | Modulos |
|------|----------|---------|
| HEREDAR (100%) | 4 | RT-001 |
| EXTENDER (30-80%) | 6 | RT-003, RT-004, RT-005, RT-006, RT-008, RT-010 |
| CREAR NUEVO (10-20%) | 3 | RT-002, RT-007, RT-009 |

### 8.2 Por Capa

| Capa | Heredar | Extender | Crear |
|------|---------|----------|-------|
| Database | 144 tablas | 0 | 26 tablas |
| Backend Services | 6 | 6 | 13 |
| Entities | 13 | 0 | 16 |
| Endpoints | 10+ | 5 | 20+ |

---

**Documento generado:** 2025-12-18
**Fase:** 1 - Planeacion - Mapeo Core-Retail
**Estado:** COMPLETO
