myVouchers = auth()->user()->vouchers() ->withPivot('quantity', 'created_at') ->orderBy('user_voucher.created_at', 'desc') ->get() ->map(function ($voucher) { // Status Logic $now = now(); $isActive = $voucher->start_date <= $now && ($voucher->end_date === null || $voucher->end_date >= $now); $isExpired = $voucher->end_date && $voucher->end_date < $now; $isUpcoming = $voucher->start_date > $now; $status = 'active'; if ($isExpired) { $status = 'expired'; } elseif ($isUpcoming) { $status = 'upcoming'; } // Discount Display Logic if ($voucher->type === VoucherType::PERCENTAGE) { $discountDisplay = "Diskon {$voucher->discount_amount}%"; if ($voucher->max_discount) { $discountDisplay .= ' (Max Rp'.formatCurrencyNumber($voucher->max_discount).')'; } } else { $discountDisplay = 'Potongan Rp'.formatCurrencyNumber($voucher->discount_amount); } // Date Display Logic $dateDisplay = formatDateLocalized($voucher->start_date); if ($voucher->end_date) { $dateDisplay .= ' - '.formatDateLocalized($voucher->end_date); } else { $dateDisplay .= ' - Tidak ada batas waktu'; } $voucher->claimed_at_display = formatDateTimeLocalized($voucher->pivot->created_at); $voucher->date_display = $dateDisplay; $voucher->min_purchase_display = $voucher->min_purchase ? 'Min. Belanja: Rp'.formatCurrencyNumber($voucher->min_purchase) : null; $voucher->discount_display = $discountDisplay; $voucher->status = $status; $voucher->quantity = $voucher->pivot->quantity; return $voucher; }) ->toArray(); } public function render(): View { return view('livewire.member.my-vouchers', [ 'pageTitle' => 'Voucher Saya', 'pageDescription' => 'Daftar voucher yang telah Anda klaim dan dapat digunakan ketika belanja di toko.', ]); } }