INVOICE
Invoice #: {{ $order->invoice_number ?? ($order->order_number ?? $order->id) }}
Order #: {{ $order->order_number ?? $order->id }}
@php $orderDate = \Carbon\Carbon::parse($order->created_at); $appTimezone = env('APP_TIMEZONE', config('app.timezone', 'UTC')); if ($appTimezone) { $orderDate->setTimezone($appTimezone); } $dateFormat = env('DATE_FORMAT', 'd M, Y'); $timeFormat = env('TIME_FORMAT', 'h:i A'); @endphp Date: {{ $orderDate->format($dateFormat) }}
Time: {{ $orderDate->format($timeFormat) }}
Status: {{ ucfirst($order->order_status ?? 'N/A') }}

Bill To:

@php // Properly extract user and address info from their respective tables $user = $order->user ?? null; $address = $order->shippingAddress ?? null; @endphp {{-- Name: Prefer address name, then user name --}} @if ($address && !empty($address->name)) {{ $address->name }}
@elseif($user && !empty($user->first_name) && !empty($user->last_name)) {{ $user->first_name }} {{ $user->last_name }}
@elseif($user && !empty($user->first_name)) {{ $user->first_name }}
@elseif($user && !empty($user->name)) {{ $user->name }}
@endif {{-- Email: Prefer user table --}} @if ($user && !empty($user->email)) {{ $user->email }}
@endif {{-- Phone: Prefer address.phone, else user.phone --}} @if ($address && !empty($address->phone)) {{ $address->phone }}
@elseif($user && !empty($user->phone)) {{ $user->phone }}
@endif

Address: @if ($address && !empty($address->address)) {{ $address->address }} @elseif($address && !empty($address->address_line1)) {{ $address->address_line1 ?? '' }}@if (!empty($address->address_line1) && !empty($address->address_line2)) , @endif{{ $address->address_line2 ?? '' }} @endif
City: @if ($address && !empty($address->city)) {{ $address->city }} @endif
State: @if ($address && !empty($address->state)) {{ $address->state }} @endif
Postal Code: @if ($address && !empty($address->pincode)) {{ $address->pincode }} @elseif($address && !empty($address->postal_code)) {{ $address->postal_code }} @endif
@foreach ($order->orderItems as $i => $item) @php $itemProduct = $item->product; $itemVendor = $item->vendorProduct; $itemName = $itemProduct->product_name ?? $itemVendor->product_name ?? 'N/A'; @endphp @endforeach
# Product Name Qty Price Total
{{ $i + 1 }} {{ $itemName }} {{ $item->quantity }} ₹{{ number_format($item->price, 2) }} ₹{{ number_format($item->total, 2) }}
@if (isset($order->product_discount) && $order->product_discount > 0) @endif @if (isset($order->coupon_discount) && $order->coupon_discount > 0) @endif @if (isset($order->gst_amount) && $order->gst_amount > 0) @endif
Subtotal ₹ @php // Show subtotal from order if set and > 0, else calculate as sum of item->price * item->quantity $calculatedSubtotal = 0; if (isset($order->orderItems) && count($order->orderItems) > 0) { foreach ($order->orderItems as $item) { $calculatedSubtotal += ($item->price * $item->quantity); } } $subtotalToShow = (isset($order->subtotal) && $order->subtotal > 0) ? $order->subtotal : $calculatedSubtotal; @endphp {{ number_format($subtotalToShow, 2) }}
Product Discount - ₹{{ number_format($order->product_discount, 2) }}
Coupon Discount @if ($order->coupon_code) ({{ $order->coupon_code }}) @endif - ₹{{ number_format($order->coupon_discount, 2) }}
GST ₹{{ number_format($order->gst_amount, 2) }}
Grand Total ₹{{ number_format($order->total_amount ?? 0, 2) }}
Payment Method {{ ucfirst($order->payment_method ?? 'N/A') }}
Payment Status @if (isset($order->payment_status)) {{ ucfirst($order->payment_status) }} @else N/A @endif
Order Status @if (isset($order->order_status)) {{ ucwords(str_replace('_', ' ', $order->order_status)) }} @else N/A @endif