@if($isPointsEnabledForCustomerSite ?? false)
{{ __('loyalty::app.redeemLoyaltyPoints') }}
@if($customer && ($availableLoyaltyPoints ?? 0) > 0)
@php // Ensure order has taxes loaded for calculation if (!$order->relationLoaded('taxes')) { $order->load('taxes.tax'); } if (!$order->relationLoaded('items')) { $order->load('items'); } // Calculate preview total correctly: // 1. Start with subtotal (use order->sub_total to match order detail page calculation) // This ensures consistency with how taxes are calculated elsewhere $previewSubTotal = (float)($order->sub_total ?? 0); // 2. Apply regular discount (if any) $previewSubTotal -= (float)($order->discount_amount ?? 0); // 3. Apply loyalty discount (only to subtotal) $previewDiscount = (float)($loyaltyDiscountAmount ?? 0); $newSubTotal = $previewSubTotal - $previewDiscount; // 4. Calculate taxes - FIRST calculate current tax, THEN calculate tax after loyalty discount // Match the calculation method used in order detail page (line 438) $currentTaxAmount = 0.0; // Tax on current subtotal (before loyalty discount) $previewTaxAmount = 0.0; // Tax on new subtotal (after loyalty discount) $newTaxAmountAfterDiscount = 0.0; // Tax amount after loyalty discount (for new total calculation) if ($order->tax_mode === 'order' && $order->taxes && $order->taxes->count() > 0) { // IMPORTANT: Don't round individual tax amounts, only round the final sum // Ensure we process ALL taxes (no deduplication) // Make sure taxes relationship is loaded if (!$order->relationLoaded('taxes')) { $order->load('taxes.tax'); } // Get the base for CURRENT tax calculation (subtotal - regular discount, BEFORE loyalty discount) // This matches the order detail page calculation: (tax_percent / 100) * (sub_total - discount_amount) $currentTaxBase = (float)($order->sub_total ?? 0) - (float)($order->discount_amount ?? 0); // Process ALL taxes - iterate through ALL order taxes without any filtering // Get all taxes directly from the relationship to ensure no filtering $allOrderTaxes = $order->taxes()->with('tax')->get(); foreach ($allOrderTaxes as $orderTax) { $tax = $orderTax->tax ?? null; if ($tax && isset($tax->tax_percent) && $tax->tax_percent > 0) { $taxPercent = (float)$tax->tax_percent; // Calculate CURRENT tax amount (on current subtotal before loyalty discount) // This is what the order currently has: 7.50 (3.75 + 3.75) $currentTax = ($taxPercent / 100.0) * (float)$currentTaxBase; $currentTaxAmount += $currentTax; // Calculate NEW tax amount (on new subtotal after loyalty discount) // This is what the tax will be after loyalty discount is applied $newTax = ($taxPercent / 100.0) * (float)$newSubTotal; $previewTaxAmount += $newTax; } } // Round ONLY the final sums to 2 decimal places for display $currentTaxAmount = round($currentTaxAmount, 2); $previewTaxAmount = round($previewTaxAmount, 2); // Store the new tax amount (after discount) for reference // Tax should be calculated on discounted subtotal (after loyalty discount) $newTaxAmountAfterDiscount = $previewTaxAmount; // For display in modal, show the NEW tax (after loyalty discount) // $previewTaxAmount already contains the correct tax calculated on newSubTotal } else { // Item-level taxes - sum from order items (already calculated with precision) $previewTaxAmount = (float)($order->items->sum('tax_amount') ?? 0); // For item-level taxes, tax amount doesn't change with subtotal discount (it's per item) // So the new tax amount is the same as current tax $newTaxAmountAfterDiscount = $previewTaxAmount; // Order doesn't have direct restaurant relationship, use $restaurant from component $isInclusive = ($restaurant->tax_inclusive ?? false); // For inclusive taxes, tax is already in item prices, so don't add again // For exclusive taxes, we'll add it below } // 5. Calculate charges on discounted subtotal (ensure float precision) $previewCharges = 0.0; if ($order->charges && $order->charges->count() > 0) { foreach ($order->charges as $chargeRelation) { if ($chargeRelation->charge) { $chargeAmount = $chargeRelation->charge->getAmount((float)$newSubTotal); $previewCharges += (float)$chargeAmount; } } // Round to 2 decimal places $previewCharges = round($previewCharges, 2); } // 6. Build new total: new subtotal + taxes (if exclusive) + charges + tip + delivery // Ensure all values are floats for proper calculation // Order doesn't have direct restaurant relationship, use $restaurant from component $isInclusive = ($restaurant->tax_inclusive ?? false); $newTotal = (float)$newSubTotal; // Use the NEW tax amount (after loyalty discount) for the new total // $newTaxAmountAfterDiscount is always set (either from order-level or item-level calculation) if (!$isInclusive && $order->tax_mode !== 'order') { // Add item-level exclusive taxes (use new tax amount after discount) $newTotal += (float)$newTaxAmountAfterDiscount; } elseif ($order->tax_mode === 'order') { // Add order-level taxes (always exclusive) - use new tax amount after discount $newTotal += (float)$newTaxAmountAfterDiscount; } $newTotal += (float)$previewCharges; $newTotal += (float)($order->tip_amount ?? 0); $newTotal += (float)($order->delivery_fee ?? 0); // Round final total to 2 decimal places $newTotal = round($newTotal, 2); // Current total for display $currentTotal = $order->total ?? 0; @endphp
@lang('modules.order.subTotal') {{ currency_format($previewSubTotal, $restaurant->currency_id) }}
@if(($order->discount_amount ?? 0) > 0)
@lang('modules.order.discount') - {{ currency_format($order->discount_amount, $restaurant->currency_id) }}
@endif
@lang('loyalty::app.loyaltyDiscount') - {{ currency_format($previewDiscount, $restaurant->currency_id) }}
@if($previewTaxAmount > 0)
@lang('modules.order.totalTax') {{ currency_format($previewTaxAmount, $restaurant->currency_id) }}
@endif @if($previewCharges > 0)
@lang('modules.order.extraCharges') {{ currency_format($previewCharges, $restaurant->currency_id) }}
@endif @if(($order->tip_amount ?? 0) > 0)
@lang('modules.order.tip') {{ currency_format($order->tip_amount, $restaurant->currency_id) }}
@endif @if(($order->delivery_fee ?? 0) > 0)
@lang('modules.delivery.deliveryFee') {{ currency_format($order->delivery_fee, $restaurant->currency_id) }}
@endif
@lang('modules.order.newTotal') {{ currency_format($newTotal, $restaurant->currency_id) }}

{{ $customer->name }} {{ __('loyalty::app.hasAvailablePoints') }}: {{ number_format($availableLoyaltyPoints) }} @lang('loyalty::app.points')

{{ __('loyalty::app.pointsValue') }}: {{ currency_format($loyaltyPointsValue, $restaurant->currency_id) }}

@if($maxLoyaltyDiscount > 0)

{{ __('loyalty::app.maxDiscountToday') }}: {{ currency_format($maxLoyaltyDiscount, $restaurant->currency_id) }}

@endif

@if($maxRedeemablePoints > 0) {{ __('Maximum applicable points based on order subtotal') }}: {{ number_format($maxRedeemablePoints) }} @lang('loyalty::app.points') @else {{ __('loyalty::app.maxPoints') }}: {{ number_format($availableLoyaltyPoints) }} @endif

@else

{{ __('loyalty::app.noPointsAvailable') }}

@endif
{{ __('app.cancel') }} {{ __('loyalty::app.redeem') }}
@endif @if($isStampsEnabledForCustomerSite ?? false)
{{ __('loyalty::app.redeemStamps') }}
@if($customer && !empty($customerStamps)) @php $redeemableStamps = collect($customerStamps)->filter(function ($stampData) { return $stampData['can_redeem'] ?? false; }); @endphp @if($redeemableStamps->count() > 0)

{{ __('loyalty::app.selectStampRuleToRedeem') }}

@foreach($redeemableStamps as $stampData) @php $rule = $stampData['rule']; $availableStamps = $stampData['available_stamps']; $stampsRequired = $stampData['stamps_required']; $menuItem = $rule->menuItem ?? null; $rewardMenuItem = $rule->rewardMenuItem ?? null; $isSelected = in_array($rule->id, $selectedStampRuleIds ?? []); @endphp

{{ $menuItem->item_name ?? __('loyalty::app.unknownItem') }}

@if($isSelected) @endif

{{ __('loyalty::app.stampsRequired') }}: {{ $stampsRequired }} | {{ __('loyalty::app.stampsEarned') }}: {{ $availableStamps }}

{{ __('loyalty::app.reward') }}: @if($rule->reward_type === 'free_item') {{ __('loyalty::app.freeItem') }}: {{ $rewardMenuItem->item_name ?? __('loyalty::app.unknownItem') }} @elseif($rule->reward_type === 'discount_percent') {{ $rule->reward_value }}% {{ __('loyalty::app.discount') }} @elseif($rule->reward_type === 'discount_amount') {{ currency_format($rule->reward_value, $restaurant->currency_id) }} {{ __('loyalty::app.discount') }} @endif
@endforeach
@else

{{ __('loyalty::app.noStampsAvailable') }}

@endif @else

{{ __('loyalty::app.noStampsAvailable') }}

@endif
{{ __('app.cancel') }} @if(!empty($selectedStampRuleIds) && count($selectedStampRuleIds) > 0) {{ __('loyalty::app.redeem') }} ({{ count($selectedStampRuleIds) }}) @else {{ __('loyalty::app.redeem') }} @endif
@endif