# PLAN REFINADO COMPLETO - CIERRE DE GAPS

**ID:** PLAN-REFINADO-2026-01-10
**Fecha:** 2026-01-10
**Version:** 2.0 (Refinado)
**Sistema:** SIMCO v3.5 + CAPVED
**Orquestador:** Claude Code - Opus 4.5
**Fase:** R (Refinamiento) - FASE 5

---

## 1. RESUMEN DE CAMBIOS VS PLAN ORIGINAL

### 1.1 Items Agregados

| Categoria | Items Agregados | SP Adicionales |
|-----------|-----------------|----------------|
| Tests Backend | 21 tests faltantes | 42 SP |
| Frontend API | System API service | 3 SP |
| Frontend Fix | CategoryDetailPage productCount | 1 SP |
| **TOTAL AGREGADO** | **23 items** | **46 SP** |

### 1.2 Story Points Finales

| Sprint | SP Original | SP Agregados | SP Final |
|--------|-------------|--------------|----------|
| Sprint 1 | 45 | 0 | 45 |
| Sprint 2 | 47 | 12 | 59 |
| Sprint 3 | 45 | 12 | 57 |
| Sprint 4 | 40 | 13 | 53 |
| Sprint 5 | 43 | 9 | 52 |
| **TOTAL** | **220** | **46** | **266** |

---

## 2. SPRINT 1: GAPS CRITICOS (45 SP) - SIN CAMBIOS

### 2.1 DATABASE - Seeds Criticos (24 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S1-DB-01 | Seed de secuencias | `seeds/05-sequences.sql` | 5 |
| S1-DB-02 | Seed de categorias producto | `seeds/06-product-categories.sql` | 3 |
| S1-DB-03 | Seed financiero completo | `seeds/07-financial-setup.sql` | 8 |
| S1-DB-04 | Seed de inventario | `seeds/08-inventory-setup.sql` | 3 |
| S1-DB-05 | Seed de productos | `seeds/09-products.sql` | 5 |

### 2.2 BACKEND - Correccion TODOs Criticos (8 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S1-BE-01 | Implementar calculo impuestos quotations | `sales/quotations.service.ts` | 4 |
| S1-BE-02 | Implementar calculo impuestos orders | `sales/orders.service.ts` | 4 |

### 2.3 FRONTEND - API Services Criticos (13 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S1-FE-01 | Products API service | `features/products/api/products.api.ts` | 3 |
| S1-FE-02 | Inventory API service | `features/inventory/api/inventory.api.ts` | 5 |
| S1-FE-03 | Sales API service | `features/sales/api/sales.api.ts` | 5 |

---

## 3. SPRINT 2: GAPS ALTOS (59 SP) - +12 SP

### 3.1 DATABASE - Seeds Adicionales (6 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S2-DB-01 | Seed de listas de precio | `seeds/10-pricelists.sql` | 3 |
| S2-DB-02 | Seed de partners con direcciones | `seeds/11-sample-partners.sql` | 3 |

### 3.2 BACKEND - Correccion TODOs Altos (15 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S2-BE-01 | Email service productivo | `shared/services/email.service.ts` | 5 |
| S2-BE-02 | Envio email cotizacion | `sales/quotations.service.ts` | 3 |
| S2-BE-03 | Permission middleware | `shared/middleware/auth.middleware.ts` | 5 |
| S2-BE-04 | Notifications scheduler | `reports/scheduler.service.ts` | 2 |

### 3.3 BACKEND - Tests Sales/Purchases/Audit (26 SP - Original)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S2-BE-05 | Tests orders.service | `sales/__tests__/orders.service.spec.ts` | 5 |
| S2-BE-06 | Tests quotations.service | `sales/__tests__/quotations.service.spec.ts` | 5 |
| S2-BE-07 | Tests pricelists.service | `sales/__tests__/pricelists.service.spec.ts` | 3 |
| S2-BE-08 | Tests purchases.service | `purchases/__tests__/purchases.service.spec.ts` | 5 |
| S2-BE-09 | Tests audit.service | `audit/__tests__/audit.service.spec.ts` | 3 |
| S2-BE-10 | Tests access-logs.service | `audit/__tests__/access-logs.service.spec.ts` | 3 |
| S2-BE-11 | Tests security-events.service | `audit/__tests__/security-events.service.spec.ts` | 2 |

### 3.4 BACKEND - Tests AGREGADOS Sprint 2 (12 SP) - NUEVO

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S2-BE-12 | Tests apiKeys.service | `auth/__tests__/apiKeys.service.spec.ts` | 3 |
| S2-BE-13 | Tests email-verification.service | `auth/__tests__/email-verification.service.spec.ts` | 2 |
| S2-BE-14 | Tests customer-groups.service | `sales/__tests__/customer-groups.service.spec.ts` | 2 |
| S2-BE-15 | Tests sales-teams.service | `sales/__tests__/sales-teams.service.spec.ts` | 2 |
| S2-BE-16 | Tests rfqs.service | `purchases/__tests__/rfqs.service.spec.ts` | 3 |

---

## 4. SPRINT 3: GAPS MEDIOS P1 (57 SP) - +12 SP

### 4.1 BACKEND - Tests HR/Reports/Projects Original (35 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S3-BE-01 | Tests employees.service | `hr/__tests__/employees.service.spec.ts` | 5 |
| S3-BE-02 | Tests contracts.service | `hr/__tests__/contracts.service.spec.ts` | 3 |
| S3-BE-03 | Tests leaves.service | `hr/__tests__/leaves.service.spec.ts` | 3 |
| S3-BE-04 | Tests payslips.service | `hr/__tests__/payslips.service.spec.ts` | 5 |
| S3-BE-05 | Tests departments.service | `hr/__tests__/departments.service.spec.ts` | 2 |
| S3-BE-06 | Tests reports.service | `reports/__tests__/reports.service.spec.ts` | 3 |
| S3-BE-07 | Tests dashboards.service | `reports/__tests__/dashboards.service.spec.ts` | 3 |
| S3-BE-08 | Tests report-builder.service | `reports/__tests__/report-builder.service.spec.ts` | 3 |
| S3-BE-09 | Tests projects.service | `projects/__tests__/projects.service.spec.ts` | 3 |
| S3-BE-10 | Tests tasks.service | `projects/__tests__/tasks.service.spec.ts` | 3 |
| S3-BE-11 | Tests timesheets.service | `projects/__tests__/timesheets.service.spec.ts` | 2 |

### 4.2 BACKEND - Tests AGREGADOS Sprint 3 (12 SP) - NUEVO

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S3-BE-12 | Tests product-categories.service | `core/__tests__/product-categories.service.spec.ts` | 3 |
| S3-BE-13 | Tests sequences.service | `core/__tests__/sequences.service.spec.ts` | 3 |
| S3-BE-14 | Tests export.service | `reports/__tests__/export.service.spec.ts` | 2 |
| S3-BE-15 | Tests scheduler.service | `reports/__tests__/scheduler.service.spec.ts` | 3 |
| S3-BE-16 | Tests oauth.service | `auth/__tests__/oauth.service.spec.ts` | 1 |

### 4.3 FRONTEND - API Services (10 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S3-FE-01 | Projects API service | `features/projects/api/projects.api.ts` | 5 |
| S3-FE-02 | CRM API service | `features/crm/api/crm.api.ts` | 5 |

---

## 5. SPRINT 4: GAPS MEDIOS P2 (53 SP) - +13 SP

### 5.1 BACKEND - Tests Financial/Inventory/CRM Original (30 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S4-BE-01 | Tests taxes.service | `financial/__tests__/taxes.service.spec.ts` | 3 |
| S4-BE-02 | Tests journals.service | `financial/__tests__/journals.service.spec.ts` | 3 |
| S4-BE-03 | Tests fiscalPeriods.service | `financial/__tests__/fiscalPeriods.service.spec.ts` | 3 |
| S4-BE-04 | Tests reconcile-models.service | `financial/__tests__/reconcile-models.service.spec.ts` | 5 |
| S4-BE-05 | Tests warehouses.service | `inventory/__tests__/warehouses.service.spec.ts` | 3 |
| S4-BE-06 | Tests locations.service | `inventory/__tests__/locations.service.spec.ts` | 3 |
| S4-BE-07 | Tests pickings.service | `inventory/__tests__/pickings.service.spec.ts` | 5 |
| S4-BE-08 | Tests leads.service | `crm/__tests__/leads.service.spec.ts` | 3 |
| S4-BE-09 | Tests opportunities.service | `crm/__tests__/opportunities.service.spec.ts` | 2 |

### 5.2 BACKEND - Tests AGREGADOS Sprint 4 (13 SP) - NUEVO

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S4-BE-10 | Tests incoterms.service | `financial/__tests__/incoterms.service.spec.ts` | 1 |
| S4-BE-11 | Tests payment-methods.service | `financial/__tests__/payment-methods.service.spec.ts` | 2 |
| S4-BE-12 | Tests payment-terms.service | `financial/__tests__/payment-terms.service.spec.ts` | 2 |
| S4-BE-13 | Tests adjustments.service | `inventory/__tests__/adjustments.service.spec.ts` | 3 |
| S4-BE-14 | Tests lots.service | `inventory/__tests__/lots.service.spec.ts` | 2 |
| S4-BE-15 | Tests stages.service | `crm/__tests__/stages.service.spec.ts` | 1 |
| S4-BE-16 | Tests tags.service | `crm/__tests__/tags.service.spec.ts` | 1 |
| S4-BE-17 | Tests token.service | `auth/__tests__/token.service.spec.ts` | 1 |

### 5.3 FRONTEND - API Services (10 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S4-FE-01 | HR API service | `features/hr/api/hr.api.ts` | 5 |
| S4-FE-02 | Purchases API service | `features/purchases/api/purchases.api.ts` | 5 |

---

## 6. SPRINT 5: GAPS BAJOS + E2E (52 SP) - +9 SP

### 6.1 BACKEND - Tests Restantes Original (14 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S5-BE-01 | Tests base.service | `shared/__tests__/base.service.spec.ts` | 2 |
| S5-BE-02 | Tests email.service | `shared/__tests__/email.service.spec.ts` | 2 |
| S5-BE-03 | Tests cache.service | `shared/__tests__/cache.service.spec.ts` | 2 |
| S5-BE-04 | Tests notifications.service | `system/__tests__/notifications.service.spec.ts` | 2 |
| S5-BE-05 | Tests companies.service | `companies/__tests__/companies.service.spec.ts` | 3 |

### 6.2 BACKEND - Tests AGREGADOS Sprint 5 (9 SP) - NUEVO

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S5-BE-06 | Tests package-types.service | `inventory/__tests__/package-types.service.spec.ts` | 1 |
| S5-BE-07 | Tests pdf.service | `reports/__tests__/pdf.service.spec.ts` | 1 |
| S5-BE-08 | Tests ranking.service | `partners/__tests__/ranking.service.spec.ts` | 1 |
| S5-BE-09 | Tests activities.service | `system/__tests__/activities.service.spec.ts` | 2 |
| S5-BE-10 | Tests messages.service | `system/__tests__/messages.service.spec.ts` | 2 |

### 6.3 FRONTEND - Items AGREGADOS (4 SP) - NUEVO

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S5-FE-01 | System API service | `features/system/api/system.api.ts` | 3 |
| S5-FE-02 | Fix CategoryDetailPage productCount | `pages/catalogs/categories/CategoryDetailPage.tsx` | 1 |

### 6.4 E2E TESTS (21 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S5-E2E-01 | Setup Playwright | `e2e/playwright.config.ts` | 3 |
| S5-E2E-02 | Auth E2E tests | `e2e/tests/auth.spec.ts` | 5 |
| S5-E2E-03 | Sales E2E tests | `e2e/tests/sales.spec.ts` | 5 |
| S5-E2E-04 | Inventory E2E tests | `e2e/tests/inventory.spec.ts` | 5 |
| S5-E2E-05 | Financial E2E tests | `e2e/tests/financial.spec.ts` | 3 |

### 6.5 DATABASE - Seeds Demo (8 SP)

| ID | Tarea | Archivo | SP |
|----|-------|---------|-----|
| S5-DB-01 | Seeds HR demo | `seeds/demo/hr-demo.sql` | 3 |
| S5-DB-02 | Seeds CRM demo | `seeds/demo/crm-demo.sql` | 2 |
| S5-DB-03 | Seeds Projects demo | `seeds/demo/projects-demo.sql` | 3 |

---

## 7. RESUMEN TOTAL DE ARCHIVOS

### 7.1 Seeds (12 archivos)

| Archivo | Sprint | Descripcion |
|---------|--------|-------------|
| `seeds/05-sequences.sql` | 1 | 15 secuencias de numeracion |
| `seeds/06-product-categories.sql` | 1 | Categorias de producto |
| `seeds/07-financial-setup.sql` | 1 | COA, journals, taxes, terms |
| `seeds/08-inventory-setup.sql` | 1 | Warehouses, locations |
| `seeds/09-products.sql` | 1 | 20 productos sample |
| `seeds/10-pricelists.sql` | 2 | Listas de precio |
| `seeds/11-sample-partners.sql` | 2 | Partners con direcciones |
| `seeds/demo/hr-demo.sql` | 5 | Empleados, contratos demo |
| `seeds/demo/crm-demo.sql` | 5 | Leads, oportunidades demo |
| `seeds/demo/projects-demo.sql` | 5 | Proyectos, tareas demo |

### 7.2 Backend Modificaciones (5 archivos)

| Archivo | Sprint | Modificacion |
|---------|--------|--------------|
| `sales/quotations.service.ts` | 1, 2 | Tax calc, email |
| `sales/orders.service.ts` | 1 | Tax calculation |
| `shared/middleware/auth.middleware.ts` | 2 | Permission check |
| `shared/services/email.service.ts` | 2 | Production email |
| `reports/scheduler.service.ts` | 2 | Notifications |

### 7.3 Backend Tests (51 archivos)

| Modulo | Tests | Sprint |
|--------|-------|--------|
| auth | 5 | 2, 3, 4 |
| core | 2 | 3 |
| financial | 7 | 4 |
| inventory | 6 | 4, 5 |
| sales | 5 | 2 |
| purchases | 2 | 2 |
| hr | 5 | 3 |
| audit | 3 | 2 |
| reports | 6 | 3, 5 |
| projects | 3 | 3 |
| crm | 4 | 4 |
| companies | 1 | 5 |
| partners | 1 | 5 |
| system | 3 | 5 |
| shared | 3 | 5 |
| **TOTAL** | **51** | - |

### 7.4 Frontend API Services (9 archivos)

| Archivo | Sprint |
|---------|--------|
| `features/products/api/products.api.ts` | 1 |
| `features/inventory/api/inventory.api.ts` | 1 |
| `features/sales/api/sales.api.ts` | 1 |
| `features/projects/api/projects.api.ts` | 3 |
| `features/crm/api/crm.api.ts` | 3 |
| `features/hr/api/hr.api.ts` | 4 |
| `features/purchases/api/purchases.api.ts` | 4 |
| `features/system/api/system.api.ts` | 5 |
| `pages/catalogs/categories/CategoryDetailPage.tsx` | 5 |

### 7.5 E2E Tests (5 archivos)

| Archivo | Sprint |
|---------|--------|
| `e2e/playwright.config.ts` | 5 |
| `e2e/tests/auth.spec.ts` | 5 |
| `e2e/tests/sales.spec.ts` | 5 |
| `e2e/tests/inventory.spec.ts` | 5 |
| `e2e/tests/financial.spec.ts` | 5 |

---

## 8. COBERTURA FINAL ESPERADA

### 8.1 Tests por Modulo

| Modulo | Servicios | Tests Planeados | Cobertura |
|--------|-----------|-----------------|-----------|
| Auth | 8 | 8 | 100% |
| Core | 7 | 7 | 100% |
| Financial | 11 | 11 | 100% |
| Inventory | 9 | 9 | 100% |
| Sales | 5 | 5 | 100% |
| Purchases | 2 | 2 | 100% |
| HR | 7 | 7 | 100% |
| Audit | 3 | 3 | 100% |
| Reports | 6 | 6 | 100% |
| Projects | 3 | 3 | 100% |
| CRM | 4 | 4 | 100% |
| Roles | 2 | 2 (existentes) | 100% |
| Users | 1 | 1 (existente) | 100% |
| Tenants | 1 | 1 (existente) | 100% |
| Companies | 1 | 1 | 100% |
| Partners | 2 | 2 | 100% |
| System | 4 | 4 | 100% |
| Shared | 3 | 3 | 100% |
| **TOTAL** | **76** | **76** | **100%** |

### 8.2 Frontend API Coverage

| Modulo | API Service | Estado |
|--------|-------------|--------|
| Auth | Existente | 100% |
| Financial | Existente | 100% |
| Catalogs | Existente | 100% |
| Users | Existente | 100% |
| Partners | Existente | 100% |
| Companies | Existente | 100% |
| Audit | Existente | 100% |
| Notifications | Existente | 100% |
| Dashboards | Existente | 100% |
| Report Builder | Existente | 100% |
| Scheduled Reports | Existente | 100% |
| Tenants | Existente | 100% |
| Products | Planeado S1 | 100% |
| Inventory | Planeado S1 | 100% |
| Sales | Planeado S1 | 100% |
| Projects | Planeado S3 | 100% |
| CRM | Planeado S3 | 100% |
| HR | Planeado S4 | 100% |
| Purchases | Planeado S4 | 100% |
| System | Planeado S5 | 100% |
| **TOTAL** | **20/20** | **100%** |

### 8.3 Seeds Coverage

| Schema | Tablas | Seeds | % |
|--------|--------|-------|---|
| auth | 33 | 7 | 21% |
| core | 16 | 8 | 50% |
| financial | 21 | 15 | 71% |
| inventory | 33 | 10 | 30% |
| sales | 12 | 4 | 33% |
| purchase | 9 | 1 | 11% |
| hr | 19 | 3 (demo) | 16% |
| crm | 12 | 3 (demo) | 25% |
| projects | 15 | 3 (demo) | 20% |
| system | 11 | 2 | 18% |
| **TOTAL** | **177** | **~56** | **~32%** |

*Nota: Seeds cubren tablas criticas de configuracion, no todas las tablas operacionales*

---

## 9. VALIDACION DEL PLAN REFINADO

### 9.1 Checklist de Completitud

- [x] Todos los GAPS criticos cubiertos (10/10)
- [x] Todos los GAPS altos cubiertos (8/8)
- [x] Todos los GAPS medios cubiertos (9/9)
- [x] GAPS bajos cubiertos (6/6)
- [x] 100% servicios backend con tests planeados
- [x] 100% frontend APIs planeados
- [x] E2E tests planeados (4 flujos)
- [x] Seeds de datos maestros planeados
- [x] Dependencias correctamente ordenadas

### 9.2 Gate de Aprobacion

```
╔════════════════════════════════════════════════════════════╗
║                                                            ║
║   PLAN REFINADO: APROBADO                                  ║
║                                                            ║
║   Total Story Points: 266 SP                               ║
║   Sprints: 5                                               ║
║   Archivos a crear: 77                                     ║
║   Archivos a modificar: 5                                  ║
║   Cobertura tests esperada: 100%                           ║
║   Cobertura frontend APIs: 100%                            ║
║                                                            ║
║   LISTO PARA EJECUCION                                     ║
║                                                            ║
╚════════════════════════════════════════════════════════════╝
```

---

## 10. ORDEN DE EJECUCION SPRINT 1

Para iniciar la ejecucion, el orden de tareas en Sprint 1 es:

```
1. S1-DB-01: seeds/05-sequences.sql
2. S1-DB-02: seeds/06-product-categories.sql
3. S1-DB-03: seeds/07-financial-setup.sql
4. S1-DB-04: seeds/08-inventory-setup.sql
5. S1-DB-05: seeds/09-products.sql
6. Ejecutar: ./scripts/recreate-database.sh --force
7. S1-BE-01: sales/quotations.service.ts (tax calc)
8. S1-BE-02: sales/orders.service.ts (tax calc)
9. Ejecutar: npm run build && npm test
10. S1-FE-01: features/products/api/products.api.ts
11. S1-FE-02: features/inventory/api/inventory.api.ts
12. S1-FE-03: features/sales/api/sales.api.ts
13. Ejecutar: npm run build (frontend)
```

---

**Documento generado por:** ORQUESTADOR (Claude Code Opus 4.5)
**Sistema:** SIMCO v3.5 + CAPVED
**Fase:** R (Refinamiento) - COMPLETADA
**Estado:** PLAN APROBADO
**Siguiente fase:** FASE 6 - Ejecucion
