{{-- resources/views/admin/sales_invoices/pdf.blade.php --}} @php $fmt = fn($n, $d=2) => number_format((float)($n ?? 0), $d); $date = fn($v) => $v ? \Carbon\Carbon::parse($v)->format('Y-m-d') : '-'; // $shape coming from controller (optional) $shape = $shape ?? fn($t) => $t; // Detect mixed Arabic+Latin/Numbers (avoid shaping + avoid .ar class) $isMixed = function (?string $text): bool { if (!$text) return false; return (bool) preg_match('/[A-Za-z0-9]/', $text); }; // Render helper: $renderAr = function (?string $text) use ($shape, $isMixed) { $text = (string)($text ?? ''); if ($text === '') return ''; if ($isMixed($text)) return '' . e($text) . ''; return '' . e($shape($text)) . ''; }; $statusLabel = match ($invoice->status ?? 'draft') { 'draft' => 'مسودة', 'posted' => 'مُرحّلة', 'paid' => 'مدفوعة', 'partial' => 'جزئي', 'cancelled' => 'ملغاة', default => (string)($invoice->status ?? '-'), }; $payLabel = ($invoice->payment_type ?? 'cash') === 'cash' ? 'كاش' : 'آجل'; $companyNameRaw = $setting->name ?? config('app.name'); $companyPhoneRaw = $setting->phone ?? null; $companyAddressRaw = $setting->address ?? null; $customerNameRaw = $invoice->customer?->name ?? ('Customer #'.$invoice->customer_id); $customerPhoneRaw = $invoice->customer?->phone ?? null; $customerCodeRaw = $invoice->customer?->code ?? null; $invCode = $invoice->invoice_code ?? ('SI-'.$invoice->id); $invNumber = $invoice->invoice_number ?? $invCode; // Cairo fonts $cairoR = storage_path('fonts/Cairo-Regular.ttf'); $cairoB = storage_path('fonts/Cairo-Bold.ttf'); // DomPDF logo base64 $logo64 = null; if (!empty($setting?->logo)) { $p = public_path('storage/' . ltrim($setting->logo, '/')); if (is_file($p)) { $mime = mime_content_type($p) ?: 'image/png'; $logo64 = 'data:' . $mime . ';base64,' . base64_encode(file_get_contents($p)); } } // Items $items = $invoice->items ?? collect(); // Payments (optional - if loaded) $payments = $invoice->payments ?? collect(); @endphp
|
{!! $renderAr('فاتورة مبيعات') !!} — {!! $renderAr($companyNameRaw) !!}
|
@if($logo64)
@if($companyAddressRaw)
{!! $renderAr($companyAddressRaw) !!}
@endif
@if($companyPhoneRaw)
{{ $companyPhoneRaw }} {!! $renderAr('هاتف') !!}
@endif
|
| {!! $renderAr('الإجمالي') !!} | VAT | {!! $renderAr('خصم') !!} | {!! $renderAr('السعر') !!} | {!! $renderAr('الكمية') !!} | {!! $renderAr('الصنف') !!} | # |
|---|---|---|---|---|---|---|
| {{ $fmt($line->total, 4) }} | {{ $fmt($line->vat, 4) }} | {{ $fmt($line->discount, 4) }} | {{ $fmt($line->price, 4) }} | {{ $fmt($line->quantity, 4) }} |
{!! $renderAr($itemNameRaw) !!}
@if($code) #{{ $code }} @endif
@if($code && $barcode) — @endif
@if($barcode) {{ $barcode }} @endif
|
{{ $i + 1 }} |
| {!! $renderAr('لا يوجد بنود') !!} | ||||||
|
{!! $renderAr('الإجماليات') !!}
{!! $renderAr('المدفوعات') !!}
|
{{-- LEFT: Customer Info --}}
{!! $renderAr('معلومات العميل') !!}
|