@extends('layouts.app')
@section('title', 'Assisted Purchase')
@section('content')
@include('wuser.partials.delivery-badge-styles')
@if(session('success'))
{{ session('success') }}
@endif
@if(session('error'))
{{ session('error') }}
@endif
@forelse(($payments ?? collect()) as $payment)
@php
$lines = $payment->items->map(function ($row) {
return $row->assistedPurchaseRequest;
})->filter()->values();
$pathway = strtolower((string) ($payment->pathway ?: ''));
$payStatus = strtolower((string) $payment->payment_status);
$isPaid = in_array($payStatus, ['success', 'completed'], true);
$isFailed = !$isPaid && $pathway === 'a' && in_array($payStatus, ['failed', 'cancelled', 'canceled'], true);
$bankRecorded = $pathway === 'c' && $payment->bank_transactionID;
if ($isFailed) {
$statusLabel = 'Failed';
$statusClass = 'is-fail';
} elseif ($bankRecorded && !$isPaid) {
$statusLabel = 'Recorded';
$statusClass = 'is-done';
} elseif ($isPaid) {
$statusLabel = 'Completed';
$statusClass = 'is-done';
} else {
$statusLabel = 'Pending';
$statusClass = 'is-pending';
}
$trackingStatus = optional($payment->tracking)->status ?: $payment->status;
if ($trackingStatus && !$isFailed) {
$statusLabel = $trackingStatus;
$statusClass = $trackingStatus === 'Customer Paid' ? 'is-done' : 'is-pending';
}
$pathwayNames = ['a' => 'Card Gateway', 'b' => 'Maldives Post Link', 'c' => 'Cash / Bank Transfer'];
$shortNames = ['a' => 'Card Gateway', 'b' => 'Maldives Post', 'c' => 'Cash / Bank'];
$methodLabel = isset($pathwayNames[$pathway]) ? 'Payment method - Pathway '.strtoupper($pathway).': '.$pathwayNames[$pathway] : '';
$suiteNumber = $payment->suite_number ?: optional($lines->first())->suite_number;
$suiteAddress = $payment->virtualAddress;
if (!$suiteAddress && $suiteNumber && isset($addressesBySuite)) {
$suiteAddress = $addressesBySuite->get($suiteNumber);
}
$suiteBadges = $suiteAddress ? $suiteAddress->deliveryBadges() : null;
$purchaseCount = max($lines->count(), 1);
$currencyCode = strtoupper((string) ($payment->currency ?: 'INR'));
$currencyMark = ['INR' => '₹', 'USD' => '$', 'MVR' => 'Rf'][$currencyCode] ?? $currencyCode;
$payableAmount = $payment->amount !== null ? (float) $payment->amount : null;
$payableUsd = ($payableAmount !== null && $currencyCode === 'INR' && $usdToInr > 0) ? $payableAmount / $usdToInr : null;
$stores = $lines->pluck('store')->map(function ($store) {
return trim((string) $store);
})->filter()->unique()->values();
@endphp
@if($suiteNumber || $suiteBadges)
Suite {{ $suiteNumber ?: 'N/A' }}
@if($suiteBadges)
@include('wuser.partials.delivery-badges', ['badges' => $suiteBadges, 'popId' => 'wap-dl-'.$payment->id, 'suiteLine' => $suiteNumber])
@endif
@endif
@foreach($stores as $storeName)
{{ $storeName }}
@endforeach
@if($statusLabel)
{{ $statusLabel }}
@endif
@if($payment->created_at)
{{ $payment->created_at->format('d M Y') }}
@endif
{{ $purchaseCount }} {{ $purchaseCount === 1 ? 'purchase' : 'purchases' }}
@if(isset($shortNames[$pathway]))
{{ $shortNames[$pathway] }}
@endif
@if($payment->currency)
{{ $currencyMark }}
@endif
@if($suiteNumber)
{{ $suiteNumber }}
@endif
@forelse($lines as $line)
-
{{ $loop->iteration }}
{{ $line->title }}
@if($line->url)
@endif
@empty
- 1Purchase
@endforelse
@if($methodLabel !== '')
{{ $methodLabel }}
@endif
@include('partials.assisted-purchase-money', ['payment' => $payment])
@empty
No assisted purchases are mapped to this warehouse.
@endforelse
@endsection
@push('scripts')
@endpush