@php /** * A compact, self-contained summary of a referenced document, inserted into * the letter body. Uses only sanitiser-allowed tags (table/th/td/p/strong + * a text-align style) so it survives Html::sanitize() on save. * * Expects: $document (Model), $label (string), $number (string), $symbol (string). */ $symbol = $symbol ?? ''; $money = fn ($v) => trim($symbol.' '.number_format((float) $v, 2)); $date = isset($document->created_at) ? $document->created_at?->format('d M Y') : ''; foreach (['delivery_date', 'order_date', 'bill_date'] as $df) { if ($document->{$df} ?? null) { $date = \Illuminate\Support\Carbon::parse($document->{$df})->format('d M Y'); break; } } // Invoices and quotes carry line items; other documents may not. $items = method_exists($document, 'lineItems') ? $document->lineItems : collect(); $hasColour = $items->contains(fn ($l) => filled($l->colour ?? null)); $hasSize = $items->contains(fn ($l) => filled($l->size_breakdown ?? null)); @endphp

{{ $label }} {{ $number ?? '' }}@if ($date) — {{ $date }}@endif

@if ($items->isNotEmpty()) @if ($hasColour)@endif @if ($hasSize)@endif @foreach ($items as $line) @if ($hasColour)@endif @if ($hasSize)@endif @endforeach @if (isset($document->total)) @endif @if (isset($document->balance_due) && (float) $document->balance_due > 0) @endif
ItemColourSize breakdownQty Amount
{{ $line->name ?: ($line->description ?: '—') }}{{ $line->colour ?: '—' }}{{ $line->size_breakdown ?: '—' }}{{ rtrim(rtrim(number_format((float) $line->qty, 2), '0'), '.') }} {{ $money($line->line_total) }}
Total {{ $money($document->total) }}
Balance due {{ $money($document->balance_due) }}
@else @if ($date)@endif @if (isset($document->total))@endif @if (isset($document->balance_due))@endif
Date{{ $date }}
Total{{ $money($document->total) }}
Balance due{{ $money($document->balance_due) }}
@endif