@extends($layout) @section('title', 'Pesanan Saya') @section('content')
@if (session('info')) @endif @if (session('success')) @endif @if (session('error')) @endif @if (request('info')) @endif

πŸ“¦ Pesanan Saya

@php // Jika datang dari API paginate: $list = isset($orders['data']) ? $orders['data'] : (is_array($orders) ? $orders : []); $meta = isset($orders['data']) ? [ 'current_page' => $orders['current_page'] ?? 1, 'last_page' => $orders['last_page'] ?? 1, 'total' => $orders['total'] ?? count($list), 'per_page' => $orders['per_page'] ?? 10, ] : null; // Helper: tentukan status display ringkas + kelas badge function compactOrderStatus(array $o): array { $method = strtolower($o['method'] ?? 'delivery'); $pay = strtolower($o['paymentStatus'] ?? 'waiting'); $proc = strtolower($o['statusProcess'] ?? 'waiting'); $pick = strtolower($o['pickup_status'] ?? 'waiting'); $ship = strtolower($o['statusKirim'] ?? 'waiting'); $resi = trim((string) ($o['nomor_resi'] ?? '')); // Default $label = 'Menunggu Pembayaran'; $badge = 'bg-warning text-dark'; if ($method === 'pickup') { // PICKUP if ($pay !== 'paid') { $label = 'Menunggu Pembayaran'; $badge = 'bg-warning text-dark'; } elseif ($pick === 'picked') { $label = 'Sudah Diambil'; $badge = 'bg-primary'; } elseif ($proc === 'processed') { $label = 'Siap Diambil'; $badge = 'bg-primary'; } else { $label = 'Menunggu Diproses'; $badge = 'bg-info text-dark'; } } else { // DELIVERY if ($pay !== 'paid') { $label = 'Menunggu Pembayaran'; $badge = 'bg-warning text-dark'; } elseif ($proc !== 'processed') { $label = 'Menunggu Diproses'; $badge = 'bg-info text-dark'; } elseif ($ship === 'processed' || ($resi !== '' && strtolower($resi) !== 'waiting')) { $label = 'Dalam Pengiriman'; $badge = 'bg-primary'; } else { $label = 'Menunggu Kurir'; $badge = 'bg-secondary'; } } return ['label' => $label, 'badge' => $badge]; } @endphp @if (empty($list))
Belum ada pesanan.
βž• Buat Pesanan @else
@foreach ($list as $o) @php $status = compactOrderStatus($o); $method = strtolower($o['method'] ?? 'delivery'); $hasResi = !empty($o['nomor_resi']) && strtolower($o['nomor_resi']) !== 'waiting'; $payStatus = strtolower($o['paymentStatus'] ?? 'waiting'); $createdAt = \Carbon\Carbon::parse($o['created_at']); $isWaitingDelivery = $method === 'delivery' && $payStatus === 'waiting' && $createdAt->gt(now('Asia/Jakarta')->subHour()); // hanya yg < 1 jam // final_image_path bisa berupa array (kalau API sudah decode) atau string serialized $itemsRaw = $o['final_image_path'] ?? null; $itemsAll = is_array($itemsRaw) ? $itemsRaw : (@unserialize($itemsRaw) ?: []); $thumbs = array_slice($itemsAll, 0, 5); $moreCount = max(0, count($itemsAll) - count($thumbs)); $paymentUrl = $isWaitingDelivery ? route('payment.status', $o['uoid']) : null; @endphp
@if ($isWaitingDelivery) @endif
Order #{{ $o['uoid'] }}
{{ \Carbon\Carbon::parse($o['created_at'])->timezone('Asia/Jakarta')->format('d M Y, H:i') }}
@if ($isWaitingDelivery)
Klik kartu ini untuk menyelesaikan pembayaran (delivery).
@endif @if ($method === 'pickup')
Pembayaran dilakukan di lokasi (on the spot).
@endif
{{ ucfirst($method) }}

Ringkasan
Subtotal Rp {{ number_format((int) ($o['sub_total'] ?? 0), 0, ',', '.') }}
@if ($o['discount_amount'] > 0)
Diskon - Rp {{ number_format((int) ($o['discount_amount'] ?? 0), 0, ',', '.') }}
@endif
Ongkir Rp {{ number_format((int) ($o['ongkir'] ?? 0), 0, ',', '.') }}
Total ({{ (int) ($o['qty'] ?? 0) }} item) Rp {{ number_format((int) ($o['total'] ?? 0), 0, ',', '.') }}
{{-- Thumbnail item --}} @if (!empty($thumbs))
Item
@foreach ($thumbs as $it) @php $img = $it['image_path'] ?? ''; $qty = (int) ($it['quantity'] ?? 1); $name = $it['sku_name'] ?? 'Item'; @endphp
{{ $name }} x{{ $qty }}
@endforeach @if ($moreCount > 0)
+{{ $moreCount }}
@endif
@endif
@if ($isWaitingDelivery) @endif
@endforeach
{{-- Pagination simple --}} @if ($meta && ($meta['last_page'] ?? 1) > 1)
Halaman {{ $meta['current_page'] }} dari {{ $meta['last_page'] }} β€’ Total {{ $meta['total'] }} pesanan
@php $prev = max(1, $meta['current_page'] - 1); $next = min($meta['last_page'], $meta['current_page'] + 1); @endphp ← Sebelumnya Berikutnya β†’
@endif @endif
@endsection @push('styles') @endpush @push('modals') @endpush @push('scripts') @endpush @push('scripts') {{-- Modal tracking --}} @endpush @push('scripts') @endpush @push('scripts') @endpush ob_start();