Add KDS web interface files
- index.html: Complete KDS interface with dark theme - Responsive grid layout for order cards - Status indicator with connection monitoring - Configuration panel for settings - Empty state display - kds.js: Real-time order management JavaScript - Auto-refresh with configurable interval - Order status updates via API - Elapsed time calculation with visual warnings - Hierarchical line item rendering with recursive modifiers - LocalStorage-based configuration persistence 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
97a2621705
commit
d7f68e8098
2 changed files with 677 additions and 0 deletions
351
kds/index.html
Normal file
351
kds/index.html
Normal file
|
|
@ -0,0 +1,351 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Payfrit KDS - Kitchen Display System</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
padding: 20px;
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header h1 {
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header .status {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #4ade80;
|
||||||
|
animation: pulse 2s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0.5; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot.error {
|
||||||
|
background: #ef4444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.orders-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-card {
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 20px;
|
||||||
|
border: 3px solid transparent;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-card.new {
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-card.preparing {
|
||||||
|
border-color: #f59e0b;
|
||||||
|
box-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-card.ready {
|
||||||
|
border-color: #10b981;
|
||||||
|
box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
padding-bottom: 15px;
|
||||||
|
border-bottom: 1px solid #3a3a3a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-number {
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-time {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elapsed-time {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elapsed-time.warning {
|
||||||
|
color: #f59e0b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.elapsed-time.critical {
|
||||||
|
color: #ef4444;
|
||||||
|
animation: blink 1s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes blink {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0.6; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-time {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-info {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-info div {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-items {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-item {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
padding: 12px;
|
||||||
|
background: #1a1a1a;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-item-main {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-name {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-qty {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #3b82f6;
|
||||||
|
margin-left: 10px;
|
||||||
|
min-width: 30px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modifiers {
|
||||||
|
margin-left: 15px;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modifier {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #aaa;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
padding-left: 12px;
|
||||||
|
border-left: 2px solid #3a3a3a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-remark {
|
||||||
|
margin-top: 8px;
|
||||||
|
padding: 8px;
|
||||||
|
background: #f59e0b22;
|
||||||
|
border-left: 3px solid #f59e0b;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #fbbf24;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.order-remarks {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
padding: 10px;
|
||||||
|
background: #ef444422;
|
||||||
|
border-left: 3px solid #ef4444;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #fca5a5;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
flex: 1;
|
||||||
|
padding: 12px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-start {
|
||||||
|
background: #f59e0b;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-ready {
|
||||||
|
background: #10b981;
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-complete {
|
||||||
|
background: #3b82f6;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
text-align: center;
|
||||||
|
padding: 60px 20px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state svg {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state h2 {
|
||||||
|
font-size: 24px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state p {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-panel {
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
right: 20px;
|
||||||
|
background: #2a2a2a;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-panel.show {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-panel label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-panel input,
|
||||||
|
.config-panel select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
background: #1a1a1a;
|
||||||
|
border: 1px solid #3a3a3a;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-config {
|
||||||
|
background: #3a3a3a;
|
||||||
|
color: #fff;
|
||||||
|
padding: 8px 16px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<div>
|
||||||
|
<h1>Kitchen Display System</h1>
|
||||||
|
<div style="margin-top: 5px; font-size: 14px; color: #888;" id="servicePointName">Loading...</div>
|
||||||
|
</div>
|
||||||
|
<div class="status">
|
||||||
|
<div class="status-dot" id="statusDot"></div>
|
||||||
|
<span id="statusText">Connected</span>
|
||||||
|
<button class="btn-config" onclick="toggleConfig()">⚙️ Settings</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="config-panel" id="configPanel">
|
||||||
|
<label>
|
||||||
|
Business ID:
|
||||||
|
<input type="number" id="businessIdInput" placeholder="Enter Business ID" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Service Point ID (optional):
|
||||||
|
<input type="number" id="servicePointIdInput" placeholder="Leave blank for all" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Refresh Interval (seconds):
|
||||||
|
<input type="number" id="refreshIntervalInput" value="5" min="1" max="60" />
|
||||||
|
</label>
|
||||||
|
<button class="btn-config" onclick="saveConfig()" style="width: 100%; background: #3b82f6;">Save & Reload</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="orders-grid" id="ordersGrid">
|
||||||
|
<div class="empty-state">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
|
||||||
|
</svg>
|
||||||
|
<h2>No Active Orders</h2>
|
||||||
|
<p>New orders will appear here automatically</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="kds.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
326
kds/kds.js
Normal file
326
kds/kds.js
Normal file
|
|
@ -0,0 +1,326 @@
|
||||||
|
// Configuration
|
||||||
|
let config = {
|
||||||
|
apiBaseUrl: '/biz.payfrit.com/api',
|
||||||
|
businessId: null,
|
||||||
|
servicePointId: null,
|
||||||
|
refreshInterval: 5000, // 5 seconds
|
||||||
|
};
|
||||||
|
|
||||||
|
// State
|
||||||
|
let orders = [];
|
||||||
|
let refreshTimer = null;
|
||||||
|
|
||||||
|
// Status ID mapping
|
||||||
|
const STATUS = {
|
||||||
|
NEW: 1,
|
||||||
|
PREPARING: 2,
|
||||||
|
READY: 3,
|
||||||
|
COMPLETED: 4
|
||||||
|
};
|
||||||
|
|
||||||
|
const STATUS_NAMES = {
|
||||||
|
1: 'New',
|
||||||
|
2: 'Preparing',
|
||||||
|
3: 'Ready',
|
||||||
|
4: 'Completed'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
loadConfig();
|
||||||
|
startAutoRefresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Load config from localStorage
|
||||||
|
function loadConfig() {
|
||||||
|
const saved = localStorage.getItem('kds_config');
|
||||||
|
if (saved) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(saved);
|
||||||
|
config.businessId = parsed.businessId || null;
|
||||||
|
config.servicePointId = parsed.servicePointId || null;
|
||||||
|
config.refreshInterval = (parsed.refreshInterval || 5) * 1000;
|
||||||
|
|
||||||
|
document.getElementById('businessIdInput').value = config.businessId || '';
|
||||||
|
document.getElementById('servicePointIdInput').value = config.servicePointId || '';
|
||||||
|
document.getElementById('refreshIntervalInput').value = config.refreshInterval / 1000;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to load config:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no business ID, show config panel
|
||||||
|
if (!config.businessId) {
|
||||||
|
toggleConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save config to localStorage
|
||||||
|
function saveConfig() {
|
||||||
|
const businessId = parseInt(document.getElementById('businessIdInput').value) || null;
|
||||||
|
const servicePointId = parseInt(document.getElementById('servicePointIdInput').value) || null;
|
||||||
|
const refreshInterval = parseInt(document.getElementById('refreshIntervalInput').value) || 5;
|
||||||
|
|
||||||
|
if (!businessId) {
|
||||||
|
alert('Business ID is required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.businessId = businessId;
|
||||||
|
config.servicePointId = servicePointId;
|
||||||
|
config.refreshInterval = refreshInterval * 1000;
|
||||||
|
|
||||||
|
localStorage.setItem('kds_config', JSON.stringify({
|
||||||
|
businessId: config.businessId,
|
||||||
|
servicePointId: config.servicePointId,
|
||||||
|
refreshInterval: refreshInterval
|
||||||
|
}));
|
||||||
|
|
||||||
|
toggleConfig();
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle config panel
|
||||||
|
function toggleConfig() {
|
||||||
|
const panel = document.getElementById('configPanel');
|
||||||
|
panel.classList.toggle('show');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start auto-refresh
|
||||||
|
function startAutoRefresh() {
|
||||||
|
if (!config.businessId) return;
|
||||||
|
|
||||||
|
loadOrders();
|
||||||
|
|
||||||
|
if (refreshTimer) clearInterval(refreshTimer);
|
||||||
|
refreshTimer = setInterval(loadOrders, config.refreshInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load orders from API
|
||||||
|
async function loadOrders() {
|
||||||
|
if (!config.businessId) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${config.apiBaseUrl}/orders/listForKDS.cfm`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
BusinessID: config.businessId,
|
||||||
|
ServicePointID: config.servicePointId || 0
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.OK) {
|
||||||
|
orders = data.ORDERS || [];
|
||||||
|
renderOrders();
|
||||||
|
updateStatus(true, `${orders.length} active orders`);
|
||||||
|
} else {
|
||||||
|
updateStatus(false, `Error: ${data.MESSAGE || data.ERROR}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load orders:', error);
|
||||||
|
updateStatus(false, 'Connection error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update status indicator
|
||||||
|
function updateStatus(isConnected, message) {
|
||||||
|
const dot = document.getElementById('statusDot');
|
||||||
|
const text = document.getElementById('statusText');
|
||||||
|
|
||||||
|
if (isConnected) {
|
||||||
|
dot.classList.remove('error');
|
||||||
|
text.textContent = message || 'Connected';
|
||||||
|
} else {
|
||||||
|
dot.classList.add('error');
|
||||||
|
text.textContent = message || 'Disconnected';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render orders to DOM
|
||||||
|
function renderOrders() {
|
||||||
|
const grid = document.getElementById('ordersGrid');
|
||||||
|
|
||||||
|
if (orders.length === 0) {
|
||||||
|
grid.innerHTML = `
|
||||||
|
<div class="empty-state">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
|
||||||
|
</svg>
|
||||||
|
<h2>No Active Orders</h2>
|
||||||
|
<p>New orders will appear here automatically</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
grid.innerHTML = orders.map(order => renderOrder(order)).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render single order card
|
||||||
|
function renderOrder(order) {
|
||||||
|
const statusClass = getStatusClass(order.OrderStatusID);
|
||||||
|
const elapsedTime = getElapsedTime(order.OrderSubmittedOn);
|
||||||
|
const timeClass = getTimeClass(elapsedTime);
|
||||||
|
|
||||||
|
// Group line items by root items and their modifiers
|
||||||
|
const rootItems = order.LineItems.filter(item => item.OrderLineItemParentOrderLineItemID === 0);
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="order-card ${statusClass}">
|
||||||
|
<div class="order-header">
|
||||||
|
<div class="order-number">#${order.OrderID}</div>
|
||||||
|
<div class="order-time">
|
||||||
|
<div class="elapsed-time ${timeClass}">${formatElapsedTime(elapsedTime)}</div>
|
||||||
|
<div class="submit-time">${formatSubmitTime(order.OrderSubmittedOn)}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="order-info">
|
||||||
|
<div><strong>Table:</strong> ${order.ServicePointName || 'N/A'}</div>
|
||||||
|
<div><strong>Customer:</strong> ${order.UserFirstName || ''} ${order.UserLastName || ''}</div>
|
||||||
|
<div><strong>Status:</strong> ${STATUS_NAMES[order.OrderStatusID] || 'Unknown'}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${order.OrderRemarks ? `<div class="order-remarks">Note: ${escapeHtml(order.OrderRemarks)}</div>` : ''}
|
||||||
|
|
||||||
|
<div class="line-items">
|
||||||
|
${rootItems.map(item => renderLineItem(item, order.LineItems)).join('')}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="action-buttons">
|
||||||
|
${renderActionButtons(order)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render line item with modifiers
|
||||||
|
function renderLineItem(item, allItems) {
|
||||||
|
const modifiers = allItems.filter(mod => mod.OrderLineItemParentOrderLineItemID === item.OrderLineItemID);
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="line-item">
|
||||||
|
<div class="line-item-main">
|
||||||
|
<div class="item-name">${escapeHtml(item.ItemName)}</div>
|
||||||
|
<div class="item-qty">×${item.OrderLineItemQuantity}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${modifiers.length > 0 ? `
|
||||||
|
<div class="modifiers">
|
||||||
|
${modifiers.map(mod => renderModifier(mod, allItems)).join('')}
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
|
|
||||||
|
${item.OrderLineItemRemark ? `
|
||||||
|
<div class="item-remark">Note: ${escapeHtml(item.OrderLineItemRemark)}</div>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render modifier (recursive for nested modifiers)
|
||||||
|
function renderModifier(modifier, allItems) {
|
||||||
|
const subModifiers = allItems.filter(mod => mod.OrderLineItemParentOrderLineItemID === modifier.OrderLineItemID);
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="modifier">
|
||||||
|
+ ${escapeHtml(modifier.ItemName)}
|
||||||
|
${subModifiers.length > 0 ? `
|
||||||
|
<div class="modifiers">
|
||||||
|
${subModifiers.map(sub => renderModifier(sub, allItems)).join('')}
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render action buttons based on order status
|
||||||
|
function renderActionButtons(order) {
|
||||||
|
switch (order.OrderStatusID) {
|
||||||
|
case STATUS.NEW:
|
||||||
|
return `<button class="btn btn-start" onclick="updateOrderStatus(${order.OrderID}, ${STATUS.PREPARING})">Start Preparing</button>`;
|
||||||
|
|
||||||
|
case STATUS.PREPARING:
|
||||||
|
return `<button class="btn btn-ready" onclick="updateOrderStatus(${order.OrderID}, ${STATUS.READY})">Mark as Ready</button>`;
|
||||||
|
|
||||||
|
case STATUS.READY:
|
||||||
|
return `<button class="btn btn-complete" onclick="updateOrderStatus(${order.OrderID}, ${STATUS.COMPLETED})">Complete</button>`;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update order status
|
||||||
|
async function updateOrderStatus(orderId, newStatusId) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${config.apiBaseUrl}/orders/updateStatus.cfm`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
OrderID: orderId,
|
||||||
|
StatusID: newStatusId
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.OK) {
|
||||||
|
// Immediately reload orders to reflect the change
|
||||||
|
await loadOrders();
|
||||||
|
} else {
|
||||||
|
alert(`Failed to update order: ${data.MESSAGE || data.ERROR}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to update order status:', error);
|
||||||
|
alert('Failed to update order status. Please try again.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper functions
|
||||||
|
function getStatusClass(statusId) {
|
||||||
|
switch (statusId) {
|
||||||
|
case STATUS.NEW: return 'new';
|
||||||
|
case STATUS.PREPARING: return 'preparing';
|
||||||
|
case STATUS.READY: return 'ready';
|
||||||
|
default: return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getElapsedTime(submittedOn) {
|
||||||
|
if (!submittedOn) return 0;
|
||||||
|
const submitted = new Date(submittedOn);
|
||||||
|
const now = new Date();
|
||||||
|
return Math.floor((now - submitted) / 1000); // seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTimeClass(seconds) {
|
||||||
|
if (seconds > 900) return 'critical'; // > 15 min
|
||||||
|
if (seconds > 600) return 'warning'; // > 10 min
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatElapsedTime(seconds) {
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const secs = seconds % 60;
|
||||||
|
return `${minutes}:${secs.toString().padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatSubmitTime(dateString) {
|
||||||
|
if (!dateString) return '';
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(text) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = text;
|
||||||
|
return div.innerHTML;
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue