@foreach($paymentGroups as $detail)
@php
$payment = $detail['payment'];
$paymentDetails = $payment->getPaymentDetailsArray();
$paidMethod = strtolower((string) ($paymentDetails['paid_via'] ?? $payment->payment_method ?? ''));
$isWalkIn = in_array($paidMethod, ['upi', 'cash'], true);
$paymentState = strtolower((string) $payment->payment_status);
$isPaid = in_array($paymentState, ['success', 'paid', 'completed', 'payment_processed'], true);
$isFailed = $paymentState === 'failed';
if ($isWalkIn && $isPaid) {
$badgeClass = 'su-paid';
$badgeLabel = 'Paid · ' . strtoupper($paidMethod);
} elseif ($isWalkIn) {
$badgeClass = 'su-pending';
$badgeLabel = strtoupper($paidMethod);
} elseif ($isPaid) {
$badgeClass = 'su-paid';
$badgeLabel = 'Paid';
} elseif ($isFailed) {
$badgeClass = 'su-failed';
$badgeLabel = 'Failed';
} else {
$badgeClass = 'su-pending';
$badgeLabel = 'Pending';
}
$shipmentCount = (int) ($detail['shipment_count'] ?? 0);
$itemCount = (int) ($detail['item_count'] ?? 0);
$shipmentLabel = $shipmentCount === 1 ? '1 shipment' : $shipmentCount . ' shipments';
$itemLabel = $itemCount === 1 ? '1 item' : $itemCount . ' items';
$currentDisplayStatus = $detail['current_status'] ?? null;
if (in_array($currentDisplayStatus, ['Processed', 'Delivered'], true)) {
$shipmentBadgeClass = 'su-paid';
} elseif (in_array($currentDisplayStatus, ['In Transit', 'Out for Delivery'], true)) {
$shipmentBadgeClass = 'su-transit';
} elseif ($currentDisplayStatus) {
$shipmentBadgeClass = 'su-pending';
} else {
$shipmentBadgeClass = 'su-none';
}
$statusUpdatedBy = $detail['status_updated_by'] ?? null;
$partnerInfo = $detail['partner_info'] ?? null;
$wuserInfo = $detail['wuser_info'] ?? null;
$updatedAt = $detail['latest_status_date'] ?? $payment->paid_at;
if (is_string($updatedAt)) {
$updatedAt = \Carbon\Carbon::parse($updatedAt);
}
@endphp
@php
$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();
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').')';
if ($linkedShipment->relationLoaded('photos')) {
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()->values();
$popId = 'statPop'.$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);
$updatedText = $updatedAt ? $updatedAt->format('d M Y, h:i A') : 'N/A';
$statusSearch = strtolower(implode(' ', array_filter([
$payment->tracking_number,
$payment->suite_number,
optional($payment->kuser)->name,
$badgeLabel,
$currentDisplayStatus,
$shipmentLabel,
$itemLabel,
implode(' ', $shipBits),
$updatedText,
])));
@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) }}
{{ $badgeLabel }}
{{ $currentDisplayStatus ?: 'N/A' }}
{{ count($shipBits) ? implode(', ', $shipBits) : ($shipmentLabel.' · '.$itemLabel) }}
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($statusUpdatedBy)
Updated by
@if(in_array($statusUpdatedBy, ['partner', 'mms'], true))
Maldivian Post
@elseif($statusUpdatedBy === 'wuser' && $wuserInfo)
{{ $wuserInfo->name }}
@else
{{ ucfirst($statusUpdatedBy) }}
@endif
@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
View & Update
@endforeach