@php use App\Support\Html; // Combined print/download packet: the letter followed by each referenced // document flagged "attach to print", each on its own page(s). Rendered as a // single dompdf pass (dompdf cannot merge pre-rendered PDF binaries), reusing // the letterhead band so the whole packet is branded consistently. $showBand = (bool) $letter->insert_letterhead; $accent = $setting?->primary_color ?: '#2e86ab'; $ink = '#1f2937'; $muted = '#6b7280'; $line = '#d5dde5'; $font = $setting?->font_family ? $setting->font_family.', Arial, sans-serif' : 'Arial, Helvetica, sans-serif'; $rainbowStops = [[46, 134, 171], [168, 25, 46], [255, 210, 63], [27, 27, 27], [255, 210, 63], [168, 25, 46], [46, 134, 171]]; $rainbow = []; $segs = count($rainbowStops) - 1; $steps = 72; for ($i = 0; $i < $steps; $i++) { $p = $i / ($steps - 1) * $segs; $idx = (int) min($segs - 1, floor($p)); $t = $p - $idx; [$a, $b] = [$rainbowStops[$idx], $rainbowStops[$idx + 1]]; $rainbow[] = sprintf('#%02x%02x%02x', (int) round($a[0] + ($b[0] - $a[0]) * $t), (int) round($a[1] + ($b[1] - $a[1]) * $t), (int) round($a[2] + ($b[2] - $a[2]) * $t)); } $mRight = (int) ($setting?->letter_margin_right ?? 44); $mLeft = (int) ($setting?->letter_margin_left ?? 44); $mTop = $showBand ? 158 : (int) ($setting?->letter_margin_top ?? 40); $mBottom = $showBand ? 96 : (int) ($setting?->letter_margin_bottom ?? 40); $position = in_array($setting?->letter_header_position, ['left', 'center', 'right'], true) ? $setting->letter_header_position : 'left'; $logoData = null; if ($showBand && $setting?->logo_path) { try { $logoFull = \Illuminate\Support\Facades\Storage::disk('public')->path($setting->logo_path); if (is_file($logoFull)) { $logoData = 'data:'.(mime_content_type($logoFull) ?: 'image/png').';base64,'.base64_encode(file_get_contents($logoFull)); } } catch (\Throwable $e) { $logoData = null; } } $companyName = $setting?->company_name ?: $letter->team?->name; $watermarkText = $setting?->letter_watermark_text ?: $companyName; $showWatermark = $showBand && $setting?->letter_watermark_enabled && $watermarkText; // $attachments: array of ['document' => Model, 'label', 'number', 'symbol']. $attachments = $attachments ?? []; @endphp {{ $letter->letter_number ?: __('Letter') }} @if ($showWatermark)
{{ $watermarkText }}
@endif @if ($showBand)
@if ($position === 'center') @else @php $logoCell = ''; $contactCell = ''; @endphp @if ($position === 'right'){!! $contactCell !!}{!! $logoCell !!}@else{!! $logoCell !!}{!! $contactCell !!}@endif @endif
@if ($logoData)@else
{{ $companyName }}
@endif
@if ($setting?->address){{ str_replace(["\r\n", "\n"], ' · ', $setting->address) }}
@endif @if ($setting?->phone){{ $setting->phone }}@endif @if ($setting?->email) · {{ $setting->email }}@endif @if ($setting?->website) · {{ $setting->website }}@endif
'.($logoData ? '' : '
'.e($companyName).'
').'
' .($setting?->address ? ''.nl2br(e($setting->address)).'
' : '') .($setting?->phone ? 'Call / WhatsApp: '.e($setting->phone).'
' : '') .($setting?->email ? 'Email: '.e($setting->email).'
' : '') .($setting?->website ? 'Website: '.e($setting->website).'
' : '') .($setting?->tin_number ? 'TIN: '.e($setting->tin_number) : '') .'
@foreach ($rainbow as $c)@endforeach
@endif
@if ($letter->letter_date)
{{ $letter->letter_date->format('d F Y') }}
@endif @if ($letter->reference)
{{ __('Our ref') }}: {{ $letter->reference }}
@endif @if ($letter->recipient_name || $letter->recipient_address)
@if ($letter->recipient_name)
{{ $letter->recipient_name }}
@endif @if ($letter->recipient_address){!! nl2br(e($letter->recipient_address)) !!}@endif
@endif
@if ($letter->title)
{{ $letter->title }}
@endif
{!! Html::sanitize($letter->body_html) !!}
@foreach ($attachments as $att)
@include('letters.partials.document-detail', [ 'document' => $att['document'], 'label' => $att['label'], 'number' => $att['number'], 'symbol' => $att['symbol'], ])
@endforeach