@extends('layouts.app') @section('title', 'Assisted Purchase') @section('content') @include('wuser.partials.delivery-badge-styles')

Assisted Purchase

Purchases for the suites mapped to this warehouse

@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(); $storeGroups = $lines->groupBy(function ($line) { $store = trim((string) $line->store); return $store !== '' ? $store : 'Store'; }); $totalQty = (int) $lines->sum(function ($line) { return max(1, (int) ($line->quantity ?? 1)); }); $listMoney = $payment->selectedMoney(); @endphp
@forelse($storeGroups as $storeName => $storeLines) @php $storeIconPath = trim((string) optional($storeLines->first())->store_icon); if ($storeIconPath === '') { $storeIconPath = \App\Support\AssistedStoreIcon::match(optional($storeLines->first())->url)['path']; } $storeIconUrl = preg_match('#^https?://#i', $storeIconPath) ? $storeIconPath : asset($storeIconPath); @endphp
{{ $storeName }}
@foreach($storeLines as $line) @include('partials.assisted-product-photos', ['photos' => is_array($line->meta ?? null) ? ($line->meta['images'] ?? []) : [], 'photoSize' => 'small', 'photoLimit' => 1]) @endforeach
@empty Store @endforelse
Suite {{ $suiteNumber ?: 'N/A' }} @if($suiteBadges) @include('wuser.partials.delivery-badges', ['badges' => $suiteBadges, 'popId' => 'wap-dl-'.$payment->id, 'suiteLine' => $suiteNumber]) @endif @if($statusLabel) {{ $statusLabel }} @endif @if($methodLabel !== '') {{ $methodLabel }} @endif {{ $purchaseCount }} {{ $purchaseCount === 1 ? 'Purchase' : 'Purchases' }}
@forelse($lines as $line)
@if($purchaseCount > 1){{ $loop->iteration }}@endif {{ $line->title ?: 'Purchase' }} @if($line->url) @endif
@empty
Purchase
@endforelse
{{ $listMoney['total'] !== null ? $currencyMark.number_format($listMoney['total'], 2) : '—' }} Qty {{ $totalQty }}
@empty @endforelse
@endsection @push('scripts') @endpush