@php /** @var \App\Models\Order $record */ $record = $this->record; $statusFlow = ['pending', 'paid', 'processing', 'shipped', 'delivered']; $terminal = in_array($record->status, ['cancelled', 'closed']); $currentIdx = array_search($record->status, $statusFlow); $statusMeta = [ 'pending' => ['label' => 'Pending', 'color' => '#d97706', 'icon' => 'M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z'], 'paid' => ['label' => 'Paid', 'color' => '#16a34a', 'icon' => 'M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z'], 'processing' => ['label' => 'Processing', 'color' => '#2563eb', 'icon' => 'M4.5 12a7.5 7.5 0 0015 0m-15 0a7.5 7.5 0 1115 0m-15 0H3m16.5 0H21m-1.5 0H12m-8.457 3.077l1.41-.513m14.095-5.13l1.41-.513M5.106 17.785l1.15-.964m11.49-9.642l1.149-.964M7.501 19.795l.75-1.3m7.5-12.99l.75-1.3m-6.063 16.658l.26-1.477m2.605-14.772l.26-1.477m0 17.726l-.26-1.477M10.698 4.614l-.26-1.477M16.5 19.794l-.75-1.299M7.5 4.205L12 12m6.894 5.785l-1.149-.964M6.256 7.178l-1.15-.964m15.352 8.864l-1.41-.513M4.954 9.435l-1.41-.514M12.002 12l-3.75 6.495'], 'shipped' => ['label' => 'Shipped', 'color' => '#7c3aed', 'icon' => 'M8.25 18.75a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m3 0h6m-9 0H3.375a1.125 1.125 0 01-1.125-1.125V14.25m17.25 4.5a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m3 0h1.125c.621 0 1.129-.504 1.09-1.124a17.902 17.902 0 00-3.213-9.193 2.056 2.056 0 00-1.58-.86H14.25M16.5 18.75h-2.25m0-11.177v-.958c0-.568-.422-1.048-.987-1.106a48.554 48.554 0 00-10.026 0 1.106 1.106 0 00-.987 1.106v7.635m12-6.677v6.677m0 4.5v-4.5m0 0h-12'], 'delivered' => ['label' => 'Delivered', 'color' => '#059669', 'icon' => 'M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z'], 'cancelled' => ['label' => 'Cancelled', 'color' => '#dc2626', 'icon' => 'M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z'], 'closed' => ['label' => 'Closed', 'color' => '#6b7280', 'icon' => 'M16.5 10.5V6.75a4.5 4.5 0 10-9 0v3.75m-.75 11.25h10.5a2.25 2.25 0 002.25-2.25v-6.75a2.25 2.25 0 00-2.25-2.25H6.75a2.25 2.25 0 00-2.25 2.25v6.75a2.25 2.25 0 002.25 2.25z'], ]; $canEdit = auth()->user()?->can('orders.edit'); $canClose = auth()->user()?->can('orders.close'); $subtotal = $record->subtotal_excl ?? 0; $vat = $record->vat_amount ?? 0; $shipping = $record->shipping_cost ?? 0; $credit = $record->credit_applied ?? 0; $total = $record->total_incl ?? 0; $events = $record->events ?? collect(); $dotColors = [ 'order_placed' => '#16a34a', 'status_change' => '#3b82f6', 'item_edit' => '#f59e0b', 'shipping_change' => '#06b6d4', 'credit_issued' => '#16a34a', 'note_added' => '#9ca3af', 'message_sent' => '#8b5cf6', 'private_note' => '#f59e0b', ]; $eventLabels = [ 'order_placed' => 'Order Placed', 'status_change' => 'Status Update', 'item_edit' => 'Items Modified', 'shipping_change' => 'Shipping Updated', 'credit_issued' => 'Credit Issued', 'note_added' => 'Note Added', 'message_sent' => 'Message Sent', 'private_note' => 'Private Note', ]; @endphp
{{-- ═══════════════════ LEFT PANEL ═══════════════════ --}}
{{-- Order header bar --}}
Order
#{{ $record->id }}
Customer
@if($record->user_id) {{ $record->shipping_name }} @else {{ $record->shipping_name }} @endif
Date
{{ $record->created_at->format('d M Y, H:i') }}
Total
R {{ number_format($total, 2) }}
Payment
{{ str_replace('_', ' ', $record->payment_method ?? '—') }} @if($record->payment_ref)
{{ $record->payment_ref }}
@endif
Invoice
@if($record->invoice) {{ $record->invoice->invoice_number }} @else Not generated @endif
@if($record->placed_by_user_id)
Counter Sale By
{{ $record->placedByUser?->name ?? '—' }}
@endif
{{-- Items table --}}
Order Items {{ $record->items->count() }} line{{ $record->items->count() !== 1 ? 's' : '' }}
@foreach($record->items as $item) @endforeach
Product Brand Qty Unit Total
{{ $item->product_name }}
{{ $item->part_number }}
{{ $item->brand_name ?? '—' }} {{ $item->qty }} R {{ number_format($item->unit_price_incl, 2) }} R {{ number_format($item->line_total_incl, 2) }}
Subtotal (excl. VAT) R {{ number_format($subtotal, 2) }}
VAT (15%) R {{ number_format($vat, 2) }}
Shipping R {{ number_format($shipping, 2) }}
@if($credit > 0)
Credit Applied − R {{ number_format($credit, 2) }}
@endif
Total (incl. VAT) R {{ number_format($total, 2) }}
{{-- Timeline --}}
Timeline {{ $events->count() }} events
@php // Group consecutive same-type events (collapse repeated item_edit runs) $groupedEvents = []; $prevType = null; foreach ($events as $event) { $type = $event->event_type ?? 'note_added'; if ($prevType === $type && in_array($type, ['item_edit', 'shipping_change']) && !empty($groupedEvents)) { $groupedEvents[count($groupedEvents) - 1]['events'][] = $event; } else { $groupedEvents[] = ['type' => $type, 'events' => [$event]]; } $prevType = $type; } @endphp @if($events->isEmpty())

No events recorded yet.

@else
    @foreach($groupedEvents as $gIdx => $group) @php $isGroup = count($group['events']) > 1; $rep = $group['events'][0]; // representative event $type = $group['type']; $dot = $dotColors[$type] ?? '#9ca3af'; $label = $eventLabels[$type] ?? ucfirst(str_replace('_', ' ', $type)); $isLast = $gIdx === count($groupedEvents) - 1; $badgeBg = match($type) { 'status_change' => '#dbeafe', 'message_sent' => '#ede9fe', 'order_placed' => '#dcfce7', 'credit_issued' => '#dcfce7', 'item_edit' => '#fef3c7', 'shipping_change' => '#cffafe', 'private_note' => '#fef9c3', 'collection_requested' => '#dcfce7', default => '#f3f4f6', }; $badgeFg = match($type) { 'status_change' => '#1d4ed8', 'message_sent' => '#6d28d9', 'order_placed' => '#15803d', 'credit_issued' => '#15803d', 'item_edit' => '#b45309', 'shipping_change' => '#0e7490', 'private_note' => '#b45309', 'collection_requested' => '#15803d', default => '#6b7280', }; @endphp @if($isGroup) {{-- Collapsed group of consecutive same-type events --}}
  1. @if(!$isLast)
    @endif
    {{ $label }} {{ $group['events'][count($group['events'])-1]->created_at?->format('d M Y, H:i') }} – {{ $rep->created_at?->format('H:i') }}
    @foreach($group['events'] as $ev) @php $evWho = $ev->createdBy?->name; $evWhen = $ev->created_at?->format('d M Y, H:i') ?? '—'; $evMeta = $ev->metadata ?? []; @endphp
    {{ $ev->description }} {{ $evWhen }}
    @if(!empty($evMeta['changes']))
      @foreach($evMeta['changes'] as $ch)
    • @if(($ch['action'] ?? '') === 'removed') − Removed: {{ $ch['name'] }} @elseif(($ch['action'] ?? '') === 'added') + Added: {{ $ch['name'] }} ×{{ $ch['qty'] }} @if(!empty($ch['price'])) (R{{ number_format($ch['price'],2) }})@endif @else ~ {{ $ch['name'] }}: qty {{ $ch['qty_from'] }} → {{ $ch['qty_to'] }} @endif
    • @endforeach
    @endif @if($evWho)by {{ $evWho }}@endif
    @endforeach
  2. @else {{-- Single event --}} @php $ev = $rep; $meta = $ev->metadata ?? []; $who = $ev->createdBy?->name; $when = $ev->created_at?->format('d M Y, H:i') ?? '—'; @endphp
  3. @if(!$isLast)
    @endif
    {{ $label }} {{ $when }}

    {{ $ev->description }}

    @if(!empty($meta['changes']))
      @foreach($meta['changes'] as $ch)
    • @if(($ch['action'] ?? '') === 'removed') − Removed: {{ $ch['name'] }} @elseif(($ch['action'] ?? '') === 'added') + Added: {{ $ch['name'] }} ×{{ $ch['qty'] }} @if(!empty($ch['price'])) (R{{ number_format($ch['price'],2) }})@endif @else ~ {{ $ch['name'] }}: qty {{ $ch['qty_from'] }} → {{ $ch['qty_to'] }} @endif
    • @endforeach
    @endif @if($who)

    by {{ $who }}

    @endif
  4. @endif @endforeach
@endif
{{-- Messages thread --}}
Messages @php $msgCount = $record->messages->where('is_private_note', false)->count(); @endphp @if($msgCount > 0) {{ $msgCount }} @endif
@livewire('admin.order-chat', ['orderId' => $record->id], key('chat-'.$record->id))
{{-- /oc-left --}} {{-- ═══════════════════ RIGHT PANEL ══════════════════ --}}
{{-- Status stepper card --}}
Order Status
@if($terminal) @php $tm = $statusMeta[$record->status] ?? $statusMeta['cancelled']; @endphp
{{ $tm['label'] }}
@if($canEdit) @endif @else
    @foreach($statusFlow as $i => $step) @php $meta = $statusMeta[$step]; $isDone = $currentIdx !== false && $i < $currentIdx; $isCurrent= $record->status === $step; $isFuture = $currentIdx !== false ? $i > $currentIdx : true; $stateClass = $isDone ? 'done' : ($isCurrent ? 'current' : 'future'); $isLast = $i === count($statusFlow) - 1; @endphp
  1. @if($isDone) {{-- checkmark --}} @else @endif
    {{ $meta['label'] }}
    @if($isFuture && $canEdit) @elseif($isCurrent)
    ● Current
    @endif
  2. @endforeach
@endif
@if($canEdit && !$terminal)
Destructive Actions
@endif {{-- Order meta card --}}
Details
{{-- Contact & Delivery --}}
Contact & Delivery
{{ $record->shipping_name }}
@if($record->shipping_email)
{{ $record->shipping_email }}
@endif @if($record->shipping_phone)
{{ $record->shipping_phone }}
@endif
{{ $record->shipping_address }}
{{ $record->shipping_city }}, {{ $record->shipping_province }} {{ $record->shipping_postal_code }}
{{-- Carrier + Waybill --}} @if($record->shipping_carrier || $record->waybill_number)
Shipping
@if($record->shipping_carrier)
Carrier: {{ $record->shipping_carrier }} @if($record->shipping_service) · {{ $record->shipping_service }} @endif
@endif @if($record->waybill_number)
Waybill: {{ $record->waybill_number }}
@endif @if($record->cart_weight_kg)
Weight: {{ number_format($record->cart_weight_kg, 2) }} kg
@endif
@endif {{-- Order notes --}} @if($record->order_notes)
Customer Notes
{{ $record->order_notes }}
@endif {{-- Credits summary --}} @if($record->credits->count() > 0)
Credits / Refunds
@foreach($record->credits as $credit)
{{ $credit->reason }} R {{ number_format($credit->amount, 2) }}
@endforeach
@endif
{{-- /oc-right --}}
{{-- /oc-console --}}