@php $data = is_array($report->data) ? $report->data : json_decode($report->data, true); $header = $data['header'] ?? []; $body = $data['body'] ?? []; $footer = $data['footer'] ?? []; $ownerAuthorizedAgentDisplay = trim((string) ($header['owner_authorized_agent_name'] ?? $footer['owner_authorized_agent_name'] ?? '')); $ownerAuthorizedAgentDisplay = $ownerAuthorizedAgentDisplay !== '' ? $ownerAuthorizedAgentDisplay : '—'; /* |-------------------------------------------------------------------------- | Header / service band |-------------------------------------------------------------------------- */ $reportDate = $header['service_date'] ?? optional($report->service_date)->format('m/d/Y') ?? '—'; $startTime = trim((string) ($header['start_time'] ?? '')) ?: '—'; $endTime = trim((string) ($header['end_time'] ?? '')) ?: '—'; $totalHours = trim((string) ($header['total_hours'] ?? '')) ?: '—'; $technician = trim((string) ($header['technician_name'] ?? '')) ?: '—'; $contact = trim((string) ($header['contact_name'] ?? '')) ?: '—'; $technicianContact = null; $technicianStampUrl = null; if (!empty($header['technician_name'])) { $parts = preg_split('/\s+/', trim($header['technician_name'])); $firstName = $parts[0] ?? null; $lastName = count($parts) ? $parts[count($parts) - 1] : null; if ($firstName && $lastName) { $technicianContact = \App\Models\Contact::query() ->where('first_name', 'like', $firstName . '%') ->where('last_name', 'like', $lastName . '%') ->first(); } if ($technicianContact) { $stampMedia = $technicianContact->getFirstMedia('technician_stamp'); if ($stampMedia) { $technicianStampUrl = $stampMedia->getPath(); } } } /* |-------------------------------------------------------------------------- | Account block |-------------------------------------------------------------------------- */ $accountName = trim((string) optional($report->account)->company_name); $accountSuffix = trim((string) optional($report->account)->suffix); $accountDisplay = trim($accountName . ($accountSuffix ? ' (' . $accountSuffix . ')' : '')); $accountDisplay = $accountDisplay !== '' ? $accountDisplay : '—'; $primaryAddress = optional($report->account)->primaryAddress; $primaryPhone = optional($report->account)->primaryPhone; $addressLine1 = trim((string) ($primaryAddress->line_1 ?? '')) ?: '—'; $addressLine2 = trim((string) ($primaryAddress->line_2 ?? '')) ?: '—'; $city = trim((string) ($primaryAddress->city ?? '')); $province = trim((string) ($primaryAddress->state ?? '')); $postalCode = trim((string) ($primaryAddress->zip ?? '')); $cityProvPostal = trim(implode(' ', array_filter([$city, $province, $postalCode]))) ?: '—'; $phone = trim((string) ($primaryPhone->number ?? '')) ?: '—'; $mobilePhone = '—'; /* |-------------------------------------------------------------------------- | FS body sections |-------------------------------------------------------------------------- */ $systemDetails = is_array($body['system_details'] ?? null) ? $body['system_details'] : []; $serviceDetails = is_array($body['service_details'] ?? null) ? $body['service_details'] : []; $checklist = is_array($body['inspection_checklist'] ?? null) ? $body['inspection_checklist'] : []; /* |-------------------------------------------------------------------------- | System details |-------------------------------------------------------------------------- */ $systemType = trim((string) ($systemDetails['system_type'] ?? '')) ?: '—'; $manufacturer = trim((string) ($systemDetails['manufacturer'] ?? '')) ?: '—'; $model = trim((string) ($systemDetails['model'] ?? '')) ?: '—'; $serial = trim((string) ($systemDetails['serial'] ?? '')) ?: '—'; /* |-------------------------------------------------------------------------- | Service details |-------------------------------------------------------------------------- */ $cylinderPressure = trim((string) ($serviceDetails['cylinder_pressure'] ?? '')) ?: '—'; $agentType = trim((string) ($serviceDetails['agent_type'] ?? '')) ?: '—'; $lastInspectionDate = trim((string) ($serviceDetails['last_inspection_date'] ?? '')) ?: '—'; $deficienciesFound = trim((string) ($serviceDetails['deficiencies_found'] ?? '')) ?: '—'; $repairsMade = trim((string) ($serviceDetails['repairs_made'] ?? '')) ?: '—'; /* |-------------------------------------------------------------------------- | Footer |-------------------------------------------------------------------------- */ $comments = trim((string) ($footer['comments'] ?? '')) ?: '—'; $additionalNotes = trim((string) ($footer['additional_notes'] ?? '')) ?: '—'; $scheduledCycle = trim((string) ($footer['scheduled_cycle'] ?? '')) ?: '—'; $recommendedCycle = trim((string) ($footer['recommended_cycle'] ?? '')) ?: '—'; $signedDate = trim((string) ($footer['signed_date'] ?? '')) ?: '—'; /* |-------------------------------------------------------------------------- | Helpers |-------------------------------------------------------------------------- */ $statusMark = function ($answer, $expected) { return strtolower((string) $answer) === strtolower((string) $expected) ? 'X' : ''; }; $defaultChecklistRows = [ ['key' => 'system_operational', 'label' => 'System operational'], ['key' => 'cylinders_secured', 'label' => 'Cylinders in place and secured'], ['key' => 'nozzles_unobstructed', 'label' => 'Nozzles unobstructed'], ['key' => 'pull_station_accessible', 'label' => 'Pull station accessible'], ['key' => 'gas_shutoff_working', 'label' => 'Gas shutoff working'], ['key' => 'detection_line_intact', 'label' => 'Detection line intact'], ['key' => 'control_panel_functional', 'label' => 'Control panel functional'], ['key' => 'tags_present_valid', 'label' => 'Tags present and valid'], ]; $savedChecklist = []; foreach ($checklist as $row) { if (!empty($row['key'])) { $savedChecklist[$row['key']] = $row; } } $rows = []; foreach ($defaultChecklistRows as $row) { $saved = $savedChecklist[$row['key']] ?? null; $rows[] = [ 'label' => $saved['label'] ?? $row['label'], 'answer' => $saved['answer'] ?? '', 'repaired' => !empty($saved['repaired']), ]; } @endphp
@include('pdfs.service-reports.partials.header', [ 'report' => $report, 'title' => 'Fire Suppression System Report', ])
{{-- TOP BAND --}}
Account
Service / Equipment
Service Date {{ $reportDate }}
Start Time {{ $startTime }}
End Time {{ $endTime }}
Total Hours {{ $totalHours }}
Technician {{ $technician }}
System Type {{ $systemType }}
Manufacturer {{ $manufacturer }}
Model {{ $model }}
Serial {{ $serial }}
{{-- TWO COLUMN BODY --}}
Inspection Checklist
@foreach($rows as $row) @endforeach
Item Pass Fail N/A Repaired
{{ $row['label'] }} {{ $statusMark($row['answer'], 'pass') }} {{ $statusMark($row['answer'], 'fail') }} {{ $statusMark($row['answer'], 'na') }} {{ !empty($row['repaired']) ? 'X' : '' }}
System / Service Details
Cylinder Pressure {{ $cylinderPressure }}
Agent Type {{ $agentType }}
Last Inspection Date {{ $lastInspectionDate }}
Deficiencies Found {{ $deficienciesFound }}
Repairs Made {{ $repairsMade }}
Mark checklist items Pass / Fail / N/A. Use Repaired only where corrective action was completed during service.
{{-- BOTTOM STRIP --}}
@include('pdfs.service-reports.partials.footer')
@include('pdfs.service-reports.partials.header', [ 'report' => $report, 'title' => 'Fire Suppression System Report', ])
Additional Notes
{{ $additionalNotes !== '' ? $additionalNotes : '—' }}
@include('pdfs.service-reports.partials.footer')