feat(reports): complete reporting system with deviations, progress curves, multi-format export

- Added planned/actual/baseline dates to Phase and Feature models
- Created ProgressSnapshot model + migration for historical tracking
- Implemented CaptureDailyProgressSnapshot job (scheduled daily at 06:30)
- Added DeviationCalculator logic (SPI, planned progress, deviation days)
- ReportGenerator service with complete data aggregation
- ReportController with builder, preview, generate (HTML/Excel)
- ReportBuilder Livewire component with date range, entity selection, format
- ProjectReportExport with 10 sheets (Summary, Phases, Features, Inspections, Issues, Tasks, Deviations, Media, Progress Curve, Parameters)
- Blade partials for all sections (header, summary, phases, features, inspections, issues, tasks, media, deviations, progress curve)
- New routes: /projects/{project}/reports/*
- Added 'generate reports' permission
- All 101 tests passing
This commit is contained in:
Javier Braña
2026-08-24 12:32:08 +02:00
parent c58a49f22d
commit ee32544525
30 changed files with 3170 additions and 7 deletions
@@ -0,0 +1,179 @@
@extends('layouts.app')
@section('content')
<div class="container mx-auto px-4 py-8">
{{-- Header --}}
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-8">
<div>
<h1 class="text-2xl font-bold text-gray-800">
{{ __('Generar Informe') }}: {{ $project->name }}
</h1>
<p class="text-gray-500 mt-1">
{{ $project->address ?? 'Sin dirección' }}
@if($project->reference)
&nbsp;|&nbsp; Ref: {{ $project->reference }}
@endif
</p>
</div>
<a href="{{ route('projects.map', $project) }}" class="btn btn-ghost btn-sm">
<x-heroicon-o-arrow-left class="w-4 h-4 mr-1" /> {{ __('Volver al mapa') }}
</a>
</div>
{{-- Report Builder Form --}}
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<form wire:submit.prevent="generateReport" class="space-y-6">
{{-- Date Range --}}
<div class="border-b border-gray-200 pb-6">
<h3 class="text-lg font-semibold text-gray-700 mb-4 flex items-center gap-2">
<x-heroicon-o-calendar-days class="w-5 h-5 text-blue-600" />
{{ __('Rango de fechas') }}
</h3>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
{{ __('Fecha desde') }}
</label>
<input type="date"
wire:model="filters.date_from"
class="input input-bordered w-full"
placeholder="dd/mm/yyyy">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
{{ __('Fecha hasta') }}
</label>
<input type="date"
wire:model="filters.date_to"
class="input input-bordered w-full"
placeholder="dd/mm/yyyy">
</div>
<div class="md:col-span-4 flex flex-wrap gap-2">
<button type="button" wire:click="setDateRange('week')" class="btn btn-sm btn-outline">
{{ __('Esta semana') }}
</button>
<button type="button" wire:click="setDateRange('month')" class="btn btn-sm btn-outline">
{{ __('Este mes') }}
</button>
<button type="button" wire:click="setDateRange('quarter')" class="btn btn-sm btn-outline">
{{ __('Este trimestre') }}
</button>
<button type="button" wire:click="setDateRange('year')" class="btn btn-sm btn-outline">
{{ __('Este año') }}
</button>
<button type="button" wire:click="clearDateRange" class="btn btn-sm btn-ghost">
{{ __('Limpiar') }}
</button>
</div>
</div>
</div>
{{-- Entity Types --}}
<div class="border-b border-gray-200 pb-6">
<h3 class="text-lg font-semibold text-gray-700 mb-4 flex items-center gap-2">
<x-heroicon-o-squares-2x2 class="w-5 h-5 text-blue-600" />
{{ __('Secciones a incluir') }}
</h3>
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
@foreach($availableEntities as $key => $label)
<label class="flex items-center gap-2 cursor-pointer p-3 border rounded-lg hover:bg-gray-50 transition-colors">
<input type="checkbox"
wire:model="filters.entity_types"
value="{{ $key }}"
class="checkbox checkbox-primary">
<span class="text-sm font-medium">{{ $label }}</span>
</label>
@endforeach
</div>
</div>
{{-- Options --}}
<div class="border-b border-gray-200 pb-6">
<h3 class="text-lg font-semibold text-gray-700 mb-4 flex items-center gap-2">
<x-heroicon-o-cog-6-tooth class="w-5 h-5 text-blue-600" />
{{ __('Opciones') }}
</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" wire:model="filters.include_photos" class="checkbox checkbox-primary">
<span class="text-sm">{{ __('Incluir fotos') }}</span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" wire:model="filters.include_charts" class="checkbox checkbox-primary">
<span class="text-sm">{{ __('Incluir gráficos (curva S)') }}</span>
</label>
</div>
</div>
{{-- Format Selection --}}
<div>
<h3 class="text-lg font-semibold text-gray-700 mb-4 flex items-center gap-2">
<x-heroicon-o-document-arrow-down class="w-5 h-5 text-blue-600" />
{{ __('Formato de salida') }}
</h3>
<div class="flex flex-wrap gap-4">
<label class="flex items-center gap-2 cursor-pointer p-4 border-2 rounded-lg {{ $filters['format'] === 'html' ? 'border-blue-500 bg-blue-50' : 'border-gray-200 hover:border-gray-300' }} transition-colors">
<input type="radio" wire:model="filters.format" value="html" class="radio radio-primary">
<div>
<span class="font-medium">{{ __('HTML (Imprimible / PDF)') }}</span>
<p class="text-xs text-gray-500">{{ __('Visualizar en navegador, imprimir o guardar como PDF') }}</p>
</div>
</label>
<label class="flex items-center gap-2 cursor-pointer p-4 border-2 rounded-lg {{ $filters['format'] === 'excel' ? 'border-green-500 bg-green-50' : 'border-gray-200 hover:border-gray-300' }} transition-colors">
<input type="radio" wire:model="filters.format" value="excel" class="radio radio-success">
<div>
<span class="font-medium">{{ __('Excel (.xlsx)') }}</span>
<p class="text-xs text-gray-500">{{ __('Múltiples hojas: Resumen, Fases, Elementos, Inspecciones, Issues, Tareas, Desvíos, Media, Curva S, Parámetros') }}</p>
</div>
</label>
</div>
</div>
{{-- Actions --}}
<div class="flex flex-wrap gap-4 pt-6 border-t border-gray-200">
<button type="submit"
wire:loading.attr="disabled"
class="btn btn-primary gap-2">
<x-heroicon-o-document-arrow-down class="w-5 h-5" />
{{ $filters['format'] === 'excel' ? __('Descargar Excel') : __('Generar Informe HTML') }}
</button>
<button type="button"
wire:click="previewReport"
wire:loading.attr="disabled"
class="btn btn-outline gap-2">
<x-heroicon-o-eye class="w-5 h-5" />
{{ __('Previsualizar') }}
</button>
</div>
</form>
{{-- Preview Modal --}}
@if($showPreview)
<div class="fixed inset-0 z-50 overflow-y-auto" wire:ignore.self>
<div class="flex min-h-full items-center justify-center p-4">
<div class="fixed inset-0 bg-black/50" wire:click="closePreview"></div>
<div class="relative bg-white rounded-lg shadow-xl max-w-4xl w-full max-h-[90vh] overflow-hidden">
<div class="flex items-center justify-between p-4 border-b">
<h3 class="text-lg font-semibold">{{ __('Previsualización del Informe') }}</h3>
<button wire:click="closePreview" class="btn btn-ghost btn-sm">
<x-heroicon-o-x-mark class="w-5 h-5" />
</button>
</div>
<div class="p-4 overflow-y-auto max-h-[70vh]">
@if($previewData)
@include('reports.partials._preview', ['data' => $previewData])
@else
<div class="text-center py-8 text-gray-500">
<x-heroicon-o-arrow-path class="w-8 h-8 mx-auto animate-spin text-blue-500 mb-2" />
<p>{{ __('Generando previsualización...') }}</p>
</div>
@endif
</div>
</div>
</div>
</div>
@endif
</div>
</div>
@endsection
@@ -0,0 +1,73 @@
@extends('layouts.app')
@section('content')
<div class="page-wrapper">
{{-- Print Button --}}
<div class="mb-6 text-right no-print">
<button onclick="window.print()" class="btn btn-primary gap-2">
<x-heroicon-o-printer class="w-5 h-5" /> {{ __('Imprimir / Guardar PDF') }}
</button>
<a href="{{ route('reports.project.excel', ['project' => $project->id] + $filters->toArray()) }}"
class="btn btn-success gap-2 ml-2">
<x-heroicon-o-document-arrow-down class="w-5 h-5" /> {{ __('Descargar Excel') }}
</a>
<a href="{{ route('projects.map', $project) }}" class="btn btn-ghost btn-sm ml-2">
<x-heroicon-o-arrow-left class="w-4 h-4 mr-1" /> {{ __('Volver') }}
</a>
</div>
{{-- Header --}}
@include('reports.partials._header', ['project' => $project, 'filters' => $filters])
{{-- Summary KPIs --}}
@include('reports.partials._summary', ['summary' => $summary])
{{-- Progress Curve Chart --}}
@if(isset($progress_curve) && !empty($progress_curve['labels']))
@include('reports.partials._progress-curve', ['curveData' => $progress_curve])
@endif
{{-- Deviations --}}
@if(isset($deviations))
@include('reports.partials._deviations', ['deviations' => $deviations])
@endif
{{-- Phases --}}
@if(isset($phases) && !empty($phases))
@include('reports.partials._phases', ['phases' => $phases])
@endif
{{-- Features --}}
@if(isset($features) && !empty($features))
@include('reports.partials._features', ['features' => $features])
@endif
{{-- Inspections --}}
@if(isset($inspections) && !empty($inspections))
@include('reports.partials._inspections', ['inspections' => $inspections])
@endif
{{-- Issues --}}
@if(isset($issues) && !empty($issues))
@include('reports.partials._issues', ['issues' => $issues])
@endif
{{-- Tasks --}}
@if(isset($tasks) && !empty($tasks))
@include('reports.partials._tasks', ['tasks' => $tasks])
@endif
{{-- Media --}}
@if(isset($media) && !empty($media) && $filters['include_photos'])
@include('reports.partials._media', ['media' => $media])
@endif
{{-- Footer --}}
<div class="report-footer no-print">
<div class="flex justify-between items-center">
<span>ConstProgress &mdash; Sistema de Gestión de Obras</span>
<span>{{ now()->format('d/m/Y H:i') }}</span>
</div>
</div>
</div>
@endsection
@@ -0,0 +1,148 @@
<div class="section-title">{{ __('Análisis de Desvíos') }}</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<div class="stat-card">
<div class="stat-value" style="color:#ef4444;">{{ $deviations['summary']['phases_delayed'] ?? 0 }}</div>
<div class="stat-label">{{ __('Fases retrasadas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#10b981;">{{ $deviations['summary']['phases_early'] ?? 0 }}</div>
<div class="stat-label">{{ __('Fases adelantadas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#6b7280;">{{ $deviations['summary']['phases_on_time'] ?? 0 }}</div>
<div class="stat-label">{{ __('Fases en plazo') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#ef4444;">{{ $deviations['summary']['features_delayed'] ?? 0 }}</div>
<div class="stat-label">{{ __('Elementos retrasados') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#10b981;">{{ $deviations['summary']['features_early'] ?? 0 }}</div>
<div class="stat-label">{{ __('Elementos adelantados') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#6b7280;">{{ $deviations['summary']['features_on_time'] ?? 0 }}</div>
<div class="stat-label">{{ __('Elementos en plazo') }}</div>
</div>
</div>
@if(!empty($deviations['phases']))
<div class="phase-block mb-8">
<div class="section-title" style="margin-top:0;">{{ __('Desvíos por Fase') }}</div>
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>Fase</th>
<th>Inicio Plan</th>
<th>Fin Plan</th>
<th>Inicio Real</th>
<th>Fin Real</th>
<th>Δ Inicio (d)</th>
<th>Δ Fin (d)</th>
<th>Prog. Plan (%)</th>
<th>Prog. Real (%)</th>
<th>Δ Prog.</th>
<th>SPI</th>
<th>En Plazo</th>
</tr>
</thead>
<tbody>
@foreach($deviations['phases'] as $phase)
<tr>
<td class="font-medium">{{ $phase['name'] }}</td>
<td>{{ $phase['planned_start'] ?? '—' }}</td>
<td>{{ $phase['planned_end'] ?? '—' }}</td>
<td>{{ $phase['actual_start'] ?? '—' }}</td>
<td>{{ $phase['actual_end'] ?? '—' }}</td>
<td class="{{ ($phase['start_deviation'] ?? 0) > 0 ? 'text-red-600' : (($phase['start_deviation'] ?? 0) < 0 ? 'text-green-600' : '') }}">
{{ $phase['start_deviation'] ?? '—' }}
</td>
<td class="{{ ($phase['end_deviation'] ?? 0) > 0 ? 'text-red-600' : (($phase['end_deviation'] ?? 0) < 0 ? 'text-green-600' : '') }}">
{{ $phase['end_deviation'] ?? '—' }}
</td>
<td>{{ $phase['planned_progress'] }}%</td>
<td>{{ $phase['actual_progress'] }}%</td>
<td class="{{ ($phase['progress_deviation'] ?? 0) < 0 ? 'text-red-600' : 'text-green-600' }}">
{{ $phase['progress_deviation'] ?? '—' }}%
</td>
<td>{{ $phase['spi'] ?? '—' }}</td>
<td>
@if($phase['is_on_track'] === true)
<span class="badge badge-success">{{ __('Sí') }}</span>
@elseif($phase['is_on_track'] === false)
<span class="badge badge-error">{{ __('No') }}</span>
@else
<span class="badge badge-ghost">{{ __('N/A') }}</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
@if(!empty($deviations['features']))
<div class="phase-block">
<div class="section-title" style="margin-top:0;">{{ __('Desvíos por Elemento') }}</div>
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>Elemento</th>
<th>Fase</th>
<th>Inicio Plan</th>
<th>Fin Plan</th>
<th>Inicio Real</th>
<th>Fin Real</th>
<th>Δ Inicio (d)</th>
<th>Δ Fin (d)</th>
<th>Prog. Plan (%)</th>
<th>Prog. Real (%)</th>
<th>Δ Prog.</th>
<th>SPI</th>
<th>En Plazo</th>
<th>Responsable</th>
</tr>
</thead>
<tbody>
@foreach($deviations['features'] as $feature)
<tr>
<td class="font-medium">{{ $feature['name'] }}</td>
<td>{{ $feature['phase'] }}</td>
<td>{{ $feature['planned_start'] ?? '—' }}</td>
<td>{{ $feature['planned_end'] ?? '—' }}</td>
<td>{{ $feature['actual_start'] ?? '—' }}</td>
<td>{{ $feature['actual_end'] ?? '—' }}</td>
<td class="{{ ($feature['start_deviation'] ?? 0) > 0 ? 'text-red-600' : (($feature['start_deviation'] ?? 0) < 0 ? 'text-green-600' : '') }}">
{{ $feature['start_deviation'] ?? '—' }}
</td>
<td class="{{ ($feature['end_deviation'] ?? 0) > 0 ? 'text-red-600' : (($feature['end_deviation'] ?? 0) < 0 ? 'text-green-600' : '') }}">
{{ $feature['end_deviation'] ?? '—' }}
</td>
<td>{{ $feature['planned_progress'] }}%</td>
<td>{{ $feature['actual_progress'] }}%</td>
<td class="{{ ($feature['progress_deviation'] ?? 0) < 0 ? 'text-red-600' : 'text-green-600' }}">
{{ $feature['progress_deviation'] ?? '—' }}%
</td>
<td>{{ $feature['spi'] ?? '—' }}</td>
<td>
@if($feature['is_on_track'] === true)
<span class="badge badge-success">{{ __('Sí') }}</span>
@elseif($feature['is_on_track'] === false)
<span class="badge badge-error">{{ __('No') }}</span>
@else
<span class="badge badge-ghost">{{ __('N/A') }}</span>
@endif
</td>
<td>{{ $feature['responsible'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
@@ -0,0 +1,95 @@
<div class="section-title">{{ __('Elementos (Features)') }}</div>
@if(empty($features))
<div class="text-center text-gray-400 py-8">
<p>{{ __('No hay elementos en el rango seleccionado.') }}</p>
</div>
@else
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>Elemento</th>
<th>Fase</th>
<th>Capa</th>
<th>Estado</th>
<th>Progreso (%)</th>
<th>Prog. Plan (%)</th>
<th>Inicio Plan</th>
<th>Fin Plan</th>
<th>Inicio Real</th>
<th>Fin Real</th>
<th>Δ Fin (d)</th>
<th>Δ Inicio (d)</th>
<th>SPI</th>
<th>En Plazo</th>
<th>Responsable</th>
<th>Template</th>
<th>Últ. Insp.</th>
<th>Resultado</th>
<th>Insp.</th>
<th>Issues</th>
</tr>
</thead>
<tbody>
@foreach($features as $feature)
@php
$hasEndDev = $feature['deviation_days'] !== null;
$endDevColor = $hasEndDev && $feature['deviation_days'] > 0 ? 'text-red-600' : ($hasEndDev && $feature['deviation_days'] < 0 ? 'text-green-600' : '');
$hasStartDev = $feature['start_deviation_days'] !== null;
$startDevColor = $hasStartDev && $feature['start_deviation_days'] > 0 ? 'text-red-600' : ($hasStartDev && $feature['start_deviation_days'] < 0 ? 'text-green-600' : '');
$hasProgDev = $feature['progress_deviation'] !== null;
$progDevColor = $hasProgDev && $feature['progress_deviation'] < 0 ? 'text-red-600' : 'text-green-600';
@endphp
<tr>
<td class="font-medium">{{ $feature['name'] }}</td>
<td>{{ $feature['phase'] }}</td>
<td>{{ $feature['layer'] }}</td>
<td>
<span class="badge" style="background: {{ $feature['status_color'] }}20; color: {{ $feature['status_color'] }};">
{{ $feature['status_label'] }}
</span>
</td>
<td>
<div style="display:flex;align-items:center;gap:6px;">
<div style="flex:1;background:#e5e7eb;border-radius:4px;height:6px;min-width:60px;">
<div style="height:6px;border-radius:4px;background:{{ $feature['status_color'] }};width:{{ min(100, $feature['progress']) }}%;"></div>
</div>
<span style="font-size:11px;color:#6b7280;white-space:nowrap;">{{ $feature['progress'] }}%</span>
</div>
</td>
<td>{{ $feature['planned_progress'] }}%</td>
<td>{{ $feature['planned_start'] ?? '—' }}</td>
<td>{{ $feature['planned_end'] ?? '—' }}</td>
<td>{{ $feature['actual_start'] ?? '—' }}</td>
<td>{{ $feature['actual_end'] ?? '—' }}</td>
<td class="{{ $endDevColor }}">{{ $feature['deviation_days'] ?? '—' }}</td>
<td class="{{ $startDevColor }}">{{ $feature['start_deviation_days'] ?? '—' }}</td>
<td>{{ $feature['spi'] ?? '—' }}</td>
<td>
@if($feature['is_on_track'] === true)
<span class="badge badge-success">{{ __('Sí') }}</span>
@elseif($feature['is_on_track'] === false)
<span class="badge badge-error">{{ __('No') }}</span>
@else
<span class="badge badge-ghost">{{ __('N/A') }}</span>
@endif
</td>
<td>{{ $feature['responsible'] }}</td>
<td>{{ $feature['template'] }}</td>
<td>{{ $feature['last_inspection_date'] ?? '—' }}</td>
<td>
@if($feature['last_inspection_result'])
<span class="badge {{ $feature['last_inspection_result'] === 'pass' ? 'badge-success' : ($feature['last_inspection_result'] === 'fail' ? 'badge-error' : 'badge-warning') }}">
{{ $feature['last_inspection_result'] === 'pass' ? 'Aprobada' : ($feature['last_inspection_result'] === 'fail' ? 'Fallida' : 'Condicional') }}
</span>
@endif
</td>
<td>{{ $feature['inspections_count'] }}</td>
<td>{{ $feature['open_issues_count'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@@ -0,0 +1,26 @@
<div class="report-header">
<div class="logo-placeholder">LOGO<br>EMPRESA</div>
<div class="report-header-info">
<div class="report-title">{{ $project->name }}</div>
@if($project->address)
<div class="report-subtitle">{{ $project->address }}</div>
@endif
<div class="report-subtitle" style="margin-top:8px;">
@if($project->start_date)
Inicio: <strong style="color:#1f2937">{{ $project->start_date->format('d/m/Y') }}</strong>
@endif
@if($project->end_date_estimated)
&nbsp;&bull;&nbsp; Fin estimado: <strong style="color:#1f2937">{{ $project->end_date_estimated->format('d/m/Y') }}</strong>
@endif
</div>
</div>
<div class="report-meta">
<strong>Informe de Proyecto</strong>
Generado el {{ $filters['generated_at'] ?? now()->format('d/m/Y H:i') }}<br>
Período: {{ $filters['getDateRangeLabel']() }}<br>
Estado:
<span class="badge {{ $project->status === 'completed' ? 'badge-success' : ($project->status === 'in_progress' ? 'badge-in_progress' : 'badge-planned') }}">
{{ ucfirst(str_replace('_', ' ', $project->status ?? 'N/A')) }}
</span>
</div>
</div>
@@ -0,0 +1,56 @@
<div class="section-title">{{ __('Inspecciones') }}</div>
@if(empty($inspections))
<div class="text-center text-gray-400 py-8">
<p>{{ __('No hay inspecciones en el rango seleccionado.') }}</p>
</div>
@else
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>ID</th>
<th>Elemento</th>
<th>Fase</th>
<th>Template</th>
<th>Inspector</th>
<th>Fecha</th>
<th>Estado</th>
<th>Resultado</th>
<th>Notas</th>
<th>Fotos</th>
</tr>
</thead>
<tbody>
@foreach($inspections as $inspection)
<tr>
<td>{{ $inspection['id'] }}</td>
<td>{{ $inspection['feature'] }}</td>
<td>{{ $inspection['phase'] }}</td>
<td>{{ $inspection['template'] }}</td>
<td>{{ $inspection['inspector'] }}</td>
<td>{{ $inspection['date'] }}</td>
<td>
<span class="badge badge-{{ match($inspection['status']) {
'completed' => 'success',
'pending' => 'warning',
default => 'ghost'
} }}">
{{ $inspection['status'] }}
</span>
</td>
<td>
@if($inspection['result'])
<span class="badge {{ $inspection['result'] === 'pass' ? 'badge-success' : ($inspection['result'] === 'fail' ? 'badge-error' : 'badge-warning') }}">
{{ $inspection['result_label'] }}
</span>
@endif
</td>
<td class="max-w-xs truncate">{{ $inspection['notes'] ?? '—' }}</td>
<td>{{ $inspection['photos_count'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@@ -0,0 +1,75 @@
<div class="section-title">{{ __('Incidencias (Issues)') }}</div>
@if(empty($issues))
<div class="text-center text-gray-400 py-8">
<p>{{ __('No hay incidencias en el rango seleccionado.') }}</p>
</div>
@else
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>ID</th>
<th>Título</th>
<th>Elemento</th>
<th>Fase</th>
<th>Prioridad</th>
<th>Estado</th>
<th>Reportado por</th>
<th>Asignado a</th>
<th>Creado</th>
<th>Cerrado</th>
<th>Días abierto</th>
<th>Tareas</th>
</tr>
</thead>
<tbody>
@foreach($issues as $issue)
@php
$priorityColor = match($issue['priority']) {
'critical' => 'text-red-600',
'high' => 'text-orange-600',
'medium' => 'text-amber-600',
'low' => 'text-gray-600',
default => 'text-gray-600',
};
$statusColor = match($issue['status']) {
'open' => 'badge-error',
'in_review' => 'badge-warning',
'closed' => 'badge-success',
default => 'badge-ghost',
};
@endphp
<tr>
<td>{{ $issue['id'] }}</td>
<td class="font-medium max-w-xs truncate">{{ $issue['title'] }}</td>
<td>{{ $issue['feature'] }}</td>
<td>{{ $issue['phase'] }}</td>
<td>
<span class="badge {{ match($issue['priority']) {
'critical' => 'badge-error',
'high' => 'badge-warning',
'medium' => 'badge-info',
'low' => 'badge-ghost',
default => 'badge-ghost',
} }}">
{{ $issue['priority_label'] }}
</span>
</td>
<td>
<span class="badge {{ $statusColor }}">
{{ $issue['status_label'] }}
</span>
</td>
<td>{{ $issue['reporter'] }}</td>
<td>{{ $issue['assignee'] }}</td>
<td>{{ $issue['created_at'] }}</td>
<td>{{ $issue['closed_at'] ?? '—' }}</td>
<td>{{ $issue['days_open'] }}</td>
<td>{{ $issue['tasks_completed'] }} / {{ $issue['tasks_total'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@@ -0,0 +1,47 @@
<div class="section-title">{{ __('Archivos / Media') }}</div>
@if(empty($media))
<div class="text-center text-gray-400 py-8">
<p>{{ __('No hay archivos en el rango seleccionado.') }}</p>
</div>
@else
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Tipo</th>
<th>Entidad</th>
<th>Entidad Nombre</th>
<th>Tamaño</th>
<th>Subido por</th>
<th>Fecha</th>
</tr>
</thead>
<tbody>
@foreach($media as $item)
<tr>
<td>{{ $item['id'] }}</td>
<td>{{ $item['name'] }}</td>
<td>
<span class="badge {{ match($item['type']) {
'image' => 'badge-info',
'document' => 'badge-success',
'video' => 'badge-warning',
default => 'badge-ghost',
} }}">
{{ $item['type'] }}
</span>
</td>
<td>{{ $item['entity'] }}</td>
<td>{{ $item['entity_name'] }}</td>
<td>{{ $item['size'] }}</td>
<td>{{ $item['uploaded_by'] }}</td>
<td>{{ $item['uploaded_at'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@@ -0,0 +1,67 @@
<div class="section-title">{{ __('Detalle por Fase') }}</div>
@forelse($phases as $phase)
@php
$phaseColor = $phase['color'] ?? '#3b82f6';
$hasDeviation = $phase['deviation_days'] !== null;
$deviationColor = $hasDeviation && $phase['deviation_days'] > 0 ? 'text-red-600' : ($hasDeviation && $phase['deviation_days'] < 0 ? 'text-green-600' : '');
@endphp
<div class="phase-block mb-8" style="border-left-color: {{ $phaseColor }};">
<div class="phase-header" style="border-left-color: {{ $phaseColor }};">
<div>
<div class="phase-name">{{ $phase['name'] }}</div>
<div class="phase-meta">
@if($phase['planned_start'])
{{ $phase['planned_start'] }} &mdash; {{ $phase['planned_end'] ?? 'Sin fecha fin' }}
@else
Sin fechas planificadas
@endif
&nbsp;&bull;&nbsp; {{ $phase['features_count'] }} elementos
&nbsp;&bull;&nbsp; {{ $phase['completed_features'] }} completados
</div>
</div>
<div style="text-align:right;">
<div style="font-size:16px;font-weight:700;color: {{ $phaseColor }};">{{ $phase['progress_percent'] }}%</div>
<div class="phase-progress-bar-wrap" style="margin-top:4px;width:160px;">
<div class="phase-progress-bar" style="width:{{ min(100, $phase['progress_percent']) }}%;background: {{ $phaseColor }};"></div>
</div>
<div class="phase-meta" style="margin-top:4px;">
Plan: {{ $phase['planned_progress'] }}% &nbsp;|&nbsp;
@if($hasDeviation)
<span class="{{ $deviationColor }}">
{{ $phase['deviation_days'] > 0 ? '+' : '' }}{{ $phase['deviation_days'] }}d
</span>
@endif
@if($phase['spi'] !== null)
&nbsp;|&nbsp; SPI: {{ $phase['spi'] }}
@endif
</div>
</div>
</div>
@if(!empty($phase['layers']))
<div class="p-4">
<table class="w-full text-sm">
<thead>
<tr class="bg-gray-50">
<th class="text-left p-2">{{ __('Capa') }}</th>
<th class="text-left p-2">{{ __('Elementos') }}</th>
</tr>
</thead>
<tbody>
@foreach($phase['layers'] as $layer)
<tr class="border-t">
<td class="p-2">{{ $layer['name'] }}</td>
<td class="p-2">{{ $layer['features_count'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
@empty
<div class="text-center text-gray-400 py-8">
<p>{{ __('No hay fases registradas en este proyecto.') }}</p>
</div>
@endforelse
@@ -0,0 +1,126 @@
@php
$data = $data ?? [];
$project = $data['project'] ?? null;
$filters = $data['filters'] ?? null;
$summary = $data['summary'] ?? null;
$phases = $data['phases'] ?? null;
$features = $data['features'] ?? null;
$inspections = $data['inspections'] ?? null;
$issues = $data['issues'] ?? null;
$tasks = $data['tasks'] ?? null;
$deviations = $data['deviations'] ?? null;
$progress_curve = $data['progress_curve'] ?? null;
$media = $data['media'] ?? null;
@endphp
<div class="page-wrapper" style="max-width: 100%; padding: 20px; font-size: 12px;">
{{-- Header --}}
@include('reports.partials._header', ['project' => $project, 'filters' => $filters])
{{-- Summary --}}
@if($summary)
@include('reports.partials._summary', ['summary' => $summary])
@endif
{{-- Progress Curve --}}
@if($progress_curve && !empty($progress_curve['labels']))
<div class="section-title">{{ __('Curva S: Progreso Planificado vs Real') }}</div>
<div class="card bg-base-100 shadow p-4 mb-8" style="height: 300px;">
<canvas id="previewProgressCurveChart"></canvas>
</div>
@endif
{{-- Deviations --}}
@if($deviations)
@include('reports.partials._deviations', ['deviations' => $deviations])
@endif
{{-- Phases --}}
@if($phases && !empty($phases))
@include('reports.partials._phases', ['phases' => $phases])
@endif
{{-- Features --}}
@if($features && !empty($features))
@include('reports.partials._features', ['features' => $features])
@endif
{{-- Inspections --}}
@if($inspections && !empty($inspections))
@include('reports.partials._inspections', ['inspections' => $inspections])
@endif
{{-- Issues --}}
@if($issues && !empty($issues))
@include('reports.partials._issues', ['issues' => $issues])
@endif
{{-- Tasks --}}
@if($tasks && !empty($tasks))
@include('reports.partials._tasks', ['tasks' => $tasks])
@endif
{{-- Media --}}
@if($media && !empty($media) && ($filters['include_photos'] ?? false))
@include('reports.partials._media', ['media' => $media])
@endif
</div>
<script>
function initializePreviewProgressCurveChart() {
if (typeof Chart === 'undefined') {
setTimeout(initializePreviewProgressCurveChart, 100);
return;
}
const ctx = document.getElementById('previewProgressCurveChart');
if (!ctx) return;
if (ctx.chart instanceof Chart) {
ctx.chart.destroy();
}
const labels = @json($progress_curve['labels'] ?? []);
const planned = @json($progress_curve['planned'] ?? []);
const actual = @json($progress_curve['actual'] ?? []);
if (!labels || labels.length === 0) return;
ctx.chart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: '{{ __('Progreso Planificado') }} (%)',
data: planned,
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
fill: true,
tension: 0.3,
},
{
label: '{{ __('Progreso Real') }} (%)',
data: actual,
borderColor: '#10b981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
fill: true,
tension: 0.3,
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { position: 'bottom' } },
scales: {
y: { beginAtZero: true, max: 100 },
}
}
});
}
document.addEventListener('DOMContentLoaded', initializePreviewProgressCurveChart);
</script>
@@ -0,0 +1,99 @@
<div class="section-title">{{ __('Curva S: Progreso Planificado vs Real') }}</div>
<div class="card bg-base-100 shadow p-6 mb-8">
<canvas id="progressCurveChart" height="100"></canvas>
</div>
<script>
document.addEventListener('livewire:load', function() {
initializeProgressCurveChart();
});
document.addEventListener('livewire:updated', function() {
initializeProgressCurveChart();
});
function initializeProgressCurveChart() {
if (typeof Chart === 'undefined') {
console.warn('Chart.js not loaded');
return;
}
const ctx = document.getElementById('progressCurveChart');
if (!ctx) return;
// Destroy existing chart
if (ctx.chart instanceof Chart) {
ctx.chart.destroy();
}
const labels = @json($curveData['labels'] ?? []);
const planned = @json($curveData['planned'] ?? []);
const actual = @json($curveData['actual'] ?? []);
if (!labels || labels.length === 0) return;
ctx.chart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: '{{ __('Progreso Planificado') }} (%)',
data: planned,
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
fill: true,
tension: 0.3,
pointRadius: 4,
pointHoverRadius: 6,
},
{
label: '{{ __('Progreso Real') }} (%)',
data: actual,
borderColor: '#10b981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
fill: true,
tension: 0.3,
pointRadius: 4,
pointHoverRadius: 6,
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: '{{ __('Evolución del progreso') }}',
font: { size: 16, weight: 'bold' }
},
legend: {
position: 'bottom',
},
tooltip: {
mode: 'index',
intersect: false,
}
},
scales: {
y: {
beginAtZero: true,
max: 100,
title: {
display: true,
text: '{{ __('Progreso') }} (%)'
}
},
x: {
title: {
display: true,
text: '{{ __('Fecha') }}'
}
}
}
}
});
}
</script>
@@ -0,0 +1,76 @@
<div class="section-title">{{ __('Resumen Ejecutivo') }}</div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value">{{ $summary['total_features'] }}</div>
<div class="stat-label">{{ __('Total elementos') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#22c55e;">{{ $summary['completed_features'] }}</div>
<div class="stat-label">{{ __('Completados') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#f59e0b;">{{ $summary['completion_rate'] }}%</div>
<div class="stat-label">{{ __('Tasa completitud') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#3b82f6;">{{ $summary['avg_planned_progress'] }}%</div>
<div class="stat-label">{{ __('Progreso planificado') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#10b981;">{{ $summary['avg_actual_progress'] }}%</div>
<div class="stat-label">{{ __('Progreso real') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color: {{ ($summary['overall_spi'] ?? 0) >= 1 ? '#10b981' : '#ef4444' }};">
{{ $summary['overall_spi'] ?? 'N/A' }}
</div>
<div class="stat-label">{{ __('SPI Global') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#6366f1;">{{ $summary['total_inspections'] }}</div>
<div class="stat-label">{{ __('Inspecciones') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#10b981;">{{ $summary['passed_inspections'] }}</div>
<div class="stat-label">{{ __('Aprobadas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#ef4444;">{{ $summary['failed_inspections'] }}</div>
<div class="stat-label">{{ __('Fallidas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#f59e0b;">{{ $summary['pass_rate'] }}%</div>
<div class="stat-label">{{ __('Tasa aprobación') }}</div>
</div>
<div class="stat-card">
<div class="stat-value">{{ $summary['open_issues'] }}</div>
<div class="stat-label">{{ __('Issues abiertos') }}</div>
</div>
<div class="stat-card">
<div class="stat-value">{{ $summary['closed_issues'] }}</div>
<div class="stat-label">{{ __('Issues cerrados') }}</div>
</div>
<div class="stat-card">
<div class="stat-value">{{ $summary['total_tasks'] }}</div>
<div class="stat-label">{{ __('Total tareas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value">{{ $summary['completed_tasks'] }}</div>
<div class="stat-label">{{ __('Tareas completadas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:{{ ($summary['task_completion_rate'] ?? 0) >= 80 ? '#10b981' : '#f59e0b' }};">
{{ $summary['task_completion_rate'] ?? 0 }}%
</div>
<div class="stat-label">{{ __('Completitud tareas') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#10b981;">{{ $summary['phases_on_track'] }}</div>
<div class="stat-label">{{ __('Fases en plazo') }}</div>
</div>
<div class="stat-card">
<div class="stat-value" style="color:#ef4444;">{{ $summary['phases_delayed'] }}</div>
<div class="stat-label">{{ __('Fases retrasadas') }}</div>
</div>
</div>
@@ -0,0 +1,86 @@
<div class="section-title">{{ __('Tareas') }}</div>
@if(empty($tasks))
<div class="text-center text-gray-400 py-8">
<p>{{ __('No hay tareas en el rango seleccionado.') }}</p>
</div>
@else
<div class="overflow-x-auto">
<table>
<thead>
<tr>
<th>ID</th>
<th>Tarea</th>
<th>Fase</th>
<th>Estado</th>
<th>Prioridad</th>
<th>Asignado</th>
<th>Creador</th>
<th>Inicio</th>
<th>Fin</th>
<th>Completada</th>
<th>Horas Est.</th>
<th>Horas Real</th>
<th>Progreso</th>
<th>Vencida</th>
<th>Subtareas</th>
</tr>
</thead>
<tbody>
@foreach($tasks as $task)
@php
$statusBadge = match($task['status']) {
'completed' => 'badge-success',
'in_progress' => 'badge-info',
'pending' => 'badge-warning',
'cancelled' => 'badge-error',
default => 'badge-ghost',
};
$priorityBadge = match($task['priority']) {
'critical' => 'badge-error',
'high' => 'badge-warning',
'medium' => 'badge-info',
'low' => 'badge-ghost',
default => 'badge-ghost',
};
$subtaskTitles = $task['subtasks'] ? implode('; ', array_column($task['subtasks'], 'title')) : '—';
@endphp
<tr>
<td>{{ $task['id'] }}</td>
<td class="font-medium">{{ $task['title'] }}</td>
<td>{{ $task['phase'] }}</td>
<td>
<span class="badge {{ $statusBadge }}">{{ $task['status_label'] }}</span>
</td>
<td>
<span class="badge {{ $priorityBadge }}">{{ $task['priority_label'] }}</span>
</td>
<td>{{ $task['assignee'] }}</td>
<td>{{ $task['creator'] }}</td>
<td>{{ $task['start_date'] ?? '—' }}</td>
<td>{{ $task['due_date'] ?? '—' }}</td>
<td>{{ $task['completed_at'] ?? '—' }}</td>
<td>{{ $task['estimated_hours'] ?? '—' }}</td>
<td>{{ $task['actual_hours'] ?? '—' }}</td>
<td>
<div style="display:flex;align-items:center;gap:6px;">
<div style="flex:1;background:#e5e7eb;border-radius:4px;height:6px;min-width:60px;">
<div style="height:6px;border-radius:4px;background:#3b82f6;width:{{ min(100, $task['progress']) }}%;"></div>
</div>
<span style="font-size:11px;color:#6b7280;white-space:nowrap;">{{ $task['progress'] }}%</span>
</div>
</td>
<td>
@if($task['is_overdue'])
<span class="badge badge-error">{{ __('Sí') }}</span>
@else
<span class="badge badge-success">{{ __('No') }}</span>
@endif
</td>
<td class="max-w-xs truncate">{{ $subtaskTitles }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif