@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 : '—'; $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(); } } } $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 ?? '')) ?: '—'; $city = trim((string) ($primaryAddress->city ?? '')) ?: '—'; $province = trim((string) ($primaryAddress->state ?? '')) ?: '—'; $postalCode = trim((string) ($primaryAddress->zip ?? '')) ?: '—'; $phone = trim((string) ($primaryPhone->number ?? '')) ?: '—'; $systemDetails = is_array($body['system_details'] ?? null) ? $body['system_details'] : []; $equipmentProtected = is_array($body['equipment_protected'] ?? null) ? $body['equipment_protected'] : []; $inspections = is_array($body['inspections'] ?? null) ? $body['inspections'] : []; $semiAnnualInspection = is_array($body['semi_annual_inspection'] ?? null) ? $body['semi_annual_inspection'] : []; $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'] ?? '')) ?: '—'; $systemTypeLabel = '—'; $wetChemical = !empty($systemDetails['system_type']['wet_chemical']); $dryChemical = !empty($systemDetails['system_type']['dry_chemical']); if ($wetChemical && $dryChemical) { $systemTypeLabel = 'Wet Chemical / Dry Chemical'; } elseif ($wetChemical) { $systemTypeLabel = 'Wet Chemical'; } elseif ($dryChemical) { $systemTypeLabel = 'Dry Chemical'; } $manufacturer = trim((string) ($systemDetails['manufacturer_details']['manufacturer'] ?? '')) ?: '—'; $model = trim((string) ($systemDetails['manufacturer_details']['model'] ?? '')) ?: '—'; $serial = trim((string) ($systemDetails['manufacturer_details']['serial'] ?? '')) ?: '—'; $fusibleLink1 = trim((string) ($systemDetails['fusible_link_details']['fusible_link_1'] ?? '')) ?: '—'; $fusibleLink2 = trim((string) ($systemDetails['fusible_link_details']['fusible_link_2'] ?? '')) ?: '—'; $fusibleLink3 = trim((string) ($systemDetails['fusible_link_details']['fusible_link_3'] ?? '')) ?: '—'; $otherDetail = trim((string) ($systemDetails['fusible_link_details']['other'] ?? '')) ?: '—'; $shutoffLabels = []; if (!empty($systemDetails['shutoff_details']['fuel_shutoff'])) $shutoffLabels[] = 'Fuel Shut Off'; if (!empty($systemDetails['shutoff_details']['electric'])) $shutoffLabels[] = 'Electric'; if (!empty($systemDetails['shutoff_details']['gas'])) $shutoffLabels[] = 'Gas'; $shutoffDisplay = !empty($shutoffLabels) ? implode(', ', $shutoffLabels) : '—'; $cylinderMasterSize = trim((string) ($systemDetails['cylinder_details']['cylinder_master_size'] ?? '')) ?: '—'; $cylinderSlaveSize1 = trim((string) ($systemDetails['cylinder_details']['cylinder_slave_size_1'] ?? '')) ?: '—'; $cylinderSlaveSize2 = trim((string) ($systemDetails['cylinder_details']['cylinder_slave_size_2'] ?? '')) ?: '—'; $cylinderSlaveSize3 = trim((string) ($systemDetails['cylinder_details']['cylinder_slave_size_3'] ?? '')) ?: '—'; $equipment1 = trim((string) ($equipmentProtected['equipment_1'] ?? '')) ?: ''; $equipment2 = trim((string) ($equipmentProtected['equipment_2'] ?? '')) ?: ''; $equipment3 = trim((string) ($equipmentProtected['equipment_3'] ?? '')) ?: ''; $equipment4 = trim((string) ($equipmentProtected['equipment_4'] ?? '')) ?: ''; $statusMark = function ($answer, $expected) { return strtolower((string) $answer) === strtolower((string) $expected) ? 'X' : ''; }; $buildChecklistRows = function (array $rowsConfig, array $savedRows) { $savedMap = []; foreach ($savedRows as $row) { if (!empty($row['key'])) { $savedMap[$row['key']] = $row; } } $rows = []; foreach ($rowsConfig as $row) { $saved = $savedMap[$row['key']] ?? null; $rows[] = [ 'label' => $saved['label'] ?? $row['label'], 'answer' => $saved['answer'] ?? '', 'repaired' => !empty($saved['repaired']), ]; } return $rows; }; $inspectionRowsConfig = [ ['key' => 'grease_accumulation', 'label' => 'No significant grease accumulation on nozzles or links?'], ['key' => 'corrosive_cleaning_agents', 'label' => 'Check that corrosive cleaning agents are not used?'], ['key' => 'nozzles_aimed', 'label' => 'Nozzles aim at the cooking surfaces they protect?'], ['key' => 'caps_and_seals', 'label' => 'Nozzle caps and seals are in place?'], ['key' => 'extinguishing_location', 'label' => 'The extinguishing system is in its proper location?'], ['key' => 'manual_actuators', 'label' => 'Manual actuators are unobstructed?'], ['key' => 'tamper_indicators', 'label' => 'Tamper indicators and seals are intact?'], ['key' => 'maintenance_tag', 'label' => 'Maintenance tag or certificate is in place?'], ['key' => 'physical_damage', 'label' => 'No physical damage exists that may prevent operation?'], ['key' => 'pressure_gauges', 'label' => 'Pressure gauges are in the operable range?'], ['key' => 'hazard_same', 'label' => 'Has the hazard remained the same?'], ['key' => 'filters_position', 'label' => 'Filters are listed and in proper position?'], ['key' => 'clearance_from_flame', 'label' => 'Proper clearance from flame to filters?'], ['key' => 'damper_operates', 'label' => 'Damper operates as intended?'], ['key' => 'fryer_open_flame_separation', 'label' => 'Proper separation between fryers and open flame?'], ['key' => 'portable_extinguisher', 'label' => 'Proper portable fire extinguisher in accessible location?'], ['key' => 'personnel_instruction', 'label' => 'Personnel instructed in manual operation?'], ['key' => 'operating_instructions_posted', 'label' => 'Operating instructions posted in a conspicuous way?'], ['key' => 'manual_remote_sets', 'label' => 'Manual and remote set/seals in place?'], ['key' => 'system_operational_seals', 'label' => 'System operational & seals in place?'], ]; $semiAnnualRowsConfig = [ ['key' => 'clean_nozzles', 'label' => 'Clean nozzles?'], ['key' => 'chemical_cartridge_pressure', 'label' => 'Chemical cylinder pressure - 175 PSI/KPA?'], ['key' => 'expellant_gas_cartridge', 'label' => 'Expellant gas cartridge'], ['key' => 'nitrogen_pressure', 'label' => '(a) Pressure (nitrogen) - 2700 PSI'], ['key' => 'co2_weight', 'label' => '(b) Weight (carbon dioxide) - LBS/KGS?'], ['key' => 'dry_chemical_condition', 'label' => 'Check dry chemical agent for lumping or caking?'], ['key' => 'fusible_links_replaced', 'label' => 'Fusible links replaced semi-annually?'], ['key' => 'detectors_release_devices', 'label' => 'Check detectors, releasing devices, hose nozzles, alarms?'], ['key' => 'system_piping_examined', 'label' => 'System piping examined and not obstructed?'], ['key' => 'piping_conduit_bracketed', 'label' => 'Piping and conduit securely bracketed?'], ['key' => 'cable_nuts_hooks', 'label' => 'Check travel of cable nuts/hooks?'], ]; $maintenanceAndHydrostaticRowsConfig = [ ['key' => 'cleaned_cylinder_mount', 'label' => 'Cleaned cylinder and mount?'], ['key' => 'pull_station_test', 'label' => 'Actuating test from pull station?'], ['key' => 'fusible_link_test', 'label' => 'Actuating test from fusible link?'], ['key' => 'electrical_detection_test', 'label' => 'Actuating test from electrical detection?'], ['key' => 'fusible_link_checked', 'label' => 'Fusible link checked, cleaned or replaced?'], ['key' => 'fire_alarm_connection', 'label' => 'Connection to fire alarm test?'], ['key' => 'fuel_shutoff_test', 'label' => 'Fuel shutoff tested?'], ['key' => 'exhaust_fan_test', 'label' => 'Exhaust fan tested and is operational?'], ['key' => 'hydrostatic_test_12_year', 'label' => 'Hydrostatic test, 12 yr.'], ['key' => 'dry_chemical_containers', 'label' => 'Dry Chemical Containers?'], ['key' => 'wet_chemical_containers', 'label' => 'Wet Chemical Containers?'], ['key' => 'hoses_and_fittings', 'label' => 'Hoses and fittings?'], ['key' => 'auxiliary_pressure_containers', 'label' => 'Auxiliary Pressure Containers?'], ]; $inspectionRows = $buildChecklistRows($inspectionRowsConfig, $inspections); $semiAnnualRows = $buildChecklistRows($semiAnnualRowsConfig, $semiAnnualInspection); $maintenanceAndHydrostatic = is_array($body['maintenance_and_hydrostatic'] ?? null) ? $body['maintenance_and_hydrostatic'] : []; $lastTestYear = trim((string) ($maintenanceAndHydrostatic['last_test_year'] ?? '')) ?: '—'; $maintenanceAndHydrostaticRows = $buildChecklistRows( $maintenanceAndHydrostaticRowsConfig, is_array($maintenanceAndHydrostatic) ? $maintenanceAndHydrostatic : [] ); @endphp
@include('pdfs.service-reports.partials.header', [ 'report' => $report, 'title' => 'Fire Suppression System Report', ])
Account
Site {{ $accountDisplay }}
Owner/Auth {{ $ownerAuthorizedAgentDisplay }}
Address {{ $addressLine1 }}
City {{ $city }}
Province {{ $province }}
Postal Code {{ $postalCode }}
Phone {{ $phone }}
Date of Service {{ $reportDate }}    Time {{ $startTime }}
Service Technician {{ $technician }}
Fixed Extinguishing System
System Type {{ $systemTypeLabel }}
Manufacturer {{ $manufacturer }}
Model {{ $model }}
Serial No. {{ $serial }}
Fusible Link {{ $fusibleLink1 }}
Fusible Link {{ $fusibleLink2 }}
Fusible Link {{ $fusibleLink3 }}
Other {{ $otherDetail }}
Shutoff {{ $shutoffDisplay }}
Cylinder Master Size {{ $cylinderMasterSize }}
Cylinder Slave Size {{ $cylinderSlaveSize1 }}
Cylinder Slave Size {{ $cylinderSlaveSize2 }}
Cylinder Slave Size {{ $cylinderSlaveSize3 }}
Equipment Protected (left to right)
{{ $equipment1 !== '' ? $equipment1 : '—' }} {{ $equipment2 !== '' ? $equipment2 : '—' }} {{ $equipment3 !== '' ? $equipment3 : '—' }} {{ $equipment4 !== '' ? $equipment4 : '—' }}
Mark appropriate: “✓” Yes - Acceptable, “X” No - Unacceptable, “N/A” - Not Applicable. All No answers shall be explained in Comments.
Inspections
@foreach($inspectionRows as $row) @endforeach
Item X N/A
{{ $row['label'] }} {{ $statusMark($row['answer'], 'pass') }} {{ $statusMark($row['answer'], 'fail') }} {{ $statusMark($row['answer'], 'na') }}
Semi-Annual Inspection
@foreach($semiAnnualRows as $row) @endforeach
Item X N/A
{{ $row['label'] }} {{ $statusMark($row['answer'], 'pass') }} {{ $statusMark($row['answer'], 'fail') }} {{ $statusMark($row['answer'], 'na') }}
Maintenance Items / Hydrostatic Test Required Every 12 Years
@foreach($maintenanceAndHydrostaticRows as $row) @endforeach
Item X N/A
{{ $row['label'] }} {{ $statusMark($row['answer'], 'pass') }} {{ $statusMark($row['answer'], 'fail') }} {{ $statusMark($row['answer'], 'na') }}
Last date test {{ $lastTestYear }}
@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')