@php $shipments = $payment->warehousePaymentShipments->map(function ($row) { return $row->shipment; })->filter()->values(); $itemLines = collect(); foreach ($shipments as $shipment) { $names = $shipment->items->pluck('item_name')->filter(); if ($names->isEmpty()) { $itemLines->push($shipment->item_name ?: 'Shipment'); } else { foreach ($names as $name) { $itemLines->push($name); } } } $paid = strtolower((string) $payment->maldivianpost_payment_status) === 'payment completed' || in_array(strtolower((string) $payment->payment_status), ['success', 'paid', 'completed', 'payment_processed'], true); $linkSent = strtolower((string) $payment->maldivianpost_link_status) === 'link sent to customer'; $statusLabel = $paid ? 'Customer Paid' : ($linkSent ? 'Payment Link Sent to Customer' : 'Pending From Customer'); $statusClass = $paid ? 'is-done' : 'is-pending'; $figures = $payment->shippingFigures(); $payable = $figures['shipping'] !== null ? $figures['shipping'] : $payment->amount; $shipmentCount = max($shipments->count(), 1); $itemCount = max($itemLines->count(), 1); $suiteAddress = $payment->relationLoaded('suiteAddress') ? $payment->suiteAddress : null; $suiteBadges = $suiteAddress ? $suiteAddress->deliveryBadges() : null; $photos = $shipments->map(function ($shipment) { $photo = $shipment->relationLoaded('photos') ? $shipment->photos->first(function ($row) { return trim((string) $row->photo_path) !== ''; }) : null; if (!$photo) { return null; } try { return \Illuminate\Support\Facades\Storage::disk('s3')->url($photo->photo_path); } catch (\Throwable $e) { return null; } })->filter()->values(); $kurNumber = trim((string) $payment->tracking_number); $popId = 'pfr-dl-'.$payment->id; @endphp