@php
function parseImageString($imageStr) {
if (!$imageStr) return [];
if (is_array($imageStr)) return $imageStr;
if (str_starts_with($imageStr, '[') && str_ends_with($imageStr, ']')) {
try {
$cleanStr = trim($imageStr, '[]');
$decoded = json_decode('[' . $cleanStr . ']', true);
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
return array_filter($decoded, function($url) {
return !empty(trim($url));
});
}
$cleanStr = str_replace('\\', '', $cleanStr);
$cleanStr = str_replace('\"', '"', $cleanStr);
$imageArray = [];
$current = '';
$inQuotes = false;
$escapeNext = false;
for ($i = 0; $i < strlen($cleanStr); $i++) {
$char = $cleanStr[$i];
if ($escapeNext) {
$current .= $char;
$escapeNext = false;
continue;
}
if ($char === '\\') {
$escapeNext = true;
continue;
}
if ($char === '"') {
$inQuotes = !$inQuotes;
continue;
}
if ($char === ',' && !$inQuotes) {
$imageArray[] = trim($current);
$current = '';
continue;
}
$current .= $char;
}
if (!empty(trim($current))) {
$imageArray[] = trim($current);
}
$imageArray = array_map(function($url) {
$url = trim($url);
$url = trim($url, '"\'');
return $url;
}, $imageArray);
return array_filter($imageArray, function($url) {
return !empty($url) && $url !== '""' && $url !== "''";
});
} catch (Exception $error) {
$cleanStr = trim($imageStr, '[]');
$cleanStr = str_replace('\\', '', $cleanStr);
$imageArray = array_map('trim', explode(',', $cleanStr));
$imageArray = array_map(function($url) {
return trim($url, '"\'');
}, $imageArray);
return array_filter($imageArray, function($url) {
return !empty($url) && $url !== '""' && $url !== "''";
});
}
}
return [trim($imageStr)];
}
function extractImageUrls($imageStr) {
if (!$imageStr) return [];
if (is_array($imageStr)) return $imageStr;
if (preg_match('/^(.*?\/storage\/maintenance_findings\/)\[(.*)\]$/', $imageStr, $matches)) {
$basePath = $matches[1];
$fileList = $matches[2];
$files = array_map('trim', explode(',', $fileList));
$files = array_filter($files, function($file) {
return !empty(trim($file, ' \\"'));
});
$urls = [];
foreach ($files as $file) {
$file = trim($file, ' \\"');
if (!empty($file)) {
$urls[] = $basePath . $file;
}
}
return $urls;
}
return parseImageString($imageStr);
}
@endphp
SECTION (A): GENERAL INFORMATION
Facility/Location: {{ $fieldName }} / {{ $craneInventory->platform }}
Date: {{ \Carbon\Carbon::parse($maintenanceReport->report_date)->format('d M Y') }}
Task/Job Description: {{ $maintenanceReport->job_description }}
Tag No: {{ $craneInventory->tag_no }}
Manufacturer: {{ $craneInventory->manufacturer }}
Status: {{ $maintenanceStatus->maintenance_name ?? 'N/A' }}
Model No: {{ $craneInventory->model }}
Serial No: {{ $craneInventory->serial_no }}
SECTION (B): MANPOWER / PERSONNEL
| No |
Name |
Designation |
@foreach($manpower as $index => $person)
| {{ $index + 1 }} |
{{ $person->name }} |
{{ $person->designation ?? 'N/A' }} |
@endforeach
SECTION (C): TODAY'S WORK ACTIVITY
| No |
Activity |
@foreach($activities as $index => $activity)
| {{ $index + 1 }} |
{{ $activity->activity }} |
@endforeach
@if($equipmentStatuses->count() > 0)
COMPONENTS STATUS
| No |
Components Name |
Status |
@foreach($equipmentStatuses as $index => $status)
| {{ $index + 1 }} |
{{ $status->system_name }} |
{{ $status->maintenance_name }}
|
@endforeach
@endif
@if($primaryStatuses->count() > 0)
PRIMARY SYSTEMS STATUS
| No |
Primary System Name |
Status |
@foreach($primaryStatuses as $index => $status)
| {{ $index + 1 }} |
{{ $status->system_name }} |
{{ $status->maintenance_name }}
|
@endforeach
@endif
@if($subPrimaryStatuses->count() > 0)
SUB-PRIMARY SYSTEMS STATUS
| No |
Sub-Primary System Name |
Status |
@foreach($subPrimaryStatuses as $index => $status)
| {{ $index + 1 }} |
{{ $status->system_name }} |
{{ $status->maintenance_name }}
|
@endforeach
@endif
@if($secondaryStatuses->count() > 0)
SECONDARY SYSTEMS STATUS
| No |
Secondary System Name |
Status |
@foreach($secondaryStatuses as $index => $status)
| {{ $index + 1 }} |
{{ $status->system_name }} |
{{ $status->maintenance_name }}
|
@endforeach
@endif
@if($equipmentStatuses->count() > 0 || $primaryStatuses->count() > 0 || $subPrimaryStatuses->count() > 0 || $secondaryStatuses->count() > 0)
@endif
SECTION (D): TOMORROW PLAN
| No |
Activity |
@foreach($tomorrowPlans as $index => $plan)
| {{ $index + 1 }} |
{{ $plan->planning_activity }} |
@endforeach
SECTION (E): FINDINGS & REMARKS
@if($findings->count() > 0)
| No |
System Name |
Attribute |
Action to do |
Recommendation |
Status |
@foreach($findings as $index => $finding)
| {{ $index + 1 }} |
@if($finding->crane_inventory_equipment_id)
@php
$system = $equipmentStatuses->firstWhere('system_id', $finding->crane_inventory_equipment_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Equipment)
@elseif($finding->crane_inventory_equipment_component_id)
@php
$system = $primaryStatuses->firstWhere('system_id', $finding->crane_inventory_equipment_component_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Primary)
@elseif($finding->crane_inventory_component_part_id)
@php
$system = $subPrimaryStatuses->firstWhere('system_id', $finding->crane_inventory_component_part_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Sub-Primary)
@elseif($finding->crane_inventory_part_detail_id)
@php
$system = $secondaryStatuses->firstWhere('system_id', $finding->crane_inventory_part_detail_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Secondary)
@else
N/A
@endif
|
{{ $finding->remarks }} |
{{ $finding->action }} |
{{ ucfirst($finding->recommendation ?? '') }} |
{{ ucfirst($finding->status ?? '') }} |
@endforeach
@else
No findings and remarks available
@endif
@php
$findingsWithImages = $findings->filter(function($finding) {
return (isset($finding->image_urls) && count($finding->image_urls) > 0) ||
(isset($finding->image_after_urls) && count($finding->image_after_urls) > 0);
});
@endphp
@if($findingsWithImages->count() > 0)
FINDINGS IMAGES
@foreach($findingsWithImages as $index => $finding)
@php
$beforeImages = $finding->image_urls ?? [];
$afterImages = $finding->image_after_urls ?? [];
$hasBeforeImages = count($beforeImages) > 0;
$hasAfterImages = count($afterImages) > 0;
@endphp
@if($hasBeforeImages || $hasAfterImages)
Finding #{{ $index + 1 }}:
@if($finding->crane_inventory_equipment_id)
@php
$system = $equipmentStatuses->firstWhere('system_id', $finding->crane_inventory_equipment_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Equipment)
@elseif($finding->crane_inventory_equipment_component_id)
@php
$system = $primaryStatuses->firstWhere('system_id', $finding->crane_inventory_equipment_component_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Primary)
@elseif($finding->crane_inventory_component_part_id)
@php
$system = $subPrimaryStatuses->firstWhere('system_id', $finding->crane_inventory_component_part_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Sub-Primary)
@elseif($finding->crane_inventory_part_detail_id)
@php
$system = $secondaryStatuses->firstWhere('system_id', $finding->crane_inventory_part_detail_id);
@endphp
{{ $system->system_name ?? 'N/A' }} (Secondary)
@else
General Finding
@endif
@if($hasBeforeImages)
Before Images
@foreach($beforeImages as $imageIndex => $imageUrl)
@if($imageUrl)
Image {{ $imageIndex + 1 }} not found
URL: {{ $imageUrl }}
Before {{ $imageIndex + 1 }}
@endif
@endforeach
@endif
@if($hasAfterImages)
After Images
@foreach($afterImages as $imageIndex => $imageUrl)
@if($imageUrl)
Image {{ $imageIndex + 1 }} not found
URL: {{ $imageUrl }}
After {{ $imageIndex + 1 }}
@endif
@endforeach
@endif
@endif
@endforeach
@endif
SECTION (F): GENERAL DESCRIPTIONS & IMAGES
@if($generalItems->count() > 0)
@foreach($generalItems as $index => $item)
Item {{ $index + 1 }}: {{ $item->description ?? 'No description available' }}
@if(count($item->media_urls) > 0)
@foreach($item->media_urls as $imageUrl)
@if($imageUrl)
Image not found
URL: {{ $imageUrl }}
Image {{ $loop->iteration }}
@endif
@endforeach
@else
No images available for this item
@endif
@if(!$loop->last)
@endif
@endforeach
@else
No general descriptions and images available
@endif
Prepared By:
@if(count($manpower) > 0)
{{ $manpower[0]->name }}
{{ $manpower[0]->designation ?? '' }}
@endif
Signature
Date: {{ \Carbon\Carbon::parse($maintenanceReport->report_date)->format('d M Y') }}
|
Verified By:
Name & Designation
Signature
Date: {{ \Carbon\Carbon::parse($maintenanceReport->report_date)->format('d M Y') }}
|