0 total for loyalty
This commit is contained in:
parent
9b31c32aba
commit
a7bd1b142a
@ -46,7 +46,8 @@ foreach ($items as $item) {
|
||||
$subtotal += $item['unit_price'] * $item['quantity'];
|
||||
}
|
||||
|
||||
$vat_or_discount = (float)$order['discount'];
|
||||
$vat_amount = (float)($order['vat'] ?? 0);
|
||||
$discount_amount = (float)($order['discount'] ?? 0);
|
||||
$company_settings = get_company_settings();
|
||||
$vat_rate = (float)($company_settings['vat_rate'] ?? 0);
|
||||
?>
|
||||
@ -191,16 +192,24 @@ $vat_rate = (float)($company_settings['vat_rate'] ?? 0);
|
||||
</tbody>
|
||||
<tfoot class="bg-light">
|
||||
<tr>
|
||||
<td colspan="3" class="text-end py-3 ps-4">
|
||||
<div class="text-muted mb-1">Subtotal</div>
|
||||
<div class="text-muted mb-1"><?= ($vat_or_discount >= 0) ? "VAT ($vat_rate%)" : 'Discount' ?></div>
|
||||
<td colspan="3" class="text-end py-3 ps-4 border-0">
|
||||
<div class="text-muted mb-1 small">Subtotal</div>
|
||||
<?php if ($vat_amount > 0): ?>
|
||||
<div class="text-muted mb-1 small">VAT</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($discount_amount > 0): ?>
|
||||
<div class="text-muted mb-1 small">Discount</div>
|
||||
<?php endif; ?>
|
||||
<h5 class="fw-bold mb-0 text-dark">Total Amount</h5>
|
||||
</td>
|
||||
<td class="text-end py-3 pe-4">
|
||||
<div class="mb-1"><?= format_currency($subtotal) ?></div>
|
||||
<div class="mb-1 <?= $vat_or_discount < 0 ? 'text-danger' : 'text-primary' ?>">
|
||||
<?= ($vat_or_discount > 0 ? '+' : '') . format_currency($vat_or_discount) ?>
|
||||
</div>
|
||||
<td class="text-end py-3 pe-4 border-0">
|
||||
<div class="mb-1 small"><?= format_currency($subtotal) ?></div>
|
||||
<?php if ($vat_amount > 0): ?>
|
||||
<div class="mb-1 small text-primary">+<?= format_currency($vat_amount) ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($discount_amount > 0): ?>
|
||||
<div class="mb-1 small text-danger">-<?= format_currency($discount_amount) ?></div>
|
||||
<?php endif; ?>
|
||||
<h5 class="fw-bold mb-0 text-primary"><?= format_currency($order['total_amount']) ?></h5>
|
||||
</td>
|
||||
</tr>
|
||||
@ -343,12 +352,13 @@ function printThermalReceipt() {
|
||||
];
|
||||
}, $items)) ?>,
|
||||
total: <?= (float)$order['total_amount'] ?>,
|
||||
vat: <?= (float)$order['discount'] ?>,
|
||||
vat: <?= (float)$order['vat'] ?>,
|
||||
discount: <?= (float)$order['discount'] ?>,
|
||||
orderType: '<?= $order['order_type'] ?>',
|
||||
tableNumber: '<?= $order['table_number'] ?>',
|
||||
date: '<?= date('M d, Y H:i', strtotime($order['created_at'])) ?>',
|
||||
paymentMethod: '<?= $order['payment_type_name'] ?? 'Unpaid' ?>',
|
||||
loyaltyRedeemed: <?= ($order['discount'] < 0) ? 'true' : 'false' ?>
|
||||
loyaltyRedeemed: <?= ($order['payment_type_name'] === 'Loyalty Redeem' || (float)$order['total_amount'] <= 0) ? 'true' : 'false' ?>
|
||||
};
|
||||
|
||||
const width = 400;
|
||||
@ -424,7 +434,6 @@ function printThermalReceipt() {
|
||||
|
||||
const loyaltyHtml = data.loyaltyRedeemed ? `<div style="color: #d63384; font-weight: bold; margin: 5px 0; text-align: center;">* Loyalty Reward Applied *</div>` : '';
|
||||
|
||||
const subtotal = data.total - data.vat;
|
||||
const logoHtml = COMPANY_SETTINGS.logo_url ? `<img src="${BASE_URL}${COMPANY_SETTINGS.logo_url}" style="max-height: 80px; max-width: 150px; margin-bottom: 10px;">` : '';
|
||||
const vatRate = COMPANY_SETTINGS.vat_rate || 0;
|
||||
|
||||
@ -519,12 +528,18 @@ function printThermalReceipt() {
|
||||
<table style="width: 100%">
|
||||
<tr>
|
||||
<td>Subtotal / ${tr['Subtotal']}</td>
|
||||
<td style="text-align: right">${formatCurrency(subtotal)}</td>
|
||||
<td style="text-align: right">${formatCurrency(data.items.reduce((acc, i) => acc + (i.price * i.quantity), 0))}</td>
|
||||
</tr>
|
||||
${data.vat > 0 ? `
|
||||
<tr>
|
||||
<td>${data.vat < 0 ? 'Discount' : 'VAT (' + vatRate + '%)'} / ${tr['VAT']}</td>
|
||||
<td style="text-align: right">${data.vat < 0 ? '-' : '+'}${formatCurrency(Math.abs(data.vat))}</td>
|
||||
</tr>
|
||||
<td>VAT (${vatRate}%) / ${tr['VAT']}</td>
|
||||
<td style="text-align: right">+${formatCurrency(data.vat)}</td>
|
||||
</tr>` : ''}
|
||||
${data.discount > 0 ? `
|
||||
<tr>
|
||||
<td>Discount / الخصم</td>
|
||||
<td style="text-align: right">-${formatCurrency(data.discount)}</td>
|
||||
</tr>` : ''}
|
||||
<tr style="font-weight: bold; font-size: 18px;">
|
||||
<td style="padding-top: 10px;">TOTAL / ${tr['TOTAL']}</td>
|
||||
<td style="text-align: right; padding-top: 10px;">${formatCurrency(data.total)}</td>
|
||||
@ -555,4 +570,4 @@ function printThermalReceipt() {
|
||||
win.document.write(html);
|
||||
win.document.close();
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
@ -169,9 +169,11 @@ try {
|
||||
|
||||
$total_loyalty_qty = 0;
|
||||
foreach ($processed_items as $item) {
|
||||
if ($item['is_loyalty']) {
|
||||
$total_loyalty_qty += $item['quantity'];
|
||||
// Safety check: Redemption orders should only contain loyalty items as per JS logic
|
||||
if (!$item['is_loyalty']) {
|
||||
throw new Exception("Loyalty redemption orders can only contain loyalty-eligible products. Please remove non-eligible items.");
|
||||
}
|
||||
$total_loyalty_qty += $item['quantity'];
|
||||
}
|
||||
|
||||
$possible_redemptions = floor($current_points / $points_threshold);
|
||||
@ -265,6 +267,12 @@ try {
|
||||
}
|
||||
|
||||
$final_total = max(0, $calculated_subtotal + $calculated_vat);
|
||||
|
||||
// Explicitly ensure loyalty redemption orders have 0 total
|
||||
if ($redeem_loyalty) {
|
||||
$final_total = 0;
|
||||
$calculated_vat = 0;
|
||||
}
|
||||
|
||||
// User/Payment info
|
||||
$user = get_logged_user();
|
||||
@ -420,4 +428,4 @@ You've earned *{points_earned} points* with this order.
|
||||
if ($pdo->inTransaction()) $pdo->rollBack();
|
||||
error_log("Order Error: " . $e->getMessage());
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
@ -697,8 +697,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
customer_id: selectedCustomerId ? selectedCustomerId.value : null,
|
||||
outlet_id: CURRENT_OUTLET ? CURRENT_OUTLET.id : 1,
|
||||
payment_type_id: paymentTypeId,
|
||||
total_amount: subtotal + totalVat,
|
||||
vat: totalVat,
|
||||
total_amount: isLoyaltyRedemption ? 0 : (subtotal + totalVat), // If loyalty redeemed, total is 0 for this transaction
|
||||
vat: isLoyaltyRedemption ? 0 : totalVat,
|
||||
items: itemsData,
|
||||
redeem_loyalty: isLoyaltyRedemption
|
||||
};
|
||||
@ -711,17 +711,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
name: item.name,
|
||||
variant_name: item.variant_name,
|
||||
quantity: item.quantity,
|
||||
price: item.price,
|
||||
vat_percent: item.vat_percent,
|
||||
vat_amount: (item.price * item.quantity) * (item.vat_percent / 100)
|
||||
price: isLoyaltyRedemption ? 0 : item.price, // If loyalty redeemed, price is 0 for this transaction
|
||||
vat_percent: isLoyaltyRedemption ? 0 : item.vat_percent,
|
||||
vat_amount: isLoyaltyRedemption ? 0 : ((item.price * item.quantity) * (item.vat_percent / 100))
|
||||
})),
|
||||
subtotal: subtotal,
|
||||
total: subtotal + totalVat,
|
||||
vat: totalVat,
|
||||
subtotal: isLoyaltyRedemption ? 0 : subtotal,
|
||||
total: isLoyaltyRedemption ? 0 : (subtotal + totalVat),
|
||||
vat: isLoyaltyRedemption ? 0 : totalVat,
|
||||
orderType: orderType,
|
||||
tableNumber: (orderType === 'dine-in') ? currentTableName : null,
|
||||
date: new Date().toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }),
|
||||
paymentMethod: paymentTypeName || 'Unpaid',
|
||||
paymentMethod: paymentTypeName || (isLoyaltyRedemption ? 'Loyalty Redeem' : 'Unpaid'),
|
||||
loyaltyRedeemed: isLoyaltyRedemption
|
||||
};
|
||||
|
||||
@ -890,4 +890,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const modal = new bootstrap.Modal(document.getElementById('qrRatingModal'));
|
||||
modal.show();
|
||||
};
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user