@extends('layouts.app')
@section('title', 'Update Shipment Status')
@push('styles')
@include('wuser.partials.delivery-badge-styles')
@endpush
@section('content')
@php
$receivedItemCount = $shipments->sum(function ($shipment) {
$count = $shipment->relationLoaded('items') ? $shipment->items->count() : $shipment->items()->count();
if ($count === 0 && $shipment->item_name) {
return 1;
}
return $count;
});
$paymentDetails = $shipmentPayment->getPaymentDetailsArray();
$paidMethod = strtolower((string) ($paymentDetails['paid_via'] ?? $shipmentPayment->payment_method ?? ''));
$isWalkIn = in_array($paidMethod, ['upi', 'cash'], true);
$paymentState = strtolower((string) $shipmentPayment->payment_status);
$isPaid = in_array($paymentState, ['success', 'paid', 'completed', 'payment_processed'], true);
$isFailed = $paymentState === 'failed';
if ($isWalkIn && $isPaid) {
$payClass = 'paid';
$payLabel = 'Paid · ' . strtoupper($paidMethod);
} elseif ($isWalkIn) {
$payClass = 'pending';
$payLabel = strtoupper($paidMethod);
} elseif ($isPaid) {
$payClass = 'paid';
$payLabel = 'Paid';
} elseif ($isFailed) {
$payClass = 'failed';
$payLabel = 'Failed';
} else {
$payClass = 'pending';
$payLabel = 'Pending';
}
@endphp
Consolidation & Freight
Tracking {{ $shipmentPayment->tracking_number }} · {{ $shipments->count() }} received {{ $shipments->count() === 1 ? 'shipment' : 'shipments' }} · {{ $receivedItemCount === 1 ? '1 item' : $receivedItemCount . ' items' }}
Back to List
@if(session('success'))
{{ session('success') }}
@endif
@if(session('error'))
{{ session('error') }}
@endif
@php
$statusSuite = optional($shipments->first())->virtualAddress;
$paymentFigures = $shipmentPayment->shippingFigures();
$flowCurrentCard = (!empty($trackingData['current_status']) && is_array($trackingData['current_status'])) ? $trackingData['current_status'] : null;
$mpNumbers = $shipmentPayment->activeMmsTrackingMappings
->pluck('mms_tracking_number')
->map(function ($number) {
return trim((string) $number);
})
->filter()
->unique()
->values();
$statusServices = $shipmentPayment->services()->orderBy('created_at', 'desc')->get()
->concat($shipmentPayment->additionalServices()->orderBy('created_at', 'desc')->get());
@endphp
@if($statusSuite)
@include('wuser.partials.delivery-badges', ['badges' => $statusSuite->deliveryBadges(), 'inline' => true, 'suiteLine' => optional($shipments->first())->suite_number])
@endif
Payment
{{ $shipmentPayment->tracking_number ?: ('#' . $shipmentPayment->id) }}
{{ $payLabel }}
@if(!empty($flowCurrentCard['display_status']))
{{ $flowCurrentCard['display_status'] }}
@endif
@foreach($mpNumbers as $mpNumber)
{{ $mpNumber }}
@endforeach
@if($shipmentPayment->paymentMethodLabel() !== '')
{{ $shipmentPayment->paymentMethodLabel() }}
@endif
{{ $shipmentPayment->kuser->name ?? 'N/A' }}
@if($paidMethod === 'upi' && !empty($paymentDetails['transaction_id'] ?? $shipmentPayment->provider_payment_id))
Txn {{ $paymentDetails['transaction_id'] ?? $shipmentPayment->provider_payment_id }}
@endif
@php
$viewShippingRate = $shipmentPayment->shipping_rate;
if ($viewShippingRate === null && $paymentFigures['notax'] !== null) {
$viewShippingRate = round((float) $paymentFigures['notax'] - (float) ($shipmentPayment->additional_charges ?? 0), 2);
}
@endphp
@if($viewShippingRate !== null)
Shipping rate ₹{{ number_format((float) $viewShippingRate, 2) }}
@endif
@if((float) ($shipmentPayment->additional_charges ?? 0) > 0)
Additional charge ₹{{ number_format((float) $shipmentPayment->additional_charges, 2) }}
@endif
@if($paymentFigures['gst'] !== null)
GST ₹{{ number_format((float) $paymentFigures['gst'], 2) }}
@endif
@include('wuser.payments.partials.link-dates', ['payment' => $shipmentPayment, 'variant' => 'card'])
Total amount
₹{{ number_format((float) ($paymentFigures['shipping'] ?? $shipmentPayment->amount), 2) }}
₹{{ number_format((float) $shipmentPayment->amount, 2) }} payable
Shipments ({{ $shipments->count() }})
@include('wuser.payments.partials.shipment-summary-cards', ['shipments' => $shipments])
@include('wuser.payments.partials.shipment-photo-rail', [
'photoShipments' => $shipments,
'galleryId' => 'statusPhoto',
'photoTitle' => $shipments->count().' shipment(s)',
])
@include('wuser.payments.partials.service-summary-card', ['serviceRows' => $statusServices, 'serviceTitle' => 'Additional services'])
@if(!empty($trackingData['error']))
{{ ($trackingData['error'] ?? '') === 'not_found' ? 'Tracking not found' : 'Tracking not available yet' }}
{{ $trackingData['message'] ?? '' }}
@elseif(!empty($trackingData['statuses']))
@foreach($trackingData['statuses'] as $status)
@php
$isCompleted = $status['is_completed'] ?? false;
$isActive = $status['is_active'] ?? false;
$iconClass = 'fas fa-' . ($status['icon'] ?? 'circle');
$markerClass = $isCompleted ? ($isActive ? 'active' : 'completed') : '';
$dateText = !empty($status['status_date']) ? \Carbon\Carbon::parse($status['status_date'])->format('d-m-Y H:i') : '';
$statusKey = strtoupper((string) ($status['status'] ?? ''));
$statusTitle = strtolower((string) ($status['display_status'] ?? ''));
$isMailItemGenerated = $statusKey === 'EMA' || strpos($statusTitle, 'mail item generated') !== false;
@endphp
{{ $status['display_status'] }}
{{ $status['description'] }}
@if(!empty($status['days_in_status']))
In {{ $status['display_status'] }} for {{ $status['days_in_status'] }} {{ (int) $status['days_in_status'] === 1 ? 'day' : 'days' }}
@endif
@if($dateText !== '')
{{ $dateText }} @endif
@if(!empty($status['time_zone_display_label']))
{{ $status['time_zone_display_label'] }} @endif
@if($isMailItemGenerated)
@include('partials.mms-tracking-number', ['mmsTrackingNumber' => $status['mms_tracking_number'] ?? ($trackingData['mms_tracking_number'] ?? ($mmsTrackingNumber ?? null))])
@endif
@endforeach
@else
No timeline data yet. It will appear once tracking history exists for this payment.
@endif
@php
$flowCurrent = null;
if (empty($trackingData['error'] ?? null) && isset($trackingData['current_status']) && is_array($trackingData['current_status'])) {
$flowCurrent = $trackingData['current_status'];
}
@endphp
@if($flowCurrent)
@php
$badgeColor = $flowCurrent['color'] ?? (($statusMapping[$flowCurrent['status'] ?? ''] ?? null)['color'] ?? 'grey');
$cardTz = $flowCurrent['time_zone_display_label'] ?? 'Indian Standard Time';
$cardDt = null;
if (!empty($flowCurrent['status_date'])) {
$cardDt = \Carbon\Carbon::parse($flowCurrent['status_date']);
}
@endphp
{{ $flowCurrent['display_status'] ?? 'N/A' }}
@if($mpNumbers->isNotEmpty())
@foreach($mpNumbers as $mpNumber)
{{ $mpNumber }}
@endforeach
@endif
Latest entry from tracking history
{{ $flowCurrent['description'] ?? '' }}
@if($cardDt)
Last updated: {{ $cardDt->format('d-m-Y H:i') }} ({{ $cardTz }})
@if(!empty($statusUpdatedBy))
Updated by:
@if(in_array($statusUpdatedBy, ['partner', 'mms'], true))
Maldivian Post
@elseif($statusUpdatedBy === 'wuser' && $latestTrackingStatusRow && $latestTrackingStatusRow->wuser)
{{ $latestTrackingStatusRow->wuser->name ?? 'Warehouse user' }}
@else
{{ ucfirst((string) $statusUpdatedBy) }}
@endif
@endif
@endif
@elseif(isset($latestTrackingStatusRow) && $latestTrackingStatusRow)
@php
$rowMap = $statusMapping[$latestTrackingStatusRow->status] ?? null;
$badgeColor = $rowMap['color'] ?? 'grey';
$fallbackTitle = $latestTrackingStatusRow->display_status ?: ($rowMap['display_status'] ?? $latestTrackingStatusRow->status);
$fallbackDesc = $latestTrackingStatusRow->description !== null && $latestTrackingStatusRow->description !== ''
? $latestTrackingStatusRow->description
: ($rowMap['description'] ?? '');
@endphp
{{ $fallbackTitle }}
@if($mpNumbers->isNotEmpty())
@foreach($mpNumbers as $mpNumber)
{{ $mpNumber }}
@endforeach
@endif
Latest entry from tracking history
{{ $fallbackDesc }}
@if($latestTrackingStatusRow->status_date)
@php $tzLbl = (($latestTrackingStatusRow->status_updated_type ?? '') === 'mms') ? 'Maldives Time' : 'Indian Standard Time'; @endphp
Last updated: {{ $latestTrackingStatusRow->status_date->format('d-m-Y H:i') }} ({{ $tzLbl }})
@if(!empty($statusUpdatedBy))
Updated by:
@if(in_array($statusUpdatedBy, ['partner', 'mms'], true))
Maldivian Post
@elseif($statusUpdatedBy === 'wuser' && $latestTrackingStatusRow->wuser)
{{ $latestTrackingStatusRow->wuser->name ?? 'Warehouse user' }}
@else
{{ ucfirst((string) $statusUpdatedBy) }}
@endif
@endif
@endif
@else
No tracking history yet. The timeline below will appear after the first status update.
@endif
@if(count($nextStatuses) > 0 && empty($showMpModeChoice))
@include('wuser.status-update.partials.dispatch-form')
@endif
@if(!empty($showMmsSync))
@if((string) ($shipmentPayment->mp_number_mode ?? '') === 'single')One Maldives Post number is used for this consolidated package. A number that already exists is not created again.@else Each shipment gets its own Maldives Post number. A shipment that already has a number is not created again.@endif
@endif
@if(!empty($mmsLabels))
@foreach($mmsLabels as $mmsLabel)
{{ $mmsLabel['shipment_tracking_number'] }}
@if($mmsLabel['mms_tracking_number'] !== '')
· {{ $mmsLabel['mms_tracking_number'] }}
@endif
@endforeach
@endif
@if(!empty($showMpModeChoice) && count($nextStatuses) > 0)
@php
$savedMpMode = old('mp_number_mode', $shipmentPayment->mp_number_mode ?: 'separate');
if (!in_array($savedMpMode, ['single', 'separate'], true)) {
$savedMpMode = 'separate';
}
@endphp
Choose one option. It is saved with this update and used when the MP number is created.
@include('wuser.status-update.partials.dispatch-form')
@endif