fix pug in pos
This commit is contained in:
parent
3245d00d29
commit
2a7531af42
@ -12,6 +12,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Global settings with fallbacks
|
||||||
|
const settings = (typeof COMPANY_SETTINGS !== 'undefined') ? COMPANY_SETTINGS : {
|
||||||
|
currency_symbol: '$',
|
||||||
|
currency_decimals: 2,
|
||||||
|
vat_rate: 0
|
||||||
|
};
|
||||||
|
|
||||||
let cart = [];
|
let cart = [];
|
||||||
let currentOrderId = null; // Track order ID for updates
|
let currentOrderId = null; // Track order ID for updates
|
||||||
const cartItemsContainer = document.getElementById('cart-items');
|
const cartItemsContainer = document.getElementById('cart-items');
|
||||||
@ -49,11 +56,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
let currentTableName = null;
|
let currentTableName = null;
|
||||||
const tableDisplay = document.getElementById('current-table-display');
|
const tableDisplay = document.getElementById('current-table-display');
|
||||||
const tableModalEl = document.getElementById('tableSelectionModal');
|
const tableModalEl = document.getElementById('tableSelectionModal');
|
||||||
const tableSelectionModal = new bootstrap.Modal(tableModalEl);
|
const tableSelectionModal = tableModalEl ? new bootstrap.Modal(tableModalEl) : null;
|
||||||
|
|
||||||
// Variant Management
|
// Variant Management
|
||||||
const variantModalEl = document.getElementById('variantSelectionModal');
|
const variantModalEl = document.getElementById('variantSelectionModal');
|
||||||
const variantSelectionModal = new bootstrap.Modal(variantModalEl);
|
const variantSelectionModal = variantModalEl ? new bootstrap.Modal(variantModalEl) : null;
|
||||||
let pendingProduct = null;
|
let pendingProduct = null;
|
||||||
|
|
||||||
// Customer Search Elements
|
// Customer Search Elements
|
||||||
@ -67,7 +74,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Payment Modal
|
// Payment Modal
|
||||||
const paymentModalEl = document.getElementById('paymentSelectionModal');
|
const paymentModalEl = document.getElementById('paymentSelectionModal');
|
||||||
const paymentSelectionModal = new bootstrap.Modal(paymentModalEl);
|
const paymentSelectionModal = paymentModalEl ? new bootstrap.Modal(paymentModalEl) : null;
|
||||||
const paymentMethodsContainer = document.getElementById('payment-methods-container');
|
const paymentMethodsContainer = document.getElementById('payment-methods-container');
|
||||||
|
|
||||||
// Product Search & Filter
|
// Product Search & Filter
|
||||||
@ -77,7 +84,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Helper for currency
|
// Helper for currency
|
||||||
function formatCurrency(amount) {
|
function formatCurrency(amount) {
|
||||||
const settings = (typeof COMPANY_SETTINGS !== 'undefined') ? COMPANY_SETTINGS : { currency_symbol: '$', currency_decimals: 2 };
|
|
||||||
const symbol = settings.currency_symbol || '$';
|
const symbol = settings.currency_symbol || '$';
|
||||||
const decimals = parseInt(settings.currency_decimals || 2);
|
const decimals = parseInt(settings.currency_decimals || 2);
|
||||||
return symbol + parseFloat(amount).toFixed(decimals);
|
return symbol + parseFloat(amount).toFixed(decimals);
|
||||||
@ -106,8 +112,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (btnElement) {
|
if (btnElement) {
|
||||||
document.querySelectorAll('.category-btn').forEach(btn => btn.classList.remove('active'));
|
document.querySelectorAll('.category-btn').forEach(btn => btn.classList.remove('active'));
|
||||||
btnElement.classList.add('active');
|
btnElement.classList.add('active');
|
||||||
} else if (typeof btnElement === 'undefined' && categoryId !== 'all') {
|
|
||||||
// Try to find the button corresponding to this category ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filterProducts();
|
filterProducts();
|
||||||
@ -194,10 +198,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populate Cart
|
// Populate Cart
|
||||||
cart = data.items; // Assuming format matches
|
cart = data.items;
|
||||||
|
|
||||||
// Note: In auto-VAT mode, we don't load data.order.discount into cartVatInput
|
|
||||||
// as it will be re-calculated based on subtotal.
|
|
||||||
|
|
||||||
updateCart();
|
updateCart();
|
||||||
if (recallModal) recallModal.hide();
|
if (recallModal) recallModal.hide();
|
||||||
@ -263,7 +264,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
customerSearchInput.disabled = true; // Lock input
|
customerSearchInput.disabled = true; // Lock input
|
||||||
customerResults.style.display = 'none';
|
customerResults.style.display = 'none';
|
||||||
clearCustomerBtn.classList.remove('d-none');
|
clearCustomerBtn.classList.remove('d-none');
|
||||||
// customerInfo.classList.remove('d-none');
|
|
||||||
|
|
||||||
// Loyalty Logic
|
// Loyalty Logic
|
||||||
if (loyaltySection && typeof LOYALTY_SETTINGS !== 'undefined' && LOYALTY_SETTINGS.is_enabled) {
|
if (loyaltySection && typeof LOYALTY_SETTINGS !== 'undefined' && LOYALTY_SETTINGS.is_enabled) {
|
||||||
@ -280,7 +280,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset redemption state when switching customer (though usually we clear first)
|
|
||||||
isLoyaltyRedemption = false;
|
isLoyaltyRedemption = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,9 +290,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
customerSearchInput.value = '';
|
customerSearchInput.value = '';
|
||||||
customerSearchInput.disabled = false;
|
customerSearchInput.disabled = false;
|
||||||
clearCustomerBtn.classList.add('d-none');
|
clearCustomerBtn.classList.add('d-none');
|
||||||
customerInfo.classList.add('d-none');
|
if (customerInfo) customerInfo.classList.add('d-none');
|
||||||
|
|
||||||
// Hide Loyalty
|
|
||||||
if (loyaltySection) loyaltySection.classList.add('d-none');
|
if (loyaltySection) loyaltySection.classList.add('d-none');
|
||||||
isLoyaltyRedemption = false;
|
isLoyaltyRedemption = false;
|
||||||
updateCart();
|
updateCart();
|
||||||
@ -312,7 +310,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- STRICT ONE ITEM RESTRICTION ---
|
|
||||||
if (cart.length > 1) {
|
if (cart.length > 1) {
|
||||||
showToast("Can only redeem a free meal with exactly one item in cart!", "warning");
|
showToast("Can only redeem a free meal with exactly one item in cart!", "warning");
|
||||||
return;
|
return;
|
||||||
@ -332,8 +329,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
isLoyaltyRedemption = true;
|
isLoyaltyRedemption = true;
|
||||||
updateCart();
|
updateCart();
|
||||||
|
|
||||||
// Directly process order with Loyalty payment type
|
|
||||||
processOrder(null, 'Loyalty Redeem');
|
processOrder(null, 'Loyalty Redeem');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -396,7 +391,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
const selected = checked.value;
|
const selected = checked.value;
|
||||||
if (selected === 'dine-in') {
|
if (selected === 'dine-in') {
|
||||||
if (!currentTableId) openTableSelectionModal();
|
if (!currentTableId && tableSelectionModal) openTableSelectionModal();
|
||||||
if (tableDisplay) tableDisplay.style.display = 'inline-block';
|
if (tableDisplay) tableDisplay.style.display = 'inline-block';
|
||||||
} else {
|
} else {
|
||||||
if (tableDisplay) tableDisplay.style.display = 'none';
|
if (tableDisplay) tableDisplay.style.display = 'none';
|
||||||
@ -408,7 +403,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function openTableSelectionModal() {
|
function openTableSelectionModal() {
|
||||||
|
if (!tableSelectionModal) return;
|
||||||
const container = document.getElementById('table-list-container');
|
const container = document.getElementById('table-list-container');
|
||||||
|
if (!container) return;
|
||||||
container.innerHTML = '<div class="text-center py-5"><div class="spinner-border text-primary" role="status"></div></div>';
|
container.innerHTML = '<div class="text-center py-5"><div class="spinner-border text-primary" role="status"></div></div>';
|
||||||
|
|
||||||
// Update Modal Title
|
// Update Modal Title
|
||||||
@ -436,6 +433,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
function renderTables(tables) {
|
function renderTables(tables) {
|
||||||
const container = document.getElementById('table-list-container');
|
const container = document.getElementById('table-list-container');
|
||||||
|
if (!container) return;
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
|
|
||||||
if (tables.length === 0) {
|
if (tables.length === 0) {
|
||||||
@ -473,7 +471,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
tableDisplay.innerHTML = `Table: ${name}`;
|
tableDisplay.innerHTML = `Table: ${name}`;
|
||||||
tableDisplay.style.display = 'block';
|
tableDisplay.style.display = 'block';
|
||||||
}
|
}
|
||||||
tableSelectionModal.hide();
|
if (tableSelectionModal) tableSelectionModal.hide();
|
||||||
showToast(`Selected Table: ${name}`, 'success');
|
showToast(`Selected Table: ${name}`, 'success');
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -502,19 +500,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function openVariantModal(product) {
|
function openVariantModal(product) {
|
||||||
|
if (!variantSelectionModal) return;
|
||||||
pendingProduct = product;
|
pendingProduct = product;
|
||||||
const variants = PRODUCT_VARIANTS[product.id] || [];
|
const variants = (typeof PRODUCT_VARIANTS !== 'undefined') ? (PRODUCT_VARIANTS[product.id] || []) : [];
|
||||||
const list = document.getElementById('variant-list');
|
const list = document.getElementById('variant-list');
|
||||||
const title = document.getElementById('variantModalTitle');
|
const title = document.getElementById('variantModalTitle');
|
||||||
title.textContent = `Select option for ${product.name}`;
|
if (title) title.textContent = `Select option for ${product.name}`;
|
||||||
|
|
||||||
|
if (!list) return;
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
|
|
||||||
variants.forEach(v => {
|
variants.forEach(v => {
|
||||||
const btn = document.createElement('button');
|
const btn = document.createElement('button');
|
||||||
btn.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center';
|
btn.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center';
|
||||||
const adj = parseFloat(v.price_adjustment);
|
const adj = parseFloat(v.price_adjustment);
|
||||||
const sign = adj > 0 ? '+' : '';
|
|
||||||
const finalPrice = product.base_price + adj;
|
const finalPrice = product.base_price + adj;
|
||||||
|
|
||||||
btn.innerHTML = `
|
btn.innerHTML = `
|
||||||
@ -562,69 +561,71 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cart.length === 0) {
|
if (cart.length === 0) {
|
||||||
cartItemsContainer.innerHTML = `
|
if (cartItemsContainer) {
|
||||||
<div class="text-center text-muted mt-5">
|
cartItemsContainer.innerHTML = `
|
||||||
<i class="bi bi-basket3 fs-1 text-light"></i>
|
<div class="text-center text-muted mt-5">
|
||||||
<p class="mt-2">Cart is empty</p>
|
<i class="bi bi-basket3 fs-1 text-light"></i>
|
||||||
</div>`;
|
<p class="mt-2">Cart is empty</p>
|
||||||
cartSubtotal.innerText = formatCurrency(0);
|
</div>`;
|
||||||
cartVatInput.value = 0;
|
}
|
||||||
cartTotalPrice.innerText = formatCurrency(0);
|
if (cartSubtotal) cartSubtotal.innerText = formatCurrency(0);
|
||||||
|
if (cartVatInput) cartVatInput.value = 0;
|
||||||
|
if (cartTotalPrice) cartTotalPrice.innerText = formatCurrency(0);
|
||||||
if (quickOrderBtn) quickOrderBtn.disabled = true;
|
if (quickOrderBtn) quickOrderBtn.disabled = true;
|
||||||
if (placeOrderBtn) placeOrderBtn.disabled = true;
|
if (placeOrderBtn) placeOrderBtn.disabled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cartItemsContainer.innerHTML = '';
|
if (cartItemsContainer) cartItemsContainer.innerHTML = '';
|
||||||
let subtotal = 0;
|
let subtotal = 0;
|
||||||
|
|
||||||
cart.forEach((item, index) => {
|
cart.forEach((item, index) => {
|
||||||
const itemTotal = item.price * item.quantity;
|
const itemTotal = item.price * item.quantity;
|
||||||
subtotal += itemTotal;
|
subtotal += itemTotal;
|
||||||
|
|
||||||
const row = document.createElement('div');
|
if (cartItemsContainer) {
|
||||||
row.className = 'd-flex justify-content-between align-items-center mb-3 border-bottom pb-2';
|
const row = document.createElement('div');
|
||||||
|
row.className = 'd-flex justify-content-between align-items-center mb-3 border-bottom pb-2';
|
||||||
|
|
||||||
const variantLabel = item.variant_name ? `<span class="badge bg-light text-dark border ms-1">${item.variant_name}</span>` : '';
|
const variantLabel = item.variant_name ? `<span class="badge bg-light text-dark border ms-1">${item.variant_name}</span>` : '';
|
||||||
const arabicNameDisplay = item.name_ar ? `<div class="text-primary small fw-semibold" dir="rtl" style="font-size: 0.75rem;">${item.name_ar}</div>` : '';
|
const arabicNameDisplay = item.name_ar ? `<div class="text-primary small fw-semibold" dir="rtl" style="font-size: 0.75rem;">${item.name_ar}</div>` : '';
|
||||||
|
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<div class="flex-grow-1 me-2">
|
<div class="flex-grow-1 me-2">
|
||||||
<div class="fw-bold text-truncate" style="max-width: 140px;">${item.name}</div>
|
<div class="fw-bold text-truncate" style="max-width: 140px;">${item.name}</div>
|
||||||
${arabicNameDisplay}
|
${arabicNameDisplay}
|
||||||
<div class="small text-muted">${formatCurrency(item.price)} ${variantLabel}</div>
|
<div class="small text-muted">${formatCurrency(item.price)} ${variantLabel}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex align-items-center bg-light rounded px-1">
|
<div class="d-flex align-items-center bg-light rounded px-1">
|
||||||
<button class="btn btn-sm text-secondary p-0" style="width: 24px;" onclick="changeQuantity(${index}, -1)"><i class="bi bi-dash"></i></button>
|
<button class="btn btn-sm text-secondary p-0" style="width: 24px;" onclick="changeQuantity(${index}, -1)"><i class="bi bi-dash"></i></button>
|
||||||
<span class="mx-1 fw-bold small" style="min-width: 20px; text-align: center;">${item.quantity}</span>
|
<span class="mx-1 fw-bold small" style="min-width: 20px; text-align: center;">${item.quantity}</span>
|
||||||
<button class="btn btn-sm text-secondary p-0" style="width: 24px;" onclick="changeQuantity(${index}, 1)"><i class="bi bi-plus"></i></button>
|
<button class="btn btn-sm text-secondary p-0" style="width: 24px;" onclick="changeQuantity(${index}, 1)"><i class="bi bi-plus"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-end ms-3" style="min-width: 60px;">
|
<div class="text-end ms-3" style="min-width: 60px;">
|
||||||
<div class="fw-bold">${formatCurrency(itemTotal)}</div>
|
<div class="fw-bold">${formatCurrency(itemTotal)}</div>
|
||||||
<button class="btn btn-sm text-danger p-0 mt-1" style="font-size: 0.8rem;" onclick="removeFromCart(${index})">Remove</button>
|
<button class="btn btn-sm text-danger p-0 mt-1" style="font-size: 0.8rem;" onclick="removeFromCart(${index})">Remove</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
cartItemsContainer.appendChild(row);
|
cartItemsContainer.appendChild(row);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cartSubtotal.innerText = formatCurrency(subtotal);
|
if (cartSubtotal) cartSubtotal.innerText = formatCurrency(subtotal);
|
||||||
|
|
||||||
let vat = 0;
|
let vat = 0;
|
||||||
if (isLoyaltyRedemption) {
|
if (isLoyaltyRedemption) {
|
||||||
// Internal trick: send negative VAT to represent discount for loyalty
|
|
||||||
vat = -subtotal;
|
vat = -subtotal;
|
||||||
} else {
|
} else {
|
||||||
// Automatic VAT calculation from system settings
|
const vatRate = parseFloat(settings.vat_rate) || 0;
|
||||||
const vatRate = parseFloat(COMPANY_SETTINGS.vat_rate) || 0;
|
|
||||||
vat = subtotal * (vatRate / 100);
|
vat = subtotal * (vatRate / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
cartVatInput.value = vat.toFixed(2);
|
if (cartVatInput) cartVatInput.value = vat.toFixed(2);
|
||||||
|
|
||||||
let total = subtotal + vat;
|
let total = subtotal + vat;
|
||||||
if (total < 0) total = 0;
|
if (total < 0) total = 0;
|
||||||
|
|
||||||
cartTotalPrice.innerText = formatCurrency(total);
|
if (cartTotalPrice) cartTotalPrice.innerText = formatCurrency(total);
|
||||||
if (quickOrderBtn) quickOrderBtn.disabled = false;
|
if (quickOrderBtn) quickOrderBtn.disabled = false;
|
||||||
if (placeOrderBtn) placeOrderBtn.disabled = false;
|
if (placeOrderBtn) placeOrderBtn.disabled = false;
|
||||||
}
|
}
|
||||||
@ -647,7 +648,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
cart = [];
|
cart = [];
|
||||||
cartVatInput.value = 0;
|
if (cartVatInput) cartVatInput.value = 0;
|
||||||
currentOrderId = null;
|
currentOrderId = null;
|
||||||
isLoyaltyRedemption = false;
|
isLoyaltyRedemption = false;
|
||||||
updateCart();
|
updateCart();
|
||||||
@ -707,7 +708,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
if (quickOrderBtn) {
|
if (quickOrderBtn) {
|
||||||
quickOrderBtn.addEventListener('click', () => {
|
quickOrderBtn.addEventListener('click', () => {
|
||||||
if (validateOrder()) {
|
if (validateOrder() && paymentSelectionModal) {
|
||||||
paymentSelectionModal.show();
|
paymentSelectionModal.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -738,19 +739,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const orderTypeInput = document.querySelector('input[name="order_type"]:checked');
|
const orderTypeInput = document.querySelector('input[name="order_type"]:checked');
|
||||||
const orderType = orderTypeInput ? orderTypeInput.value : 'takeaway';
|
const orderType = orderTypeInput ? orderTypeInput.value : 'takeaway';
|
||||||
const subtotal = cart.reduce((acc, item) => acc + (item.price * item.quantity), 0);
|
const subtotal = cart.reduce((acc, item) => acc + (item.price * item.quantity), 0);
|
||||||
const vat = parseFloat(cartVatInput.value) || 0;
|
const vat = parseFloat(cartVatInput ? cartVatInput.value : 0) || 0;
|
||||||
const totalAmount = Math.max(0, subtotal + vat);
|
const totalAmount = Math.max(0, subtotal + vat);
|
||||||
const custId = selectedCustomerId.value;
|
const custId = selectedCustomerId ? selectedCustomerId.value : null;
|
||||||
|
|
||||||
const orderData = {
|
const orderData = {
|
||||||
order_id: currentOrderId, // Include ID if updating
|
order_id: currentOrderId,
|
||||||
table_number: (orderType === 'dine-in') ? currentTableId : null,
|
table_number: (orderType === 'dine-in') ? currentTableId : null,
|
||||||
order_type: orderType,
|
order_type: orderType,
|
||||||
customer_id: custId || null,
|
customer_id: custId || null,
|
||||||
outlet_id: new URLSearchParams(window.location.search).get('outlet_id') || 1,
|
outlet_id: new URLSearchParams(window.location.search).get('outlet_id') || 1,
|
||||||
payment_type_id: paymentTypeId,
|
payment_type_id: paymentTypeId,
|
||||||
total_amount: totalAmount,
|
total_amount: totalAmount,
|
||||||
vat: vat, // Send as vat
|
vat: vat,
|
||||||
redeem_loyalty: isLoyaltyRedemption,
|
redeem_loyalty: isLoyaltyRedemption,
|
||||||
items: cart.map(item => ({
|
items: cart.map(item => ({
|
||||||
product_id: item.id,
|
product_id: item.id,
|
||||||
@ -782,7 +783,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (quickOrderBtn) quickOrderBtn.disabled = false;
|
if (quickOrderBtn) quickOrderBtn.disabled = false;
|
||||||
if (placeOrderBtn) placeOrderBtn.disabled = false;
|
if (placeOrderBtn) placeOrderBtn.disabled = false;
|
||||||
|
|
||||||
paymentSelectionModal.hide();
|
if (paymentSelectionModal) paymentSelectionModal.hide();
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
// Print Receipt
|
// Print Receipt
|
||||||
@ -800,9 +801,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
cart = [];
|
cart = [];
|
||||||
cartVatInput.value = 0;
|
if (cartVatInput) cartVatInput.value = 0;
|
||||||
currentOrderId = null; // Reset
|
currentOrderId = null;
|
||||||
isLoyaltyRedemption = false; // Reset
|
isLoyaltyRedemption = false;
|
||||||
updateCart();
|
updateCart();
|
||||||
if (clearCustomerBtn) clearCustomerBtn.click();
|
if (clearCustomerBtn) clearCustomerBtn.click();
|
||||||
showToast(`Order #${data.order_id} placed!`, 'success');
|
showToast(`Order #${data.order_id} placed!`, 'success');
|
||||||
@ -818,7 +819,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (quickOrderBtn) quickOrderBtn.disabled = false;
|
if (quickOrderBtn) quickOrderBtn.disabled = false;
|
||||||
if (placeOrderBtn) placeOrderBtn.disabled = false;
|
if (placeOrderBtn) placeOrderBtn.disabled = false;
|
||||||
|
|
||||||
paymentSelectionModal.hide();
|
if (paymentSelectionModal) paymentSelectionModal.hide();
|
||||||
showToast('Network Error', 'danger');
|
showToast('Network Error', 'danger');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -839,7 +840,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (!currentOrderId) return;
|
if (!currentOrderId) return;
|
||||||
|
|
||||||
const subtotal = cart.reduce((acc, item) => acc + (item.price * item.quantity), 0);
|
const subtotal = cart.reduce((acc, item) => acc + (item.price * item.quantity), 0);
|
||||||
const vat = parseFloat(cartVatInput.value) || 0;
|
const vat = parseFloat(cartVatInput ? cartVatInput.value : 0) || 0;
|
||||||
const totalAmount = Math.max(0, subtotal + vat);
|
const totalAmount = Math.max(0, subtotal + vat);
|
||||||
const orderType = document.querySelector('input[name="order_type"]:checked').value;
|
const orderType = document.querySelector('input[name="order_type"]:checked').value;
|
||||||
|
|
||||||
@ -858,7 +859,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function printReceipt(data) {
|
function printReceipt(data) {
|
||||||
const settings = (typeof COMPANY_SETTINGS !== "undefined") ? COMPANY_SETTINGS : {};
|
|
||||||
const width = 400;
|
const width = 400;
|
||||||
const height = 800;
|
const height = 800;
|
||||||
const left = (screen.width - width) / 2;
|
const left = (screen.width - width) / 2;
|
||||||
@ -934,7 +934,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const loyaltyHtml = data.loyaltyRedeemed ? `<div style="color: #d63384; font-weight: bold; margin: 5px 0; text-align: center;">* Loyalty Reward Applied *</div>` : '';
|
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 subtotal = data.total - data.vat;
|
||||||
const logoHtml = settings.logo_url ? `<img src="${BASE_URL}${settings.logo_url}" style="max-height: 80px; max-width: 150px; margin-bottom: 10px;">` : '';
|
const baseUrl = (typeof BASE_URL !== 'undefined') ? BASE_URL : '';
|
||||||
|
const logoHtml = settings.logo_url ? `<img src="${baseUrl}${settings.logo_url}" style="max-height: 80px; max-width: 150px; margin-bottom: 10px;">` : '';
|
||||||
|
const outletName = (typeof CURRENT_OUTLET !== 'undefined') ? CURRENT_OUTLET.name : '';
|
||||||
|
const staffName = (typeof CURRENT_USER !== 'undefined') ? CURRENT_USER.name : '';
|
||||||
|
|
||||||
const html = `
|
const html = `
|
||||||
<html dir="ltr">
|
<html dir="ltr">
|
||||||
@ -971,7 +974,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
<div class="header">
|
<div class="header">
|
||||||
${logoHtml}
|
${logoHtml}
|
||||||
<h2>${settings.company_name}</h2>
|
<h2>${settings.company_name}</h2>
|
||||||
<div style="font-weight: bold;">${CURRENT_OUTLET.name}</div>
|
<div style="font-weight: bold;">${outletName}</div>
|
||||||
<div>${settings.address}</div>
|
<div>${settings.address}</div>
|
||||||
<div>Tel: ${settings.phone}</div>
|
<div>Tel: ${settings.phone}</div>
|
||||||
${settings.vat_number ? `<div style="margin-top: 4px;">VAT No / الرقم الضريبي: ${settings.vat_number}</div>` : ''}
|
${settings.vat_number ? `<div style="margin-top: 4px;">VAT No / الرقم الضريبي: ${settings.vat_number}</div>` : ''}
|
||||||
@ -994,8 +997,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
<span><strong>${tr['Date']}:</strong> ${data.date}</span>
|
<span><strong>${tr['Date']}:</strong> ${data.date}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="order-info-row">
|
<div class="order-info-row">
|
||||||
<span><strong>Staff:</strong> ${CURRENT_USER.name}</span>
|
<span><strong>Staff:</strong> ${staffName}</span>
|
||||||
<span><strong>${tr['Staff']}:</strong> ${CURRENT_USER.name}</span>
|
<span><strong>${tr['Staff']}:</strong> ${staffName}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -1078,20 +1081,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
checkOrderType();
|
checkOrderType();
|
||||||
|
|
||||||
// --- Add Customer Logic ---
|
// --- Add Customer Logic ---
|
||||||
const addCustomerBtn = document.getElementById('add-customer-btn');
|
|
||||||
const addCustomerModalEl = document.getElementById('addCustomerModal');
|
const addCustomerModalEl = document.getElementById('addCustomerModal');
|
||||||
if (addCustomerBtn && addCustomerModalEl) {
|
const saveCustomerBtn = document.getElementById('save-new-customer');
|
||||||
const addCustomerModal = new bootstrap.Modal(addCustomerModalEl);
|
const newCustomerName = document.getElementById('new-customer-name');
|
||||||
const saveCustomerBtn = document.getElementById('save-new-customer');
|
const newCustomerPhone = document.getElementById('new-customer-phone');
|
||||||
const newCustomerName = document.getElementById('new-customer-name');
|
|
||||||
const newCustomerPhone = document.getElementById('new-customer-phone');
|
|
||||||
|
|
||||||
addCustomerBtn.addEventListener('click', () => {
|
|
||||||
newCustomerName.value = '';
|
|
||||||
newCustomerPhone.value = '';
|
|
||||||
addCustomerModal.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (saveCustomerBtn && newCustomerName && newCustomerPhone) {
|
||||||
saveCustomerBtn.addEventListener('click', () => {
|
saveCustomerBtn.addEventListener('click', () => {
|
||||||
const name = newCustomerName.value.trim();
|
const name = newCustomerName.value.trim();
|
||||||
const phone = newCustomerPhone.value.trim();
|
const phone = newCustomerPhone.value.trim();
|
||||||
@ -1115,7 +1110,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
saveCustomerBtn.textContent = 'Save Customer';
|
saveCustomerBtn.textContent = 'Save Customer';
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
addCustomerModal.hide();
|
if (addCustomerModalEl) {
|
||||||
|
const modal = bootstrap.Modal.getInstance(addCustomerModalEl);
|
||||||
|
if (modal) modal.hide();
|
||||||
|
}
|
||||||
selectCustomer(data.customer);
|
selectCustomer(data.customer);
|
||||||
showToast('Customer created successfully', 'success');
|
showToast('Customer created successfully', 'success');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
12
pos.php
12
pos.php
@ -539,6 +539,18 @@ if (!$loyalty_settings) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Global POS Variables -->
|
||||||
|
<script>
|
||||||
|
const COMPANY_SETTINGS = <?= json_encode($settings) ?>;
|
||||||
|
const PRODUCT_VARIANTS = <?= json_encode($variants_by_product) ?>;
|
||||||
|
const PAYMENT_TYPES = <?= json_encode($payment_types) ?>;
|
||||||
|
const BASE_URL = '<?= get_base_url() ?>';
|
||||||
|
const CURRENT_OUTLET = { id: <?= $outlet_id ?>, name: '<?= addslashes($current_outlet_name) ?>' };
|
||||||
|
const CURRENT_USER = { id: <?= $currentUser['id'] ?>, name: '<?= addslashes($currentUser['username']) ?>' };
|
||||||
|
const LOYALTY_SETTINGS = <?= json_encode($loyalty_settings) ?>;
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="assets/js/main.js?v=<?= time() ?>"></script>
|
<script src="assets/js/main.js?v=<?= time() ?>"></script>
|
||||||
<script>
|
<script>
|
||||||
function showRatingQR() {
|
function showRatingQR() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user