@php $layoutCss = is_array($document['layout'] ?? null) ? $document['layout'] : []; $accent = $layoutCss['accent_color'] ?? \App\Support\Documents\DocumentLayout::DEFAULT_ACCENT; $secondary = $layoutCss['secondary_color'] ?? \App\Support\Documents\DocumentLayout::DEFAULT_SECONDARY; $text = '#666261'; $border = $secondary; $font = \App\Support\Documents\DocumentPrintFonts::FAMILY; $descriptionFontSize = \App\Support\Documents\DocumentLayout::resolvedFontSize($layoutCss, 'description_font_size'); $typeFontSize = \App\Support\Documents\DocumentLayout::resolvedFontSize($layoutCss, 'type_font_size'); $amountFontSize = \App\Support\Documents\DocumentLayout::resolvedFontSize($layoutCss, 'amount_font_size'); $bankDetailsFontSize = \App\Support\Documents\DocumentLayout::resolvedFontSize($layoutCss, 'bank_details_font_size'); $amountInWordsFontSize = \App\Support\Documents\DocumentLayout::resolvedFontSize($layoutCss, 'amount_in_words_font_size'); @endphp
@php use App\Support\Documents\AmountInWords; use App\Support\Documents\DocumentHtml; $layout = $document['layout'] ?? []; $values = $document['values'] ?? []; $fields = $document['fields'] ?? []; $byKey = []; foreach ($fields as $field) { $byKey[$field['key']] = $field; } $currency = strtoupper((string) ($layout['currency'] ?? 'TSH')); $contactLines = $layout['header_contact_lines'] ?? preg_split("/\r\n|\n|\r/", (string) ($layout['header_contact'] ?? '')) ?: []; $contactLines = array_values(array_filter(array_map('trim', $contactLines))); $bankLines = $layout['bank_detail_lines'] ?? preg_split("/\r\n|\n|\r/", (string) ($layout['bank_details'] ?? '')) ?: []; $bankLines = array_values(array_filter(array_map('trim', $bankLines))); $nbLines = $layout['nb_note_lines'] ?? preg_split("/\r\n|\n|\r/", (string) ($layout['nb_note'] ?? '')) ?: []; $nbLines = array_values(array_filter(array_map('trim', $nbLines))); $amountDisplay = AmountInWords::formatDisplay($values['amount'] ?? ''); $totalDisplay = $amountDisplay !== '' ? $amountDisplay.' '.$currency : ''; $fxEquivalent = \App\Support\Money\ExchangeRates::equivalentLabel( (string) ($values['amount'] ?? ''), $currency, is_array($document['fx_snapshot'] ?? null) ? $document['fx_snapshot'] : null, ); $date = (string) ($values['date'] ?? ''); if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $date, $m) === 1) { $date = $m[3].'-'.$m[2].'-'.$m[1]; } $style = (string) ($layout['style'] ?? 'plain'); $blocks = is_array($layout['blocks'] ?? null) ? $layout['blocks'] : []; $showDescription = \App\Support\Documents\DocumentLayout::showsColumn($layout, 'description'); $showType = \App\Support\Documents\DocumentLayout::showsColumn($layout, 'type'); $showAmount = \App\Support\Documents\DocumentLayout::showsColumn($layout, 'amount'); $columnWidths = \App\Support\Documents\DocumentLayout::invoiceColumnWidths($layout); $resolveBlockValue = static function (array $values, ?string $field, string $fallback = '') use ($byKey): array { $key = trim((string) $field); if ($key !== '' && array_key_exists($key, $values)) { $raw = (string) $values[$key]; $type = (string) ($byKey[$key]['type'] ?? ''); return [$raw, $type === 'wysiwyg' || preg_match('/<[a-z][\s\S]*>/i', $raw) === 1, $byKey[$key]['label'] ?? $key]; } return [$fallback, preg_match('/<[a-z][\s\S]*>/i', $fallback) === 1, '']; }; @endphp @if ($style === 'invoice')
@if (! empty($layout['logo_url'])) @else {{ $layout['company_name'] ?? 'Chato Beach Resort' }} @endif
{{ $layout['title'] ?? 'INVOICE' }}
@foreach ($contactLines as $line)

{{ $line }}

@endforeach
@if ($showDescription) @endif @if ($showType) @endif @if ($showAmount) @endif @if ($showDescription) @endif @if ($showType) @endif @if ($showAmount) @endif @if ($showDescription) @endif @if ($showType) @endif @if ($showAmount) @endif @if ($showAmount) @php $leadingEmpty = 2 + (int) $showDescription + (int) $showType - 1; @endphp @if ($leadingEmpty >= 2) @for ($i = 2; $i < $leadingEmpty; $i++) @endfor @elseif ($leadingEmpty === 1) @endif @endif
No. {{ $values['number'] ?? $document['reference'] }}DESCRIPTIONTYPEAMOUNT
DATE {{ $date }}
CLIENT
{{ $values['client'] ?? '—' }}
{!! DocumentHtml::sanitize((string) ($values['description'] ?? '')) ?: e($values['description'] ?? '') !!}{{ $values['type'] ?? '—' }}{{ $amountDisplay !== '' ? $amountDisplay : '—' }}
TOTAL {{ $totalDisplay }}@if ($fxEquivalent !== '')
{{ $fxEquivalent }}@endif
@foreach ($nbLines as $line) {{ $line }}
@endforeach

BANK DETAILS

@foreach ($bankLines as $line)

{{ $line }}

@endforeach
@if ($showAmount)

AMOUNT IN A WORDS:

{{ $values['amount_in_words'] ?? '—' }}

@endif @if (! empty($layout['show_signature']))
SIGNATURE :
@if (! empty($layout['signature_image_url'])) Authorized signature @elseif (! empty($values['signature'])) {{ $values['signature'] }} @endif
@endif @elseif ($style === 'builder') @foreach ($blocks as $block) @php $type = (string) ($block['type'] ?? ''); @endphp @if ($type === 'header')
@if (($block['show_logo'] ?? true) !== false)
@if (! empty($layout['logo_url'])) @else {{ $layout['company_name'] ?? 'Document' }} @endif
@endif @if (($block['show_title'] ?? true) !== false)
{{ $layout['title'] ?? 'Document' }}
@endif @if (($block['show_contact'] ?? true) !== false)
@foreach ($contactLines as $line)

{{ $line }}

@endforeach
@endif
@elseif ($type === 'heading') @php [$heading] = $resolveBlockValue($values, $block['field'] ?? null, (string) ($block['text'] ?? '')); @endphp

{{ $heading !== '' ? $heading : '—' }}

@elseif ($type === 'paragraph') @php [$content, $isRich] = $resolveBlockValue($values, $block['field'] ?? null, (string) ($block['html'] ?? '')); @endphp
@if ($isRich) {!! DocumentHtml::sanitize($content) ?: '—' !!} @else {!! nl2br(e($content !== '' ? $content : '—')) !!} @endif
@elseif ($type === 'field') @php $key = (string) ($block['field'] ?? ''); $raw = (string) ($values[$key] ?? ''); $meta = $byKey[$key] ?? null; $isRich = (($meta['type'] ?? '') === 'wysiwyg') || preg_match('/<[a-z][\s\S]*>/i', $raw) === 1; @endphp
@if (($block['show_label'] ?? true) !== false)
{{ $meta['label'] ?? $key }}
@endif
@if ($isRich) {!! DocumentHtml::sanitize($raw) ?: '—' !!} @else {!! nl2br(e($raw !== '' ? $raw : '—')) !!} @endif
@elseif ($type === 'fields')
@foreach (($block['fields'] ?? []) as $key) @php $raw = (string) ($values[$key] ?? ''); $meta = $byKey[$key] ?? null; $isRich = (($meta['type'] ?? '') === 'wysiwyg') || preg_match('/<[a-z][\s\S]*>/i', $raw) === 1; @endphp
@if (($block['show_labels'] ?? true) !== false)
{{ $meta['label'] ?? $key }}
@endif
@if ($isRich) {!! DocumentHtml::sanitize($raw) ?: '—' !!} @else {!! nl2br(e($raw !== '' ? $raw : '—')) !!} @endif
@endforeach
@elseif ($type === 'table') @php $columns = is_array($block['columns'] ?? null) ? $block['columns'] : []; $colCount = max(count($columns), 1); @endphp
@foreach ($columns as $column)
{{ $column['label'] ?? ($column['field'] ?? '') }}
@endforeach
@foreach ($columns as $column) @php $key = (string) ($column['field'] ?? ''); $raw = (string) ($values[$key] ?? ''); $meta = $byKey[$key] ?? null; $isRich = (($meta['type'] ?? '') === 'wysiwyg') || preg_match('/<[a-z][\s\S]*>/i', $raw) === 1; @endphp
@if ($isRich) {!! DocumentHtml::sanitize($raw) ?: '—' !!} @else {{ $raw !== '' ? $raw : '—' }} @endif
@endforeach
@elseif ($type === 'divider')
@elseif ($type === 'signature' && ! empty($layout['show_signature']))
SIGNATURE :
@if (! empty($layout['signature_image_url'])) Authorized signature @elseif (! empty($values['signature'])) {{ $values['signature'] }} @endif
@elseif ($type === 'footer') @endif @endforeach @else
@if (! empty($layout['company_name']))

{{ $layout['company_name'] }}

@endif

{{ $layout['title'] ?? 'Document' }}

@if (! empty($layout['subtitle']))

{{ $layout['subtitle'] }}

@endif
@if (($layout['qr_position'] ?? '') === 'top-right') Verification QR code @endif

Reference {{ $document['reference'] }}@if (! empty($document['issued_at'])) · Issued {{ $document['issued_at'] }}@endif

@foreach ($fields as $field) @php $fieldValue = (string) ($values[$field['key']] ?? ''); $isRich = ($field['type'] ?? '') === 'wysiwyg' || preg_match('/<[a-z][\s\S]*>/i', $fieldValue) === 1; @endphp
{{ $field['label'] }}
@if ($isRich) {!! DocumentHtml::sanitize($fieldValue) ?: '—' !!} @else {!! nl2br(e($fieldValue)) !!} @endif
@endforeach @endif