@extends('layouts.app') @section('title', 'Freight Charge Collection') @section('content') @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'; $nextAction = $paid ? null : ($linkSent ? 'payment_completed' : 'link_sent'); $nextLabel = $linkSent ? 'Customer Paid' : 'Payment Link Sent to Customer'; $figures = $payment->shippingFigures(); $shippingRate = $payment->shipping_rate; if ($shippingRate === null && $figures['notax'] !== null) { $shippingRate = round((float) $figures['notax'] - (float) ($payment->additional_charges ?? 0), 2); } $payable = $figures['shipping'] !== null ? $figures['shipping'] : $payment->amount; $collection = [ ['label' => 'Pending From Customer', 'state' => ($paid || $linkSent) ? 'done' : 'now'], ['label' => 'Payment Link Sent', 'state' => $paid ? 'done' : ($linkSent ? 'now' : 'wait')], ['label' => 'Customer Paid', 'state' => $paid ? 'done' : 'wait'], ]; $ranks = [ 'item_arrived_at_warehouse' => 1, 'item_reached_warehouse' => 1, 'received' => 1, 'payment_link_send' => 2, 'payment_link_generated' => 2, 'payment_processed' => 2, 'processed' => 2, 'item_dispatched_from_warehouse' => 3, 'item_shipped' => 3, 'shipped_from_warehouse' => 3, 'reached_destination_airport' => 3, 'pending_customs_excise_duty' => 3, 'reached_local_partner' => 4, 'item_reached' => 4, 'reached_final_destination' => 4, ]; $maxRank = $shipments->isEmpty() ? -1 : 0; foreach ($shipments as $shipment) { $rank = $ranks[strtolower((string) $shipment->status)] ?? 0; if ($rank > $maxRank) { $maxRank = $rank; } } $shipmentLabels = ['Created', 'Received', 'Freight paid', 'Dispatched', 'Delivered']; $shipmentFlow = []; foreach ($shipmentLabels as $index => $label) { if ($maxRank < 0) { $state = $index === 0 ? 'now' : 'wait'; } elseif ($index < $maxRank || ($index === 4 && $maxRank === 4)) { $state = 'done'; } elseif ($index === $maxRank) { $state = 'now'; } else { $state = 'wait'; } $shipmentFlow[] = ['label' => $label, 'state' => $state]; } @endphp
{{ optional($payment->kuser)->name ?: 'Customer' }}
@if($payment->tracking_number){{ $payment->tracking_number }}
@endif{{ $payment->tracking_number }}
@endif