343 lines
12 KiB
PHP
343 lines
12 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Customer Display</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
<style>
|
|
body {
|
|
background-color: var(--bg);
|
|
color: var(--text);
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
display: flex;
|
|
flex-direction: column;
|
|
transition: background-color 0.3s, color 0.3s;
|
|
}
|
|
.header {
|
|
background: var(--surface);
|
|
padding: 1rem 2rem;
|
|
border-bottom: 1px solid var(--border);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
.logo {
|
|
font-size: 1.5rem;
|
|
font-weight: bold;
|
|
color: var(--accent);
|
|
}
|
|
.content {
|
|
flex: 1;
|
|
display: flex;
|
|
overflow: hidden;
|
|
}
|
|
.items-section {
|
|
flex: 2;
|
|
padding: 2rem;
|
|
overflow-y: auto;
|
|
border-right: 1px solid var(--border);
|
|
background: var(--surface);
|
|
}
|
|
.totals-section {
|
|
flex: 1;
|
|
padding: 2rem;
|
|
background: var(--bg);
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
}
|
|
.cart-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 1rem;
|
|
border-bottom: 1px solid var(--border);
|
|
margin-bottom: 0.5rem;
|
|
background: var(--surface);
|
|
border-radius: var(--radius);
|
|
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
|
|
}
|
|
.item-name {
|
|
font-size: 2.5vmin;
|
|
font-weight: 600;
|
|
color: var(--text);
|
|
}
|
|
.item-details {
|
|
color: var(--text-muted);
|
|
font-size: 2vmin;
|
|
}
|
|
.item-price {
|
|
font-size: 2.5vmin;
|
|
font-weight: bold;
|
|
color: var(--accent);
|
|
}
|
|
.total-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
margin-bottom: 1rem;
|
|
font-size: 2.5vmin;
|
|
color: var(--text-muted);
|
|
}
|
|
.grand-total {
|
|
background: var(--accent);
|
|
color: white;
|
|
padding: 2rem;
|
|
border-radius: 12px;
|
|
text-align: center;
|
|
margin-top: auto;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.grand-total-label {
|
|
font-size: 3vmin;
|
|
text-transform: uppercase;
|
|
opacity: 0.9;
|
|
}
|
|
.grand-total-amount {
|
|
font-size: 10vmin;
|
|
font-weight: 800;
|
|
line-height: 1.2;
|
|
}
|
|
.welcome-screen {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
text-align: center;
|
|
color: var(--text-muted);
|
|
}
|
|
.welcome-icon {
|
|
font-size: 15vmin;
|
|
margin-bottom: 1rem;
|
|
color: var(--border);
|
|
opacity: 0.5;
|
|
}
|
|
/* Custom scrollbar */
|
|
::-webkit-scrollbar {
|
|
width: 8px;
|
|
}
|
|
::-webkit-scrollbar-track {
|
|
background: var(--bg);
|
|
}
|
|
::-webkit-scrollbar-thumb {
|
|
background: var(--border);
|
|
border-radius: 4px;
|
|
}
|
|
::-webkit-scrollbar-thumb:hover {
|
|
background: var(--text-muted);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<div class="logo">
|
|
<i class="bi bi-cart4 me-2"></i>Customer Display
|
|
</div>
|
|
<div class="d-flex align-items-center">
|
|
<button onclick="toggleFullScreen()" class="btn btn-sm btn-link text-muted me-3" title="Toggle Fullscreen"><i class="bi bi-arrows-fullscreen"></i></button>
|
|
<div id="debugInfo" class="me-3 badge bg-secondary" style="display: none;">Items: 0</div>
|
|
<div id="customerName" class="badge bg-light text-dark fs-6 fw-normal border">
|
|
Welcome
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="activeCart" class="content" style="display: none;">
|
|
<div class="items-section" id="itemsList">
|
|
<!-- Items will be injected here -->
|
|
</div>
|
|
|
|
<div class="totals-section">
|
|
<div class="total-row">
|
|
<span>Subtotal</span>
|
|
<span id="displaySubtotal">OMR 0.000</span>
|
|
</div>
|
|
<div id="displayDiscountRow" class="total-row text-danger" style="display: none;">
|
|
<span>Discount</span>
|
|
<span id="displayDiscount">- OMR 0.000</span>
|
|
</div>
|
|
<div id="displayLoyaltyRow" class="total-row text-success" style="display: none;">
|
|
<span>Loyalty Redeemed</span>
|
|
<span id="displayLoyalty">- OMR 0.000</span>
|
|
</div>
|
|
<div id="displayTaxRow" class="total-row text-muted" style="display: none;">
|
|
<small>VAT Included</small>
|
|
<small id="displayTax">OMR 0.000</small>
|
|
</div>
|
|
|
|
<div class="grand-total">
|
|
<div class="grand-total-label">Total to Pay</div>
|
|
<div class="grand-total-amount" id="displayTotal">OMR 0.000</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="welcomeScreen" class="welcome-screen">
|
|
<div class="welcome-icon">
|
|
<i class="bi bi-shop"></i>
|
|
</div>
|
|
<h1 class="display-4 fw-bold" style="color: var(--text)">Welcome</h1>
|
|
<p class="lead">Next customer, please.</p>
|
|
</div>
|
|
|
|
<script>
|
|
let lastTimestamp = 0;
|
|
|
|
function formatMoney(amount) {
|
|
return 'OMR ' + parseFloat(amount).toFixed(3);
|
|
}
|
|
|
|
function updateDisplay(data) {
|
|
if (!data) return;
|
|
lastTimestamp = data.timestamp || 0;
|
|
|
|
// Debug info
|
|
const debugEl = document.getElementById('debugInfo');
|
|
if (debugEl) {
|
|
debugEl.innerText = 'Items: ' + (data.items ? data.items.length : 0);
|
|
// debugEl.style.display = 'block'; // Uncomment to show always
|
|
}
|
|
|
|
// Update Theme
|
|
if (data.theme) {
|
|
document.body.className = data.theme;
|
|
}
|
|
|
|
if (!Array.isArray(data.items) || data.items.length === 0) {
|
|
document.getElementById('activeCart').style.display = 'none';
|
|
document.getElementById('welcomeScreen').style.display = 'flex';
|
|
document.getElementById('customerName').innerText = 'Welcome';
|
|
return;
|
|
}
|
|
|
|
document.getElementById('welcomeScreen').style.display = 'none';
|
|
document.getElementById('activeCart').style.display = 'flex';
|
|
|
|
// Update Customer Name
|
|
if (data.customerName && data.customerName !== 'Walk-in Customer' && data.customerName !== 'عميل عابر') {
|
|
document.getElementById('customerName').innerHTML = '<i class="bi bi-person me-1"></i> ' + data.customerName;
|
|
} else {
|
|
document.getElementById('customerName').innerText = 'Welcome';
|
|
}
|
|
|
|
// Update Items (Safer rendering)
|
|
const itemsList = document.getElementById('itemsList');
|
|
if (itemsList) {
|
|
itemsList.innerHTML = ''; // Clear existing
|
|
|
|
data.items.forEach(item => {
|
|
try {
|
|
const row = document.createElement('div');
|
|
row.className = 'cart-item';
|
|
|
|
const name = item.name || 'Item';
|
|
const price = parseFloat(item.price) || 0;
|
|
const qty = parseFloat(item.qty) || 0;
|
|
const total = price * qty;
|
|
|
|
row.innerHTML = `
|
|
<div>
|
|
<div class="item-name"></div>
|
|
<div class="item-details">
|
|
${qty} x ${formatMoney(price)}
|
|
</div>
|
|
</div>
|
|
<div class="item-price">
|
|
${formatMoney(total)}
|
|
</div>
|
|
`;
|
|
// Set text content safely
|
|
const nameEl = row.querySelector('.item-name');
|
|
if (nameEl) nameEl.textContent = name;
|
|
itemsList.appendChild(row);
|
|
} catch (err) {
|
|
console.error('Error rendering item:', err);
|
|
}
|
|
});
|
|
|
|
// Scroll to bottom of list
|
|
requestAnimationFrame(() => {
|
|
itemsList.scrollTop = itemsList.scrollHeight;
|
|
});
|
|
}
|
|
|
|
// Update Totals
|
|
document.getElementById('displaySubtotal').innerText = formatMoney(data.subtotal || 0);
|
|
|
|
const discount = parseFloat(data.discount) || 0;
|
|
if (discount > 0) {
|
|
document.getElementById('displayDiscountRow').style.display = 'flex';
|
|
document.getElementById('displayDiscount').innerText = '- ' + formatMoney(discount);
|
|
} else {
|
|
document.getElementById('displayDiscountRow').style.display = 'none';
|
|
}
|
|
|
|
const loyalty = parseFloat(data.loyalty) || 0;
|
|
if (loyalty > 0) {
|
|
document.getElementById('displayLoyaltyRow').style.display = 'flex';
|
|
document.getElementById('displayLoyalty').innerText = '- ' + formatMoney(loyalty);
|
|
} else {
|
|
document.getElementById('displayLoyaltyRow').style.display = 'none';
|
|
}
|
|
|
|
document.getElementById('displayTotal').innerText = formatMoney(data.total || 0);
|
|
}
|
|
|
|
// Listen for storage events
|
|
window.addEventListener('storage', (e) => {
|
|
if (e.key === 'pos_cart_update') {
|
|
try {
|
|
const data = JSON.parse(e.newValue);
|
|
updateDisplay(data);
|
|
} catch (err) {
|
|
console.error('Error parsing cart data', err);
|
|
}
|
|
}
|
|
});
|
|
|
|
// Polling fallback (every 1 second)
|
|
setInterval(() => {
|
|
const stored = localStorage.getItem('pos_cart_update');
|
|
if (stored) {
|
|
try {
|
|
const data = JSON.parse(stored);
|
|
if (data.timestamp && data.timestamp !== lastTimestamp) {
|
|
updateDisplay(data);
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
}, 1000);
|
|
|
|
// Initial check
|
|
const stored = localStorage.getItem('pos_cart_update');
|
|
if (stored) {
|
|
try {
|
|
updateDisplay(JSON.parse(stored));
|
|
} catch (e) {}
|
|
}
|
|
|
|
function toggleFullScreen() {
|
|
if (!document.fullscreenElement) {
|
|
document.documentElement.requestFullscreen();
|
|
} else {
|
|
if (document.exitFullscreen) {
|
|
document.exitFullscreen();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Attempt to maximize on load
|
|
window.addEventListener('load', () => {
|
|
try {
|
|
window.moveTo(0, 0);
|
|
window.resizeTo(screen.availWidth, screen.availHeight);
|
|
} catch(e) {}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|