# TRACEABILITY.yml - MAE-016: Reportes y BI
# Matriz de trazabilidad: Documentacion -> Codigo
# Ubicacion: docs/02-definicion-modulos/MAE-016-reportes/implementacion/

epic_code: MAE-016
epic_name: Reportes y BI
phase: 2
phase_name: Modulos Avanzados
story_points: 28
status: rf_documented
reused_from_core: 75%
core_module: MGN-009

# =============================================================================
# DOCUMENTACION
# =============================================================================

documentation:

  requirements:
    - id: RF-BI-001
      title: Dashboards Ejecutivos
      file: ../requerimientos/RF-BI-001.md
      priority: P0
      story_points: 8
      status: documented
      reused_from: MGN-009/RF-REPORT-002
      reuse_percentage: 70%
      adaptations:
        - "Dashboards especificos para construccion"
        - "KPIs de obras: avance fisico, financiero, rentabilidad"
        - "Widgets de alertas de desviaciones presupuestarias"
        - "Graficos de flujo de caja por proyecto"
        - "Indicadores de productividad de cuadrillas"
      traces_to:
        tables: [dashboards, dashboard_widgets, construction_kpis]
        services: [DashboardsService, WidgetService, ConstructionKPIService]
        endpoints: [GET /api/v1/bi/dashboards, POST /api/v1/bi/dashboards, GET /api/v1/bi/dashboards/:id/data]

    - id: RF-BI-002
      title: Reportes Operativos
      file: ../requerimientos/RF-BI-002.md
      priority: P0
      story_points: 8
      status: documented
      reused_from: MGN-009/RF-REPORT-001
      reuse_percentage: 80%
      adaptations:
        - "Reportes de avance fisico y financiero"
        - "Reportes de consumo de recursos por obra"
        - "Reportes de productividad de personal"
        - "Reportes de estimaciones y facturacion"
        - "Reportes de incidencias y bitacora"
        - "Reportes de compras e inventarios"
      traces_to:
        tables: [report_definitions, report_executions, construction_report_templates]
        services: [ReportsService, ExportService, ConstructionReportService]
        endpoints: [GET /api/v1/bi/reports, POST /api/v1/bi/reports/:id/execute, GET /api/v1/bi/reports/:id/export/:format]

    - id: RF-BI-003
      title: Exportacion de Datos
      file: ../requerimientos/RF-BI-003.md
      priority: P1
      story_points: 6
      status: documented
      reused_from: MGN-009/RF-REPORT-001
      reuse_percentage: 90%
      adaptations:
        - "Exportacion a Excel con formato especifico de construccion"
        - "Exportacion de estimaciones en formato CFE/SECODAM"
        - "Exportacion de bitacora en PDF firmado"
        - "Exportacion masiva de fotografias de obra"
      traces_to:
        tables: [export_templates, export_history]
        services: [ExportService, PdfGeneratorService, ExcelGeneratorService]
        endpoints: [POST /api/v1/bi/export, GET /api/v1/bi/export/:id/download, GET /api/v1/bi/export/templates]

    - id: RF-BI-004
      title: Indicadores KPI
      file: ../requerimientos/RF-BI-004.md
      priority: P0
      story_points: 6
      status: documented
      reused_from: null
      reuse_percentage: 0%
      adaptations:
        - "KPIs especificos de construccion (nuevo desarrollo)"
        - "Indice de Desempeno de Costos (CPI)"
        - "Indice de Desempeno del Cronograma (SPI)"
        - "Rentabilidad por proyecto"
        - "Productividad de mano de obra"
        - "Tasa de consumo de materiales vs presupuestado"
        - "Indice de calidad (NC/conformes)"
      traces_to:
        tables: [construction_kpis, kpi_definitions, kpi_history]
        services: [KPIService, ConstructionMetricsService, EVMService]
        endpoints: [GET /api/v1/bi/kpis, GET /api/v1/bi/kpis/:projectId, POST /api/v1/bi/kpis/calculate]

  specifications: []
  # Pendiente de documentacion

  user_stories: []
  # Pendiente de documentacion

# =============================================================================
# IMPLEMENTACION
# =============================================================================

implementation:

  database:
    schema: construction_bi
    path: apps/database/ddl/schemas/construction_bi/
    status: pending

    tables:
      # Tablas reutilizadas del core (MGN-009)
      - name: dashboards
        file: apps/database/ddl/schemas/core_reports/tables/dashboards.sql
        status: reused
        requirement: RF-BI-001
        reused_from: MGN-009
        adaptations:
          - "Agregar campo construction_context JSONB"
          - "Agregar campo project_filter UUID[]"
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: tenant_id, type: UUID, fk: tenants}
          - {name: user_id, type: UUID, fk: users}
          - {name: name, type: VARCHAR(255)}
          - {name: description, type: TEXT}
          - {name: layout, type: JSONB}
          - {name: construction_context, type: JSONB, note: "Nuevo campo"}
          - {name: project_filter, type: UUID[], note: "Nuevo campo"}
          - {name: refresh_interval, type: INTEGER}
          - {name: is_default, type: BOOLEAN, default: false}
          - {name: is_shared, type: BOOLEAN, default: false}
          - {name: shared_with, type: JSONB}
          - {name: created_at, type: TIMESTAMPTZ}
          - {name: updated_at, type: TIMESTAMPTZ}

      - name: dashboard_widgets
        file: apps/database/ddl/schemas/core_reports/tables/dashboard_widgets.sql
        status: reused
        requirement: RF-BI-001
        reused_from: MGN-009
        adaptations:
          - "Agregar widget_types especificos de construccion"

      - name: report_definitions
        file: apps/database/ddl/schemas/core_reports/tables/report_definitions.sql
        status: reused
        requirement: RF-BI-002
        reused_from: MGN-009
        adaptations:
          - "Agregar templates especificos de construccion"

      - name: report_executions
        file: apps/database/ddl/schemas/core_reports/tables/report_executions.sql
        status: reused
        requirement: RF-BI-002
        reused_from: MGN-009
        adaptations: []

      # Tablas nuevas especificas de construccion
      - name: construction_kpis
        file: apps/database/ddl/schemas/construction_bi/tables/construction_kpis.sql
        status: pending
        requirement: RF-BI-004
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: tenant_id, type: UUID, fk: tenants}
          - {name: project_id, type: UUID, fk: projects}
          - {name: kpi_code, type: VARCHAR(50), note: "CPI, SPI, etc"}
          - {name: kpi_name, type: VARCHAR(255)}
          - {name: kpi_value, type: DECIMAL(10,4)}
          - {name: target_value, type: DECIMAL(10,4)}
          - {name: threshold_warning, type: DECIMAL(10,4)}
          - {name: threshold_critical, type: DECIMAL(10,4)}
          - {name: status, type: VARCHAR(20), note: "ok, warning, critical"}
          - {name: calculation_data, type: JSONB}
          - {name: period_start, type: DATE}
          - {name: period_end, type: DATE}
          - {name: calculated_at, type: TIMESTAMPTZ}
          - {name: calculated_by, type: UUID, fk: users}

      - name: kpi_definitions
        file: apps/database/ddl/schemas/construction_bi/tables/kpi_definitions.sql
        status: pending
        requirement: RF-BI-004
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: code, type: VARCHAR(50), unique: true}
          - {name: name, type: VARCHAR(255)}
          - {name: description, type: TEXT}
          - {name: formula, type: TEXT}
          - {name: data_sources, type: JSONB}
          - {name: calculation_frequency, type: VARCHAR(20)}
          - {name: target_value, type: DECIMAL(10,4)}
          - {name: threshold_warning, type: DECIMAL(10,4)}
          - {name: threshold_critical, type: DECIMAL(10,4)}
          - {name: unit, type: VARCHAR(50)}
          - {name: is_active, type: BOOLEAN, default: true}
          - {name: created_at, type: TIMESTAMPTZ}
          - {name: updated_at, type: TIMESTAMPTZ}

      - name: kpi_history
        file: apps/database/ddl/schemas/construction_bi/tables/kpi_history.sql
        status: pending
        requirement: RF-BI-004
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: kpi_id, type: UUID, fk: construction_kpis}
          - {name: project_id, type: UUID, fk: projects}
          - {name: kpi_value, type: DECIMAL(10,4)}
          - {name: status, type: VARCHAR(20)}
          - {name: recorded_at, type: TIMESTAMPTZ}

      - name: construction_report_templates
        file: apps/database/ddl/schemas/construction_bi/tables/construction_report_templates.sql
        status: pending
        requirement: RF-BI-002
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: tenant_id, type: UUID, fk: tenants}
          - {name: code, type: VARCHAR(100), unique: true}
          - {name: name, type: VARCHAR(255)}
          - {name: template_type, type: VARCHAR(50), note: "estimacion, bitacora, avance"}
          - {name: template_file, type: TEXT, note: "Path o contenido del template"}
          - {name: format, type: VARCHAR(20), note: "PDF, XLSX, DOCX"}
          - {name: parameters, type: JSONB}
          - {name: header_config, type: JSONB}
          - {name: footer_config, type: JSONB}
          - {name: is_system, type: BOOLEAN, default: false}
          - {name: is_active, type: BOOLEAN, default: true}
          - {name: created_at, type: TIMESTAMPTZ}
          - {name: updated_at, type: TIMESTAMPTZ}

      - name: export_templates
        file: apps/database/ddl/schemas/construction_bi/tables/export_templates.sql
        status: pending
        requirement: RF-BI-003
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: tenant_id, type: UUID, fk: tenants}
          - {name: name, type: VARCHAR(255)}
          - {name: export_type, type: VARCHAR(50), note: "CFE, SECODAM, custom"}
          - {name: format, type: VARCHAR(20), note: "XLSX, PDF"}
          - {name: template_config, type: JSONB}
          - {name: columns_mapping, type: JSONB}
          - {name: is_active, type: BOOLEAN, default: true}
          - {name: created_at, type: TIMESTAMPTZ}

      - name: export_history
        file: apps/database/ddl/schemas/construction_bi/tables/export_history.sql
        status: pending
        requirement: RF-BI-003
        columns:
          - {name: id, type: UUID, pk: true}
          - {name: tenant_id, type: UUID, fk: tenants}
          - {name: template_id, type: UUID, fk: export_templates, nullable: true}
          - {name: user_id, type: UUID, fk: users}
          - {name: entity_type, type: VARCHAR(50), note: "estimacion, bitacora, etc"}
          - {name: entity_id, type: UUID}
          - {name: file_name, type: VARCHAR(255)}
          - {name: file_url, type: TEXT}
          - {name: file_format, type: VARCHAR(20)}
          - {name: file_size, type: BIGINT}
          - {name: status, type: VARCHAR(20)}
          - {name: error, type: TEXT, nullable: true}
          - {name: created_at, type: TIMESTAMPTZ}

  backend:
    module: construction-bi
    path: apps/backend/src/modules/construction-bi/
    framework: NestJS
    status: pending

    entities:
      - name: ConstructionKPI
        file: apps/backend/src/modules/construction-bi/entities/construction-kpi.entity.ts
        status: pending
        requirement: RF-BI-004

      - name: KPIDefinition
        file: apps/backend/src/modules/construction-bi/entities/kpi-definition.entity.ts
        status: pending
        requirement: RF-BI-004

      - name: KPIHistory
        file: apps/backend/src/modules/construction-bi/entities/kpi-history.entity.ts
        status: pending
        requirement: RF-BI-004

      - name: ConstructionReportTemplate
        file: apps/backend/src/modules/construction-bi/entities/construction-report-template.entity.ts
        status: pending
        requirement: RF-BI-002

      - name: ExportTemplate
        file: apps/backend/src/modules/construction-bi/entities/export-template.entity.ts
        status: pending
        requirement: RF-BI-003

    services:
      # Servicios reutilizados del core (adaptados)
      - name: DashboardsService
        file: apps/backend/src/modules/construction-bi/dashboards.service.ts
        status: pending
        requirement: RF-BI-001
        reused_from: MGN-009/DashboardsService
        reuse_percentage: 70%
        adaptations:
          - "Agregar metodos para dashboards de construccion"
          - "Integracion con KPIs de obra"
        methods:
          - {name: create, description: Crear dashboard}
          - {name: update, description: Actualizar dashboard}
          - {name: getData, description: Obtener datos de widgets}
          - {name: getConstructionDashboard, description: Dashboard especifico de construccion}
          - {name: getProjectKPIs, description: Obtener KPIs de proyecto}

      - name: ReportsService
        file: apps/backend/src/modules/construction-bi/reports.service.ts
        status: pending
        requirement: RF-BI-002
        reused_from: MGN-009/ReportsService
        reuse_percentage: 80%
        adaptations:
          - "Agregar reportes especificos de construccion"
        methods:
          - {name: execute, description: Ejecutar reporte}
          - {name: getAvailable, description: Listar reportes disponibles}
          - {name: getExecution, description: Obtener resultado de ejecucion}
          - {name: executeConstructionReport, description: Ejecutar reporte de construccion}
          - {name: getEstimacionReport, description: Reporte de estimacion}
          - {name: getBitacoraReport, description: Reporte de bitacora}
          - {name: getAvanceFisicoReport, description: Reporte de avance fisico}

      - name: ExportService
        file: apps/backend/src/modules/construction-bi/export.service.ts
        status: pending
        requirement: RF-BI-003
        reused_from: MGN-009/ExportService
        reuse_percentage: 85%
        adaptations:
          - "Formatos especificos de construccion"
        methods:
          - {name: toPdf, description: Exportar a PDF}
          - {name: toExcel, description: Exportar a Excel}
          - {name: toCsv, description: Exportar a CSV}
          - {name: exportEstimacionCFE, description: Exportar estimacion formato CFE}
          - {name: exportBitacoraFirmada, description: Exportar bitacora con firma digital}
          - {name: exportFotosObra, description: Exportacion masiva de fotos}

      # Servicios nuevos especificos
      - name: KPIService
        file: apps/backend/src/modules/construction-bi/kpi.service.ts
        status: pending
        requirement: RF-BI-004
        methods:
          - {name: calculateKPI, description: Calcular KPI especifico}
          - {name: calculateAllProjectKPIs, description: Calcular todos los KPIs de un proyecto}
          - {name: getKPIHistory, description: Obtener historial de KPI}
          - {name: getKPIDefinitions, description: Listar definiciones de KPIs}
          - {name: createKPIDefinition, description: Crear definicion de KPI}

      - name: ConstructionMetricsService
        file: apps/backend/src/modules/construction-bi/construction-metrics.service.ts
        status: pending
        requirement: RF-BI-004
        methods:
          - {name: getProjectMetrics, description: Obtener metricas de proyecto}
          - {name: getResourceProductivity, description: Productividad de recursos}
          - {name: getMaterialConsumption, description: Consumo de materiales}
          - {name: getLaborProductivity, description: Productividad de mano de obra}

      - name: EVMService
        file: apps/backend/src/modules/construction-bi/evm.service.ts
        status: pending
        requirement: RF-BI-004
        note: "Earned Value Management - Nuevo servicio"
        methods:
          - {name: calculateCPI, description: Calcular Cost Performance Index}
          - {name: calculateSPI, description: Calcular Schedule Performance Index}
          - {name: calculateEAC, description: Calcular Estimate at Completion}
          - {name: calculateETC, description: Calcular Estimate to Complete}
          - {name: getEVMReport, description: Reporte completo de EVM}

      - name: ConstructionReportService
        file: apps/backend/src/modules/construction-bi/construction-report.service.ts
        status: pending
        requirement: RF-BI-002
        methods:
          - {name: getReportTemplates, description: Listar templates de reportes}
          - {name: generateFromTemplate, description: Generar reporte desde template}
          - {name: createCustomTemplate, description: Crear template personalizado}

      - name: PdfGeneratorService
        file: apps/backend/src/modules/construction-bi/pdf-generator.service.ts
        status: pending
        requirement: RF-BI-003
        methods:
          - {name: generatePdf, description: Generar PDF generico}
          - {name: generateEstimacionPdf, description: Generar PDF de estimacion}
          - {name: generateBitacoraPdf, description: Generar PDF de bitacora}
          - {name: addDigitalSignature, description: Agregar firma digital al PDF}

      - name: ExcelGeneratorService
        file: apps/backend/src/modules/construction-bi/excel-generator.service.ts
        status: pending
        requirement: RF-BI-003
        methods:
          - {name: generateExcel, description: Generar Excel generico}
          - {name: generateEstimacionExcel, description: Generar Excel de estimacion}
          - {name: applyTemplate, description: Aplicar template de Excel}

    controllers:
      - name: ConstructionBIController
        file: apps/backend/src/modules/construction-bi/construction-bi.controller.ts
        status: pending
        endpoints:
          # Dashboards
          - method: GET
            path: /api/v1/bi/dashboards
            description: Listar dashboards
            requirement: RF-BI-001

          - method: POST
            path: /api/v1/bi/dashboards
            description: Crear dashboard
            requirement: RF-BI-001

          - method: GET
            path: /api/v1/bi/dashboards/:id/data
            description: Obtener datos de dashboard
            requirement: RF-BI-001

          - method: GET
            path: /api/v1/bi/dashboards/construction/:projectId
            description: Dashboard de construccion por proyecto
            requirement: RF-BI-001

          # Reportes
          - method: GET
            path: /api/v1/bi/reports
            description: Listar reportes disponibles
            requirement: RF-BI-002

          - method: POST
            path: /api/v1/bi/reports/:id/execute
            description: Ejecutar reporte
            requirement: RF-BI-002

          - method: GET
            path: /api/v1/bi/reports/:id/export/:format
            description: Exportar reporte
            requirement: RF-BI-002

          - method: GET
            path: /api/v1/bi/reports/estimacion/:estimacionId
            description: Reporte de estimacion
            requirement: RF-BI-002

          - method: GET
            path: /api/v1/bi/reports/bitacora/:obraId
            description: Reporte de bitacora
            requirement: RF-BI-002

          - method: GET
            path: /api/v1/bi/reports/avance-fisico/:obraId
            description: Reporte de avance fisico
            requirement: RF-BI-002

          # Exportacion
          - method: POST
            path: /api/v1/bi/export
            description: Crear exportacion
            requirement: RF-BI-003

          - method: GET
            path: /api/v1/bi/export/:id/download
            description: Descargar archivo exportado
            requirement: RF-BI-003

          - method: GET
            path: /api/v1/bi/export/templates
            description: Listar templates de exportacion
            requirement: RF-BI-003

          - method: POST
            path: /api/v1/bi/export/estimacion-cfe
            description: Exportar estimacion formato CFE
            requirement: RF-BI-003

          - method: POST
            path: /api/v1/bi/export/bitacora-firmada
            description: Exportar bitacora con firma digital
            requirement: RF-BI-003

          # KPIs
          - method: GET
            path: /api/v1/bi/kpis
            description: Listar definiciones de KPIs
            requirement: RF-BI-004

          - method: GET
            path: /api/v1/bi/kpis/:projectId
            description: Obtener KPIs de proyecto
            requirement: RF-BI-004

          - method: POST
            path: /api/v1/bi/kpis/calculate
            description: Calcular KPIs de proyecto
            requirement: RF-BI-004

          - method: GET
            path: /api/v1/bi/kpis/:projectId/history
            description: Historial de KPIs
            requirement: RF-BI-004

          - method: GET
            path: /api/v1/bi/kpis/:projectId/evm
            description: Earned Value Management
            requirement: RF-BI-004

  frontend:
    module: construction-bi
    path: apps/frontend/src/features/construction-bi/
    framework: React
    status: pending

    components:
      # Dashboards
      - name: DashboardBuilder
        file: apps/frontend/src/features/construction-bi/components/DashboardBuilder.tsx
        requirement: RF-BI-001
        reused_from: MGN-009
        reuse_percentage: 60%

      - name: ConstructionDashboard
        file: apps/frontend/src/features/construction-bi/components/ConstructionDashboard.tsx
        requirement: RF-BI-001
        note: "Nuevo componente especifico"

      - name: KPIWidget
        file: apps/frontend/src/features/construction-bi/components/KPIWidget.tsx
        requirement: RF-BI-001
        note: "Widget para mostrar KPIs"

      - name: ProjectMetricsWidget
        file: apps/frontend/src/features/construction-bi/components/ProjectMetricsWidget.tsx
        requirement: RF-BI-001

      - name: CashFlowWidget
        file: apps/frontend/src/features/construction-bi/components/CashFlowWidget.tsx
        requirement: RF-BI-001

      # Reportes
      - name: ReportGenerator
        file: apps/frontend/src/features/construction-bi/components/ReportGenerator.tsx
        requirement: RF-BI-002
        reused_from: MGN-009
        reuse_percentage: 75%

      - name: ReportTemplateSelector
        file: apps/frontend/src/features/construction-bi/components/ReportTemplateSelector.tsx
        requirement: RF-BI-002

      - name: EstimacionReportViewer
        file: apps/frontend/src/features/construction-bi/components/EstimacionReportViewer.tsx
        requirement: RF-BI-002

      - name: BitacoraReportViewer
        file: apps/frontend/src/features/construction-bi/components/BitacoraReportViewer.tsx
        requirement: RF-BI-002

      # Exportacion
      - name: ExportDialog
        file: apps/frontend/src/features/construction-bi/components/ExportDialog.tsx
        requirement: RF-BI-003
        reused_from: MGN-009
        reuse_percentage: 80%

      - name: ExportTemplateManager
        file: apps/frontend/src/features/construction-bi/components/ExportTemplateManager.tsx
        requirement: RF-BI-003

      - name: ExportHistory
        file: apps/frontend/src/features/construction-bi/components/ExportHistory.tsx
        requirement: RF-BI-003

      # KPIs
      - name: KPIDashboard
        file: apps/frontend/src/features/construction-bi/components/KPIDashboard.tsx
        requirement: RF-BI-004

      - name: KPIChart
        file: apps/frontend/src/features/construction-bi/components/KPIChart.tsx
        requirement: RF-BI-004

      - name: EVMChart
        file: apps/frontend/src/features/construction-bi/components/EVMChart.tsx
        requirement: RF-BI-004

      - name: KPIHistoryChart
        file: apps/frontend/src/features/construction-bi/components/KPIHistoryChart.tsx
        requirement: RF-BI-004

      - name: KPIDefinitionManager
        file: apps/frontend/src/features/construction-bi/components/KPIDefinitionManager.tsx
        requirement: RF-BI-004

# =============================================================================
# DEPENDENCIAS
# =============================================================================

dependencies:
  depends_on:
    # Dependencias del core
    - module: MGN-001
      type: hard
      reason: Autenticacion requerida
    - module: MGN-004
      type: hard
      reason: Aislamiento por tenant
    - module: MGN-009
      type: hard
      reason: Reutilizacion de infraestructura de reportes (75%)

    # Dependencias de verticales construccion
    - module: MAI-001
      type: hard
      reason: Datos de proyectos de construccion
    - module: MAI-002
      type: hard
      reason: Datos de planificacion y presupuestos
    - module: MAI-004
      type: hard
      reason: Datos de compras e inventarios
    - module: MAI-005
      type: hard
      reason: Datos de avances fisicos y financieros

  required_by: []

# =============================================================================
# INTEGRACIONES
# =============================================================================

integrations:
  core_modules:
    - code: MGN-009
      name: Reports
      reuse_percentage: 75%
      components_reused:
        - DashboardsService
        - ReportsService
        - ExportService
        - Dashboard UI components
      adaptations:
        - "Dashboards especificos de construccion"
        - "Reportes especificos de obra"
        - "Templates de exportacion CFE/SECODAM"

  construction_modules:
    - code: MAI-001
      name: Fundamentos
      integration: Datos de proyectos y usuarios
    - code: MAI-002
      name: Planificacion de Obras
      integration: Presupuestos, cronogramas, WBS
    - code: MAI-004
      name: Compras e Inventarios
      integration: Datos de consumo de materiales
    - code: MAI-005
      name: Control de Obra
      integration: Avances fisicos, financieros, bitacora

# =============================================================================
# METRICAS
# =============================================================================

metrics:
  story_points:
    estimated: 28
    actual: null
    saved_by_reuse: 12
    note: "75% reutilizado de MGN-009 ahorra ~12 SP"

  reuse_metrics:
    from_core: 75%
    core_module: MGN-009
    components_reused: 8
    components_new: 7
    components_adapted: 5
    lines_reused: ~2500
    lines_new: ~1200

  documentation:
    requirements: 4
    specifications: 0
    user_stories: 0

  files:
    database: 8
    backend: 15
    frontend: 15
    total: 38

# =============================================================================
# REUTILIZACION DE MGN-009
# =============================================================================

reuse_details:
  database:
    reused_tables:
      - name: dashboards
        percentage: 85%
        adaptations: ["Agregar campos de construccion"]
      - name: dashboard_widgets
        percentage: 90%
        adaptations: ["Widgets especificos"]
      - name: report_definitions
        percentage: 80%
        adaptations: ["Templates de construccion"]
      - name: report_executions
        percentage: 100%
        adaptations: []

    new_tables:
      - construction_kpis
      - kpi_definitions
      - kpi_history
      - construction_report_templates
      - export_templates
      - export_history

  backend:
    reused_services:
      - name: DashboardsService
        percentage: 70%
        adaptations: ["Metodos especificos de construccion"]
      - name: ReportsService
        percentage: 80%
        adaptations: ["Reportes de obra"]
      - name: ExportService
        percentage: 85%
        adaptations: ["Formatos CFE/SECODAM"]

    new_services:
      - KPIService
      - ConstructionMetricsService
      - EVMService
      - ConstructionReportService
      - PdfGeneratorService
      - ExcelGeneratorService

  frontend:
    reused_components:
      - name: DashboardBuilder
        percentage: 60%
      - name: ReportGenerator
        percentage: 75%
      - name: ExportDialog
        percentage: 80%

    new_components:
      - ConstructionDashboard
      - KPIDashboard
      - EVMChart
      - EstimacionReportViewer
      - BitacoraReportViewer
      - KPIWidget
      - ProjectMetricsWidget
      - CashFlowWidget

# =============================================================================
# HISTORIAL
# =============================================================================

history:
  - date: "2025-12-06"
    action: "Creacion de estructura MAE-016"
    author: Requirements-Analyst
    changes:
      - "Creacion de TRACEABILITY.yml"
      - "Definicion de estructura base"
      - "Documentacion de reutilizacion de MGN-009 (75%)"

  - date: "2025-12-06"
    action: "Documentacion de RF"
    author: Requirements-Analyst
    changes:
      - "RF-BI-001: Dashboards Ejecutivos"
      - "RF-BI-002: Reportes Operativos"
      - "RF-BI-003: Exportacion de Datos"
      - "RF-BI-004: Indicadores KPI"
      - "Actualizacion de trazabilidad RF -> implementacion"
      - "Documentacion de adaptaciones vs MGN-009"

# =============================================================================
# NOTAS DE IMPLEMENTACION
# =============================================================================

notes:
  - "75% de reutilizacion de MGN-009 reduce significativamente el esfuerzo"
  - "KPIs especificos de construccion (CPI, SPI, EVM) requieren desarrollo nuevo"
  - "Formatos de exportacion CFE/SECODAM son requerimientos especificos de Mexico"
  - "Firma digital en bitacora requiere integracion con certificados digitales"
  - "Dashboard ejecutivo debe mostrar metricas en tiempo real"
  - "Considerar integracion con Power BI / Tableau para analisis avanzado"
  - "Implementar cache de KPIs para mejorar rendimiento"
  - "Sistema de alertas automaticas cuando KPIs caen fuera de umbrales"
  - "Reportes deben soportar multiples idiomas (ES/EN)"
  - "Exportacion de fotos debe incluir metadata EXIF (ubicacion, fecha)"
