@extends('admin.layout.app') @section('content')

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

Order: {{ $order->order_id ?? $order->id }}
@if (session('error'))
{{ session('error') }}
@endif @php // Ensure $response is decoded 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'] ?? []; // Parse manifest date/time if available (use Carbon if present) $manifestedDtRaw = $tracking['order_date_time']['manifest_date_time'] ?? null; $manifestedDt = null; try { if (!empty($manifestedDtRaw) && $manifestedDtRaw !== '0000-00-00' && trim($manifestedDtRaw) !== '') { $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; } // Progress mapping (1..4) $statusSteps = [ 'manifested' => 1, 'in transit' => 2, 'out for delivery' => 3, 'delivered' => 4, ]; // determine current step $curStep = 0; $currentStatus = strtolower($tracking['current_status'] ?? ''); foreach ($statusSteps as $k => $v) { if (strpos($currentStatus, $k) !== false) { $curStep = $v; break; } } // fallback using lastScan if ($curStep === 0 && !empty($lastScan['status'])) { $ls = strtolower($lastScan['status']); foreach ($statusSteps as $k => $v) { if (strpos($ls, $k) !== false) { $curStep = $v; break; } } } // if manifest datetime exists, consider step 1 completed if ($manifestedDt && $curStep < 1) { $curStep = max($curStep, 1); } $steps = [ 1 => 'Manifested', 2 => 'In Transit', 3 => 'Out for Delivery', 4 => 'Delivered', ]; // percent for horizontal fill (if you use it) $percent = $isCancelled ? 0 : ($curStep > 0 ? round((($curStep - 1) / (count($steps) - 1)) * 100) : 0); // dd($percent,$curStep,count($steps)); @endphp
{{-- SUMMARY CARD --}}
Shipment Summary
@if ($order->shipmentTracking?->tracking_url)

Tracking URL : {{ $order->shipmentTracking?->tracking_url }}

@endif {{-- Cancelled indicator --}} @if($isCancelled)
Shipment Cancelled
Marked cancelled via carrier/portal.
Cancelled
Cancel status: {{ $tracking['cancel_status'] ?? '—' }}
@endif
{{ $tracking['logistic'] ?? '—' }} {{ $tracking['current_status'] ?? 'Unknown' }}
AWB
{{ $tracking['awb_no'] ?? ($displayAwb ?? $awb) }}
@if (!empty($awbList) && count($awbList) > 1)
AWB List
{{ implode(', ', $awbList) }}
@endif
Order Type
{{ $tracking['order_type'] ?? '—' }}
Message
{{ $tracking['message'] ?? '—' }}
Last Updated
{{ $lastScan['status_date_time'] ?? ($lastScan['scan_date_time'] ?? '—') }}
@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
{{-- ORDER DETAILS --}}
Order Details
@php $od = $tracking['order_details'] ?? [] @endphp
Order #
{{ $od['order_number'] ?? '—' }}
Weight (g)
{{ $od['phy_weight'] ?? '—' }}
Net Payment
{{ $od['net_payment'] ?? '—' }}
Dimensions (L×W×H)
{{ $od['ship_length'] ?? '—' }} × {{ $od['ship_width'] ?? '—' }} × {{ $od['ship_height'] ?? '—' }}
{{-- CUSTOMER --}}
Customer
@php $c = $tracking['customer_details'] ?? [] @endphp

{{ $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'] ?? '—') }}

{{-- TIMELINE / SCANS --}}
Last status
{{-- Manifested banner (if manifest datetime exists) --}} @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'] ?? '') }}

{{ $lastScan['remark'] ?? '' }}

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

@else @if(!$manifestedDt)
No last scan info available.
@endif @endif
Scan History
@if (count($scanDetails))
    @foreach ($scanDetails as $s)
  • {{ $s['scan_date_time'] ?? ($s['status_date_time'] ?? '') }}
    {{ $s['status'] ?? '-' }}

    {{ $s['remark'] ?? '' }}

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

  • @endforeach
{{-- Also show table for precise view --}}
@foreach ($scanDetails as $s) @endforeach
Date / Time Status Location Remark
{{ $s['scan_date_time'] ?? ($s['status_date_time'] ?? '') }} {{ $s['status'] ?? '' }} ({{ $s['status_code'] ?? '' }}) {{ $s['scan_location'] ?? '' }} {{ $s['remark'] ?? '' }}
@else
No scan history available.
@endif
{{-- Progress / Steps (professional horizontal look) --}}
Progress
{{-- If cancelled, show cancelled state --}} @if($isCancelled)
Shipment Cancelled
Cancelled shipments do not show progress.
@endif {{-- Horizontal track --}}
@foreach($steps as $idx => $label) @php $isCompleted = $idx < $curStep; $isActive = $idx === $curStep; @endphp
@if($isCompleted) ✓ @elseif($isActive) ● @else {{ $idx }} @endif
{{ $label }}
{{-- show manifested date/time under manifested label --}} @if($idx === 1 && $manifestedDt)
{{ $manifestedDt->format('d M Y, h:i a') }}
@endif
@endforeach
{{-- Raw JSON (collapsible) --}}
Raw Response
{{ json_encode($resp, JSON_PRETTY_PRINT) }}
{{-- Small timeline CSS --}} @push('styles') @endpush @endsection