@lang('modules.order.subTotal')
@php
// Display stamp discount
$displayStampDiscountAmount = (float)($order->stamp_discount_amount ?? 0);
if ($displayStampDiscountAmount == 0) {
$displayStampDiscountAmount = (float)($stampDiscountAmount ?? 0);
}
// Check if there are free items from stamp redemption
$hasFreeStampItems = $order->items()->where('is_free_item_from_stamp', true)->exists();
@endphp
@if($displayStampDiscountAmount > 0 || $hasFreeStampItems)
@lang('app.stampDiscount')
@if($displayStampDiscountAmount > 0)
(-{{ currency_format($displayStampDiscountAmount, $restaurant->currency_id) }})
@elseif($hasFreeStampItems)
(@lang('app.freeItem'))
@endif
@endif
@php
// Get sub_total directly from order (already refreshed in mount)
// Use getOriginal to get database value if order was modified
$displaySubTotal = (float)($order->getOriginal('sub_total') ?? $order->sub_total ?? 0);
@endphp
{{ currency_format($displaySubTotal, $restaurant->currency_id) }}
{{-- @if(function_exists('module_enabled') && module_enabled('Loyalty')) --}}
@php
// Always prioritize order data from database
$displayLoyaltyPointsRedeemed = (float)($order->loyalty_points_redeemed ?? 0);
$displayLoyaltyDiscountAmount = (float)($order->loyalty_discount_amount ?? 0);
// Fallback to component variables if order values are 0
if ($displayLoyaltyPointsRedeemed == 0) {
$displayLoyaltyPointsRedeemed = (float)($loyaltyPointsRedeemed ?? 0);
}
if ($displayLoyaltyDiscountAmount == 0) {
$displayLoyaltyDiscountAmount = (float)($loyaltyDiscountAmount ?? 0);
}
@endphp
@if($displayLoyaltyPointsRedeemed > 0 && $displayLoyaltyDiscountAmount > 0)
@lang('app.loyaltyDiscount')
@if($displayLoyaltyPointsRedeemed > 0)
({{ number_format($displayLoyaltyPointsRedeemed, 0) }} @lang('app.points'))
@endif
-{{ currency_format($displayLoyaltyDiscountAmount, $restaurant->currency_id) }}
@endif
{{-- @endif --}}
@php
// Use order data if component variables are not set (for discount check)
$checkLoyaltyPointsRedeemed = $loyaltyPointsRedeemed ?? $order->loyalty_points_redeemed ?? 0;
@endphp
@if (!is_null($order->discount_amount) && $checkLoyaltyPointsRedeemed == 0)
@lang('modules.order.discount') @if ($order->discount_type == 'percent')
({{ rtrim(rtrim(number_format($order->discount_value, 2), '0'), '.') }}%)
@endif
-{{ currency_format($order->discount_amount, $restaurant->currency_id) }}
@endif
@php
$orderTypeSlug = optional($order->orderType)->slug ?? ($order->order_type ?? null);
// Step 1: Calculate net = subtotal - discount
$net = $order->sub_total - ($order->discount_amount ?? 0);
// Separate applicable and non-applicable charges
$applicableCharges = collect();
$nonApplicableCharges = collect();
foreach ($order->charges as $item) {
$charge = $item->charge;
if (!$charge) {
continue;
}
$allowedTypes = $charge->order_types ?? [];
// Handle string (JSON) format
if (is_string($allowedTypes)) {
$decoded = json_decode($allowedTypes, true);
$allowedTypes = json_last_error() === JSON_ERROR_NONE ? $decoded : [];
}
// If order_types is empty or not an array, charge doesn't apply
if (!is_array($allowedTypes) || empty($allowedTypes)) {
$nonApplicableCharges->push($item);
continue;
}
// Check if charge applies to this order type
if (in_array($orderTypeSlug, $allowedTypes, true)) {
$applicableCharges->push($item);
} else {
$nonApplicableCharges->push($item);
}
}
// Use saved tax_base from database (calculated during order save)
$taxBase = $order->tax_base ?? ($net + $applicableCharges->sum(fn($item) => $item->charge->getAmount($net)));
@endphp
@foreach ($applicableCharges as $item)
{{ $item->charge->charge_name }}
@if ($item->charge->charge_type == 'percent')
({{ $item->charge->charge_value }}%)
@endif
@php
// Calculate discounted subtotal for charges (after both regular and loyalty discounts)
$chargeBase = $order->sub_total
- ($order->discount_amount ?? 0)
- ($order->loyalty_discount_amount ?? 0);
@endphp
{{ currency_format($item->charge->getAmount($chargeBase), $restaurant->currency_id) }}
@endforeach
@if ($taxMode == 'order')
@foreach ($order->taxes as $item)
{{ $item->tax->tax_name }} ({{ $item->tax->tax_percent }}%)
@php
// Step 1: Calculate discounted subtotal (after both regular and loyalty discounts)
// Loyalty points are always removed from subtotal before calculating tax
$discountedSubtotal = $order->sub_total
- ($order->discount_amount ?? 0)
- ($order->loyalty_discount_amount ?? 0);
// Step 2: Calculate service charges on discounted subtotal
$serviceTotal = 0;
if ($order->charges && $order->charges->count() > 0) {
foreach ($order->charges as $chargeRelation) {
$charge = $chargeRelation->charge;
if ($charge) {
$chargeAmount = $charge->getAmount((float)$discountedSubtotal);
$serviceTotal += (float)$chargeAmount;
}
}
}
// Step 3: Calculate tax_base based on Tax Calculation Base setting
// Check if service charges should be included in tax base
$includeChargesInTaxBase = false;
if ($restaurant && isset($restaurant->include_charges_in_tax_base)) {
$includeChargesInTaxBase = (bool)$restaurant->include_charges_in_tax_base;
}
// Tax base = (subtotal - discounts) + service charges (if enabled)
$taxBase = $includeChargesInTaxBase
? ($discountedSubtotal + $serviceTotal)
: $discountedSubtotal;
$taxBase = max(0, (float)$taxBase);
// Step 4: Calculate tax on tax_base
$taxAmount = ($item->tax->tax_percent / 100) * $taxBase;
@endphp
{{ currency_format($taxAmount, $restaurant->currency_id) }}
@endforeach
@else
@if($order->total_tax_amount > 0)
@php
$taxTotals = [];
$totalTax = 0;
foreach ($order->items as $item) {
$qty = $item->quantity ?? 1;
$taxBreakdown = is_array($item->tax_breakup) ? $item->tax_breakup : (json_decode($item->tax_breakup, true) ?? []);
foreach ($taxBreakdown as $taxName => $taxInfo) {
if (!isset($taxTotals[$taxName])) {
$taxTotals[$taxName] = [
'percent' => $taxInfo['percent'] ?? 0,
'amount' => ($taxInfo['amount'] ?? 0) * $qty
];
} else {
$taxTotals[$taxName]['amount'] += ($taxInfo['amount'] ?? 0) * $qty;
}
}
$totalTax += $item->tax_amount ?? 0;
}
@endphp
@foreach ($taxTotals as $taxName => $taxInfo)
{{ $taxName }} ({{ $taxInfo['percent'] }}%)
{{ currency_format($taxInfo['amount'], $restaurant->currency_id) }}
@endforeach
@lang('modules.order.totalTax')
@lang($restaurant?->tax_inclusive ? 'modules.settings.taxInclusive' : 'modules.settings.taxExclusive')
{{ currency_format($totalTax, $restaurant->currency_id) }}
@endif
@endif
@if ($order->order_type === 'delivery' && !is_null($order->delivery_fee))
@lang('modules.delivery.deliveryFee')
@if($order->delivery_fee > 0)
{{ currency_format($order->delivery_fee, $restaurant->currency_id) }}
@else
@lang('modules.delivery.freeDelivery')
@endif
@endif
@include('livewire.shop.partials.order-loyalty-customer-ui')
@if ($canAddTip || $order->tip_amount > 0)
@lang('modules.order.tip')
@if($order->tip_amount > 0 && $order->tip_note)
"{{ $order->tip_note }}"
@endif
@if($order->tip_amount > 0 && !$canAddTip)
{{ currency_format($order->tip_amount, $restaurant->currency_id) }}
@endif
@if($canAddTip)
@if($order->tip_amount > 0)
{{ currency_format($order->tip_amount, $restaurant->currency_id) }}
@else
@lang('modules.order.addTip')
@endif
@endif
@endif
@lang('modules.order.total')
@php
$correctedTotal = $this->correctedTotal;
$originalTotal = $order->total;
$hasDifference = abs($correctedTotal - $originalTotal) > 0.01;
$hasNonApplicable = isset($nonApplicableCharges) && $nonApplicableCharges->isNotEmpty();
@endphp
{{ currency_format($correctedTotal, $restaurant->currency_id) }}