diff --git a/api/orders/updateStatus.cfm b/api/orders/updateStatus.cfm index bc64269..160686e 100644 --- a/api/orders/updateStatus.cfm +++ b/api/orders/updateStatus.cfm @@ -36,9 +36,9 @@ - - - - - - Payfrit KDS - Kitchen Display System + Payfrit KDS @@ -75,23 +90,14 @@
-
-

Kitchen Display System

-
-
-
- Connected - - +

Payfrit KDS

+
+
--:--:--
+
-
- - - - -
+
@@ -103,6 +109,6 @@
- + \ No newline at end of file diff --git a/kds/kds.js b/kds/kds.js index e2f6cfc..3345cc1 100644 --- a/kds/kds.js +++ b/kds/kds.js @@ -1,8 +1,7 @@ // Configuration let config = { - apiBaseUrl: 'https://biz.payfrit.com/api', - businessId: null, - servicePointId: null, + apiBaseUrl: '/api', + businessId: parseInt(localStorage.getItem('payfrit_portal_business')) || 0, stationId: null, stationName: null, stationColor: null, @@ -22,45 +21,40 @@ const STATUS_NAMES = { 1: 'New', 2: 'Preparing', 3: 'Ready', 4: 'Completed' }; document.addEventListener('DOMContentLoaded', () => { loadConfig(); checkStationSelection(); + updateClock(); + setInterval(updateClock, 1000); }); +// Update clock display +function updateClock() { + const now = new Date(); + const hours = String(now.getHours()).padStart(2, '0'); + const minutes = String(now.getMinutes()).padStart(2, '0'); + const seconds = String(now.getSeconds()).padStart(2, '0'); + document.getElementById('clock').textContent = `${hours}:${minutes}:${seconds}`; +} + // Load config from localStorage function loadConfig() { - // Get business ID from portal's shared localStorage (same key portal uses) - const portalBusinessId = localStorage.getItem('payfrit_portal_business'); - if (portalBusinessId && !isNaN(parseInt(portalBusinessId))) { - config.businessId = parseInt(portalBusinessId); - } - - // Load KDS-specific settings + // Load KDS-specific settings (station, refresh interval) const saved = localStorage.getItem('kds_config'); if (saved) { try { const parsed = JSON.parse(saved); - config.servicePointId = parsed.servicePointId || null; - config.stationId = parsed.stationId || null; + config.stationId = parsed.stationId !== undefined ? parsed.stationId : null; config.stationName = parsed.stationName || null; config.stationColor = parsed.stationColor || null; config.refreshInterval = (parsed.refreshInterval || 5) * 1000; } catch (e) { - console.error('Failed to load config:', e); + console.error('[KDS] Failed to load config:', e); } } - document.getElementById('businessIdInput').value = config.businessId || ''; - document.getElementById('servicePointIdInput').value = config.servicePointId || ''; - document.getElementById('refreshIntervalInput').value = config.refreshInterval / 1000; - - // If no business ID, show config panel - if (!config.businessId) { - toggleConfig(); - } + console.log('[KDS] Config loaded:', config); } function saveConfigToStorage() { - // Save KDS-specific settings only (businessId comes from portal) localStorage.setItem('kds_config', JSON.stringify({ - servicePointId: config.servicePointId, stationId: config.stationId, stationName: config.stationName, stationColor: config.stationColor, @@ -71,7 +65,8 @@ function saveConfigToStorage() { // Check if station selection is needed async function checkStationSelection() { if (!config.businessId) { - console.log('[KDS] No businessId, cannot start'); + console.log('[KDS] No businessId - please log in via Portal first'); + updateStatus(false, 'No business selected - log in via Portal'); return; } @@ -110,11 +105,11 @@ async function loadName() { body: JSON.stringify({ BusinessID: config.businessId }) }); const data = await response.json(); - if (data.OK && data.BUSINESS) { - document.getElementById('businessName').textContent = data.BUSINESS.Name || 'Kitchen Display System'; + if (data.OK && data.BUSINESS && data.BUSINESS.Name) { + document.getElementById('businessName').textContent = ' - ' + data.BUSINESS.Name; } } catch (e) { - console.error('Failed to load business name:', e); + console.error('[KDS] Failed to load business name:', e); } } @@ -170,19 +165,12 @@ async function showStationSelection() { // Select a station function selectStation(stationId, stationName, stationColor) { - config.stationId = stationId || null; + config.stationId = stationId; config.stationName = stationName; config.stationColor = stationColor; // Save to localStorage - localStorage.setItem('kds_config', JSON.stringify({ - businessId: config.businessId, - servicePointId: config.servicePointId, - stationId: config.stationId, - stationName: config.stationName, - stationColor: config.stationColor, - refreshInterval: config.refreshInterval / 1000 - })); + saveConfigToStorage(); // Hide overlay and start document.getElementById('stationOverlay').classList.add('hidden'); @@ -193,49 +181,8 @@ function selectStation(stationId, stationName, stationColor) { // Update station badge in header function updateStationBadge() { const badge = document.getElementById('stationBadge'); - if (config.stationId && config.stationName) { - const color = config.stationColor || '#3b82f6'; - badge.innerHTML = `${escapeHtml(config.stationName)}`; - } else { - badge.innerHTML = `All Stations`; - } -} - -// 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; - config.stationId = null; // Reset station selection when changing business - config.stationName = null; - config.stationColor = null; - - localStorage.setItem('kds_config', JSON.stringify({ - businessId: config.businessId, - servicePointId: config.servicePointId, - stationId: null, - stationName: null, - stationColor: null, - refreshInterval: refreshInterval - })); - - toggleConfig(); - location.reload(); -} - -// Toggle config panel -function toggleConfig() { - const panel = document.getElementById('configPanel'); - panel.classList.toggle('show'); + const name = config.stationId && config.stationName ? config.stationName : 'All'; + badge.innerHTML = `/ ${escapeHtml(name)}`; } // Start auto-refresh @@ -257,7 +204,6 @@ async function loadOrders() { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ BusinessID: config.businessId, - ServicePointID: config.servicePointId || 0, StationID: config.stationId || 0 }) }); @@ -279,14 +225,11 @@ async function loadOrders() { // Update status indicator function updateStatus(isConnected, message) { - const dot = document.getElementById('statusDot'); - const text = document.getElementById('statusText'); + const indicator = document.getElementById('statusIndicator'); if (isConnected) { - dot.classList.remove('error'); - text.textContent = message || 'Connected'; + indicator.classList.remove('disconnected'); } else { - dot.classList.add('error'); - text.textContent = message || 'Disconnected'; + indicator.classList.add('disconnected'); } }