@extends('layouts.app') @section('title', 'My Shipments') @push('styles') @endpush @section('content')

My Shipments

@if(session('success')) @endif
@if($shipmentPayments->isEmpty())
No Shipment Payments Found

You have no shipment payments matching the selected filters.

@else
@foreach($shipmentPayments as $shipmentPayment) @php // Get all shipments from warehouse_payment_shipments table $allShipments = $shipmentPayment->warehousePaymentShipments->map(function($wps) { return $wps->shipment; })->filter()->unique('id')->values(); // If no shipments from warehouse_payment_shipments, fallback to direct shipment relationship if ($allShipments->isEmpty()) { $shipment = $shipmentPayment->shipment; if ($shipment) { $allShipments = collect([$shipment]); } } if ($allShipments->isEmpty()) continue; // Skip if no shipments found // Use first shipment for header display (suite number, etc.) $firstShipment = $allShipments->first(); // Get status from latest tracking status first, then warehouse_payment_shipments $latestTrackingStatus = $shipmentPayment->latestTrackingStatus; $warehousePaymentShipment = $shipmentPayment->warehousePaymentShipments->first(); // Prefer tracking status over warehouse status if ($latestTrackingStatus && $latestTrackingStatus->status) { $currentStatus = $latestTrackingStatus->status; } elseif ($warehousePaymentShipment && $warehousePaymentShipment->status) { $currentStatus = $warehousePaymentShipment->status; } else { $currentStatus = $firstShipment->status ?? 'pending'; } // Get payment link from payment_details field $paymentDetails = $shipmentPayment->payment_details ?? []; $paymentLink = $shipmentPayment->getHostedPaymentLink(); $canPayShipment = $shipmentPayment->hasPayableWarehouseSession(); // Get tracking number from shipment_payment table $trackingNumber = $shipmentPayment->tracking_number ?? null; $statusColors = [ 'item_arrived_at_warehouse' => '#3b82f6', 'item_reached_warehouse' => '#3b82f6', 'Payment Link Generated' => '#f59e0b', 'payment_link_generated' => '#f59e0b', 'payment_link_send' => '#f59e0b', 'payment_processed' => '#10b981', 'item_dispatched_from_warehouse' => '#06b6d4', 'item_shipped' => '#8b5cf6', 'shipped_from_warehouse' => '#8b5cf6', 'reached_destination_airport' => '#06b6d4', 'pending_customs_excise_duty' => '#f59e0b', 'reached_local_partner' => '#059669', 'item_reached' => '#059669', 'reached_final_destination' => '#10b981' ]; $borderColor = $statusColors[$currentStatus] ?? '#6366f1'; $statusLabels = [ 'item_arrived_at_warehouse' => 'Item Arrived at Warehouse', 'item_reached_warehouse' => 'Item Arrived at Warehouse', 'Payment Link Generated' => 'Payment Link Generated', 'payment_link_generated' => 'Payment Link Generated', 'payment_link_send' => 'Payment Link Send', 'payment_processed' => 'Payment Processed', 'item_dispatched_from_warehouse' => 'Item Dispatched from Warehouse', 'item_shipped' => 'Item Shipped', 'shipped_from_warehouse' => 'Item Shipped', 'reached_destination_airport' => 'Reached Destination Airport', 'pending_customs_excise_duty' => 'Pending Customs Excise Duty', 'reached_local_partner' => 'Reached Local Partner', 'item_reached' => 'Reached Local Partner', 'reached_final_destination' => 'Reached Final Destination' ]; $statusLabel = $statusLabels[$currentStatus] ?? ucfirst(str_replace('_', ' ', $currentStatus)); @endphp @php $detailsUrl = route('kuser.shipment-payments.details', encrypt($shipmentPayment->id)); $paidStatuses = ['success', 'completed', 'paid']; $shippingPaid = in_array($shipmentPayment->payment_status, $paidStatuses, true); $allAdditionalPayments = $shipmentPayment->additionalPayments; $pendingAdditionalPayment = $allAdditionalPayments->first(function ($payment) use ($paidStatuses) { return !in_array($payment->payment_status, $paidStatuses, true); }); $completedAdditionalPayment = $allAdditionalPayments->first(function ($payment) use ($paidStatuses) { return in_array($payment->payment_status, $paidStatuses, true); }); $additionalPaymentToShow = $pendingAdditionalPayment ?? $completedAdditionalPayment; $shouldShowAdditionalPayment = $shipmentPayment->additionalServices->count() > 0 || $shipmentPayment->additionalAmounts->count() > 0 || $allAdditionalPayments->count() > 0; $freightMethod = strtolower((string) $shipmentPayment->payment_method); $freightPathway = $freightMethod === 'pathway b' ? 'b' : ($freightMethod === 'pathway c' ? 'c' : ''); $additionalPaymentLink = null; if ($pendingAdditionalPayment) { $additionalPaymentDetails = $pendingAdditionalPayment->payment_details ?? []; $additionalPaymentLink = $additionalPaymentDetails['payment_link'] ?? $additionalPaymentDetails['razorpay_payment_link'] ?? $additionalPaymentDetails['hdfc_payment_link'] ?? null; } $shipmentLinkExpired = false; $shipmentLinkDetails = $shipmentPayment->getPaymentDetailsArray(); if (!empty($shipmentLinkDetails['link_expires_at'])) { try { $shipmentLinkExpired = \Carbon\Carbon::parse($shipmentLinkDetails['link_expires_at'], 'Asia/Kolkata') ->lte(\Carbon\Carbon::now('Asia/Kolkata')); } catch (\Exception $e) { $shipmentLinkExpired = false; } } $additionalLinkExpired = false; $additionalExpiryDetails = ($additionalPaymentToShow && is_array($additionalPaymentToShow->payment_details ?? null)) ? $additionalPaymentToShow->payment_details : []; if (!empty($additionalExpiryDetails['link_expires_at'])) { try { $additionalLinkExpired = \Carbon\Carbon::parse($additionalExpiryDetails['link_expires_at'], 'Asia/Kolkata') ->lte(\Carbon\Carbon::now('Asia/Kolkata')); } catch (\Exception $e) { $additionalLinkExpired = false; } } @endphp
Shipping Amount ₹{{ number_format($shipmentPayment->amount, 2) }} @if($shipmentPayment->payment_status === 'failed' || $shipmentPayment->payment_status === 'failure') (Failed) @elseif($shippingPaid) (paid) @endif @if($freightPathway === 'b' && !$shippingPaid) Maldives Post collects this payment outside CourierConnect.@if($shipmentPayment->maldivianpost_link_status) Link sent to customer.@endif @if($shipmentPayment->maldivianpost_payment_status) {{ $shipmentPayment->maldivianpost_payment_status }}.@endif @elseif($freightPathway === 'c' && !$shippingPaid) Cash / Bank Transfer @elseif($canPayShipment && !$shipmentLinkExpired && !$shippingPaid) @elseif($shipmentLinkExpired && !$shippingPaid) Expired @elseif(!$shippingPaid) Awaiting link @endif
@if(!in_array($freightPathway, ['b', 'c'], true))
@include('kuser.shipment-payments.partials.link-expiry-notice', ['payment' => $shipmentPayment, 'variant' => 'compact'])
@endif @if($shouldShowAdditionalPayment && $additionalPaymentToShow) @php $additionalPaid = in_array($additionalPaymentToShow->payment_status, $paidStatuses, true); @endphp
Additional Amount ₹{{ number_format($additionalPaymentToShow->amount ?? 0, 2) }} @if($additionalPaymentToShow->payment_status === 'failed' || $additionalPaymentToShow->payment_status === 'failure') (Failed) @elseif($additionalPaid) (Paid) @endif @if($additionalPaymentLink && !$additionalLinkExpired && !$additionalPaid) @elseif($additionalLinkExpired && !$additionalPaid) Expired @elseif(!$additionalPaid) Awaiting link @endif
@include('kuser.shipment-payments.partials.link-expiry-notice', ['payment' => $additionalPaymentToShow, 'variant' => 'compact'])
@endif
Details
@endforeach
@endif
@push('scripts') @endpush @include('kuser.partials.surface-styles') @endsection