@extends('layouts.app') @section('content') @php $money = fn($m) => is_array($m) ? ($m['formatted_amount'] ?? (isset($m['amount']) ? number_format(((int) $m['amount']) / 100, 2) . ' ' . ($m['currency_code'] ?? '') : '-')) : '-'; $stateUpper = strtoupper($state); $stateBadge = match ($stateUpper) { 'CREATED', 'PLACED' => 'bg-amber-100 text-amber-700', 'ACCEPTED' => 'bg-green-100 text-green-700', 'PREPARING', 'IN_PROGRESS' => 'bg-blue-100 text-blue-700', 'READY_FOR_PICKUP', 'FINISHED', 'COMPLETED', 'DELIVERED' => 'bg-green-100 text-green-700', 'DENIED', 'CANCELED', 'CANCELLED' => 'bg-red-100 text-red-700', '' => 'bg-stone-100 text-stone-500', default => 'bg-stone-200 text-stone-700', }; // Accept/deny is only meaningful while Uber still waits for a POS response. $actionable = in_array($stateUpper, ['CREATED', 'PLACED', ''], true); // After acceptance the order is in the kitchen: mark it ready for pickup or // cancel it while it is being prepared (local POS-side transitions). $isPreparing = in_array($stateUpper, ['PREPARING', 'ACCEPTED'], true); $readyConfirm = __('This order will be marked READY for pickup. Are you sure?'); $cancelConfirm = __('This order will be CANCELLED. Are you sure?'); $windowOpen = $windowEnd !== null && $windowEnd->isFuture(); $secondsLeft = $windowOpen ? (int) now()->diffInSeconds($windowEnd) : 0; $items = data_get($detail, 'cart.items') ?? []; $charges = data_get($detail, 'payment.charges') ?? []; $eater = data_get($detail, 'eater') ?? []; $store = data_get($detail, 'store') ?? []; $deliveries = data_get($detail, 'deliveries') ?? []; $issues = data_get($detail, 'fulfillment_issues') ?? []; @endphp
{{-- HEADER --}}
arrow_back {{ __('Orders') }}

{{ data_get($detail, 'display_id') ?: __('Order #:id', ['id' => substr($order->order_id, 0, 8)]) }}

{{ $stateUpper !== '' ? __($stateUpper) : __('UNKNOWN') }} @if (data_get($detail, 'type')) {{ str_replace('_', ' ', data_get($detail, 'type')) }} @endif

{{ $order->order_id }}

{{ __('Business') }}: {{ $order->integration?->posAccess?->note ?? ($order->pos_service_id ? __('Business #:id', ['id' => $order->pos_service_id]) : '-') }}
{{ __('Received') }}: {{ $order->created_at?->format('d.m.Y H:i') }}
print {{ __('Print') }}
{{-- FLASH --}} @if (session('status'))
check_circle {{ session('status') }}
@endif @if (session('error'))
error {{ session('error') }}
@endif @if (isset($errors) && $errors->any())
{{ $errors->first() }}
@endif {{-- ACTION PANEL --}} @if ($actionable)

{{ __('Order approval is pending') }}

@if ($windowOpen)

timer {{ __('Uber accept/deny window: :time left — the order is auto-cancelled when it expires.', ['time' => __(':min min :sec sec', ['min' => intdiv($secondsLeft, 60), 'sec' => $secondsLeft % 60])]) }}

@else

{{ __('The approval window has closed — a response can still be sent, but Uber will most likely return "order is no longer active".') }}{{ $windowEnd ? ' (' . $windowEnd->format('H:i:s') . ')' : '' }}

@endif
@csrf
@csrf
@elseif ($isPreparing)

{{ __('Order is being prepared') }}

{{ __('Mark the order ready for pickup, or cancel it while it is being prepared.') }}

@csrf
@csrf
@else
{!! __('This order is in :status state — accept/deny cannot be applied.', ['status' => '' . e(__($stateUpper)) . '']) !!}
@endif {{-- DETAIL GRID --}}
{{-- LEFT: CART --}}

restaurant {{ __('Cart (:count items)', ['count' => count($items)]) }}

@if (count($items) > 0) @foreach ($items as $item) @endforeach
{{ __('Item') }} {{ __('Qty') }} {{ __('Unit') }} {{ __('Total') }}
{{ data_get($item, 'title') ?? data_get($item, 'id') ?? '-' }} @if (data_get($item, 'special_instructions'))

“{{ data_get($item, 'special_instructions') }}”

@endif @foreach (data_get($item, 'selected_modifier_groups') ?? [] as $group) @php $selected = data_get($group, 'selected_items') ?? []; @endphp @if (count($selected) > 0)

{{ data_get($group, 'title') }}: {{ collect($selected)->map(fn($s) => trim((data_get($s, 'title') ?? '') . (data_get($s, 'quantity', 1) > 1 ? ' ×' . data_get($s, 'quantity') : '')))->filter()->implode(', ') }}

@endif @endforeach
{{ data_get($item, 'quantity', 1) }} {{ $money(data_get($item, 'price.unit_price')) }} {{ $money(data_get($item, 'price.total_price')) }}
@else
{{ __('No cart detail — the order may not be enriched (raw webhook payload).') }}
@endif @if (count($issues) > 0)

{{ __(':count item fulfillment issue(s):', ['count' => count($issues)]) }} {{ collect($issues)->map(fn($i) => data_get($i, 'fulfillment_issue_type'))->filter()->unique()->implode(', ') }}

@endif
{{-- EVENTS TIMELINE --}}

history {{ __('Webhook events (:count)', ['count' => $events->count()]) }}

@if ($events->count() > 0) @foreach ($events as $event) @endforeach
{{ $event->event_type }} {{ $event->status }} {{ __('Signature:') }} {{ $event->signature_valid ? '✓ ' . __('valid') : '✗ ' . __('invalid') }} {{ $event->received_at?->format('d.m.Y H:i:s') }}
@else
{{ __('No webhook event records for this order.') }}
@endif
{{-- RIGHT: SUMMARY CARDS --}}
{{-- PAYMENT --}}

payments {{ __('Payment') }}

@foreach ([ __('Subtotal') => data_get($charges, 'sub_total'), __('Tax') => data_get($charges, 'tax'), __('Fees') => data_get($charges, 'total_fee'), ] as $label => $value)
{{ $label }}
{{ $money($value) }}
@endforeach
{{ __('Total') }}
{{ $money(data_get($charges, 'total')) }}
{{-- EATER --}}

person {{ __('Customer') }}

{{ data_get($eater, 'first_name') ?: '-' }}
@if (data_get($eater, 'phone'))
{{ data_get($eater, 'phone') }}
@endif
{{-- STORE + COURIER + TIMES --}}

storefront {{ __('Store & Delivery') }}

{{ __('Store') }}: {{ data_get($store, 'name') ?: ($order->store_id ? substr($order->store_id, 0, 8) . '…' : '-') }}
@foreach ($deliveries as $courier)
{{ __('Courier:') }} {{ data_get($courier, 'first_name') ?: '-' }} @if (data_get($courier, 'current_state')) {{ str_replace('_', ' ', data_get($courier, 'current_state')) }} @endif @if (data_get($courier, 'estimated_pickup_time'))
{{ __('Estimated pickup:') }} {{ \Illuminate\Support\Carbon::parse(data_get($courier, 'estimated_pickup_time'))->format('d.m.Y H:i') }}
@endif
@endforeach
@if (data_get($detail, 'placed_at'))
{{ __('Order time:') }} {{ \Illuminate\Support\Carbon::parse(data_get($detail, 'placed_at'))->format('d.m.Y H:i') }}
@endif @if (data_get($detail, 'estimated_ready_for_pickup_at'))
{{ __('Ready (estimated):') }} {{ \Illuminate\Support\Carbon::parse(data_get($detail, 'estimated_ready_for_pickup_at'))->format('d.m.Y H:i') }}
@endif
{{ __('POS sync:') }} {{ $order->synced_to_pos ? __('Sent (:time)', ['time' => $order->synced_to_pos_at?->format('d.m.Y H:i')]) : __('Pending') }}
{{-- RAW PAYLOAD --}}
data_object {{ __('Raw payload (JSON)') }}
{{ json_encode($detail, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) }}
@endsection