{{-- Service Report PDF (normalized renderer) All mapping lives in ServiceReport::normalized() --}} @php // Always work off the normalized payload $data = $data ?? ($report->relationLoaded('items') ? $report->normalized() : []); // Convenience blocks $svc = $data['service'] ?? []; $eq = $data['equipment'] ?? []; // Convert Y/N/true/false-ish values to Yes/No for display $yesNo = function ($v) { if ($v === null || $v === '') return null; if (is_bool($v)) return $v ? 'Yes' : 'No'; $u = strtoupper(trim((string) $v)); if (in_array($u, ['Y','YES','TRUE','1'], true)) return 'Yes'; if (in_array($u, ['N','NO','FALSE','0'], true)) return 'No'; return trim((string) $v); }; // Checkbox-ish display for checklist results $box = function ($v) { $u = strtoupper(trim((string) $v)); if ($u === 'PASS') return '☑ PASS'; if ($u === 'NA') return '☒ N/A'; if ($u === 'FAIL') return '☒ FAIL'; return $v === null || trim((string)$v) === '' ? '—' : (string) $v; }; // Labels (controls display order) $svcLabels = [ 'date' => 'Date', 'start_time' => 'Start', 'end_time' => 'End', 'total_hours' => 'Total Hours', 'technician' => 'Technician', 'owner_authorized_agent' => 'Owner / Authorized Agent', 'return_visit_required' => 'Return Visit Required', 'leaks_found' => 'Leaks Found', 'exhaust_fan_belt_replaced' => 'Fan Belt Replaced', ]; $eqLabels = [ 'manufacturer' => 'Manufacturer', 'model' => 'Model', 'serial_no' => 'Serial #', 'size' => 'System Size', 'cylinder_master_size' => 'Cylinder Size', 'last_date_test' => 'Last Date Tested', 'fuel' => 'Fuel', // KE template fields (won’t show unless present) 'canopy_manufacturer' => 'Canopy Manufacturer', 'model_no' => 'Model #', 'cooking_volume' => 'Cooking Volume', 'cooking_equipment' => 'Cooking Equipment', ]; // Arrays/lists that should render as multiple lines $eqListFields = [ 'fusible_links' => 'Fusible Links', 'equipment_protected' => 'Equipment Protected', 'ecologizer_uv' => 'UV System', 'chemical' => 'Chemical', ]; // Which svc fields are Yes/No formatted $svcYesNoKeys = ['return_visit_required','leaks_found','exhaust_fan_belt_replaced']; // Checklist groups (FS) $checkGroups = [ 'Inspections' => $data['inspections'] ?? [], 'Semi-Annual Inspection' => $data['semi_annual'] ?? [], 'Tests & Maintenance' => $data['tests_and_maintenance'] ?? [], 'Hydrostatic Test' => $data['hydrostatic_test'] ?? [], ]; // Compute "extra" keys (anything in normalized arrays not covered by the known labels) $svcKnownKeys = array_keys($svcLabels); $eqKnownKeys = array_merge(array_keys($eqLabels), array_keys($eqListFields)); $extraSvc = []; foreach ($svc as $k => $v) { if (in_array($k, $svcKnownKeys, true)) continue; if ($v === null || $v === '') continue; $extraSvc[$k] = $v; } $extraEq = []; foreach ($eq as $k => $v) { if (in_array($k, $eqKnownKeys, true)) continue; if ($v === null || $v === '') continue; $extraEq[$k] = $v; } // Helper to title-case keys like tests_and_maintenance $prettyKey = function ($k) { return str_replace('_', ' ', ucwords((string)$k, '_')); }; // Helper to normalize list values into an array $asList = function ($v) { if ($v === null || $v === '') return []; if (is_array($v)) return array_values(array_filter($v, fn($x)=>$x!==null && $x!=='' )); return [ (string) $v ]; }; @endphp {{-- Header card --}}
Service Report
Report # {{ $report->report_number }} • {{ $report->type }}
{{ $report->compliant ? 'Compliant' : 'Non-Compliant' }}
Status: {{ strtoupper($report->status) }}
{{-- Two-column: Service + Equipment --}}
{{-- LEFT: Service Summary --}}
Service Summary
@php $printedAnySvc = false; @endphp @foreach($svcLabels as $k => $label) @php $val = $svc[$k] ?? null; if (in_array($k, $svcYesNoKeys, true)) $val = $yesNo($val); @endphp @if($val !== null && $val !== '') @php $printedAnySvc = true; @endphp @endif @endforeach @if(!empty($extraSvc)) @foreach($extraSvc as $k => $v) @endforeach @endif @if(!$printedAnySvc && empty($extraSvc)) @endif
{{ $label }}{{ $val }}
Additional
{{ $prettyKey($k) }} {{ is_array($v) ? json_encode($v) : $v }}
No service summary data found.
{{-- RIGHT: Equipment --}}
Equipment
@php $printedAnyEq = false; @endphp @foreach($eqLabels as $k => $label) @php $val = $eq[$k] ?? null; @endphp @if($val !== null && $val !== '') @php $printedAnyEq = true; @endphp @endif @endforeach @foreach($eqListFields as $k => $label) @php $list = $asList($eq[$k] ?? null); @endphp @if(!empty($list)) @php $printedAnyEq = true; @endphp @endif @endforeach @if(!empty($extraEq)) @foreach($extraEq as $k => $v) @endforeach @endif @if(!$printedAnyEq && empty($extraEq)) @endif
{{ $label }}{{ $val }}
{{ $label }} @foreach($list as $v)
{{ $v }}
@endforeach
Additional
{{ $prettyKey($k) }} {{ is_array($v) ? json_encode($v) : $v }}
No equipment data found.
{{-- Checklist --}}
Inspection Checklist
@php $box = function ($v) { $v = strtoupper(trim((string) $v)); if ($v === 'PASS') return '☑ PASS'; if ($v === 'NA') return '☒ N/A'; if ($v === 'FAIL') return '☒ FAIL'; return $v !== '' ? $v : '—'; }; $groups = [ 'Inspections' => $data['inspections'] ?? [], 'Semi-Annual Inspection' => $data['semi_annual'] ?? [], 'Tests & Maintenance' => $data['tests_and_maintenance'] ?? [], 'Hydrostatic Test' => $data['hydrostatic_test'] ?? [], ]; $hasAny = false; foreach ($groups as $list) { if (!empty($list)) { $hasAny = true; break; } } @endphp @if(!$hasAny)
No checklist items found.
@else @foreach($groups as $title => $list) @if(!empty($list))
{{ $title }}
@foreach($list as $i => $v) @endforeach
# Result
{{ $i + 1 }} {{ $box($v) }}
@endif @endforeach @endif