@php /** * --------------------------------------------------------- * FUENTE ÚNICA DE DATOS * --------------------------------------------------------- * Puede venir como: * - $danos_json (pasado desde el controller) * - $stock->danos_json (directamente del modelo) */ $raw = $danos_json ?? ($stock->danos_json ?? []); if (is_string($raw)) { $raw = json_decode($raw, true) ?? []; } if (!is_array($raw)) { $raw = []; } // ========================================================= // ✅ CAMBIO #1: Detectar VVTT aunque no exista (default false) // ========================================================= $vvtt = isset($raw['_tt']) && strtoupper(trim((string)$raw['_tt'])) === 'TT'; /** * --------------------------------------------------------- * DEFINICIÓN DE DEFECTOS Y COLUMNAS * --------------------------------------------------------- */ $defectos = ['ABOMBADO','CORTADO','OXIDADO','ABOLLADO','TALLADO','ORIFICIO']; $columnas = ['SUPERIOR','DERECHO','IZQUIERDO','FRONTAL','PUERTAS']; /** * --------------------------------------------------------- * NORMALIZAR DAÑOS (SIN VVTT) * --------------------------------------------------------- */ $danos = []; foreach ($raw as $defecto => $lados) { // Saltar VVTT GENERAL if ($defecto === '_tt') { continue; } if (!is_array($lados)) { continue; } $defectoNorm = strtoupper($defecto); foreach ($lados as $lado => $v) { $ladoNorm = strtoupper($lado); // Normalizar nombres de lados $ladoNorm = match ($ladoNorm) { 'DERECHA' => 'DERECHO', 'IZQUIERDA' => 'IZQUIERDO', 'SUPERIOR' => 'SUPERIOR', 'FRONTAL' => 'FRONTAL', 'PUERTAS' => 'PUERTAS', default => $ladoNorm }; $danos[$defectoNorm][] = $ladoNorm; } } @endphp {{-- ========================================================= TABLA DE DAÑOS ========================================================= --}}
| P. SUPERIOR | P. DERECHO | P. IZQUIERDO | P. FRONTAL | PUERTAS | |
|---|---|---|---|---|---|
| {{ $d }} | @foreach($columnas as $col)
@if (!empty($danos[$d]) && in_array($col, $danos[$d]))
✔
@endif
|
@endforeach
|
@if($vvtt)
✔
@endif
|
VVTT — VER VERIFICAR TORCER Y TIRAR |