{{-- resources/views/user/tracking.blade.php --}} @extends('frontend.layouts.app') @section('content')

Tracking — AWB: {{ $displayAwb ?? $awb }}

Order: {{ $order->cart_id ?? $order->order_id }}
@if (session('error'))
{{ session('error') }}
@endif @php // decode response if needed if (is_string($response)) { $resp = json_decode($response, true); } else { $resp = $response ?? []; } $keyAwb = $displayAwb ?? $awb; $tracking = $resp['data'][$keyAwb] ?? $resp['data'][$awb] ?? ($tracking ?? []); $lastScan = $tracking['last_scan_details'] ?? null; $scanDetails = $tracking['scan_details'] ?? []; // order_date_time -> manifest_date_time $manifestedDtRaw = $tracking['order_date_time']['manifest_date_time'] ?? null; $manifestedDt = null; try { if (!empty($manifestedDtRaw) && $manifestedDtRaw !== '0000-00-00' && trim($manifestedDtRaw) !== '') { // Use Carbon if available (Laravel). Fallback to raw if parse fails. $manifestedDt = \Carbon\Carbon::parse($manifestedDtRaw); } } catch (\Throwable $e) { $manifestedDt = null; } // Cancellation detection $curStatusLower = strtolower($tracking['current_status'] ?? ''); $isCancelled = false; if (stripos($curStatusLower, 'cancel') !== false || !empty($tracking['cancel_status'])) { $isCancelled = true; } @endphp
{{-- LEFT: Summary --}}
Shipment Summary
@if($isCancelled)
Shipment Cancelled
This shipment has been marked cancelled.
Cancelled
Cancel status: {{ $tracking['cancel_status'] ?? '—' }} @if(!empty($tracking['current_status']))  •  Current status: {{ $tracking['current_status'] }} @endif
@endif @if ($order->shipment->status == 'success')

Tracking URL : {{ json_decode($order->shipment->response, true)['data'][1]['tracking_url'] }}

@endif

{{ $tracking['logistic'] ?? '—' }} @php $status = strtolower($tracking['current_status'] ?? ''); if (stripos($status, 'cancel') !== false || $isCancelled) { $statusClass = 'qun-badge--danger'; } elseif (strpos($status, 'delivered') !== false) { $statusClass = 'qun-badge--success'; } elseif (strpos($status, 'in transit') !== false || strpos($status, 'intransit') !== false) { $statusClass = 'qun-badge--primary'; } else { $statusClass = 'qun-badge--warning'; } @endphp {{ $tracking['current_status'] ?? 'Unknown' }}

AWB
{{ $tracking['awb_no'] ?? ($displayAwb ?? $awb) }}
Last Updated
{{ $lastScan['status_date_time'] ?? ($lastScan['scan_date_time'] ?? '—') }}
Message
{{ $tracking['message'] ?? '—' }}
@if(!empty($tracking['promise_delivery_date']) || !empty($tracking['expected_delivery_date']))
Promise Date
{{ $tracking['promise_delivery_date'] ?? $tracking['expected_delivery_date'] ?? '—' }}
@endif @if(!empty($tracking['cancel_status']))
Cancel Status
{{ $tracking['cancel_status'] }}
@endif
@if (!empty($tracking['customer_details'])) @php $c = $tracking['customer_details']; @endphp
Delivery To

{{ $c['customer_name'] ?? '—' }}

{{ $c['customer_address1'] ?? '' }} {{ $c['customer_address2'] ? ', ' . $c['customer_address2'] : '' }}
{{ $c['customer_city'] ?? '' }}, {{ $c['customer_state'] ?? '' }} - {{ $c['customer_pincode'] ?? '' }}

Mobile: {{ $c['customer_mobile'] ?? ($c['customer_phone'] ?? '—') }}

@endif {{-- Help CTA --}}

Need help?

If you think the tracking is incorrect or the delivery is delayed, contact our support.

{{-- RIGHT: Timeline / Details --}}
Latest Status
{{-- If a manifest date exists, show the manifested banner (done) --}} @if($manifestedDt)
✓ Manifested
Manifested on
Date: {{ $manifestedDt->format('d M Y') }}   •   Time: {{ $manifestedDt->format('h:i a') }}
@endif @if ($lastScan && !empty($lastScan['status']))

{{ $lastScan['status'] ?? '—' }}

{{ $lastScan['status_date_time'] ?? ($lastScan['scan_date_time'] ?? '') }}

@if (!empty($lastScan['remark']))

{{ $lastScan['remark'] }}

@endif

Location: {{ $lastScan['scan_location'] ?? '-' }}

@else {{-- If no lastScan but manifested exists, don't show empty box; show a subtle info if nothing else --}} @if(!$manifestedDt)
No status available yet for this shipment.
@endif @endif
Scan History
@if (count($scanDetails))
@foreach ($scanDetails as $s)
{{ $s['status'] ?? '-' }}
{{ $s['remark'] ?? '' }}
{{ $s['status_code'] ? "Code: {$s['status_code']}" : '' }}
@if(!empty($s['status_reason']))
Reason: {{ $s['status_reason'] }}
@endif
{{ $s['scan_date_time'] ?? ($s['status_date_time'] ?? '') }}
{{ $s['scan_location'] ?? '-' }}
@endforeach
@else
No scan history available yet.
@endif {{-- Progress bar logic --}} @php $statusSteps = [ 'manifested' => 1, 'in transit' => 2, 'out for delivery' => 3, 'delivered' => 4, ]; // determine curStep: prefer current_status mapping, then lastScan status, otherwise $curStep = 0; $curStatus = strtolower($tracking['current_status'] ?? ''); foreach ($statusSteps as $k => $v) { if (strpos($curStatus, $k) !== false) { $curStep = $v; break; } } if ($curStep === 0 && !empty($lastScan['status'])) { $ls = strtolower($lastScan['status']); foreach ($statusSteps as $k => $v) { if (strpos($ls, $k) !== false) { $curStep = $v; break; } } } // If there is a manifest datetime, consider step 1 completed if ($manifestedDt && $curStep < 1) { $curStep = max($curStep, 1); } $steps = [ 1 => 'Manifested', 2 => 'In Transit', 3 => 'Out for Delivery', 4 => 'Delivered', ]; // If cancelled, we visually disable progress if ($isCancelled) { $percent = 0; } else { $percent = $curStep > 0 ? round((($curStep - 1) / (count($steps) - 1)) * 100) : 0; } @endphp
@if($isCancelled)
@else
@endif
@if($isCancelled)
Cancelled
@else @foreach ($steps as $idx => $label) @php $isCompleted = $idx < $curStep; $isActive = $idx === $curStep; @endphp
@if($isCompleted) ✓ @elseif($isActive) ● @else {{ $idx }} @endif
{{-- If step is Manifested and we have a manifestedDt, show small date below label --}}
{{ $label }} @if($idx === 1 && $manifestedDt)
{{ $manifestedDt->format('d M Y, h:i a') }}
@endif
@endforeach @endif
{{-- Raw JSON (support/admin only) --}} @if ((auth()->check() && (auth()->user()->is_support ?? false)) || (auth()->user()->is_admin ?? false))
Raw Response (support)
{{ json_encode($response, JSON_PRETTY_PRINT) }}
@endif
@endsection