@php $locale = $locale ?? app()->getLocale(); $isAr = $locale === 'ar'; $currency = $currency ?? (tenant()?->currency ?? 'USD'); // Resolve customer info (auth user or guest from additional_data) $additionalData = is_array($order->additional_data) ? $order->additional_data : []; $isGuest = is_null($order->user_id); $customerName = $isGuest ? $additionalData['name'] ?? __('invoice.guest') : $order->user?->name ?? __('invoice.guest'); $customerPhone = $isGuest ? $additionalData['phone'] ?? '—' : $order->user?->phone ?? '—'; // Resolve address (from relation or from additional_data for guests) $address = $order->address; $guestStreet = $additionalData['street'] ?? null; $guestBuilding = $additionalData['building'] ?? null; $guestFloor = $additionalData['floor'] ?? null; $guestApartment = $additionalData['apartment'] ?? null; $guestCityId = $additionalData['city_id'] ?? null; $street = $address?->street ?? ($guestStreet ?? '—'); $building = $address?->building ?? ($guestBuilding ?? '—'); $floor = $address?->floor ?? ($guestFloor ?? '—'); $apartment = $address?->apartment ?? ($guestApartment ?? '—'); // City name (translatable) $city = null; if ($address?->city) { try { $city = $address->city->getTranslation('name', $locale); } catch (\Exception $e) { $city = $address->city->name; } $city = $city ?: $address->city->name; } elseif ($guestCityId) { $guestCity = \App\Models\City::find($guestCityId); if ($guestCity) { try { $city = $guestCity->getTranslation('name', $locale); } catch (\Exception $e) { $city = $guestCity->name; } $city = $city ?: $guestCity->name; } } $isPickup = $order->delivery_method?->value === 'receive'; $paymentMethod = $order->payment_method?->value; $paymentStatus = $order->payment_status?->value; $orderStatus = $order->status?->value; @endphp {{-- ── HEADER ──────────────────────────────────────────────── --}}
{{ tenant()?->name ?? config('app.name') }}
{{ tenant()?->country ?? '' }}
{{ __('invoice.title') }}
#{{ $order->order_number }}
{{ $order->created_at->format('d M Y, H:i') }}
{{-- ── STATUS BAR ───────────────────────────────────────────── --}}
{{ __('invoice.order_status') }}: {{ __('order.enum_labels.' . $orderStatus) }}   {{ __('invoice.payment_status') }}: {{ __('order.enum_labels.' . $paymentStatus) }}   {{ __('invoice.payment_method') }}: {{ __('order.enum_labels.' . $paymentMethod) }}
{{-- ── BODY ─────────────────────────────────────────────────── --}}
{{-- ── CUSTOMER + ADDRESS GRID ─────────────────────────── --}} {{-- Customer Info --}} {{-- Address --}}
{{ __('invoice.customer_info') }}
{{ __('invoice.customer_name') }} {{ $customerName }}
{{ __('invoice.customer_phone') }} {{ $customerPhone }}
{{ __('invoice.invoice_date') }} {{ $order->created_at->locale($locale)->isoFormat('LL') }}
{{ __('invoice.delivery_address') }}
@if ($isPickup)
{{ __('invoice.pickup') }}
@else @if ($city) @endif
{{ __('invoice.city') }} {{ $city }}
{{ __('invoice.street') }} {{ $street }}
{{ __('invoice.building') }} {{ $building }}
{{ __('invoice.floor') }} {{ $floor }}
{{ __('invoice.apartment') }} {{ $apartment }}
@endif
{{-- ── ORDER ITEMS TABLE ────────────────────────────────── --}}
{{ __('invoice.items') }}
@foreach ($order->items as $index => $item) @php $productName = '—'; if ($item->product) { try { $productName = $item->product->getTranslation('name', $locale) ?: $item->product->name; } catch (\Exception $e) { $productName = $item->product->name ?? '—'; } } $variantName = null; @endphp @endforeach
# {{ __('invoice.product') }} {{ __('invoice.qty') }} {{ __('invoice.unit_price') }} {{ __('invoice.discount') }} {{ __('invoice.total') }}
{{ $index + 1 }}
{{ $productName }}
@if ($variantName)
{{ $variantName }}
@endif
{{ $item->quantity }} {{ number_format((float) $item->unit_price, 2) }} {{ $currency }} @if ($item->discount_amount > 0) -{{ number_format((float) $item->discount_amount, 2) }} {{ $currency }} @else — @endif {{ number_format((float) $item->total_price, 2) }} {{ $currency }}
{{-- ── TOTALS ───────────────────────────────────────────── --}}
@if ($order->discount_amount > 0) @endif @if ($order->subtotal_after_discount && $order->discount_amount > 0) @endif @if ($order->coupon_discount_amount > 0) @endif @if ($order->tax_amount > 0) @endif
{{ __('invoice.subtotal') }} {{ number_format((float) $order->subtotal, 2) }} {{ $currency }}
{{ __('invoice.item_discount') }} -{{ number_format((float) $order->discount_amount, 2) }} {{ $currency }}
{{ __('invoice.subtotal_after_discount') }} {{ number_format((float) $order->subtotal_after_discount, 2) }} {{ $currency }}
{{ __('invoice.coupon_discount') }} -{{ number_format((float) $order->coupon_discount_amount, 2) }} {{ $currency }}
{{ __('invoice.tax') }} {{ number_format((float) $order->tax_amount, 2) }} {{ $currency }}
{{ __('invoice.delivery_fee') }} {{ number_format((float) $order->shipping_amount, 2) }} {{ $currency }}
{{ __('invoice.total_amount') }} {{ number_format((float) $order->total_amount, 2) }} {{ $currency }}
{{-- ── NOTES ────────────────────────────────────────────── --}} @if ($order->notes)
{{ __('invoice.notes') }}
{{ $order->notes }}
@endif
{{-- /.body-padding --}} {{-- ── FOOTER ───────────────────────────────────────────────── --}}