@if(isset($defectSummary) && count($defectSummary) > 0)
@foreach($defectSummary as $summary)
@php
$commentsCollection = collect($summary['comments'] ?? []);
$commentsBySection = $commentsCollection
->filter(function ($comment) {
$hasDescription = isset($comment['description']) && trim(strip_tags($comment['description'])) !== '';
$hasFiles = !empty($comment['files']);
return $hasDescription || $hasFiles;
})
->groupBy(function ($comment) {
return $comment['section_name'] ?? 'General';
});
$summaryHeaderHeight = 96;
$sectionHeaderHeight = 56;
$summaryHeaderRendered = false;
$summaryContainerOpen = false;
$summaryContinuationCount = 0;
@endphp
@continue($commentsBySection->isEmpty())
@foreach($commentsBySection as $sectionName => $comments)
@php
$sectionHeaderRendered = false;
$sectionContinuationCount = 0;
$comments = collect($comments)->values();
@endphp
@foreach($comments as $commentLoopIndex => $comment)
@php
$descriptionHtml = $comment['description'] ?? '';
$commentSegments = reportPdfSplitHtmlContent($descriptionHtml, 460, 13, 20, 520);
if (empty($commentSegments)) {
$commentSegments = [[
'html' => '',
'height' => 0,
]];
}
$segmentCount = count($commentSegments);
$attachments = is_iterable($comment['files'] ?? null) ? collect($comment['files'])->toArray() : [];
$attachmentHeight = reportPdfEstimateAttachmentHeight($attachments, 4, 120, 16, 40);
$priorityValue = $comment['priority_name'] ?? $comment['priority'] ?? null;
$priorityValue = is_string($priorityValue) ? trim($priorityValue) : null;
@endphp
@foreach($commentSegments as $segmentIndex => $segment)
@php
$segmentBase = $segmentIndex === 0 ? 118 : 92;
$segmentHeight = max(40, (int)round($segment['height'] ?? 0)) + $segmentBase;
if ($segmentIndex === $segmentCount - 1 && $attachmentHeight > 0) {
$segmentHeight += $attachmentHeight;
}
// Check if we need a page break before rendering this segment
$requiresBreak = $reportPdfCurrentHeight > 0 && ($reportPdfCurrentHeight + $segmentHeight) > $reportPdfPageLimit;
if ($requiresBreak) {
$reportPdfCurrentHeight = 0;
// Track that headers were rendered before break
$hadSummaryHeader = $summaryHeaderRendered;
$hadSectionHeader = $sectionHeaderRendered;
// Reset header flags for new page
$summaryHeaderRendered = false;
$sectionHeaderRendered = false;
// Increment continuation counts
if ($hadSummaryHeader) {
$summaryContinuationCount++;
}
if ($hadSectionHeader) {
$sectionContinuationCount++;
}
}
@endphp
@if($requiresBreak)
@if($summaryContainerOpen)
@php $summaryContainerOpen = false; @endphp
@endif
@endif
{{-- Render Summary Header if needed --}}
@if(!$summaryHeaderRendered)
{{ $summary['name'] }}
@if($summaryContinuationCount > 0)
(continued)
@endif
@php
$summaryHeaderRendered = true;
$summaryContainerOpen = true;
$reportPdfCurrentHeight += $summaryHeaderHeight;
@endphp
@endif
{{-- Render Section Header if needed --}}
@if(!$sectionHeaderRendered)
{{ $sectionName }}
@if($sectionContinuationCount > 0)
(continued)
@endif
@php
$sectionHeaderRendered = true;
$reportPdfCurrentHeight += $sectionHeaderHeight;
@endphp
@endif
@php $reportPdfCurrentHeight += $segmentHeight; @endphp
@if(!empty($comment['item_name']))
{{ $comment['item_name'] }}
@endif
{{ $comment['title'] ?? $comment['item_name'] ?? 'Comment' }}
@if(!empty($comment['location']))
- {{ $comment['location'] }}
@endif
@if($segmentCount > 1 && $segmentIndex > 0)
(continued)
@endif
@if($priorityValue)
@php
$priorityKey = strtolower($priorityValue);
$priorityMap = [
'high' => ['#f44336', '#fff'],
'medium' => ['#ffc107', '#212529'],
'low' => ['#4caf50', '#fff'],
];
$priorityStyles = $priorityMap[$priorityKey] ?? ['#6c757d', '#fff'];
@endphp
{{ ucfirst($priorityValue) }}
@endif
{!! $segment['html'] ?? '' !!}
@if($segmentIndex === $segmentCount - 1 && !empty($attachments))
@php
$attachmentChunks = collect($attachments)->chunk(4);
@endphp
@foreach($attachmentChunks as $chunk)
@foreach($chunk as $file)
@php
$file = is_array($file) ? $file : (array)$file;
$fileName = $file['original_name'] ?? ($file['name'] ?? 'Attachment');
$fileUrl = $file['file_url'] ?? ($file['url'] ?? '');
$isImage = $file['is_image'] ?? false;
$isVideo = $file['is_video'] ?? false;
if (!$isImage && $fileUrl) {
$isImage = (bool)preg_match('/\\.(jpe?g|png|gif|bmp|webp)$/i', $fileUrl);
}
if (!$isVideo && $fileUrl) {
$isVideo = (bool)preg_match('/\\.(mp4|mov|avi|mkv|webm|ogg|3gp|flv|wmv)$/i', $fileUrl);
}
$base64Preview = ($isImage && $fileUrl) ? convertImageUrlToBase64($fileUrl) : '';
$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
@endphp
@if($isImage && $base64Preview)
IMG
Click to view
@elseif($isVideo)
VID
{{ $fileName }}
Click to play
@else
@php
$fileIcon = '📄';
switch ($fileExtension) {
case 'pdf': $fileIcon = '📄'; break;
case 'doc':
case 'docx': $fileIcon = '📝'; break;
case 'xls':
case 'xlsx': $fileIcon = '📊'; break;
case 'ppt':
case 'pptx': $fileIcon = '📋'; break;
case 'txt': $fileIcon = '📃'; break;
case 'zip':
case 'rar':
case '7z': $fileIcon = '🗂️'; break;
}
@endphp
{{ strtoupper($fileExtension ?: 'FILE') }}
{{ $fileIcon }}
{{ $fileName }}
@endif
|
@endforeach
@for($i = $chunk->count(); $i < 4; $i++)
|
@endfor
@endforeach
@endif
@php
$reportPdfCurrentHeight += $segmentHeight;
@endphp
@endforeach
@endforeach
@endforeach
@if($summaryContainerOpen)
@php $summaryContainerOpen = false; @endphp
@php $reportPdfCurrentHeight += 12; @endphp
@endif
@endforeach
@else
No summary data available.
@endif
|