payfrit-works/portal/station-assignment.html
John Mizerek 634148f727 Add Categories table support, KDS station selection, and portal fixes
Categories Migration:
- Add ItemCategoryID column to Items table (api/admin/addItemCategoryColumn.cfm)
- Migration script to populate Categories from unified schema (api/admin/migrateToCategories.cfm)
- Updated items.cfm and getForBuilder.cfm to use Categories table with fallback

KDS Station Selection:
- KDS now prompts for station selection on load (Kitchen, Bar, or All Stations)
- Station filter persists in localStorage
- Updated listForKDS.cfm to filter orders by station
- Simplified KDS UI with station badge in header

Portal Improvements:
- Fixed drag-and-drop in station assignment (proper event propagation)
- Fixed Back button links to use BASE_PATH for local development
- Added console logging for debugging station assignment
- Order detail API now calculates Subtotal, Tax, Tip, Total properly

Admin Tools:
- setupBigDeansStations.cfm - Create Kitchen and Bar stations for Big Dean's

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 15:31:45 -08:00

781 lines
24 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Station Assignment - Payfrit</title>
<link rel="stylesheet" href="portal.css">
<style>
.assignment-container {
display: flex;
height: calc(100vh - 80px);
gap: 24px;
padding: 24px;
background: var(--bg-primary);
}
.panel {
background: var(--bg-card);
border-radius: 12px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.items-panel {
width: 350px;
flex-shrink: 0;
}
.stations-panel {
flex: 1;
display: flex;
flex-direction: column;
}
.panel-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-header h2 {
margin: 0;
font-size: 18px;
font-weight: 600;
}
.panel-header .count {
background: var(--bg-secondary);
padding: 4px 10px;
border-radius: 12px;
font-size: 13px;
color: var(--text-muted);
}
.panel-body {
flex: 1;
overflow-y: auto;
padding: 16px;
}
/* Items list */
.category-group {
margin-bottom: 20px;
}
.category-label {
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--text-muted);
margin-bottom: 8px;
padding: 0 4px;
}
.draggable-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
background: var(--bg-secondary);
border: 2px solid var(--border-color);
border-radius: 8px;
margin-bottom: 8px;
cursor: grab;
transition: all 0.2s;
}
.draggable-item:hover {
border-color: var(--primary);
background: rgba(0, 255, 136, 0.05);
}
.draggable-item:active {
cursor: grabbing;
}
.draggable-item.dragging {
opacity: 0.5;
transform: scale(0.98);
}
.draggable-item.assigned {
opacity: 0.4;
border-style: dashed;
}
.item-icon {
font-size: 20px;
}
.item-details {
flex: 1;
min-width: 0;
}
.item-name {
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.item-price {
font-size: 13px;
color: var(--primary);
}
.item-station-badge {
font-size: 11px;
padding: 3px 8px;
border-radius: 4px;
background: var(--primary);
color: #000;
}
/* Stations grid */
.stations-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.station-card {
background: var(--bg-secondary);
border: 2px solid var(--border-color);
border-radius: 12px;
min-height: 200px;
display: flex;
flex-direction: column;
transition: all 0.2s;
}
.station-card.drag-over {
border-color: var(--primary);
background: rgba(0, 255, 136, 0.05);
box-shadow: 0 0 0 4px rgba(0, 255, 136, 0.1);
}
.station-header {
display: flex;
align-items: center;
gap: 12px;
padding: 16px;
border-bottom: 1px solid var(--border-color);
}
.station-color {
width: 32px;
height: 32px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
color: white;
font-weight: bold;
}
.station-info {
flex: 1;
}
.station-name {
font-weight: 600;
font-size: 16px;
}
.station-count {
font-size: 13px;
color: var(--text-muted);
}
.station-items {
flex: 1;
padding: 12px;
display: flex;
flex-direction: column;
gap: 8px;
min-height: 100px;
}
.station-items.empty {
display: flex;
align-items: center;
justify-content: center;
color: var(--text-muted);
font-size: 14px;
}
.station-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
background: var(--bg-card);
border-radius: 6px;
border: 1px solid var(--border-color);
}
.station-item .item-name {
flex: 1;
font-size: 14px;
}
.station-item .remove-btn {
background: none;
border: none;
color: var(--text-muted);
cursor: pointer;
padding: 4px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
}
.station-item .remove-btn:hover {
background: var(--bg-secondary);
color: var(--danger);
}
/* Toolbar */
.toolbar {
display: flex;
gap: 12px;
padding: 16px 24px;
background: var(--bg-card);
border-bottom: 1px solid var(--border-color);
}
.toolbar-title {
flex: 1;
display: flex;
align-items: center;
gap: 12px;
}
.toolbar-title h1 {
margin: 0;
font-size: 20px;
}
.toolbar-title .business-name {
color: var(--text-muted);
font-size: 14px;
}
/* Empty state */
.empty-drop {
text-align: center;
padding: 40px 20px;
color: var(--text-muted);
}
.empty-drop svg {
width: 48px;
height: 48px;
margin-bottom: 12px;
opacity: 0.5;
}
/* Filter */
.filter-input {
padding: 10px 14px;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 8px;
color: var(--text-primary);
font-size: 14px;
width: 100%;
margin-bottom: 16px;
}
.filter-input:focus {
outline: none;
border-color: var(--primary);
}
/* Unassigned station */
.station-card.unassigned {
border-style: dashed;
background: transparent;
}
</style>
</head>
<body>
<div class="app" style="flex-direction: column;">
<!-- Toolbar -->
<div class="toolbar">
<div class="toolbar-title">
<a id="backLink" href="#" style="color: var(--text-muted); text-decoration: none;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M19 12H5M12 19l-7-7 7-7"/>
</svg>
</a>
<h1>Station Assignment</h1>
<span class="business-name" id="businessName"></span>
</div>
<button class="btn btn-primary" onclick="StationAssignment.save()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/>
<path d="M17 21v-8H7v8M7 3v5h8"/>
</svg>
Save Changes
</button>
</div>
<div class="assignment-container">
<!-- Left Panel: Menu Items -->
<div class="panel items-panel">
<div class="panel-header">
<h2>Menu Items</h2>
<span class="count" id="itemCount">0 items</span>
</div>
<div class="panel-body">
<input type="text" class="filter-input" placeholder="Filter items..." id="itemFilter" oninput="StationAssignment.filterItems(this.value)">
<div id="itemsList">
<div class="empty-drop">Loading items...</div>
</div>
</div>
</div>
<!-- Right Panel: Stations -->
<div class="panel stations-panel">
<div class="panel-header">
<h2>Stations</h2>
<button class="btn btn-secondary" onclick="StationAssignment.addStation()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14M5 12h14"/>
</svg>
Add Station
</button>
</div>
<div class="panel-body">
<div class="stations-grid" id="stationsGrid">
<div class="empty-drop">Loading stations...</div>
</div>
</div>
</div>
</div>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<script>
// Detect base path for API calls (handles local dev at /biz.payfrit.com/)
const BASE_PATH = (() => {
const path = window.location.pathname;
const portalIndex = path.indexOf('/portal/');
if (portalIndex > 0) {
return path.substring(0, portalIndex);
}
return '';
})();
const StationAssignment = {
config: {
apiBaseUrl: BASE_PATH + '/api',
businessId: null
},
items: [],
stations: [],
assignments: {}, // itemId -> stationId
filterText: '',
async init() {
console.log('[StationAssignment] Initializing...');
// Set back link with BASE_PATH
document.getElementById('backLink').href = BASE_PATH + '/portal/index.html#menu';
// Check authentication
const token = localStorage.getItem('payfrit_portal_token');
const savedBusiness = localStorage.getItem('payfrit_portal_business');
if (!token || !savedBusiness) {
window.location.href = BASE_PATH + '/portal/login.html';
return;
}
const urlParams = new URLSearchParams(window.location.search);
this.config.businessId = parseInt(urlParams.get('bid')) || parseInt(savedBusiness);
this.config.token = token;
await this.loadBusinessInfo();
await this.loadStations();
await this.loadItems();
console.log('[StationAssignment] Ready');
},
async loadBusinessInfo() {
try {
const response = await fetch(`${this.config.apiBaseUrl}/businesses/get.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId })
});
const data = await response.json();
if (data.OK && data.BUSINESS) {
document.getElementById('businessName').textContent = `- ${data.BUSINESS.BusinessName}`;
}
} catch (err) {
console.error('[StationAssignment] Error:', err);
}
},
async loadStations() {
try {
const response = await fetch(`${this.config.apiBaseUrl}/stations/list.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId })
});
const data = await response.json();
if (data.OK) {
this.stations = data.STATIONS || [];
}
} catch (err) {
console.error('[StationAssignment] Stations error:', err);
// Demo stations
this.stations = [
{ StationID: 1, StationName: 'Grill', StationColor: '#FF5722' },
{ StationID: 2, StationName: 'Fry', StationColor: '#FFC107' },
{ StationID: 3, StationName: 'Drinks', StationColor: '#2196F3' },
{ StationID: 4, StationName: 'Expo', StationColor: '#4CAF50' }
];
}
this.renderStations();
},
async loadItems() {
console.log('[StationAssignment] Loading items for BusinessID:', this.config.businessId);
try {
const response = await fetch(`${this.config.apiBaseUrl}/menu/items.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId })
});
console.log('[StationAssignment] Response status:', response.status);
const data = await response.json();
console.log('[StationAssignment] Response:', data);
if (data.OK) {
// Only top-level items (not modifiers) - look for items with categories
this.items = (data.Items || []).filter(item =>
item.ItemParentItemID === 0 || item.ItemCategoryID > 0
);
console.log('[StationAssignment] Filtered items count:', this.items.length);
// Build assignments from existing data
this.items.forEach(item => {
if (item.ItemStationID) {
this.assignments[item.ItemID] = item.ItemStationID;
}
});
} else {
console.error('[StationAssignment] API returned OK=false:', data.ERROR, data.MESSAGE);
}
} catch (err) {
console.error('[StationAssignment] Items error:', err);
// Demo items
this.items = [
{ ItemID: 1, ItemName: 'Cheeseburger', ItemPrice: 8.99, ItemCategoryName: 'Burgers' },
{ ItemID: 2, ItemName: 'Double-Double', ItemPrice: 10.99, ItemCategoryName: 'Burgers' },
{ ItemID: 3, ItemName: 'French Fries', ItemPrice: 3.99, ItemCategoryName: 'Sides' },
{ ItemID: 4, ItemName: 'Onion Rings', ItemPrice: 4.99, ItemCategoryName: 'Sides' },
{ ItemID: 5, ItemName: 'Chocolate Shake', ItemPrice: 5.99, ItemCategoryName: 'Drinks' },
{ ItemID: 6, ItemName: 'Lemonade', ItemPrice: 2.99, ItemCategoryName: 'Drinks' }
];
}
this.renderItems();
this.updateStationCounts();
},
renderItems() {
const container = document.getElementById('itemsList');
// Group by category
const categories = {};
this.items.forEach(item => {
const cat = item.ItemCategoryName || 'Uncategorized';
if (!categories[cat]) categories[cat] = [];
categories[cat].push(item);
});
// Filter
const filterLower = this.filterText.toLowerCase();
let html = '';
let visibleCount = 0;
Object.entries(categories).forEach(([catName, items]) => {
const filteredItems = items.filter(item =>
item.ItemName.toLowerCase().includes(filterLower) ||
catName.toLowerCase().includes(filterLower)
);
if (filteredItems.length === 0) return;
html += `<div class="category-group">`;
html += `<div class="category-label">${this.escapeHtml(catName)}</div>`;
filteredItems.forEach(item => {
const assigned = this.assignments[item.ItemID];
const station = assigned ? this.stations.find(s => s.StationID === assigned) : null;
visibleCount++;
html += `
<div class="draggable-item ${assigned ? 'assigned' : ''}"
draggable="true"
data-item-id="${item.ItemID}"
ondragstart="StationAssignment.onDragStart(event, ${item.ItemID})"
ondragend="StationAssignment.onDragEnd(event)">
<span class="item-icon">🍽️</span>
<div class="item-details">
<div class="item-name">${this.escapeHtml(item.ItemName)}</div>
<div class="item-price">$${(item.ItemPrice || 0).toFixed(2)}</div>
</div>
${station ? `<span class="item-station-badge" style="background: ${station.StationColor}">${this.escapeHtml(station.StationName)}</span>` : ''}
</div>
`;
});
html += `</div>`;
});
container.innerHTML = html || '<div class="empty-drop">No items found</div>';
document.getElementById('itemCount').textContent = `${visibleCount} items`;
},
renderStations() {
const container = document.getElementById('stationsGrid');
let html = '';
// Render each station
this.stations.forEach(station => {
const itemsInStation = this.items.filter(item =>
this.assignments[item.ItemID] === station.StationID
);
html += `
<div class="station-card"
data-station-id="${station.StationID}"
ondragover="StationAssignment.onDragOver(event)"
ondragleave="StationAssignment.onDragLeave(event)"
ondrop="StationAssignment.onDrop(event, ${station.StationID})">
<div class="station-header"
ondragover="StationAssignment.onDragOver(event)"
ondrop="StationAssignment.onDrop(event, ${station.StationID})">
<div class="station-color" style="background: ${station.StationColor}">
${station.StationName.charAt(0)}
</div>
<div class="station-info">
<div class="station-name">${this.escapeHtml(station.StationName)}</div>
<div class="station-count">${itemsInStation.length} items</div>
</div>
</div>
<div class="station-items ${itemsInStation.length === 0 ? 'empty' : ''}"
ondragover="StationAssignment.onDragOver(event)"
ondrop="StationAssignment.onDrop(event, ${station.StationID})">
${itemsInStation.length === 0 ?
'Drop items here' :
itemsInStation.map(item => `
<div class="station-item">
<span class="item-icon">🍽️</span>
<span class="item-name">${this.escapeHtml(item.ItemName)}</span>
<button class="remove-btn" onclick="StationAssignment.removeFromStation(${item.ItemID})" title="Remove">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M18 6L6 18M6 6l12 12"/>
</svg>
</button>
</div>
`).join('')
}
</div>
</div>
`;
});
// Unassigned station (optional - shows items without a station)
const unassignedItems = this.items.filter(item => !this.assignments[item.ItemID]);
if (unassignedItems.length > 0) {
html += `
<div class="station-card unassigned">
<div class="station-header">
<div class="station-color" style="background: #666">?</div>
<div class="station-info">
<div class="station-name">Unassigned</div>
<div class="station-count">${unassignedItems.length} items</div>
</div>
</div>
<div class="station-items">
${unassignedItems.slice(0, 5).map(item => `
<div class="station-item" style="opacity: 0.6;">
<span class="item-icon">🍽️</span>
<span class="item-name">${this.escapeHtml(item.ItemName)}</span>
</div>
`).join('')}
${unassignedItems.length > 5 ? `<div style="text-align: center; color: var(--text-muted); font-size: 13px;">+${unassignedItems.length - 5} more</div>` : ''}
</div>
</div>
`;
}
container.innerHTML = html || '<div class="empty-drop">No stations. Add a station to get started.</div>';
},
updateStationCounts() {
this.renderStations();
},
filterItems(text) {
this.filterText = text;
this.renderItems();
},
// Drag and drop handlers
onDragStart(event, itemId) {
console.log('[StationAssignment] Drag start, itemId:', itemId);
event.dataTransfer.setData('text/plain', itemId.toString());
event.dataTransfer.effectAllowed = 'move';
event.target.classList.add('dragging');
},
onDragEnd(event) {
console.log('[StationAssignment] Drag end');
event.target.classList.remove('dragging');
// Clean up any lingering drag-over classes
document.querySelectorAll('.drag-over').forEach(el => el.classList.remove('drag-over'));
},
onDragOver(event) {
event.preventDefault();
event.stopPropagation();
event.dataTransfer.dropEffect = 'move';
// Find the station card (might be triggered on child elements)
const stationCard = event.target.closest('.station-card');
if (stationCard) {
stationCard.classList.add('drag-over');
}
},
onDragLeave(event) {
// Only remove drag-over if actually leaving the station card
const stationCard = event.target.closest('.station-card');
const relatedTarget = event.relatedTarget;
if (stationCard && (!relatedTarget || !stationCard.contains(relatedTarget))) {
stationCard.classList.remove('drag-over');
}
},
onDrop(event, stationId) {
event.preventDefault();
event.stopPropagation();
console.log('[StationAssignment] Drop on station:', stationId);
// Find and clean up the station card
const stationCard = event.target.closest('.station-card');
if (stationCard) {
stationCard.classList.remove('drag-over');
}
const itemId = parseInt(event.dataTransfer.getData('text/plain'));
console.log('[StationAssignment] Dropped itemId:', itemId);
if (itemId) {
this.assignToStation(itemId, stationId);
}
},
assignToStation(itemId, stationId) {
this.assignments[itemId] = stationId;
this.renderItems();
this.renderStations();
const item = this.items.find(i => i.ItemID === itemId);
const station = this.stations.find(s => s.StationID === stationId);
if (item && station) {
this.toast(`${item.ItemName} assigned to ${station.StationName}`, 'success');
}
},
removeFromStation(itemId) {
delete this.assignments[itemId];
this.renderItems();
this.renderStations();
this.toast('Item removed from station', 'info');
},
async save() {
this.toast('Saving assignments...', 'info');
try {
// Build update payload
const updates = Object.entries(this.assignments).map(([itemId, stationId]) => ({
ItemID: parseInt(itemId),
StationID: stationId
}));
const response = await fetch(`${this.config.apiBaseUrl}/menu/updateStations.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
BusinessID: this.config.businessId,
Assignments: updates
})
});
const data = await response.json();
if (data.OK) {
this.toast('Assignments saved!', 'success');
} else {
this.toast(data.ERROR || 'Failed to save', 'error');
}
} catch (err) {
console.error('[StationAssignment] Save error:', err);
this.toast('Error saving (API not available)', 'error');
}
},
addStation() {
const name = prompt('Station name:');
if (!name) return;
const color = '#' + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0');
this.stations.push({
StationID: Date.now(),
StationName: name,
StationColor: color
});
this.renderStations();
this.toast(`Station "${name}" added`, 'success');
},
toast(message, type = 'info') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.textContent = message;
container.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
},
escapeHtml(str) {
if (!str) return '';
return String(str).replace(/[&<>"']/g, m => ({
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'
})[m]);
}
};
document.addEventListener('DOMContentLoaded', () => StationAssignment.init());
</script>
</body>
</html>