@forelse($payments as $payment)
@php
$popId = 'histPop'.$payment->id;
$suite = $payment->suiteAddress;
$deliveryBadges = ($suite && method_exists($suite, 'deliveryBadges')) ? $suite->deliveryBadges() : [];
$customerName = trim((string) ($deliveryBadges['name'] ?? ''));
if ($customerName === '' || $customerName === '—') {
$customerName = trim((string) optional($payment->kuser)->name);
}
$suiteText = trim((string) $payment->suite_number);
$latest = $payment->latestTrackingStatus;
$currentDisplayStatus = $latest ? trim((string) ($latest->display_status ?: $latest->status)) : '';
if (in_array($currentDisplayStatus, ['Processed', 'Delivered'], true)) {
$shipmentBadgeClass = 'is-paid';
} elseif (in_array($currentDisplayStatus, ['In Transit', 'Out for Delivery'], true)) {
$shipmentBadgeClass = 'is-port';
} elseif ($currentDisplayStatus !== '') {
$shipmentBadgeClass = 'is-wait';
} else {
$shipmentBadgeClass = 'is-wait';
$currentDisplayStatus = 'N/A';
}
$updatedBy = '';
if ($latest) {
$updatedType = (string) $latest->status_updated_type;
if ($updatedType === 'wuser') {
$updatedBy = 'Warehouse';
} elseif (in_array($updatedType, ['partner', 'mms'], true)) {
$updatedBy = 'Maldivian Post';
} elseif ($updatedType !== '') {
$updatedBy = ucfirst($updatedType);
}
}
$updatedAt = $latest ? $latest->status_date : $payment->paid_at;
if (is_string($updatedAt) && $updatedAt !== '') {
try { $updatedAt = \Carbon\Carbon::parse($updatedAt); } catch (\Throwable $e) { $updatedAt = null; }
}
$updatedText = $updatedAt ? $updatedAt->format('d M Y, h:i A') : 'N/A';
$paymentFigures = $payment->shippingFigures();
$listedShipment = $payment->warehousePaymentShipments->map->shipment->filter()->first();
$declaredInr = $listedShipment ? (float) $listedShipment->declared_value_inr : 0;
$declaredUsd = $listedShipment ? (float) $listedShipment->declared_value : 0;
$usdRate = ($declaredInr > 0 && $declaredUsd > 0) ? ($declaredInr / $declaredUsd) : 0;
$viewShippingRate = $payment->shipping_rate;
if ($viewShippingRate === null && $paymentFigures['notax'] !== null) {
$viewShippingRate = round((float) $paymentFigures['notax'] - (float) ($payment->additional_charges ?? 0), 2);
}
$shippingInr = $paymentFigures['shipping'];
$shippingUsd = ($shippingInr !== null && $usdRate > 0) ? ((float) $shippingInr / $usdRate) : null;
$shipBits = [];
$photoUrls = collect();
$senders = collect();
foreach ($payment->warehousePaymentShipments as $paymentShipment) {
$linkedShipment = $paymentShipment->shipment;
if (!$linkedShipment) {
continue;
}
$lineCount = $linkedShipment->items->count();
if ($lineCount === 0 && $linkedShipment->item_name) {
$lineCount = 1;
}
$shipBits[] = ($linkedShipment->tracking_number ?: 'N/A').' ('.$lineCount.' '.($lineCount === 1 ? 'item' : 'items').')';
$senderName = trim((string) $linkedShipment->sender_name);
if ($senderName !== '') {
$senders->push($senderName);
}
foreach ($linkedShipment->photos as $photo) {
$path = trim((string) $photo->photo_path);
if ($path === '') {
continue;
}
try {
$photoUrls->push(\Illuminate\Support\Facades\Storage::disk('s3')->url($path));
} catch (\Throwable $e) {
}
}
}
$photoUrls = $photoUrls->filter()->unique()->take(6)->values();
$senders = $senders->unique()->values();
$storeMarks = ($storeMarksByPayment ?? collect())->get($payment->id, collect());
$searchText = strtolower(implode(' ', array_filter([
$payment->tracking_number,
$payment->suite_number,
$customerName,
$currentDisplayStatus,
$updatedBy,
$updatedText,
implode(' ', $shipBits),
$senders->implode(' '),
$storeMarks->pluck('store')->implode(' '),
])));
@endphp
{{ $customerName !== '' ? $customerName : 'No customer' }}
Suite {{ $suiteText !== '' ? $suiteText : 'N/A' }}
@if($photoUrls->isNotEmpty())
@foreach($photoUrls as $photoUrl)
@endforeach
@endif
@include('wuser.partials.delivery-badges', ['badges' => $deliveryBadges, 'popId' => $popId, 'suiteLine' => $suiteText])
{{ $payment->tracking_number ?: ('#' . $payment->id) }}
@forelse($storeMarks as $storeMark)
{{ $storeMark['store'] }}
@empty
@foreach($senders as $senderName)
{{ $senderName }}
@endforeach
@endforelse
{{ $currentDisplayStatus }}
{{ count($shipBits) ? implode(', ', $shipBits) : 'No shipments' }}
Shipping rate {{ $viewShippingRate !== null ? '₹'.number_format((float) $viewShippingRate, 2) : '—' }}
Additional charge ₹{{ number_format((float) ($payment->additional_charges ?? 0), 2) }}
GST {{ $paymentFigures['gst'] !== null ? '₹'.number_format((float) $paymentFigures['gst'], 2) : '—' }}
@if($updatedBy !== '')
Updated by {{ $updatedBy }}
@endif
@include('wuser.payments.partials.link-dates', ['payment' => $payment, 'variant' => 'card'])
Shipping amount
{{ $shippingInr !== null ? '₹'.number_format((float) $shippingInr, 2) : '—' }}
@if($shippingUsd !== null)${{ number_format($shippingUsd, 2) }}@endif
@empty
No payments found
Shipment payments will appear here.
@endforelse