@extends('layouts.admin') @section('content')
Order Information

Tracking Number: {{ $order->tracking_no }}

Date Ordered : {{ $order->created_at->format('F j, Y h:i A') }}

@if ($order->status == '8')

Date Completed : {{ $order->updated_at->format('F j, Y h:i A') }}

@endif
{{$order->user->name}}
{{$order->user->last_name}}
{{$order->user->email}}
{{$order->user->phone}}
@foreach ($order->orderItems as $item) @endforeach
Name Quantity Price Image
{{ $item->product->name }} {{ $item->qty }} @php // Fetch the price that is not the latest in terms of timestamp $activePrice = $item->product->productPrices() ->where('is_active', 1) ->where('created_at', '<', $item->created_at) // Compare timestamps ->orderBy('created_at', 'desc') // Order by descending timestamp ->first(); @endphp @if ($activePrice) ₱{{ number_format($activePrice->price, 2, '.', ',') }} @else No price available @endif @if ($item->product->product_images->isNotEmpty()) Product Image @else Image not found @endif
@php // Define the getDeliveryFee function if (!function_exists('getDeliveryFee')) { function getDeliveryFee($shopId) { $deliveryRate = \App\Models\DeliveryRate:: where('is_active', 1) ->value('delivery_fee'); return $deliveryRate ? $deliveryRate : 0; } } @endphp @php // Calculate grand total $grandTotal = 0; if ($order->delivery_option == 2) { $shippingFee = getDeliveryFee($order->shop_id); $grandTotal += $shippingFee; } // Calculate subtotal foreach ($order->orderItems as $item) { if ($item->status == 0) { // Fetch the price based on timestamp comparison $activePrice = $item->product->productPrices() ->where('is_active', 1) ->where('created_at', '<', $item->created_at) // Compare timestamps ->orderBy('created_at', 'desc') // Order by descending timestamp ->first(); $originalPrice = $activePrice ? $activePrice->price : 0; $subtotal = $originalPrice * $item->qty; $grandTotal += $subtotal; } } @endphp @if ($order->delivery_option == 2)

Shipping Fee: ₱ {{ number_format($shippingFee, 2, '.', ',') }}

@endif

Grand Total: ₱{{ number_format($grandTotal, 2, '.', ',') }}

@if ($order->status == '0') Pending @elseif ($order->status == '1') Approved Order @elseif ($order->status == '2') Order Packed @elseif ($order->status == '3') Ready for Delivery @elseif ($order->status == '4') Assigned to a rider @elseif ($order->status == '5') Picked up @elseif ($order->status == '6') Order is on the way @elseif ($order->status == '7') Order Done @elseif ($order->status == '8') Order Received @endif
@if ($order->delivery_option == 1) For Pickup @else For Delivery @endif
@endsection