{{-- 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 فاتورة مبيعات {{-- HEADER --}}
{!! $renderAr('فاتورة مبيعات') !!} — {!! $renderAr($companyNameRaw) !!}
{{ $invNumber }} {!! $renderAr('رقم الفاتورة') !!} {{ $invCode }} {!! $renderAr('كود الفاتورة') !!} {!! $renderAr($payLabel) !!} {!! $renderAr('الدفع') !!}
{!! $renderAr($statusLabel) !!} {!! $renderAr('الحالة') !!} {{ $date($invoice->invoice_date) }} {!! $renderAr('تاريخ الفاتورة') !!} {{ ($invoice->payment_type ?? 'cash') === 'cash' ? '-' : $date($invoice->due_date) }} {!! $renderAr('استحقاق') !!}
@if($companyAddressRaw)
{!! $renderAr($companyAddressRaw) !!}
@endif @if($companyPhoneRaw)
{{ $companyPhoneRaw }} {!! $renderAr('هاتف') !!}
@endif
{{-- ITEMS --}}
{!! $renderAr('بنود الفاتورة') !!}
@forelse($items as $i => $line) @php $it = $line->item; $itemNameRaw = $it?->name ?? ('Item #'.$line->item_id); $code = $it?->items_code ?? $it?->code ?? null; $barcode = $it?->barcode ?? null; @endphp @empty @endforelse
{!! $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('لا يوجد بنود') !!}
{{-- TOTALS + INFO --}}
{{-- RIGHT: Totals --}} {{-- LEFT: Customer Info --}}
{!! $renderAr('الإجماليات') !!}
{{ $fmt($invoice->subtotal, 2) }} {!! $renderAr('Subtotal') !!}
{{ $fmt($invoice->discount_amount, 2) }} {!! $renderAr('خصم الفاتورة') !!}
{{ $fmt($invoice->vat_amount, 2) }} VAT
{{ $fmt($invoice->total, 2) }} {!! $renderAr('الإجمالي النهائي') !!}
{{ $fmt($invoice->paid_amount, 2) }} {!! $renderAr('المدفوع') !!}
{{ $fmt($invoice->remaining_amount, 2) }} {!! $renderAr('المتبقي') !!}
@if($payments->count())
{!! $renderAr('المدفوعات') !!}
@foreach($payments as $p) @endforeach
{{ $date($p->payment_date) }} — {!! $renderAr($p->treasury?->name ?? ('#'.$p->treasury_id)) !!} {{ $fmt($p->amount, 2) }} ({{ $p->method ?? '-' }})
@endif
{!! $renderAr('معلومات العميل') !!}
@if($invoice->posted_at) @endif @if(!empty($invoice->notes)) @endif
{!! $renderAr($customerNameRaw) !!} {!! $renderAr('اسم العميل') !!}
@if($customerPhoneRaw) {!! $renderAr($customerPhoneRaw) !!} @else - @endif {!! $renderAr('هاتف العميل') !!}
@if($customerCodeRaw) {{ $customerCodeRaw }} @else - @endif {!! $renderAr('كود العميل') !!}
{{ $date($invoice->created_at) }} {!! $renderAr('تاريخ الإنشاء') !!}
{{ \Carbon\Carbon::parse($invoice->posted_at)->format('Y-m-d H:i') }} {!! $renderAr('تم الترحيل') !!}
{!! $renderAr($invoice->notes) !!} {!! $renderAr('ملاحظات') !!}