@if(isset($consumptionData['consumption'])) @if($consumptionData['consumption']['error'] ?? false)
{{ $consumptionData['consumption']['message'] }}
@elseif($consumptionData['consumption']['has_data'] ?? false) @php $devices = collect($consumptionData['consumption']['devices'] ?? []); $devicesByType = $devices->groupBy('type'); @endphp @foreach($devicesByType as $typeId => $typeDevices) @php $firstDevice = $typeDevices->first(); $typeName = $firstDevice['name'] ?? 'Tipo ' . $typeId; @endphp @foreach($typeDevices->sortBy('code') as $device) @endforeach @endforeach
Dispositivo Código Tipo Revisiones Consumo Total
{{ $typeName }}
{{ $device['name'] ?? 'Dispositivo sin nombre' }} {{ $device['code'] }} {{ $device['type'] }} @if(!empty($device['consumptions']))
@foreach($device['consumptions'] as $consumption) @php $level = ''; $color = 'secondary'; if ($consumption == 0) { $level = 'Nulo'; $color = 'light text-dark'; } elseif ($consumption <= 0.25) { $level = 'Bajo'; $color = 'success'; } elseif ($consumption <= 0.5) { $level = 'Medio'; $color = 'warning'; } elseif ($consumption <= 0.75) { $level = 'Alto'; $color = 'orange text-white'; } else { $level = 'Total'; $color = 'danger'; } @endphp {{ number_format($consumption, 2) }} @endforeach
@else Sin datos @endif
@php $total = $device['total_consumption'] ?? 0; $avgConsumption = count($device['consumptions']) > 0 ? $total / count($device['consumptions']) : 0; $progressColor = 'bg-secondary'; if ($avgConsumption <= 0.25) $progressColor = 'bg-success'; elseif ($avgConsumption <= 0.5) $progressColor = 'bg-warning'; elseif ($avgConsumption <= 0.75) $progressColor = 'bg-orange'; else $progressColor = 'bg-danger'; @endphp
{{ number_format($total, 2) }}
Resumen de Consumos
{{ $devices->count() }}
Dispositivos
{{ $devices->sum('total_consumption') }}
Consumo Total
{{ $devices->avg('total_consumption') ? number_format($devices->avg('total_consumption'), 2) : '0.00' }}
Promedio
{{ $devices->flatMap(function($device) { return $device['consumptions']; })->count() }}
Total Revisiones
@else
No hay datos de consumo para mostrar en el rango seleccionado.
Verifica que existan órdenes aprobadas con revisiones de dispositivos en este período.
@endif @else
No se recibieron datos de consumo del servidor.
Puede ser un problema temporal. Intenta recargar la página.
@endif