@extends('layouts.app')
@section('title', 'Shipment History')
@push('styles')
@include('wuser.partials.delivery-badge-styles')
@endpush
@section('content')
@php
$details = $payment->getPaymentDetailsArray();
$paidMethod = strtolower((string) ($details['paid_via'] ?? $payment->payment_method ?? ''));
$paymentState = strtolower((string) $payment->payment_status);
$isPaid = in_array($paymentState, ['success', 'paid', 'completed', 'payment_processed'], true);
if (in_array($paidMethod, ['upi', 'cash'], true) && $isPaid) {
$payLabel = 'Paid · '.strtoupper($paidMethod);
} elseif ($isPaid) {
$payLabel = 'Paid';
} elseif ($paymentState === 'failed') {
$payLabel = 'Failed';
} else {
$payLabel = 'Pending';
}
$latest = $payment->latestTrackingStatus;
$statusLabel = $latest ? trim((string) ($latest->display_status ?: $latest->status)) : '';
$figures = $payment->shippingFigures();
$shippingRate = $payment->shipping_rate;
if ($shippingRate === null && $figures['notax'] !== null) {
$shippingRate = round((float) $figures['notax'] - (float) ($payment->additional_charges ?? 0), 2);
}
$methodLabel = $payment->paymentMethodLabel();
$suite = $payment->suiteAddress;
$mpNumbers = $payment->activeMmsTrackingMappings
->pluck('mms_tracking_number')
->map(function ($number) { return trim((string) $number); })
->filter()->unique()->values();
$photoGallery = [];
foreach ($shipments as $galleryShipment) {
foreach ($galleryShipment->photos as $galleryPhoto) {
$path = trim((string) $galleryPhoto->photo_path);
if ($path === '') {
continue;
}
try {
$photoGallery[] = \Illuminate\Support\Facades\Storage::disk('s3')->url($path);
} catch (\Throwable $e) {
}
}
}
$photoGallery = array_values(array_unique($photoGallery));
$lastStep = $timeline->last();
@endphp
Shipment history
{{ $payment->tracking_number ?: ('Payment #'.$payment->id) }}
Back to history
@if($suite)
@include('wuser.partials.delivery-badges', ['badges' => $suite->deliveryBadges(), 'inline' => true, 'suiteLine' => $payment->suite_number])
@endif
Payment
{{ $payment->tracking_number ?: ('#'.$payment->id) }}
{{ $payLabel }}
@if($statusLabel !== ''){{ $statusLabel }} @endif
@if($methodLabel !== ''){{ $methodLabel }} @endif
@foreach($mpNumbers as $mpNumber)
{{ $mpNumber }}
@endforeach
{{ optional($payment->kuser)->name ?: 'No customer' }}
Suite {{ $payment->suite_number ?: 'N/A' }}
{{ $shipments->count() }} {{ $shipments->count() === 1 ? 'shipment' : 'shipments' }}
@if($shippingRate !== null)Shipping rate ₹{{ number_format((float) $shippingRate, 2) }} @endif
Additional charge ₹{{ number_format((float) ($payment->additional_charges ?? 0), 2) }}
@if($figures['gst'] !== null)GST ₹{{ number_format((float) $figures['gst'], 2) }} @endif
@if($latest && $latest->updatedByLabel() !== '')Updated by {{ $latest->updatedByLabel() }} @endif
@include('wuser.payments.partials.link-dates', ['payment' => $payment, 'variant' => 'card'])
Total amount
₹{{ number_format((float) ($figures['shipping'] ?? $payment->amount), 2) }}
Shipments ({{ $shipments->count() }})
@forelse($shipments as $shipment)
@php
$itemLines = $shipment->items->map(function ($item) {
$name = trim((string) $item->item_name);
if ($name === '') {
return null;
}
$qty = (float) $item->unit_quantity;
if ($qty > 1) {
$qtyText = abs($qty - round($qty)) < 0.001 ? (string) (int) round($qty) : rtrim(rtrim(number_format($qty, 2, '.', ''), '0'), '.');
return $name.' ('.$qtyText.')';
}
return $name;
})->filter()->values();
if ($itemLines->isEmpty() && $shipment->item_name) {
$itemLines = collect([$shipment->item_name]);
}
$cargoLabel = $shipment->cargoTypeLabel();
if ($cargoLabel === 'N/A') {
$cargoLabel = '';
}
$isAssisted = $shipment->cargo_type === 'assisted';
@endphp
{{ $shipment->sender_name ?: 'Shipment' }}
{{ $shipment->tracking_number ?: 'N/A' }}
@if($shipment->customs_shipment_stream === 'csb_v')
CSB-V
@elseif($shipment->customs_shipment_stream === 'csb_iv')
CSB-IV
@endif
@if($cargoLabel !== '')
{{ $cargoLabel }}
@endif
{{ $itemLines->isNotEmpty() ? $itemLines->implode(', ') : 'No items recorded' }}
@if($shipment->weight)Weight {{ $shipment->weight }} @endif
Declared ₹{{ number_format((float) $shipment->declared_value_inr, 2) }}
@if($isAssisted && $methodLabel !== '')
Payment method {{ $methodLabel }}
@endif
@empty
No shipments are attached to this payment.
@endforelse
{{ count($photoGallery) }} {{ count($photoGallery) === 1 ? 'photo' : 'photos' }}
@if(count($photoGallery) > 0)
@foreach($photoGallery as $photoUrl)
@endforeach
@else
No photos
@endif
Status history
@if($timeline->isNotEmpty())
@foreach($timeline as $step)
{{ $step->display_status ?: ucfirst(str_replace('_', ' ', (string) $step->status)) }}
@if($step->description)
{{ $step->description }}
@endif
@if($step->status_date)
{{ $step->status_date->format('d M Y, h:i A') }} @endif
@if($step->updatedByLabel() !== '')
Updated by {{ $step->updatedByLabel() }} @endif
@endforeach
@else
No status history has been recorded yet.
@endif
@endsection