@php $rewardMethods = collect($paymentMethods)->filter(function($paymentMethod) { return (bool) ($paymentMethod->payments_is_discount ?? false); }); $rewardBalanceOf = function($paymentMethod) use ($customer_points_value, $customers_wallet, $customers_store_credit) { if ($paymentMethod->payments_slug == 'points') return $customer_points_value ?? 0; if ($paymentMethod->payments_slug == 'wallet') return $customers_wallet ?? 0; if ($paymentMethod->payments_slug == 'store_credit') return $customers_store_credit ?? 0; return null; }; $activeRewardPaymentOf = function($paymentMethod) use ($order) { if (!isset($order->orders_payments)) return null; foreach ($order->orders_payments as $order_payment) { if ($order_payment->orders_payments_slug == $paymentMethod->payments_slug && ($order_payment->orders_payments_status != 'pending' || in_array($order_payment->orders_payments_slug, ['cash','bank_transfer']))) { return $order_payment; } } return null; }; $totalRewardsBalance = $rewardMethods->sum(fn($m) => $rewardBalanceOf($m) ?? 0); $activeRewards = $rewardMethods->map(function($m) use ($activeRewardPaymentOf) { $payment = $activeRewardPaymentOf($m); return $payment ? ['method' => $m, 'payment' => $payment] : null; })->filter()->values(); $activeRewardIds = $activeRewards->pluck('payment.orders_payments_id')->values(); $activeRewardsTotal = $activeRewards->sum(fn($r) => $r['payment']->orders_payments_amount); $activeRewardNames = $activeRewards->pluck('method.payments_name')->values(); if ($activeRewardNames->count() <= 1) { $activeRewardNamesJoined = $activeRewardNames->first(); } else { $activeRewardNamesJoined = $activeRewardNames->slice(0, -1)->implode(', ') . ' ' . __('lang.and') . ' ' . $activeRewardNames->last(); } $pointsPer100Rate = ($customers_discount_points ?? 0) > 0 ? (($customer_points_value ?? 0) / $customers_discount_points) * 100 : 0; @endphp @if($rewardMethods->count() > 0) @push('css') @endpush
{{ __('lang.useMyRewards') }}
{{ __('lang.yourRewardsTotal', ['value'=> format_price($totalRewardsBalance,$account->accounts_number_decimal_digits)]) }}
@if(!empty($locked))
{{ __('lang.paymentLockedHint') }}
@endif
@foreach ($rewardMethods as $paymentMethod) @php $balanceValue = $rewardBalanceOf($paymentMethod); $activePayment = $activeRewardPaymentOf($paymentMethod); $canUse = $activePayment || $balanceValue === null || $balanceValue > 0; @endphp
{{ $paymentMethod->payments_name }}
@if($balanceValue !== null)
@if($paymentMethod->payments_slug == 'points') {{ __('lang.yourPointsRewardDetail', [ 'points' => (int)($customers_discount_points ?? 0), 'value' => format_price($balanceValue,$account->accounts_number_decimal_digits), 'rate' => format_price($pointsPer100Rate,$account->accounts_number_decimal_digits), ]) }} @else {{ __('lang.yourRewardBalance', ['value'=> format_price($balanceValue,$account->accounts_number_decimal_digits)]) }} @endif
@endif
@if(!empty($locked)) {{-- No order yet: show the switch but explain what is missing instead of using it --}}
@else
@endif
@endforeach
@if($activeRewards->count() > 0)
{{ __('lang.rewardsSavedUsing', [ 'value' => format_price($activeRewardsTotal,$account->accounts_number_decimal_digits), 'methods' => $activeRewardNamesJoined, ]) }}
@endif
@endif