{{-- resources/views/admin/purchase_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 $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: // - If mixed => print normal (RTL) without shaping // - Else => shape + wrap with .ar (LTR bidi embed) to fix reversed glyph order $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'); // could be mixed (COREX) $companyPhoneRaw = $setting->phone ?? null; $companyAddressRaw = $setting->address ?? null; $supplierNameRaw = $invoice->supplier->name ?? ('Supplier #'.$invoice->supplier_id); $invCode = $invoice->purchase_invoice_code ?? ('PI-'.$invoice->id); $invnumber = $invoice->invoice_number ?? ('PI-'.$invoice->id); // DOMPDF local logo $logoPath = null; if (!empty($setting?->logo)) { $p = public_path('storage/' . $setting->logo); if (is_file($p)) $logoPath = $p; } // Cairo fonts $cairoR = storage_path('fonts/Cairo-Regular.ttf'); $cairoB = storage_path('fonts/Cairo-Bold.ttf'); @endphp فاتورة مشتريات @php $logoPath = null; if (!empty($setting?->logo)) { $p = public_path('storage/' . ltrim($setting->logo, '/')); if (is_file($p)) { $logoPath = str_replace('\\', '/', realpath($p)); } } @endphp
{{-- LEFT SIDE (Company) --}} {{-- --}}
{!! $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('استحقاق') !!}
--}} {{-- --}} {{-- --}} {{-- --}} {{-- --}} {{--
--}} {{--
{!! $renderAr($companyNameRaw) !!}
--}} {{-- @if($companyAddressRaw)--}} {{--
--}} {{-- {!! $renderAr($companyAddressRaw) !!}--}} {{--
--}} {{-- @endif--}} {{-- @if($companyPhoneRaw)--}} {{--
--}} {{-- {{ $companyPhoneRaw }} {!! $renderAr('هاتف') !!}--}} {{--
--}} {{-- @endif--}} {{--
--}} {{--
{{-- ✅ ITEMS --}}
{!! $renderAr('بنود الفاتورة') !!}
{{-- ✅ IMPORTANT: order columns visually RTL by writing them from right to left --}} @forelse($invoice->items as $i => $it) @php $discType = $it->discount_type ?? 'none'; $disc = '-'; if ($discType === 'percent') $disc = $fmt($it->discount_rate, 2).'%'; elseif ($discType === 'fixed') $disc = $fmt($it->discount_value, 2); $taxRate = $it->tax_rate !== null ? $fmt($it->tax_rate, 2) : '-'; $itemNameRaw = $it->item->name ?? ('Item #'.$it->item_id); $code = $it->item->items_code ?? '-'; $barcode= $it->item->barcode ?? '-'; @endphp @empty @endforelse
{!! $renderAr('الإجمالي') !!} VAT {!! $renderAr('خصم') !!} {!! $renderAr('السعر') !!} {!! $renderAr('الكمية') !!} {!! $renderAr('الصنف') !!} #
{{ $fmt($it->line_total ?? 0, 2) }} {{ $taxRate }} {{ $disc }} {{ $fmt($it->unit_price, 2) }} {{ $fmt($it->quantity, 2) }} {!! $renderAr($itemNameRaw) !!} {{ $i + 1 }}
{!! $renderAr('لا يوجد بنود') !!}
{{-- RIGHT: Totals (place first in HTML so it's on the right) --}} {{-- LEFT: Info --}}
{!! $renderAr('الإجماليات') !!}
{{ $fmt($invoice->subtotal_before_discount, 2) }} {!! $renderAr('قبل الخصم') !!}
{{ $fmt($invoice->discount_value, 2) }} {!! $renderAr('خصم الفاتورة') !!}
{{ number_format((float)($invoice->items?->sum('discount_value') ?? 0), 2) }} {!! $renderAr('خصم السطور') !!}
{{ $fmt($invoice->subtotal, 2) }} {!! $renderAr('بعد الخصم') !!}
{{ $fmt($invoice->tax_value, 2) }} VAT
{{ $fmt($invoice->total, 2) }} {!! $renderAr('الإجمالي النهائي') !!}
{{ $fmt($invoice->paid_amount, 2) }} {!! $renderAr('المدفوع') !!}
{{ $fmt($invoice->remaining_amount, 2) }} {!! $renderAr('المتبقي') !!}
{!! $renderAr('معلومات') !!}
@if($invoice->posted_at) @endif @if(!empty($invoice->notes)) @endif
{!! $renderAr($supplierNameRaw) !!} {!! $renderAr('اسم المورد') !!}
@if($invoice->supplier->phone ?? null) {{ $invoice->supplier->phone }} @else - @endif {!! $renderAr('رقم هاتف المورد') !!}
{{ $invoice->invoice_number ?? '-' }} {!! $renderAr('رقم فاتورة المورد') !!}
{{ $date($invoice->created_at) }} {!! $renderAr('تاريخ الإنشاء') !!}
{{ \Carbon\Carbon::parse($invoice->posted_at)->format('Y-m-d H:i') }} {!! $renderAr('تم الترحيل') !!}
{!! $renderAr('ملاحظات') !!} {!! $renderAr($invoice->notes) !!}