@extends('layouts.customer') @section('title') My Orders @endsection @section('content')




My Orders

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
Rider
@if ($order->rider_id) @php $rider = \App\Models\User::where('id', $order->rider_id)->where('role_as', 3)->first(); @endphp @if ($rider)

Rider Name: {{ $rider->name }} {{ $rider->last_name }}

Contact No.: {{ $rider->phone }}

@else

Rider information not available.

@endif @else

No rider information available.

@endif
@if ($order->delivery_option == 2)
Delivery Address
@php $address = \App\Models\Addresses::find($order->addresses_id); @endphp @if($address)

{{ $address->barangay }}, {{ $address->municipal }}, {{ $address->streets }}

{{ $order->streets }}

{{ $order->description }}

@else

Address not found

@endif @elseif ($order->delivery_option == 1)
Pickup Address
@php $product = $order->product; $shopstreets = $product->user->shop->streets ?? 'N/A'; $shopMunicipal = $product->user->shop->municipal ?? 'N/A'; $shopBarangay = $product->user->shop->barangay ?? 'N/A'; @endphp

{{ $shopstreets }}, {{ $shopBarangay }}, {{ $shopMunicipal }}

@endif
Order Details

@foreach ($order->orderItems as $item) @if ($item->status == 0) @endif @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, '.', ',') }}

Status: @if ($order->delivery_option == 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 @elseif ($order->status == '11') Cancelled Order @endif @elseif ($order->delivery_option == 1) @if ($order->status == '0') Pending @elseif ($order->status == '1') Approved Order @elseif ($order->status == '2') Order Packed @elseif ($order->status == '3') Ready for Pickup @elseif ($order->status == '7') Order Done @elseif ($order->status == '8') Order Received @endif @endif



@if($order->status == '0')
@csrf @method('PATCH')
@endif
@endsection