feat(manager): the overview, online orders and the day summary on v2 (platform-v2 step 6.2)
- DashboardPage (2.8k lines) → src/pages/overview/: OverviewPage + cards (shifts, tables, pending prints, notes, bookings, messages) and dialogs (order at a glance, shift review / end with the cash handover, day summary with cash count and checks); arithmetic in overviewLogic.js (tests/overview.test.mjs). Data via useLiveQuery: orders and tables live, day and shifts every 15 s. Bookings typed in venue time; decline reason in a dialog. - OnlineOrdersPage → src/pages/online/ on react-query + live events; unused API helpers dropped. - WorkdaySummaryModal → overview/DaySummaryDialog + DaySummaryTabs. - Every text in manager.json (en + el, 342 keys); tokens only; v2.json adds overview, hooks. - Backend: business day open/close answer only with codes (license.locked, license.expired, business_day.orders_open); XeniaError's v1 `detail` removed. - @xenia/i18n: formatDateTime with Intl options threw "unknown date style" (fixed, tested). - e2e manager.mjs: open the day, a shift (start, stats, end short), a live table, a booking, day stats, Greek, close the day (forced), online orders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -263,13 +263,12 @@ CODES: dict[str, tuple[int, str]] = {
|
|||||||
class XeniaError(Exception):
|
class XeniaError(Exception):
|
||||||
"""An API error with a registered code. raise XeniaError("order.not_found", order_id=5)."""
|
"""An API error with a registered code. raise XeniaError("order.not_found", order_id=5)."""
|
||||||
|
|
||||||
def __init__(self, code: str, status: int | None = None, *, detail=None, **params):
|
def __init__(self, code: str, status: int | None = None, **params):
|
||||||
if code not in CODES:
|
if code not in CODES:
|
||||||
raise KeyError(f"unregistered error code {code!r}: add it to core/errors.py CODES")
|
raise KeyError(f"unregistered error code {code!r}: add it to core/errors.py CODES")
|
||||||
default_status, template = CODES[code]
|
default_status, template = CODES[code]
|
||||||
self.code = code
|
self.code = code
|
||||||
self.status = status or default_status
|
self.status = status or default_status
|
||||||
self.detail = detail # v1-shaped `detail` some old pages still read (6.x removes)
|
|
||||||
self.params = params
|
self.params = params
|
||||||
try:
|
try:
|
||||||
self.message = template.format(**params)
|
self.message = template.format(**params)
|
||||||
@@ -284,7 +283,7 @@ def error_body(code: str, message: str, params: dict | None = None, detail=None)
|
|||||||
|
|
||||||
|
|
||||||
async def _xenia_error_handler(request: Request, exc: XeniaError):
|
async def _xenia_error_handler(request: Request, exc: XeniaError):
|
||||||
return JSONResponse(error_body(exc.code, exc.message, exc.params, detail=exc.detail), status_code=exc.status)
|
return JSONResponse(error_body(exc.code, exc.message, exc.params), status_code=exc.status)
|
||||||
|
|
||||||
|
|
||||||
async def _http_exception_handler(request: Request, exc: StarletteHTTPException):
|
async def _http_exception_handler(request: Request, exc: StarletteHTTPException):
|
||||||
|
|||||||
@@ -49,19 +49,11 @@ def open_business_day(
|
|||||||
|
|
||||||
# Gate: admin lock (already enforced or pending)
|
# Gate: admin lock (already enforced or pending)
|
||||||
if license_state.get("locked") or license_state.get("lock_pending"):
|
if license_state.get("locked") or license_state.get("lock_pending"):
|
||||||
raise XeniaError("license.locked", detail={
|
raise XeniaError("license.locked")
|
||||||
"code": "SYSTEM_LOCKED",
|
|
||||||
"message": "Το σύστημα έχει κλειδωθεί από διαχειριστή. Επικοινωνήστε με την υποστήριξη.",
|
|
||||||
})
|
|
||||||
|
|
||||||
# Gate: license expired and expiry grace period also over
|
# Gate: license expired and expiry grace period also over
|
||||||
if not license_state.get("licensed", True):
|
if not license_state.get("licensed", True):
|
||||||
expires_at = license_state.get("expires_at", "")
|
raise XeniaError("license.expired")
|
||||||
raise XeniaError("license.expired", detail={
|
|
||||||
"code": "LICENSE_EXPIRED",
|
|
||||||
"message": "Η άδεια χρήσης έχει λήξει. Ανανεώστε την άδεια ή επικοινωνήστε με την υποστήριξη.",
|
|
||||||
"expires_at": expires_at,
|
|
||||||
})
|
|
||||||
|
|
||||||
opened_at = utcnow()
|
opened_at = utcnow()
|
||||||
day = BusinessDay(opened_by_id=user.id, notes=body.notes,
|
day = BusinessDay(opened_by_id=user.id, notes=body.notes,
|
||||||
@@ -97,11 +89,7 @@ def close_business_day(
|
|||||||
OrderItem.status == "active",
|
OrderItem.status == "active",
|
||||||
).first() is not None
|
).first() is not None
|
||||||
)
|
)
|
||||||
raise XeniaError("business_day.orders_open", detail={
|
raise XeniaError("business_day.orders_open", open_orders=len(open_orders), partially_paid=with_pending)
|
||||||
"message": f"{len(open_orders)} table(s) still open, {with_pending} with unpaid items.",
|
|
||||||
"open_orders": len(open_orders),
|
|
||||||
"partially_paid": with_pending,
|
|
||||||
}, open_orders=len(open_orders), partially_paid=with_pending)
|
|
||||||
|
|
||||||
now = utcnow()
|
now = utcnow()
|
||||||
|
|
||||||
|
|||||||
@@ -110,17 +110,3 @@ def test_backend_code_raises_codes_not_http_exceptions():
|
|||||||
for n, line in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
|
for n, line in enumerate(p.read_text(encoding="utf-8").splitlines(), 1)
|
||||||
if re.search(r"\bHTTPException\s*\(", line)]
|
if re.search(r"\bHTTPException\s*\(", line)]
|
||||||
assert found == [], "use XeniaError (core/errors.py) instead: " + ", ".join(found)
|
assert found == [], "use XeniaError (core/errors.py) instead: " + ", ".join(found)
|
||||||
|
|
||||||
|
|
||||||
def test_a_code_can_keep_a_v1_shaped_detail():
|
|
||||||
app = FastAPI()
|
|
||||||
install_error_handlers(app)
|
|
||||||
|
|
||||||
@app.get("/x")
|
|
||||||
def x():
|
|
||||||
raise XeniaError("business_day.orders_open", open_orders=2, partially_paid=1,
|
|
||||||
detail={"message": "2 tables open", "open_orders": 2, "partially_paid": 1})
|
|
||||||
|
|
||||||
body = TestClient(app).get("/x").json()
|
|
||||||
assert body["error"]["code"] == "business_day.orders_open" and body["error"]["params"] == {"open_orders": 2, "partially_paid": 1}
|
|
||||||
assert body["detail"]["open_orders"] == 2
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import LoginPage from './pages/LoginPage'
|
|||||||
import SetupWizard from './pages/SetupWizard'
|
import SetupWizard from './pages/SetupWizard'
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
import DashboardPage from './pages/DashboardPage'
|
import OverviewPage from './pages/overview/OverviewPage'
|
||||||
import TablesPage from './pages/TablesPage'
|
import TablesPage from './pages/TablesPage'
|
||||||
import OrderDetailPage from './pages/OrderDetailPage'
|
import OrderDetailPage from './pages/OrderDetailPage'
|
||||||
import OnlineOrdersPage from './pages/OnlineOrdersPage'
|
import OnlineOrdersPage from './pages/online/OnlineOrdersPage'
|
||||||
import FeesPage from './pages/online/FeesPage'
|
import FeesPage from './pages/online/FeesPage'
|
||||||
import QrCodesPage from './pages/online/QrCodesPage'
|
import QrCodesPage from './pages/online/QrCodesPage'
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ export default function App() {
|
|||||||
<Route index element={<Navigate to="/dashboard" replace />} />
|
<Route index element={<Navigate to="/dashboard" replace />} />
|
||||||
|
|
||||||
{/* ── Operation ── */}
|
{/* ── Operation ── */}
|
||||||
<Route path="dashboard" element={<DashboardPage />} />
|
<Route path="dashboard" element={<OverviewPage />} />
|
||||||
<Route path="tables" element={<TablesPage />} />
|
<Route path="tables" element={<TablesPage />} />
|
||||||
<Route path="online-orders" element={<OnlineOrdersPage />} />
|
<Route path="online-orders" element={<OnlineOrdersPage />} />
|
||||||
<Route path="online/fees" element={<FeesPage />} />
|
<Route path="online/fees" element={<FeesPage />} />
|
||||||
|
|||||||
@@ -25,15 +25,4 @@ export default client
|
|||||||
|
|
||||||
// ── Online Orders (Xenia Connect) ─────────────────────────────────────────────
|
// ── Online Orders (Xenia Connect) ─────────────────────────────────────────────
|
||||||
|
|
||||||
export const getIncomingOrders = () => client.get('/api/connect/orders/incoming')
|
export const getIncomingOrders = () => client.get('/api/connect/orders/incoming') // the sidebar's badge
|
||||||
export const getActiveOrders = () => client.get('/api/connect/orders?status=active')
|
|
||||||
export const getOrderHistory = () => client.get('/api/connect/orders?status=history')
|
|
||||||
|
|
||||||
export const acceptOnlineOrder = (id) =>
|
|
||||||
client.post(`/api/connect/orders/${id}/accept`)
|
|
||||||
|
|
||||||
export const rejectOnlineOrder = (id, reason) =>
|
|
||||||
client.post(`/api/connect/orders/${id}/reject`, { reason })
|
|
||||||
|
|
||||||
export const updateOnlineOrderStatus = (id, status) =>
|
|
||||||
client.post(`/api/connect/orders/${id}/status`, { status })
|
|
||||||
|
|||||||
@@ -1,907 +0,0 @@
|
|||||||
import { useState } from 'react'
|
|
||||||
import { useQuery } from '@tanstack/react-query'
|
|
||||||
import toast from 'react-hot-toast'
|
|
||||||
import client from '../api/client'
|
|
||||||
|
|
||||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function fmt(n) {
|
|
||||||
if (n == null) return '—'
|
|
||||||
return n.toLocaleString('el-GR', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) + ' €'
|
|
||||||
}
|
|
||||||
|
|
||||||
function fmtTime(iso) {
|
|
||||||
if (!iso) return '—'
|
|
||||||
return new Date(iso).toLocaleTimeString('el-GR', { hour: '2-digit', minute: '2-digit' })
|
|
||||||
}
|
|
||||||
|
|
||||||
function fmtDateTime(iso) {
|
|
||||||
if (!iso) return '—'
|
|
||||||
const d = new Date(iso)
|
|
||||||
return d.toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })
|
|
||||||
}
|
|
||||||
|
|
||||||
const MANAGER_ROLES = new Set(['superadmin', 'owner', 'store_manager', 'staff_manager'])
|
|
||||||
function roleBadge(role) {
|
|
||||||
if (MANAGER_ROLES.has(role)) {
|
|
||||||
return { label: 'Διευθυντής', bg: '#ede9fe', color: '#6d28d9' }
|
|
||||||
}
|
|
||||||
return { label: 'Σερβιτόρος', bg: '#e0f2fe', color: '#0369a1' }
|
|
||||||
}
|
|
||||||
|
|
||||||
// All payment methods with their display config
|
|
||||||
const PAY_METHODS = [
|
|
||||||
{ key: 'cash', label: 'Μετρητά', color: '#16a34a', bg: '#dcfce7' },
|
|
||||||
{ key: 'card', label: 'Κάρτα', color: '#2563eb', bg: '#dbeafe' },
|
|
||||||
{ key: 'transfer', label: 'Τρ. Μεταφ.', color: '#7c3aed', bg: '#ede9fe' },
|
|
||||||
{ key: 'treat', label: 'Κεράστηκε', color: '#b45309', bg: '#fef3c7' },
|
|
||||||
{ key: 'other', label: 'Άλλο', color: '#6b7280', bg: '#f3f4f6' },
|
|
||||||
]
|
|
||||||
|
|
||||||
// ── Sub-components ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function TabBtn({ label, active, onClick, badge, warn }) {
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
onClick={onClick}
|
|
||||||
style={{
|
|
||||||
padding: '9px 18px',
|
|
||||||
border: 'none',
|
|
||||||
background: 'none',
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: active ? 700 : 500,
|
|
||||||
color: active ? '#111315' : '#6b7280',
|
|
||||||
cursor: 'pointer',
|
|
||||||
borderBottom: active ? '2px solid #111315' : '2px solid transparent',
|
|
||||||
transition: 'all 150ms',
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 6,
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
{badge != null && (
|
|
||||||
<span style={{
|
|
||||||
minWidth: 18, height: 18, borderRadius: 99,
|
|
||||||
background: warn ? '#fee2e2' : '#f3f4f6',
|
|
||||||
color: warn ? '#dc2626' : '#374151',
|
|
||||||
fontSize: 11, fontWeight: 700,
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
||||||
padding: '0 5px',
|
|
||||||
}}>{badge}</span>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function StatPill({ label, value, accent = '#374151' }) {
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
background: '#f9fafb', border: '1px solid #f0f0ef',
|
|
||||||
borderRadius: 10, padding: '12px 16px',
|
|
||||||
display: 'flex', flexDirection: 'column', gap: 2,
|
|
||||||
}}>
|
|
||||||
<span style={{ fontSize: 11, color: '#9ca3af', fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.04em' }}>{label}</span>
|
|
||||||
<span style={{ fontSize: 22, fontWeight: 800, color: accent, letterSpacing: '-0.02em' }}>{value}</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function SectionTitle({ children }) {
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
fontSize: 11, fontWeight: 700, color: '#9ca3af',
|
|
||||||
textTransform: 'uppercase', letterSpacing: '0.06em',
|
|
||||||
marginBottom: 10,
|
|
||||||
}}>{children}</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function PaymentBar({ w, total }) {
|
|
||||||
if (!total) return null
|
|
||||||
const bars = PAY_METHODS.filter(m => (w[m.key] || 0) > 0)
|
|
||||||
if (bars.length === 0) return null
|
|
||||||
return (
|
|
||||||
<div style={{ marginTop: 6 }}>
|
|
||||||
<div style={{ display: 'flex', height: 7, borderRadius: 99, overflow: 'hidden', gap: 1 }}>
|
|
||||||
{bars.map(m => (
|
|
||||||
<div key={m.key} style={{ flex: w[m.key], background: m.color }}
|
|
||||||
title={`${m.label}: ${Math.round((w[m.key] / total) * 100)}%`} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div style={{ display: 'flex', gap: 10, marginTop: 5, flexWrap: 'wrap' }}>
|
|
||||||
{bars.map(m => (
|
|
||||||
<span key={m.key} style={{ fontSize: 10, color: m.color, fontWeight: 700 }}>
|
|
||||||
● {m.label} {fmt(w[m.key])}
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Tabs ──────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function FinancialRow({ label, value, sub, accent, warn, indent = false }) {
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
|
|
||||||
padding: indent ? '4px 0 4px 16px' : '5px 0',
|
|
||||||
borderBottom: indent ? 'none' : '1px solid #f9fafb',
|
|
||||||
}}>
|
|
||||||
<span style={{ fontSize: indent ? 12 : 13, color: warn ? '#d97706' : indent ? '#6b7280' : '#374151', flex: 1 }}>
|
|
||||||
{warn && <span style={{ marginRight: 5 }}>⚠</span>}{label}
|
|
||||||
</span>
|
|
||||||
<div style={{ textAlign: 'right', flexShrink: 0 }}>
|
|
||||||
<span style={{ fontSize: indent ? 12 : 13.5, fontWeight: indent ? 500 : 700, color: accent || '#111315', fontVariantNumeric: 'tabular-nums' }}>
|
|
||||||
{value}
|
|
||||||
</span>
|
|
||||||
{sub && <div style={{ fontSize: 10.5, color: '#9ca3af' }}>{sub}</div>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function OverviewTab({ data }) {
|
|
||||||
const waiters = data.waiters.filter(w => w.role === 'waiter')
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
|
|
||||||
{/* Top stats */}
|
|
||||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 10 }}>
|
|
||||||
<StatPill label="Συνολικά Έσοδα" value={fmt(data.total_revenue)} accent="#111315" />
|
|
||||||
<StatPill label="Παραγγελίες" value={String(data.total_orders)} accent="#3758c9" />
|
|
||||||
<StatPill label="Αντικείμενα" value={String(data.total_items_ordered)} accent="#7a44c9" />
|
|
||||||
<StatPill label="Σερβιτόροι" value={String(waiters.length)} accent="#0d7a8a" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Hours */}
|
|
||||||
<div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
|
|
||||||
<div style={{ background: '#f9fafb', border: '1px solid #f0f0ef', borderRadius: 10, padding: '10px 14px', flex: 1, minWidth: 130 }}>
|
|
||||||
<div style={{ fontSize: 10, color: '#9ca3af', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.04em' }}>ΑΝΟΙΓΜΑ</div>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, marginTop: 2 }}>{fmtDateTime(data.opened_at)}</div>
|
|
||||||
</div>
|
|
||||||
<div style={{ background: '#f9fafb', border: '1px solid #f0f0ef', borderRadius: 10, padding: '10px 14px', flex: 1, minWidth: 130 }}>
|
|
||||||
<div style={{ fontSize: 10, color: '#9ca3af', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.04em' }}>ΚΛΕΙΣΙΜΟ</div>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, marginTop: 2 }}>
|
|
||||||
{data.closed_at ? fmtDateTime(data.closed_at) : <span style={{ color: '#16a34a' }}>Ημέρα Ενεργή</span>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Full P&L */}
|
|
||||||
<div style={{ border: '1px solid #e5e7eb', borderRadius: 12, overflow: 'hidden' }}>
|
|
||||||
{/* REVENUE */}
|
|
||||||
<div style={{ padding: '10px 16px', background: '#f9fafb', borderBottom: '1px solid #e5e7eb' }}>
|
|
||||||
<SectionTitle>Έσοδα</SectionTitle>
|
|
||||||
<FinancialRow label="Σύνολο πωλήσεων" value={fmt(data.total_revenue)} accent="#111315" />
|
|
||||||
{data.tabbed_revenue > 0 && (
|
|
||||||
<FinancialRow label="Καρτέλες (μη εισπραχθέντα)" value={`− ${fmt(data.tabbed_revenue)}`} accent="#d97706" indent />
|
|
||||||
)}
|
|
||||||
<FinancialRow
|
|
||||||
label="Καθαρά εισπραχθέντα"
|
|
||||||
value={fmt(data.total_revenue - (data.tabbed_revenue || 0))}
|
|
||||||
accent="#16a34a"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* COGS */}
|
|
||||||
<div style={{ padding: '10px 16px', borderBottom: '1px solid #e5e7eb' }}>
|
|
||||||
<SectionTitle>Κόστος Πωληθέντων (COGS)</SectionTitle>
|
|
||||||
<FinancialRow label="Κόστος καταγεγραμμένων" value={fmt(data.cogs_trackable)} accent="#374151" />
|
|
||||||
{data.cogs_has_gap && (
|
|
||||||
<FinancialRow
|
|
||||||
label={`${data.cogs_uncosted_count} αντ. χωρίς κόστος (${fmt(data.cogs_uncosted_revenue)} έσοδα)`}
|
|
||||||
value="?" warn indent
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<FinancialRow
|
|
||||||
label="Μικτό κέρδος"
|
|
||||||
value={fmt(data.gross_profit)}
|
|
||||||
accent={data.gross_profit >= 0 ? '#16a34a' : '#dc2626'}
|
|
||||||
warn={data.cogs_has_gap}
|
|
||||||
sub={data.cogs_has_gap ? 'Μερικό — υπάρχουν αντ. χωρίς κόστος' : undefined}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* LABOR */}
|
|
||||||
<div style={{ padding: '10px 16px', borderBottom: '1px solid #e5e7eb' }}>
|
|
||||||
<SectionTitle>Μισθοδοσία</SectionTitle>
|
|
||||||
<FinancialRow label="Κόστος εργασίας (καταγεγρ.)" value={fmt(data.total_labor_cost)} accent="#374151" />
|
|
||||||
{data.labor_untracked_shifts > 0 && (
|
|
||||||
<FinancialRow label={`${data.labor_untracked_shifts} βάρδιες χωρίς ωριαία αμοιβή`} value="?" warn indent />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* WASTE */}
|
|
||||||
{(data.waste_item_count > 0) && (
|
|
||||||
<div style={{ padding: '10px 16px', borderBottom: '1px solid #e5e7eb' }}>
|
|
||||||
<SectionTitle>Αποβλήτα</SectionTitle>
|
|
||||||
<FinancialRow
|
|
||||||
label={`${data.waste_item_count} καταχωρήσεις`}
|
|
||||||
value={fmt(data.waste_estimated_cost)}
|
|
||||||
accent="#d97706"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* EXPENSES */}
|
|
||||||
{data.expenses_total > 0 && (
|
|
||||||
<div style={{ padding: '10px 16px', borderBottom: '1px solid #e5e7eb' }}>
|
|
||||||
<SectionTitle>Έξοδα (σήμερα)</SectionTitle>
|
|
||||||
<FinancialRow label="Σύνολο εξόδων" value={fmt(data.expenses_total)} accent="#374151" />
|
|
||||||
<FinancialRow label="Πλη��ωμένα σήμερα" value={fmt(data.expenses_paid_today)} accent="#374151" indent />
|
|
||||||
{data.expenses_due > 0 && (
|
|
||||||
<FinancialRow label="Ακόμη οφείλονται" value={fmt(data.expenses_due)} accent="#dc2626" warn indent />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* NET */}
|
|
||||||
<div style={{ padding: '12px 16px', background: '#f9fafb' }}>
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
||||||
<div>
|
|
||||||
<div style={{ fontSize: 13, fontWeight: 700, color: '#374151' }}>
|
|
||||||
Εκτιμώμενο Καθαρό Αποτέλεσμα
|
|
||||||
</div>
|
|
||||||
{data.net_has_unknowns && (
|
|
||||||
<div style={{ fontSize: 11, color: '#d97706', marginTop: 1 }}>
|
|
||||||
⚠ Μερικό — υπάρχουν άγνωστα κόστη
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div style={{
|
|
||||||
fontSize: 20, fontWeight: 800,
|
|
||||||
color: data.net_estimate >= 0 ? '#16a34a' : '#dc2626',
|
|
||||||
fontVariantNumeric: 'tabular-nums',
|
|
||||||
}}>
|
|
||||||
{fmt(data.net_estimate)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Payment breakdown */}
|
|
||||||
<div>
|
|
||||||
<SectionTitle>Κατανομή Πληρωμών</SectionTitle>
|
|
||||||
<div style={{ background: '#f9fafb', border: '1px solid #f0f0ef', borderRadius: 10, padding: '14px 16px' }}>
|
|
||||||
{(() => {
|
|
||||||
const totals = { cash: 0, card: 0, transfer: 0, treat: 0, other: 0 }
|
|
||||||
for (const w of data.waiters) {
|
|
||||||
for (const k of Object.keys(totals)) totals[k] += (w[k] || 0)
|
|
||||||
}
|
|
||||||
return <PaymentBar w={totals} total={data.total_revenue} />
|
|
||||||
})()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Cash reconciliation summary (if counted) */}
|
|
||||||
{data.store_closing_cash != null && (
|
|
||||||
<div>
|
|
||||||
<SectionTitle>Ταμείο</SectionTitle>
|
|
||||||
<div style={{ background: '#f9fafb', border: '1px solid #f0f0ef', borderRadius: 10, padding: '14px 16px', display: 'flex', flexDirection: 'column', gap: 6 }}>
|
|
||||||
<FinancialRow label="Αναμενόμενο ταμείο" value={fmt(data.store_expected_closing)} />
|
|
||||||
<FinancialRow label="Μετρημένο ταμείο" value={fmt(data.store_closing_cash)} />
|
|
||||||
<FinancialRow
|
|
||||||
label="Διαφορά"
|
|
||||||
value={data.store_cash_discrepancy === 0 ? '✓ Εντάξει' : fmt(data.store_cash_discrepancy)}
|
|
||||||
accent={data.store_cash_discrepancy === 0 ? '#16a34a' : '#dc2626'}
|
|
||||||
warn={data.store_cash_discrepancy !== 0}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function WaitersTab({ data }) {
|
|
||||||
const [expanded, setExpanded] = useState(null)
|
|
||||||
|
|
||||||
// Fixed column widths for the collapsed summary row
|
|
||||||
const colPx = { orders: 88, tables: 88, items: 80, collected: 104 }
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
||||||
{data.waiters.length === 0 && (
|
|
||||||
<div style={{ textAlign: 'center', color: '#9ca3af', fontSize: 13, padding: '32px 0' }}>Δεν βρέθηκαν σερβιτόροι</div>
|
|
||||||
)}
|
|
||||||
{data.waiters.map(w => {
|
|
||||||
const badge = roleBadge(w.role)
|
|
||||||
const isOpen = expanded === w.waiter_id
|
|
||||||
|
|
||||||
// Compute current cash in drawer: starting_cash + collected so far
|
|
||||||
const drawerNow = (w.starting_cash ?? 0) + (w.total_collected ?? 0)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={w.waiter_id} style={{
|
|
||||||
border: '1px solid #e5e7eb', borderRadius: 12, overflow: 'hidden',
|
|
||||||
}}>
|
|
||||||
<button
|
|
||||||
onClick={() => setExpanded(isOpen ? null : w.waiter_id)}
|
|
||||||
style={{
|
|
||||||
width: '100%', background: 'white', border: 'none', cursor: 'pointer',
|
|
||||||
padding: '14px 18px', display: 'flex', alignItems: 'center', gap: 12, textAlign: 'left',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{/* Avatar */}
|
|
||||||
<div style={{
|
|
||||||
width: 38, height: 38, borderRadius: 10, flexShrink: 0,
|
|
||||||
background: badge.bg, color: badge.color,
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
||||||
fontSize: 15, fontWeight: 800,
|
|
||||||
}}>
|
|
||||||
{w.waiter_name.charAt(0).toUpperCase()}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Name + role */}
|
|
||||||
<div style={{ flex: 1, minWidth: 0 }}>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#111315' }}>{w.waiter_name}</div>
|
|
||||||
<span style={{
|
|
||||||
fontSize: 10, fontWeight: 700, padding: '1px 6px', borderRadius: 99,
|
|
||||||
background: badge.bg, color: badge.color,
|
|
||||||
}}>{badge.label}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 4 fixed-width metric columns */}
|
|
||||||
<div style={{ display: 'flex', gap: 4, flexShrink: 0 }}>
|
|
||||||
{[
|
|
||||||
{ label: 'ΠΑΡΑΓΓΕΛΙΕΣ', value: w.orders_opened, width: colPx.orders, color: '#111315' },
|
|
||||||
{ label: 'ΕΞ. ΤΡΑΠΕΖΙΩΝ', value: w.tables_served ?? 0, width: colPx.tables, color: '#111315' },
|
|
||||||
{ label: 'ΑΝΤΙΚ. ΕΙΣΠΡ.', value: w.items_paid, width: colPx.items, color: '#111315' },
|
|
||||||
{ label: 'ΕΙΣΠΡΑΞΗ', value: fmt(w.total_collected), width: colPx.collected, color: '#16a34a' },
|
|
||||||
].map(col => (
|
|
||||||
<div key={col.label} style={{
|
|
||||||
width: col.width, flexShrink: 0, textAlign: 'right', padding: '0 6px',
|
|
||||||
}}>
|
|
||||||
<div style={{ fontSize: 10, color: '#9ca3af', fontWeight: 600, whiteSpace: 'nowrap' }}>{col.label}</div>
|
|
||||||
<div style={{ fontSize: 15, fontWeight: 800, color: col.color, whiteSpace: 'nowrap' }}>{col.value}</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Chevron */}
|
|
||||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#9ca3af" strokeWidth="2.5"
|
|
||||||
strokeLinecap="round" strokeLinejoin="round"
|
|
||||||
style={{ flexShrink: 0, transform: isOpen ? 'rotate(180deg)' : 'none', transition: 'transform 200ms' }}>
|
|
||||||
<polyline points="6 9 12 15 18 9" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{isOpen && (
|
|
||||||
<div style={{ borderTop: '1px solid #f0f0ef', background: '#fafafa', padding: '14px 18px', display: 'flex', flexDirection: 'column', gap: 8 }}>
|
|
||||||
{/* Row 1: shift timing + payroll */}
|
|
||||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
|
|
||||||
{[
|
|
||||||
{ label: 'ΕΝΑΡΞΗ ΒΑΡΔΙΑΣ', value: fmtTime(w.shift_started_at), color: '#111315' },
|
|
||||||
{
|
|
||||||
label: 'ΛΗΞΗ ΒΑΡΔΙΑΣ',
|
|
||||||
value: w.shift_ended_at ? fmtTime(w.shift_ended_at) : 'Βάρδια Ενεργή',
|
|
||||||
color: w.shift_ended_at ? '#111315' : '#16a34a',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'ΜΙΣΘΟΣ / ΩΡΑ',
|
|
||||||
value: w.hourly_rate_snapshot != null ? fmt(w.hourly_rate_snapshot) : '—',
|
|
||||||
color: '#111315',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'ΜΙΣΘΟΣ (εως τώρα)',
|
|
||||||
value: w.shift_pay != null ? fmt(w.shift_pay) : 'Δεν παρακολ.',
|
|
||||||
color: w.shift_pay != null ? '#059669' : '#9ca3af',
|
|
||||||
},
|
|
||||||
].map(cell => (
|
|
||||||
<div key={cell.label} style={{ background: 'white', border: '1px solid #e5e7eb', borderRadius: 8, padding: '9px 12px' }}>
|
|
||||||
<div style={{ fontSize: 10, color: '#9ca3af', fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{cell.label}</div>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: cell.color, marginTop: 2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{cell.value}</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
{/* Row 2: cash + collections */}
|
|
||||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 8 }}>
|
|
||||||
{[
|
|
||||||
{
|
|
||||||
label: 'ΑΡΧΙΚΑ ΜΕΤΡΗΤΑ',
|
|
||||||
value: w.starting_cash != null ? fmt(w.starting_cash) : '—',
|
|
||||||
color: '#111315',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'ΤΑΜΕΙΟ ΤΩΡΑ',
|
|
||||||
value: fmt(drawerNow),
|
|
||||||
color: '#3758c9',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'ΑΝΤΙΚ. ΕΙΣΠΡ.',
|
|
||||||
value: w.items_paid,
|
|
||||||
color: '#111315',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'ΕΞ. ΤΡΑΠΕΖΙΩΝ',
|
|
||||||
value: w.tables_served ?? 0,
|
|
||||||
color: '#111315',
|
|
||||||
},
|
|
||||||
].map(cell => (
|
|
||||||
<div key={cell.label} style={{ background: 'white', border: '1px solid #e5e7eb', borderRadius: 8, padding: '9px 12px' }}>
|
|
||||||
<div style={{ fontSize: 10, color: '#9ca3af', fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{cell.label}</div>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: cell.color, marginTop: 2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{cell.value}</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<PaymentBar w={w} total={w.total_collected} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ZonesTab({ data }) {
|
|
||||||
const maxRev = Math.max(...data.zones.map(z => z.revenue), 1)
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
|
||||||
{data.zones.length === 0 && (
|
|
||||||
<div style={{ textAlign: 'center', color: '#9ca3af', fontSize: 13, padding: '32px 0' }}>Δεν βρέθηκαν ζώνες</div>
|
|
||||||
)}
|
|
||||||
{data.zones.map(z => (
|
|
||||||
<div key={z.group_id} style={{
|
|
||||||
border: '1px solid #e5e7eb', borderRadius: 12,
|
|
||||||
padding: '16px 18px', background: 'white',
|
|
||||||
}}>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 10 }}>
|
|
||||||
<div style={{
|
|
||||||
width: 12, height: 12, borderRadius: 3, flexShrink: 0,
|
|
||||||
background: z.color || '#9ca3af',
|
|
||||||
}} />
|
|
||||||
<span style={{ fontSize: 14, fontWeight: 700, color: '#111315', flex: 1 }}>{z.group_name}</span>
|
|
||||||
<span style={{ fontSize: 20, fontWeight: 800, color: '#111315' }}>{fmt(z.revenue)}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ height: 6, background: '#f3f4f6', borderRadius: 99, marginBottom: 12, overflow: 'hidden' }}>
|
|
||||||
<div style={{
|
|
||||||
height: '100%', borderRadius: 99,
|
|
||||||
background: z.color || '#9ca3af',
|
|
||||||
width: `${Math.round((z.revenue / maxRev) * 100)}%`,
|
|
||||||
transition: 'width 400ms ease',
|
|
||||||
}} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: 20 }}>
|
|
||||||
<div>
|
|
||||||
<span style={{ fontSize: 11, color: '#9ca3af', fontWeight: 600 }}>ΠΑΡΑΓΓΕΛΙΕΣ </span>
|
|
||||||
<span style={{ fontSize: 14, fontWeight: 700 }}>{z.orders}</span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span style={{ fontSize: 11, color: '#9ca3af', fontWeight: 600 }}>ΑΝΤΙΚΕΙΜΕΝΑ </span>
|
|
||||||
<span style={{ fontSize: 14, fontWeight: 700 }}>{z.items}</span>
|
|
||||||
</div>
|
|
||||||
{z.orders > 0 && (
|
|
||||||
<div>
|
|
||||||
<span style={{ fontSize: 11, color: '#9ca3af', fontWeight: 600 }}>Μ.Ο./ΠΑΡΑΓ. </span>
|
|
||||||
<span style={{ fontSize: 14, fontWeight: 700 }}>{fmt(z.revenue / z.orders)}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function PrintersTab({ data }) {
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
|
||||||
{data.printers.length === 0 && (
|
|
||||||
<div style={{ textAlign: 'center', color: '#9ca3af', fontSize: 13, padding: '32px 0' }}>Δεν βρέθηκαν δεδομένα εκτύπωσης</div>
|
|
||||||
)}
|
|
||||||
{data.printers.map(p => {
|
|
||||||
const successRate = p.jobs > 0 ? Math.round((p.success / p.jobs) * 100) : 0
|
|
||||||
return (
|
|
||||||
<div key={p.printer_id} style={{
|
|
||||||
border: '1px solid #e5e7eb', borderRadius: 12,
|
|
||||||
padding: '16px 18px', background: 'white',
|
|
||||||
}}>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 12 }}>
|
|
||||||
<div style={{
|
|
||||||
width: 36, height: 36, borderRadius: 9, flexShrink: 0,
|
|
||||||
background: '#f3f4f6', display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
||||||
}}>
|
|
||||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#6b7280" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
||||||
<polyline points="6 9 6 2 18 2 18 9" />
|
|
||||||
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2" />
|
|
||||||
<rect x="6" y="14" width="12" height="8" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1 }}>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#111315' }}>{p.printer_name}</div>
|
|
||||||
<div style={{ fontSize: 11, color: '#9ca3af' }}>{p.ip_address}</div>
|
|
||||||
</div>
|
|
||||||
<div style={{ textAlign: 'right' }}>
|
|
||||||
<div style={{ fontSize: 18, fontWeight: 800, color: '#111315' }}>{fmt(p.items_value)}</div>
|
|
||||||
<div style={{ fontSize: 11, color: '#9ca3af', marginTop: 1 }}>αξία εκτυπ.</div>
|
|
||||||
</div>
|
|
||||||
<span style={{
|
|
||||||
fontSize: 12, fontWeight: 700, padding: '3px 10px', borderRadius: 99, marginLeft: 4,
|
|
||||||
background: successRate === 100 ? '#dcfce7' : successRate >= 80 ? '#fef9c3' : '#fee2e2',
|
|
||||||
color: successRate === 100 ? '#16a34a' : successRate >= 80 ? '#a16207' : '#dc2626',
|
|
||||||
}}>{successRate}%</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ height: 6, background: '#f3f4f6', borderRadius: 99, marginBottom: 12, overflow: 'hidden' }}>
|
|
||||||
<div style={{ height: '100%', display: 'flex' }}>
|
|
||||||
<div style={{ flex: p.success, background: '#16a34a' }} />
|
|
||||||
<div style={{ flex: p.failed, background: '#dc2626' }} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: 20 }}>
|
|
||||||
<div><span style={{ fontSize: 11, color: '#9ca3af', fontWeight: 600 }}>ΕΡΓΑΣΙΕΣ </span><span style={{ fontSize: 14, fontWeight: 700 }}>{p.jobs}</span></div>
|
|
||||||
<div><span style={{ fontSize: 11, color: '#16a34a', fontWeight: 600 }}>ΕΠΙΤΥΧΕΙΣ </span><span style={{ fontSize: 14, fontWeight: 700 }}>{p.success}</span></div>
|
|
||||||
{p.failed > 0 && <div><span style={{ fontSize: 11, color: '#dc2626', fontWeight: 600 }}>ΑΠΟΤΥΧΕΣ </span><span style={{ fontSize: 14, fontWeight: 700 }}>{p.failed}</span></div>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function CashReconciliationTab({ data, storeCash, onStoreCashChange }) {
|
|
||||||
const expected = data.store_expected_closing ?? 0
|
|
||||||
const counted = storeCash !== '' ? parseFloat(storeCash) : null
|
|
||||||
const discrepancy = counted != null ? counted - expected : null
|
|
||||||
const isShort = discrepancy != null && discrepancy < -0.005
|
|
||||||
const isOver = discrepancy != null && discrepancy > 0.005
|
|
||||||
const isClean = discrepancy != null && !isShort && !isOver
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
|
|
||||||
<div style={{ border: '1px solid #e5e7eb', borderRadius: 12, padding: '16px 18px', background: '#f9fafb' }}>
|
|
||||||
<div style={{ fontSize: 11, fontWeight: 700, color: '#9ca3af', textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 10 }}>Σύνοψη Εισπράξεων Βάρδιας</div>
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, fontSize: 13.5 }}>
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
||||||
<span style={{ color: '#6b7280' }}>Σύνολο εισπράξεων σερβιτόρων</span>
|
|
||||||
<span style={{ fontWeight: 700, color: '#111315' }}>{fmt(data.total_waiter_collected)}</span>
|
|
||||||
</div>
|
|
||||||
{data.store_opening_cash != null && (
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
||||||
<span style={{ color: '#6b7280' }}>Αρχικό ταμείο</span>
|
|
||||||
<span style={{ fontWeight: 600, color: '#111315' }}>{fmt(data.store_opening_cash)}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', borderTop: '1px solid #e5e7eb', paddingTop: 6, marginTop: 2 }}>
|
|
||||||
<span style={{ color: '#374151', fontWeight: 600 }}>Αναμενόμενο ταμείο τώρα</span>
|
|
||||||
<span style={{ fontWeight: 800, color: '#111315', fontSize: 15 }}>{fmt(expected)}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label style={{ fontSize: 13, fontWeight: 600, color: '#374151', display: 'block', marginBottom: 6 }}>
|
|
||||||
Μετρήστε το ταμείο — πόσα μετρητά υπάρχουν;
|
|
||||||
<span style={{ fontWeight: 400, color: '#9ca3af' }}> (προαιρετικό)</span>
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
step="0.01"
|
|
||||||
min="0"
|
|
||||||
value={storeCash}
|
|
||||||
onChange={e => onStoreCashChange(e.target.value)}
|
|
||||||
placeholder="0.00"
|
|
||||||
style={{
|
|
||||||
width: '100%', padding: '10px 14px', border: '1.5px solid #e5e7eb',
|
|
||||||
borderRadius: 10, fontSize: 18, fontWeight: 700, color: '#111315',
|
|
||||||
outline: 'none', boxSizing: 'border-box', background: 'white',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{discrepancy != null && (
|
|
||||||
<div style={{
|
|
||||||
padding: '14px 16px', borderRadius: 10,
|
|
||||||
background: isClean ? '#f0fdf4' : '#fef2f2',
|
|
||||||
border: `1.5px solid ${isClean ? '#86efac' : '#fca5a5'}`,
|
|
||||||
}}>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: isClean ? '#16a34a' : '#dc2626', marginBottom: 4 }}>
|
|
||||||
{isClean && '✓ Ταμείο εντάξει'}
|
|
||||||
{isShort && `⚠ Έλλειμμα ${fmt(Math.abs(discrepancy))}`}
|
|
||||||
{isOver && `⚠ Πλεόνασμα ${fmt(Math.abs(discrepancy))}`}
|
|
||||||
</div>
|
|
||||||
<div style={{ fontSize: 12.5, color: isClean ? '#166534' : '#7f1d1d', lineHeight: 1.5 }}>
|
|
||||||
{isClean && 'Το φυσικό ταμείο συμφωνεί με τις καταγεγραμμένες εισπράξεις.'}
|
|
||||||
{isShort && `Το ταμείο έχει ${fmt(Math.abs(discrepancy))} λιγότερα από το αναμενόμενο. Το κενό δεν αποδίδεται σε κάποιον σερβιτόρο συγκεκριμένα.`}
|
|
||||||
{isOver && `Το ταμείο έχει ${fmt(Math.abs(discrepancy))} περισσότερα από το αναμενόμενο.`}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{storeCash === '' && (
|
|
||||||
<p style={{ fontSize: 12, color: '#9ca3af', margin: 0 }}>
|
|
||||||
Αν παραλείψετε τη μέτρηση, η επαλήθευση δεν θα καταγραφεί.
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ChecksTab({ data, onForceClose, closing, isOpen }) {
|
|
||||||
const { checks } = data
|
|
||||||
const allGood = checks.open_orders === 0
|
|
||||||
const hasUnpaid = checks.with_unpaid_items > 0
|
|
||||||
const hasActiveShifts = checks.active_shifts > 0
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
|
||||||
|
|
||||||
<div style={{
|
|
||||||
border: `1px solid ${checks.open_orders > 0 ? '#fecaca' : '#bbf7d0'}`,
|
|
||||||
borderRadius: 12, padding: '16px 18px', background: checks.open_orders > 0 ? '#fff5f5' : '#f0fdf4',
|
|
||||||
display: 'flex', alignItems: 'flex-start', gap: 12,
|
|
||||||
}}>
|
|
||||||
<div style={{
|
|
||||||
width: 34, height: 34, borderRadius: 99, flexShrink: 0, marginTop: 1,
|
|
||||||
background: checks.open_orders > 0 ? '#fee2e2' : '#dcfce7',
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 15,
|
|
||||||
}}>
|
|
||||||
{checks.open_orders > 0 ? '⚠️' : '✓'}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#111315' }}>Ανοιχτά Τραπέζια</div>
|
|
||||||
{checks.open_orders > 0 ? (
|
|
||||||
<div style={{ fontSize: 13, color: '#dc2626', marginTop: 2 }}>
|
|
||||||
{checks.open_orders} τραπέζια ακόμα ανοιχτά
|
|
||||||
{hasUnpaid && ` · ${checks.with_unpaid_items} με απλήρωτα αντικείμενα`}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div style={{ fontSize: 13, color: '#16a34a', marginTop: 2 }}>Όλα τα τραπέζια έχουν κλείσει</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{
|
|
||||||
border: `1px solid ${hasActiveShifts ? '#fde68a' : '#bbf7d0'}`,
|
|
||||||
borderRadius: 12, padding: '16px 18px', background: hasActiveShifts ? '#fffbeb' : '#f0fdf4',
|
|
||||||
display: 'flex', alignItems: 'flex-start', gap: 12,
|
|
||||||
}}>
|
|
||||||
<div style={{
|
|
||||||
width: 34, height: 34, borderRadius: 99, flexShrink: 0, marginTop: 1,
|
|
||||||
background: hasActiveShifts ? '#fef3c7' : '#dcfce7',
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 15,
|
|
||||||
}}>
|
|
||||||
{hasActiveShifts ? '⏳' : '✓'}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 700, color: '#111315' }}>Ενεργές Βάρδιες</div>
|
|
||||||
{hasActiveShifts ? (
|
|
||||||
<div style={{ fontSize: 13, color: '#92400e', marginTop: 2 }}>
|
|
||||||
{checks.active_shifts} βάρδι{checks.active_shifts === 1 ? 'α' : 'ες'} ακόμα ενεργ{checks.active_shifts === 1 ? 'ή' : 'ές'} — θα κλείσουν αυτόματα
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div style={{ fontSize: 13, color: '#16a34a', marginTop: 2 }}>Δεν υπάρχουν ενεργές βάρδιες</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{allGood ? (
|
|
||||||
<div style={{
|
|
||||||
border: '1px solid #bbf7d0', borderRadius: 12, padding: '16px 18px',
|
|
||||||
background: '#f0fdf4', display: 'flex', alignItems: 'center', gap: 10,
|
|
||||||
}}>
|
|
||||||
<span style={{ fontSize: 20 }}>✅</span>
|
|
||||||
<div style={{ fontSize: 14, fontWeight: 600, color: '#166534' }}>
|
|
||||||
Ο έλεγχος πέρασε — η ημέρα είναι έτοιμη να κλείσει.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : hasUnpaid ? (
|
|
||||||
<div style={{ border: '1px solid #fecaca', borderRadius: 12, padding: '16px 18px', background: '#fff5f5' }}>
|
|
||||||
<div style={{ fontSize: 13, color: '#7f1d1d', lineHeight: 1.5 }}>
|
|
||||||
<strong>Προσοχή:</strong> Υπάρχουν απλήρωτα αντικείμενα. Αν κλείσετε αναγκαστικά, τα απλήρωτα ποσά δεν θα καταγραφούν στις αναφορές.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div style={{ border: '1px solid #fde68a', borderRadius: 12, padding: '16px 18px', background: '#fffbeb' }}>
|
|
||||||
<div style={{ fontSize: 13, color: '#78350f', lineHeight: 1.5 }}>
|
|
||||||
Υπάρχουν ανοιχτά τραπέζια χωρίς απλήρωτα αντικείμενα. Θα κλείσουν αυτόματα.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isOpen && (
|
|
||||||
<button
|
|
||||||
onClick={onForceClose}
|
|
||||||
disabled={closing}
|
|
||||||
style={{
|
|
||||||
marginTop: 4, height: 46, borderRadius: 10, border: 'none',
|
|
||||||
cursor: closing ? 'default' : 'pointer',
|
|
||||||
background: hasUnpaid ? '#dc2626' : '#111315',
|
|
||||||
color: 'white', fontSize: 14, fontWeight: 700,
|
|
||||||
opacity: closing ? 0.7 : 1, transition: 'opacity 150ms',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{closing ? 'Κλείσιμο…' : hasUnpaid ? '⚠ Αναγκαστικό Κλείσιμο' : 'Κλείσε Ημέρα'}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Main modal ────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export default function WorkdaySummaryModal({ dayId, onClose, showCloseAction = false, onDayClosed }) {
|
|
||||||
const [tab, setTab] = useState('overview')
|
|
||||||
const [closing, setClosing] = useState(false)
|
|
||||||
const [storeCash, setStoreCash] = useState('') // Phase 2E: store cash count
|
|
||||||
|
|
||||||
const { data, isLoading, error } = useQuery({
|
|
||||||
queryKey: ['workday-summary', dayId ?? 'current'],
|
|
||||||
queryFn: () => client.get('/api/business-day/summary' + (dayId ? `?day_id=${dayId}` : '')).then(r => r.data),
|
|
||||||
refetchInterval: showCloseAction ? 15_000 : false,
|
|
||||||
})
|
|
||||||
|
|
||||||
async function handleClose(force = false) {
|
|
||||||
setClosing(true)
|
|
||||||
try {
|
|
||||||
const payload = { force }
|
|
||||||
if (storeCash !== '') payload.store_closing_cash = parseFloat(storeCash)
|
|
||||||
await client.post('/api/business-day/close', payload)
|
|
||||||
onDayClosed?.()
|
|
||||||
} catch (e) {
|
|
||||||
const detail = e.response?.data?.detail
|
|
||||||
if (e.response?.status === 409 && detail?.open_orders) {
|
|
||||||
setTab('checks')
|
|
||||||
} else {
|
|
||||||
toast.error(typeof detail === 'string' ? detail : 'Σφάλμα κλεισίματος')
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
setClosing(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const tabs = [
|
|
||||||
{ id: 'overview', label: 'Επισκόπηση' },
|
|
||||||
{ id: 'waiters', label: 'Προσωπικό', badge: data?.waiters?.length },
|
|
||||||
{ id: 'zones', label: 'Ζώνες', badge: data?.zones?.length },
|
|
||||||
{ id: 'printers', label: 'Εκτυπωτές', badge: data?.printers?.length },
|
|
||||||
...(showCloseAction ? [
|
|
||||||
{ id: 'cash', label: 'Ταμείο' },
|
|
||||||
{
|
|
||||||
id: 'checks', label: 'Έλεγχοι',
|
|
||||||
badge: data?.checks ? (data.checks.open_orders + data.checks.active_shifts) : null,
|
|
||||||
warn: data?.checks?.with_unpaid_items > 0,
|
|
||||||
},
|
|
||||||
] : []),
|
|
||||||
]
|
|
||||||
|
|
||||||
const isOpen = data?.status === 'open'
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.45)',
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
||||||
zIndex: 1000, padding: 16,
|
|
||||||
}}
|
|
||||||
onClick={e => { if (e.target === e.currentTarget) onClose() }}
|
|
||||||
>
|
|
||||||
<div style={{
|
|
||||||
background: 'white', borderRadius: 16, width: '100%', maxWidth: 760,
|
|
||||||
maxHeight: '92vh', display: 'flex', flexDirection: 'column',
|
|
||||||
boxShadow: '0 20px 60px rgba(0,0,0,0.18)',
|
|
||||||
overflow: 'hidden',
|
|
||||||
}}>
|
|
||||||
{/* Header */}
|
|
||||||
<div style={{
|
|
||||||
padding: '20px 24px 0', borderBottom: '1px solid #f0f0ef',
|
|
||||||
display: 'flex', flexDirection: 'column', gap: 0,
|
|
||||||
}}>
|
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 14 }}>
|
|
||||||
<div style={{
|
|
||||||
width: 36, height: 36, borderRadius: 9, background: '#111315',
|
|
||||||
display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
|
|
||||||
}}>
|
|
||||||
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="white" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round">
|
|
||||||
<rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
|
|
||||||
<line x1="3" y1="9" x2="21" y2="9" />
|
|
||||||
<line x1="9" y1="21" x2="9" y2="9" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<div style={{ flex: 1 }}>
|
|
||||||
<div style={{ fontSize: 17, fontWeight: 800, color: '#111315' }}>
|
|
||||||
{showCloseAction ? 'Κλείσιμο Εργάσιμης Ημέρας' : 'Στατιστικά Ημέρας'}
|
|
||||||
</div>
|
|
||||||
{data && (
|
|
||||||
<div style={{ fontSize: 11, color: '#9ca3af', marginTop: 1 }}>
|
|
||||||
{data.status === 'open'
|
|
||||||
? <span style={{ color: '#16a34a', fontWeight: 600 }}>● Ημέρα Ενεργή</span>
|
|
||||||
: <span>Κλειστή</span>
|
|
||||||
}
|
|
||||||
{' · '}Άνοιγμα {fmtDateTime(data?.opened_at)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
onClick={onClose}
|
|
||||||
style={{
|
|
||||||
width: 32, height: 32, borderRadius: 8, border: '1px solid #e5e7eb',
|
|
||||||
background: 'white', cursor: 'pointer', display: 'flex',
|
|
||||||
alignItems: 'center', justifyContent: 'center', flexShrink: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#6b7280" strokeWidth="2.5" strokeLinecap="round">
|
|
||||||
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: 'flex', gap: 0, overflowX: 'auto' }}>
|
|
||||||
{tabs.map(t => (
|
|
||||||
<TabBtn key={t.id} label={t.label} active={tab === t.id}
|
|
||||||
onClick={() => setTab(t.id)} badge={t.badge} warn={t.warn} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Body */}
|
|
||||||
<div style={{ flex: 1, overflowY: 'auto', padding: '22px 24px' }}>
|
|
||||||
{isLoading && (
|
|
||||||
<div style={{ textAlign: 'center', color: '#9ca3af', fontSize: 13, padding: '48px 0' }}>Φόρτωση…</div>
|
|
||||||
)}
|
|
||||||
{error && (
|
|
||||||
<div style={{ textAlign: 'center', color: '#dc2626', fontSize: 13, padding: '48px 0' }}>Σφάλμα φόρτωσης δεδομένων</div>
|
|
||||||
)}
|
|
||||||
{data && (
|
|
||||||
<>
|
|
||||||
{tab === 'overview' && <OverviewTab data={data} />}
|
|
||||||
{tab === 'waiters' && <WaitersTab data={data} />}
|
|
||||||
{tab === 'zones' && <ZonesTab data={data} />}
|
|
||||||
{tab === 'printers' && <PrintersTab data={data} />}
|
|
||||||
{tab === 'cash' && (
|
|
||||||
<CashReconciliationTab
|
|
||||||
data={data}
|
|
||||||
storeCash={storeCash}
|
|
||||||
onStoreCashChange={setStoreCash}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{tab === 'checks' && (
|
|
||||||
<ChecksTab
|
|
||||||
data={data}
|
|
||||||
isOpen={isOpen}
|
|
||||||
onForceClose={() => handleClose(data.checks.open_orders > 0)}
|
|
||||||
closing={closing}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Footer — only shown when in close-flow and not already on checks tab */}
|
|
||||||
{showCloseAction && data && tab !== 'checks' && (
|
|
||||||
<div style={{
|
|
||||||
padding: '14px 24px', borderTop: '1px solid #f0f0ef',
|
|
||||||
display: 'flex', gap: 10, justifyContent: 'flex-end', background: 'white',
|
|
||||||
}}>
|
|
||||||
<button onClick={onClose} style={{
|
|
||||||
height: 40, padding: '0 18px', borderRadius: 9,
|
|
||||||
border: '1px solid #e5e7eb', background: 'white',
|
|
||||||
fontSize: 13, fontWeight: 600, cursor: 'pointer', color: '#374151',
|
|
||||||
}}>Ακύρωση</button>
|
|
||||||
{tab !== 'cash' ? (
|
|
||||||
<button onClick={() => setTab('cash')} style={{
|
|
||||||
height: 40, padding: '0 20px', borderRadius: 9,
|
|
||||||
background: '#111315', border: 'none', color: 'white',
|
|
||||||
fontSize: 13, fontWeight: 700, cursor: 'pointer',
|
|
||||||
}}>Μέτρηση Ταμείου →</button>
|
|
||||||
) : (
|
|
||||||
<button onClick={() => setTab('checks')} style={{
|
|
||||||
height: 40, padding: '0 20px', borderRadius: 9,
|
|
||||||
background: '#111315', border: 'none', color: 'white',
|
|
||||||
fontSize: 13, fontWeight: 700, cursor: 'pointer',
|
|
||||||
}}>Προχωρήστε στους Ελέγχους →</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,395 +0,0 @@
|
|||||||
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
||||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
|
||||||
import { useLiveEvent } from '../live/useLiveEvent'
|
|
||||||
import {
|
|
||||||
getIncomingOrders,
|
|
||||||
getActiveOrders,
|
|
||||||
getOrderHistory,
|
|
||||||
acceptOnlineOrder,
|
|
||||||
rejectOnlineOrder,
|
|
||||||
updateOnlineOrderStatus,
|
|
||||||
} from '../api/client'
|
|
||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function timeAgo(iso) {
|
|
||||||
const diff = Math.floor((Date.now() - new Date(iso).getTime()) / 1000)
|
|
||||||
if (diff < 60) return `${diff}s ago`
|
|
||||||
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`
|
|
||||||
return `${Math.floor(diff / 3600)}h ago`
|
|
||||||
}
|
|
||||||
|
|
||||||
function calcTotals(items = []) {
|
|
||||||
return items.reduce((sum, it) => sum + ((it.unit_price ?? 0) + (it.price_adjustment ?? 0)) * (it.quantity ?? 1), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
const STATUS_LABELS = {
|
|
||||||
pending_acceptance: { label: 'Αναμονή', cls: 'bg-amber-100 text-amber-700' },
|
|
||||||
accepted: { label: 'Αποδεκτή', cls: 'bg-blue-100 text-blue-700' },
|
|
||||||
preparing: { label: 'Προετοιμασία', cls: 'bg-indigo-100 text-indigo-700' },
|
|
||||||
ready: { label: 'Έτοιμη', cls: 'bg-green-100 text-green-700' },
|
|
||||||
out_for_delivery: { label: 'Παράδοση', cls: 'bg-purple-100 text-purple-700' },
|
|
||||||
delivered: { label: 'Παραδόθηκε', cls: 'bg-gray-100 text-gray-500' },
|
|
||||||
rejected: { label: 'Απορρίφθηκε', cls: 'bg-red-100 text-red-600' },
|
|
||||||
}
|
|
||||||
|
|
||||||
function OnlineStatusBadge({ status }) {
|
|
||||||
const { label, cls } = STATUS_LABELS[status] ?? { label: status, cls: 'bg-gray-100 text-gray-600' }
|
|
||||||
return (
|
|
||||||
<span className={`inline-block text-xs font-semibold px-2 py-0.5 rounded-full ${cls}`}>
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Order Card ────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function OrderCard({ order, onAction }) {
|
|
||||||
const [rejectOpen, setRejectOpen] = useState(false)
|
|
||||||
const [rejectReason, setRejectReason] = useState('')
|
|
||||||
const [busy, setBusy] = useState(false)
|
|
||||||
const [tick, setTick] = useState(0)
|
|
||||||
|
|
||||||
// Refresh the "X min ago" label every 30 s without a full re-render of parent
|
|
||||||
useEffect(() => {
|
|
||||||
const id = setInterval(() => setTick(t => t + 1), 30_000)
|
|
||||||
return () => clearInterval(id)
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const { t } = useTranslation('manager')
|
|
||||||
const { formatDate, formatDateTime, formatMoney, formatTime } = useFormat()
|
|
||||||
const subtotal = calcTotals(order.items)
|
|
||||||
const isDelivery = order.online_order_type === 'delivery'
|
|
||||||
const isTakeaway = order.online_order_type === 'takeaway'
|
|
||||||
const st = order.online_status
|
|
||||||
// phase 3S (S.5): when the customer wants it, and the venue's own price check
|
|
||||||
const when = order.requested_for
|
|
||||||
? t('onlineOrders.for', { when: formatDate(order.requested_for) === formatDate(new Date()) ? formatTime(order.requested_for) : formatDateTime(order.requested_for, 'datetimeShort') })
|
|
||||||
: t('onlineOrders.asap')
|
|
||||||
const diff = order.online_price_diff
|
|
||||||
|
|
||||||
async function act(fn) {
|
|
||||||
setBusy(true)
|
|
||||||
try { await fn() } finally { setBusy(false) }
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="bg-white border border-gray-200 rounded-2xl shadow-sm overflow-hidden">
|
|
||||||
{/* Card header */}
|
|
||||||
<div className="flex items-center justify-between px-4 py-3 border-b border-gray-100 bg-gray-50/60">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="font-bold text-gray-800 text-base">
|
|
||||||
{order.online_order_ref ?? `#${order.id}`}
|
|
||||||
</span>
|
|
||||||
<span className={`text-xs font-semibold px-2 py-0.5 rounded-full ${
|
|
||||||
isDelivery ? 'bg-orange-100 text-orange-700' : 'bg-teal-100 text-teal-700'
|
|
||||||
}`}>
|
|
||||||
{isDelivery ? 'Delivery' : isTakeaway ? 'Takeaway' : 'Dine-in'}
|
|
||||||
</span>
|
|
||||||
<OnlineStatusBadge status={st} />
|
|
||||||
</div>
|
|
||||||
<span className="text-xs text-gray-400">{timeAgo(order.opened_at)}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Customer info */}
|
|
||||||
<div className="px-4 py-3 space-y-0.5 border-b border-gray-100 text-sm text-gray-700">
|
|
||||||
{order.online_customer_name && (
|
|
||||||
<p className="font-medium">{order.online_customer_name}</p>
|
|
||||||
)}
|
|
||||||
{order.online_customer_phone && (
|
|
||||||
<p className="text-gray-500">{order.online_customer_phone}</p>
|
|
||||||
)}
|
|
||||||
{isDelivery && order.online_customer_address && (
|
|
||||||
<p className="text-gray-500">{order.online_customer_address}{order.online_delivery_area ? ` · ${order.online_delivery_area}` : ''}</p>
|
|
||||||
)}
|
|
||||||
{(isDelivery || isTakeaway) && (
|
|
||||||
<p className={`font-semibold ${order.requested_for ? 'text-info-ink' : 'text-ink-2'}`} data-testid="online-when">{when}</p>
|
|
||||||
)}
|
|
||||||
{diff && (
|
|
||||||
<p className="text-warning-ink bg-warning-soft rounded px-2 py-1 text-xs mt-1" data-testid="online-price-diff">
|
|
||||||
{t('onlineOrders.priceDiff', { charged: formatMoney(diff.cloud_total), here: formatMoney(diff.site_total) })}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{order.online_customer_notes && (
|
|
||||||
<p className="text-amber-700 bg-amber-50 rounded px-2 py-1 text-xs mt-1">
|
|
||||||
📝 {order.online_customer_notes}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Items */}
|
|
||||||
<div className="px-4 py-3 border-b border-gray-100">
|
|
||||||
<div className="space-y-1 text-sm text-gray-700">
|
|
||||||
{order.items.map((it, i) => (
|
|
||||||
<div key={i} className="flex justify-between">
|
|
||||||
<span className={it.system_key ? 'text-ink-2' : undefined}>
|
|
||||||
{it.system_key ? (it.product_name ?? it.product?.name) : `${it.quantity} × ${it.product_name ?? it.product?.name ?? `#${it.product_id}`}`}
|
|
||||||
</span>
|
|
||||||
<span className="text-gray-500">€{(((it.unit_price ?? 0) + (it.price_adjustment ?? 0)) * it.quantity).toFixed(2)}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<div className="mt-2 pt-2 border-t border-gray-100 flex justify-between font-semibold text-sm">
|
|
||||||
<span>Σύνολο</span>
|
|
||||||
<span>€{subtotal.toFixed(2)}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Actions */}
|
|
||||||
<div className="px-4 py-3 flex flex-wrap gap-2">
|
|
||||||
{st === 'pending_acceptance' && (
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
onClick={() => act(() => onAction('accept', order.id))}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-primary text-sm px-4 min-h-0 h-9 bg-green-600 hover:bg-green-700 border-green-600"
|
|
||||||
>
|
|
||||||
Αποδοχή
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => setRejectOpen(r => !r)}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-danger text-sm px-4 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Απόρριψη
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{st === 'accepted' && (
|
|
||||||
<button
|
|
||||||
onClick={() => act(() => onAction('status', order.id, 'preparing'))}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-secondary text-sm px-4 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Προετοιμασία
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
{st === 'preparing' && (
|
|
||||||
isDelivery ? (
|
|
||||||
<button
|
|
||||||
onClick={() => act(() => onAction('status', order.id, 'out_for_delivery'))}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-secondary text-sm px-4 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Εξωτερική Παράδοση
|
|
||||||
</button>
|
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
onClick={() => act(() => onAction('status', order.id, 'ready'))}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-secondary text-sm px-4 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Έτοιμη
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
{(st === 'ready' || st === 'out_for_delivery') && (
|
|
||||||
<button
|
|
||||||
onClick={() => act(() => onAction('status', order.id, 'delivered'))}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-primary text-sm px-4 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Παραδόθηκε
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Reject inline form */}
|
|
||||||
{rejectOpen && (
|
|
||||||
<div className="px-4 pb-4 flex gap-2 items-start border-t border-gray-100 pt-3">
|
|
||||||
<textarea
|
|
||||||
className="input flex-1 resize-none text-sm"
|
|
||||||
rows={2}
|
|
||||||
placeholder="Λόγος απόρριψης (προαιρετικό)"
|
|
||||||
value={rejectReason}
|
|
||||||
onChange={e => setRejectReason(e.target.value)}
|
|
||||||
/>
|
|
||||||
<div className="flex flex-col gap-2">
|
|
||||||
<button
|
|
||||||
onClick={() => act(() => onAction('reject', order.id, rejectReason))}
|
|
||||||
disabled={busy}
|
|
||||||
className="btn btn-danger text-sm px-3 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Επιβεβαίωση
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => setRejectOpen(false)}
|
|
||||||
className="btn btn-secondary text-sm px-3 min-h-0 h-9"
|
|
||||||
>
|
|
||||||
Ακύρωση
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Tab Panel ─────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function OrderList({ orders, onAction, emptyText }) {
|
|
||||||
if (!orders.length) {
|
|
||||||
return <p className="text-sm text-gray-400 text-center py-12">{emptyText}</p>
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
{orders.map(o => (
|
|
||||||
<OrderCard key={o.id} order={o} onAction={onAction} />
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Main Page ─────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const TABS = [
|
|
||||||
{ key: 'incoming', label: 'Εισερχόμενες' },
|
|
||||||
{ key: 'active', label: 'Ενεργές' },
|
|
||||||
{ key: 'history', label: 'Ιστορικό' },
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function OnlineOrdersPage() {
|
|
||||||
const [activeTab, setActiveTab] = useState('incoming')
|
|
||||||
const [incoming, setIncoming] = useState([])
|
|
||||||
const [active, setActive] = useState([])
|
|
||||||
const [history, setHistory] = useState([])
|
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const [error, setError] = useState(null)
|
|
||||||
const pollRef = useRef(null)
|
|
||||||
|
|
||||||
const fetchAll = useCallback(async () => {
|
|
||||||
setLoading(true)
|
|
||||||
setError(null)
|
|
||||||
try {
|
|
||||||
const [inc, act, hist] = await Promise.all([
|
|
||||||
getIncomingOrders(),
|
|
||||||
getActiveOrders(),
|
|
||||||
getOrderHistory(),
|
|
||||||
])
|
|
||||||
setIncoming(inc.data)
|
|
||||||
setActive(act.data)
|
|
||||||
setHistory(hist.data)
|
|
||||||
} catch {
|
|
||||||
setError('Σφάλμα φόρτωσης παραγγελιών.')
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
// Initial fetch + 20 s polling
|
|
||||||
useEffect(() => {
|
|
||||||
fetchAll()
|
|
||||||
pollRef.current = setInterval(fetchAll, 20_000)
|
|
||||||
return () => clearInterval(pollRef.current)
|
|
||||||
}, [fetchAll])
|
|
||||||
|
|
||||||
// Live: refetch on the WebSocket events (KI-010: this listened on /api/stream, which never
|
|
||||||
// existed). 'ready' = after a reconnect; the 20 s polling above stays as a fallback.
|
|
||||||
useLiveEvent('online_order_received', fetchAll)
|
|
||||||
useLiveEvent('online_order_updated', fetchAll)
|
|
||||||
useLiveEvent('ready', fetchAll)
|
|
||||||
|
|
||||||
async function handleAction(action, orderId, extra) {
|
|
||||||
try {
|
|
||||||
if (action === 'accept') {
|
|
||||||
const { data: updated } = await acceptOnlineOrder(orderId)
|
|
||||||
setIncoming(prev => prev.filter(o => o.id !== orderId))
|
|
||||||
setActive(prev => [updated, ...prev])
|
|
||||||
} else if (action === 'reject') {
|
|
||||||
const { data: updated } = await rejectOnlineOrder(orderId, extra)
|
|
||||||
setIncoming(prev => prev.filter(o => o.id !== orderId))
|
|
||||||
setHistory(prev => [updated, ...prev])
|
|
||||||
} else if (action === 'status') {
|
|
||||||
const { data: updated } = await updateOnlineOrderStatus(orderId, extra)
|
|
||||||
const isDone = updated.online_status === 'delivered' || updated.online_status === 'rejected'
|
|
||||||
if (isDone) {
|
|
||||||
setActive(prev => prev.filter(o => o.id !== orderId))
|
|
||||||
setHistory(prev => [updated, ...prev])
|
|
||||||
} else {
|
|
||||||
setActive(prev => prev.map(o => o.id === orderId ? updated : o))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Re-fetch to sync — avoids stale state after a failed optimistic update
|
|
||||||
fetchAll()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const pendingCount = incoming.length
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col h-full overflow-hidden">
|
|
||||||
{/* Tabs + refresh on same row */}
|
|
||||||
<div className="flex-shrink-0 flex items-stretch border-b border-slate-200 px-6 pt-2">
|
|
||||||
{TABS.map(tab => {
|
|
||||||
const count = tab.key === 'incoming' ? incoming.length
|
|
||||||
: tab.key === 'active' ? active.length
|
|
||||||
: history.length
|
|
||||||
const isActive = activeTab === tab.key
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={tab.key}
|
|
||||||
onClick={() => setActiveTab(tab.key)}
|
|
||||||
className={`relative flex items-center gap-2 px-4 py-3 text-[13.5px] font-medium transition-colors whitespace-nowrap ${
|
|
||||||
isActive ? 'text-slate-900' : 'text-slate-500 hover:text-slate-700'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{tab.label}
|
|
||||||
{count > 0 && (
|
|
||||||
<span className={`text-[11px] px-1.5 py-0.5 rounded-full font-mono font-semibold ${
|
|
||||||
tab.key === 'incoming'
|
|
||||||
? 'bg-red-100 text-red-700'
|
|
||||||
: isActive ? 'bg-sky-100 text-sky-700' : 'bg-slate-100 text-slate-500'
|
|
||||||
}`}>
|
|
||||||
{count}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{isActive && <span className="absolute inset-x-2 -bottom-px h-0.5 rounded-full bg-sky-500" />}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
<div className="flex-1" />
|
|
||||||
<div className="flex items-center pb-2">
|
|
||||||
<button
|
|
||||||
onClick={fetchAll}
|
|
||||||
disabled={loading}
|
|
||||||
className="flex items-center gap-1.5 px-3 py-1.5 text-[12px] font-medium text-slate-500 hover:text-slate-700 border border-slate-200 rounded-lg bg-white transition-colors disabled:opacity-50"
|
|
||||||
>
|
|
||||||
{loading ? '…' : '↻ Ανανέωση'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Content */}
|
|
||||||
<div className="flex-1 overflow-y-auto px-6 py-5">
|
|
||||||
{error && (
|
|
||||||
<div className="mb-4 rounded-lg bg-red-50 border border-red-200 px-4 py-3 text-sm text-red-700">
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{activeTab === 'incoming' && (
|
|
||||||
<OrderList
|
|
||||||
orders={incoming}
|
|
||||||
onAction={handleAction}
|
|
||||||
emptyText="Δεν υπάρχουν εισερχόμενες παραγγελίες."
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{activeTab === 'active' && (
|
|
||||||
<OrderList
|
|
||||||
orders={active}
|
|
||||||
onAction={handleAction}
|
|
||||||
emptyText="Δεν υπάρχουν ενεργές παραγγελίες."
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{activeTab === 'history' && (
|
|
||||||
<OrderList
|
|
||||||
orders={history}
|
|
||||||
onAction={handleAction}
|
|
||||||
emptyText="Δεν υπάρχει ιστορικό παραγγελιών."
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// Online orders (plan step 6.2, was pages/OnlineOrdersPage): orders from the online ordering app
|
||||||
|
// in three lists, new (waiting for an answer), in progress and done. A new order is accepted or
|
||||||
|
// refused (with an optional reason the customer sees); an accepted one moves on: preparing,
|
||||||
|
// then ready (takeaway) or out for delivery, then delivered. Each card shows the customer, when
|
||||||
|
// they want it, the venue's own price check and the lines. The lists refresh on the live
|
||||||
|
// events (a new order, a status change), after a reconnect, and every 20 seconds.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { Check, RefreshCw, StickyNote, X } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, EmptyState, Field, Spinner, Textarea, cx } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { lineTotal, orderTotal } from '../overview/overviewLogic'
|
||||||
|
import { Pill } from '../overview/parts'
|
||||||
|
import { ONLINE_TABS, ONLINE_TONE, onlineKind, onlineNextStep } from './onlineOrdersLogic'
|
||||||
|
|
||||||
|
const EVENTS = ['online_order_received', 'online_order_updated']
|
||||||
|
const URLS = { incoming: '/api/connect/orders/incoming', active: '/api/connect/orders?status=active', history: '/api/connect/orders?status=history' }
|
||||||
|
const KIND_TONE = { delivery: 'warning', takeaway: 'info', dine_in: 'neutral' }
|
||||||
|
|
||||||
|
function useList(tab) {
|
||||||
|
return useLiveQuery({
|
||||||
|
queryKey: ['online-orders', tab],
|
||||||
|
queryFn: () => client.get(URLS[tab]).then(r => r.data),
|
||||||
|
events: EVENTS,
|
||||||
|
refetchInterval: 20_000,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function OnlineOrdersPage() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const [tab, setTab] = useState('incoming')
|
||||||
|
const lists = { incoming: useList('incoming'), active: useList('active'), history: useList('history') }
|
||||||
|
const current = lists[tab]
|
||||||
|
const refresh = () => qc.invalidateQueries({ queryKey: ['online-orders'] })
|
||||||
|
|
||||||
|
async function act(fn) {
|
||||||
|
try { await fn() } catch (err) { toast.error(errorMessage(err, t)) } finally { refresh() }
|
||||||
|
}
|
||||||
|
const onAction = (action, id, extra) => act(() => (
|
||||||
|
action === 'accept' ? client.post(`/api/connect/orders/${id}/accept`)
|
||||||
|
: action === 'reject' ? client.post(`/api/connect/orders/${id}/reject`, { reason: extra || null })
|
||||||
|
: client.post(`/api/connect/orders/${id}/status`, { status: extra })
|
||||||
|
))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col h-full overflow-hidden" data-testid="online-orders">
|
||||||
|
<div className="shrink-0 flex items-end gap-1 border-b border-line px-4 md:px-6 pt-2" role="tablist">
|
||||||
|
{ONLINE_TABS.map(k => {
|
||||||
|
const count = lists[k].data?.length ?? 0
|
||||||
|
return (
|
||||||
|
<button key={k} type="button" role="tab" aria-selected={tab === k} onClick={() => setTab(k)} data-testid={`online-tab-${k}`}
|
||||||
|
className={cx('flex items-center gap-2 px-4 py-3 -mb-px border-b-2 text-body whitespace-nowrap transition-colors duration-fast',
|
||||||
|
tab === k ? 'border-accent text-ink font-semibold' : 'border-transparent text-ink-2 hover:text-ink')}>
|
||||||
|
{t(`onlineOrders.tab.${k}`)}
|
||||||
|
{count > 0 && <span className={cx('px-1.5 rounded-full text-caption font-bold tabular-nums', k === 'incoming' ? 'bg-danger-soft text-danger-ink' : 'bg-surface-2 text-ink-2')}>{count}</span>}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
<span className="flex-1" />
|
||||||
|
<Button size="sm" variant="ghost" className="mb-2" icon={<RefreshCw size={14} />} loading={current.isFetching} onClick={refresh}>{t('onlineOrders.refresh')}</Button>
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 overflow-y-auto p-4 md:p-6">
|
||||||
|
{current.error && <EmptyState compact title={errorMessage(current.error, t)} />}
|
||||||
|
{current.isPending ? <div className="py-10 flex justify-center"><Spinner /></div>
|
||||||
|
: current.data?.length === 0 ? <EmptyState title={t(`onlineOrders.empty.${tab}`)} />
|
||||||
|
: (
|
||||||
|
<div className="grid gap-4 max-w-3xl">
|
||||||
|
{current.data?.map(o => <OrderCard key={o.id} order={o} onAction={onAction} />)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrderCard({ order, onAction }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatDate, formatDateTime, formatMoney, formatRelative, formatTime } = useFormat()
|
||||||
|
const [rejecting, setRejecting] = useState(false)
|
||||||
|
const [reason, setReason] = useState('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const kind = onlineKind(order)
|
||||||
|
const st = order.online_status
|
||||||
|
const next = onlineNextStep(order)
|
||||||
|
// phase 3S (S.5): when the customer wants it, and the venue's own price check
|
||||||
|
const when = order.requested_for
|
||||||
|
? t('onlineOrders.for', { when: formatDate(order.requested_for) === formatDate(new Date()) ? formatTime(order.requested_for) : formatDateTime(order.requested_for, 'datetimeShort') })
|
||||||
|
: t('onlineOrders.asap')
|
||||||
|
const diff = order.online_price_diff
|
||||||
|
const run = async fn => { setBusy(true); try { await fn() } finally { setBusy(false) } }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<article className="rounded-card border border-line bg-surface shadow-raised overflow-hidden" data-testid="online-order" data-status={st}>
|
||||||
|
<header className="flex flex-wrap items-center gap-2 px-4 py-3 border-b border-line bg-surface-2">
|
||||||
|
<span className="text-body-lg font-bold text-ink">{order.online_order_ref ?? `#${order.id}`}</span>
|
||||||
|
<Pill tone={KIND_TONE[kind]}>{t(`onlineOrders.kind.${kind}`)}</Pill>
|
||||||
|
<Pill tone={ONLINE_TONE[st] ?? 'neutral'}>{t(`onlineOrders.status.${st}`, { defaultValue: st })}</Pill>
|
||||||
|
<span className="flex-1" />
|
||||||
|
<span className="text-caption text-ink-3" title={formatDateTime(order.opened_at)}>{formatRelative(order.opened_at)}</span>
|
||||||
|
</header>
|
||||||
|
<div className="px-4 py-3 border-b border-line grid gap-0.5 text-body text-ink-2">
|
||||||
|
{order.online_customer_name && <span className="font-semibold text-ink">{order.online_customer_name}</span>}
|
||||||
|
{order.online_customer_phone && <span>{order.online_customer_phone}</span>}
|
||||||
|
{kind === 'delivery' && order.online_customer_address && <span>{order.online_customer_address}{order.online_delivery_area ? ` · ${order.online_delivery_area}` : ''}</span>}
|
||||||
|
{kind !== 'dine_in' && <span className={cx('font-semibold', order.requested_for ? 'text-info-ink' : 'text-ink-2')} data-testid="online-when">{when}</span>}
|
||||||
|
{diff && (
|
||||||
|
<p className="mt-1 rounded-control px-2 py-1 text-caption bg-warning-soft text-warning-ink" data-testid="online-price-diff">
|
||||||
|
{t('onlineOrders.priceDiff', { charged: formatMoney(diff.cloud_total), here: formatMoney(diff.site_total) })}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
{order.online_customer_notes && (
|
||||||
|
<p className="mt-1 rounded-control px-2 py-1 text-caption bg-warning-soft text-warning-ink inline-flex items-start gap-1.5">
|
||||||
|
<StickyNote size={14} className="shrink-0 mt-px" aria-hidden="true" />{order.online_customer_notes}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="px-4 py-3 border-b border-line grid gap-1 text-body">
|
||||||
|
{order.items.map((it, i) => (
|
||||||
|
<div key={i} className="flex justify-between gap-3">
|
||||||
|
<span className={it.system_key ? 'text-ink-2' : 'text-ink'}>
|
||||||
|
{it.system_key ? (it.product_name ?? it.product?.name) : `${it.quantity} × ${it.product_name ?? it.product?.name ?? `#${it.product_id}`}`}
|
||||||
|
</span>
|
||||||
|
<span className="tabular-nums text-ink-2">{formatMoney(lineTotal(it))}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div className="mt-1 pt-2 border-t border-line flex justify-between font-semibold text-ink">
|
||||||
|
<span>{t('onlineOrders.total')}</span>
|
||||||
|
<span className="tabular-nums" data-testid="online-total">{formatMoney(orderTotal(order.items))}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{(st === 'pending_acceptance' || next) && (
|
||||||
|
<div className="px-4 py-3 flex flex-wrap gap-2">
|
||||||
|
{st === 'pending_acceptance' && (<>
|
||||||
|
<Button icon={<Check size={16} />} loading={busy} onClick={() => run(() => onAction('accept', order.id))} data-testid="online-accept">{t('onlineOrders.accept')}</Button>
|
||||||
|
<Button variant="danger" icon={<X size={16} />} disabled={busy} onClick={() => setRejecting(r => !r)} data-testid="online-reject">{t('onlineOrders.reject')}</Button>
|
||||||
|
</>)}
|
||||||
|
{next && <Button variant={next === 'delivered' ? 'primary' : 'secondary'} loading={busy} onClick={() => run(() => onAction('status', order.id, next))} data-testid="online-next">
|
||||||
|
{t(`onlineOrders.next.${next}`)}
|
||||||
|
</Button>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{rejecting && (
|
||||||
|
<div className="px-4 pb-4 grid gap-2 border-t border-line pt-3">
|
||||||
|
<Field label={t('onlineOrders.rejectReason')} hint={t('onlineOrders.rejectHint')}>
|
||||||
|
<Textarea rows={2} value={reason} onChange={e => setReason(e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
<div className="flex gap-2 justify-end">
|
||||||
|
<Button variant="secondary" onClick={() => setRejecting(false)}>{t('overview.back')}</Button>
|
||||||
|
<Button variant="danger" loading={busy} onClick={() => run(() => onAction('reject', order.id, reason.trim()))} data-testid="online-reject-confirm">{t('onlineOrders.rejectNow')}</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</article>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Online orders on the manager (plan step 6.2): which step comes next for an order, and the
|
||||||
|
// tones of its states. No React (tests/online-orders.test.mjs).
|
||||||
|
|
||||||
|
export const ONLINE_TABS = ['incoming', 'active', 'history']
|
||||||
|
|
||||||
|
/** The tone of each online state (a @xenia/ui tone name). */
|
||||||
|
export const ONLINE_TONE = {
|
||||||
|
pending_acceptance: 'warning', accepted: 'info', preparing: 'accent', ready: 'success',
|
||||||
|
out_for_delivery: 'accent', delivered: 'neutral', rejected: 'danger',
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The status an accepted order moves on to next, or null when nothing is left to do here. */
|
||||||
|
export function onlineNextStep(order) {
|
||||||
|
const st = order.online_status
|
||||||
|
if (st === 'accepted') return 'preparing'
|
||||||
|
if (st === 'preparing') return order.online_order_type === 'delivery' ? 'out_for_delivery' : 'ready'
|
||||||
|
if (st === 'ready' || st === 'out_for_delivery') return 'delivered'
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** delivery | takeaway | dine_in (an order without a type is eaten in). */
|
||||||
|
export const onlineKind = order => (order.online_order_type === 'delivery' || order.online_order_type === 'takeaway' ? order.online_order_type : 'dine_in')
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
// Table bookings (plan step 6.2): upcoming (requests from the online ordering app to confirm or
|
||||||
|
// decline, waiting ones, no-shows) and history. A request is confirmed or declined with a reason
|
||||||
|
// the customer sees; a waiting booking is marked "arrived" or cancelled; any booking can be
|
||||||
|
// edited. New bookings are typed in venue time (the backend reads a time without an offset as
|
||||||
|
// the venue's, D-11).
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { CalendarDays, Check, Pencil, Phone, Plus, Armchair, UserCheck, Users, X } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Textarea } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { BOOKING_OFFSETS, bookingBody, offsetFrom, tableName, tablesByZone, venueWallClock } from './overviewLogic'
|
||||||
|
import { Card, Pill } from './parts'
|
||||||
|
|
||||||
|
const STATUS_TONE = { requested: 'warning', pending: 'accent', arrived: 'success', cancelled: 'danger', no_show: 'warning', declined: 'danger' }
|
||||||
|
const EVENTS = ['reservation_updated', 'reservation_requested']
|
||||||
|
|
||||||
|
export default function BookingsCard({ tables, onNew }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const [tab, setTab] = useState('upcoming')
|
||||||
|
const [editing, setEditing] = useState(null)
|
||||||
|
const [declining, setDeclining] = useState(null)
|
||||||
|
const { data: list = [], isPending } = useLiveQuery({
|
||||||
|
queryKey: ['reservations', tab],
|
||||||
|
queryFn: () => client.get('/api/reservations/', { params: { tab } }).then(r => r.data),
|
||||||
|
events: EVENTS,
|
||||||
|
refetchInterval: 60_000,
|
||||||
|
})
|
||||||
|
const changed = () => { qc.invalidateQueries({ queryKey: ['reservations'] }); qc.invalidateQueries({ queryKey: ['tables'] }) }
|
||||||
|
const onError = err => toast.error(errorMessage(err, t))
|
||||||
|
const status = useMutation({ mutationFn: ({ id, value }) => client.patch(`/api/reservations/${id}/status`, { status: value }), onSuccess: changed, onError })
|
||||||
|
// online booking requests (phase 3S, S.6): the customer sees the answer (and the reason)
|
||||||
|
const answer = useMutation({
|
||||||
|
mutationFn: ({ id, action, reason }) => client.post(`/api/connect/bookings/${id}/${action}`, action === 'decline' ? { reason } : {}),
|
||||||
|
onSuccess: () => { changed(); setDeclining(null) }, onError,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card testId="bookings-card"
|
||||||
|
title={<span className="flex gap-1" role="tablist">
|
||||||
|
{['upcoming', 'history'].map(k => (
|
||||||
|
<Button key={k} size="sm" variant={tab === k ? 'primary' : 'ghost'} role="tab" aria-selected={tab === k} onClick={() => setTab(k)}>{t(`overview.bookings.${k}`)}</Button>
|
||||||
|
))}
|
||||||
|
</span>}
|
||||||
|
action={<Button size="sm" variant="secondary" icon={<Plus size={16} />} onClick={onNew} data-testid="booking-new">{t('overview.bookings.new')}</Button>}>
|
||||||
|
{isPending ? <div className="py-6 flex justify-center"><Spinner /></div>
|
||||||
|
: list.length === 0 ? <EmptyState compact icon={<CalendarDays size={24} />} title={t(tab === 'upcoming' ? 'overview.bookings.noneUpcoming' : 'overview.bookings.noneHistory')} />
|
||||||
|
: (
|
||||||
|
<ul className="max-h-96 overflow-y-auto divide-y divide-line">
|
||||||
|
{list.map(b => <BookingRow key={b.id} booking={b}
|
||||||
|
onEdit={() => setEditing(b)}
|
||||||
|
onStatus={value => status.mutate({ id: b.id, value })}
|
||||||
|
onConfirm={() => answer.mutate({ id: b.id, action: 'confirm' })}
|
||||||
|
onDecline={() => setDeclining(b)} />)}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
{editing && <BookingDialog tables={tables} initial={editing} onClose={() => setEditing(null)} onSaved={() => { setEditing(null); changed() }} />}
|
||||||
|
{declining && <DeclineDialog busy={answer.isPending} onClose={() => setDeclining(null)}
|
||||||
|
onDecline={reason => answer.mutate({ id: declining.id, action: 'decline', reason })} />}
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function BookingRow({ booking: b, onEdit, onStatus, onConfirm, onDecline }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime, formatDateTime } = useFormat()
|
||||||
|
const table = b.table_label || (b.table_id ? `#${b.table_id}` : null)
|
||||||
|
return (
|
||||||
|
<li className="flex items-center gap-3 px-4 py-2.5" data-testid="booking-row" data-status={b.status}>
|
||||||
|
<span className="w-12 shrink-0 text-center grid">
|
||||||
|
<span className="text-body font-bold tabular-nums text-ink">{formatTime(b.reserved_for)}</span>
|
||||||
|
<span className="text-caption text-ink-3">{formatDateTime(b.reserved_for, { day: 'numeric', month: 'short' })}</span>
|
||||||
|
</span>
|
||||||
|
<span className="flex-1 min-w-0 grid">
|
||||||
|
<span className="text-body font-semibold text-ink truncate">{b.guest_name}</span>
|
||||||
|
<span className="flex flex-wrap gap-x-3 text-caption text-ink-2">
|
||||||
|
<span className="inline-flex items-center gap-1"><Users size={12} aria-hidden="true" />{b.party_size}</span>
|
||||||
|
{table && <span className="inline-flex items-center gap-1"><Armchair size={12} aria-hidden="true" />{table}</span>}
|
||||||
|
{b.phone && <span className="inline-flex items-center gap-1"><Phone size={12} aria-hidden="true" />{b.phone}</span>}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<Pill tone={STATUS_TONE[b.status] ?? 'neutral'}>{t(`overview.bookings.status.${b.status}`, { defaultValue: b.status })}</Pill>
|
||||||
|
<span className="flex gap-1 shrink-0">
|
||||||
|
<IconButton size="sm" variant="ghost" label={t('overview.bookings.edit')} onClick={onEdit}><Pencil size={14} /></IconButton>
|
||||||
|
{b.status === 'requested' && (<>
|
||||||
|
<IconButton size="sm" variant="secondary" label={t('overview.bookings.confirm')} onClick={onConfirm} data-testid="booking-confirm"><Check size={14} /></IconButton>
|
||||||
|
<IconButton size="sm" variant="secondary" label={t('overview.bookings.decline')} onClick={onDecline} data-testid="booking-decline"><X size={14} /></IconButton>
|
||||||
|
</>)}
|
||||||
|
{b.status === 'pending' && <IconButton size="sm" variant="secondary" label={t('overview.bookings.arrived')} onClick={() => onStatus('arrived')} data-testid="booking-arrived"><UserCheck size={14} /></IconButton>}
|
||||||
|
{(b.status === 'pending' || b.status === 'no_show') && <IconButton size="sm" variant="ghost" label={t('overview.bookings.cancel')} onClick={() => onStatus('cancelled')}><X size={14} /></IconButton>}
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DeclineDialog({ busy, onClose, onDecline }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const [reason, setReason] = useState(t('overview.bookings.declineDefault'))
|
||||||
|
return (
|
||||||
|
<Dialog open size="sm" onClose={onClose} title={t('overview.bookings.declineTitle')}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||||
|
<Button variant="danger" loading={busy} onClick={() => onDecline(reason.trim() || null)} data-testid="booking-decline-confirm">{t('overview.bookings.decline')}</Button>
|
||||||
|
</>}>
|
||||||
|
<Field label={t('overview.bookings.reason')} hint={t('overview.bookings.reasonHint')}>
|
||||||
|
<Textarea rows={2} value={reason} onChange={e => setReason(e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BookingDialog({ tables, initial, onClose, onSaved }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { timeZone } = useFormat()
|
||||||
|
const edit = !!initial?.id
|
||||||
|
const [form, setForm] = useState(() => ({
|
||||||
|
guest_name: initial?.guest_name ?? '',
|
||||||
|
party_size: initial?.party_size ?? 2,
|
||||||
|
phone: initial?.phone ?? '',
|
||||||
|
email: initial?.email ?? '',
|
||||||
|
note: initial?.note ?? '',
|
||||||
|
table_id: initial?.table_id ?? null,
|
||||||
|
reserved_for: venueWallClock(initial?.reserved_for ? new Date(initial.reserved_for) : new Date(), timeZone),
|
||||||
|
}))
|
||||||
|
const [error, setError] = useState(null)
|
||||||
|
const set = (k, v) => { setForm(f => ({ ...f, [k]: v })); setError(null) }
|
||||||
|
const save = useMutation({
|
||||||
|
mutationFn: body => (edit ? client.patch(`/api/reservations/${initial.id}`, body) : client.post('/api/reservations/', body)),
|
||||||
|
onSuccess: () => { toast.success(edit ? t('overview.bookings.saved') : t('overview.bookings.created')); onSaved() },
|
||||||
|
onError: err => toast.error(errorMessage(err, t)),
|
||||||
|
})
|
||||||
|
function submit(e) {
|
||||||
|
e?.preventDefault()
|
||||||
|
if (!form.guest_name.trim()) { setError('name'); return }
|
||||||
|
if (!(Number(form.party_size) >= 1)) { setError('party'); return }
|
||||||
|
save.mutate(bookingBody(form))
|
||||||
|
}
|
||||||
|
const zones = tablesByZone(tables, t('overview.bookings.noZone'))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open onClose={onClose} title={edit ? t('overview.bookings.editTitle') : t('overview.bookings.newTitle')}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||||
|
<Button onClick={submit} loading={save.isPending} data-testid="booking-save">{edit ? t('overview.save') : t('overview.bookings.create')}</Button>
|
||||||
|
</>}>
|
||||||
|
<form onSubmit={submit} className="grid gap-3">
|
||||||
|
<div className="grid grid-cols-[1fr_6rem] gap-3">
|
||||||
|
<Field label={t('overview.bookings.name')} error={error === 'name' ? t('overview.bookings.nameNeeded') : undefined} required>
|
||||||
|
<Input value={form.guest_name} onChange={e => set('guest_name', e.target.value)} data-testid="booking-name" />
|
||||||
|
</Field>
|
||||||
|
<Field label={t('overview.bookings.people')} error={error === 'party' ? t('overview.bookings.peopleNeeded') : undefined}>
|
||||||
|
<Input type="number" min={1} max={999} value={form.party_size} onChange={e => set('party_size', e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
<Field label={t('overview.bookings.when')} hint={t('overview.bookings.whenHint')}>
|
||||||
|
<Input type="datetime-local" value={form.reserved_for} onChange={e => set('reserved_for', e.target.value)} data-testid="booking-when" />
|
||||||
|
</Field>
|
||||||
|
<div className="flex flex-wrap gap-1.5 -mt-1">
|
||||||
|
{BOOKING_OFFSETS.map(o => (
|
||||||
|
<Button key={`${o.mins}-${o.days}`} size="sm" variant="secondary"
|
||||||
|
onClick={() => set('reserved_for', venueWallClock(offsetFrom(new Date(), o), timeZone))}>
|
||||||
|
{o.mins ? (o.mins < 60 ? t('overview.bookings.inMinutes', { count: o.mins }) : t('overview.bookings.inHours', { count: o.mins / 60 })) : t('overview.bookings.inDays', { count: o.days })}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<Field label={t('overview.bookings.table')}>
|
||||||
|
<Select value={form.table_id ?? ''} onChange={e => set('table_id', e.target.value ? Number(e.target.value) : null)}>
|
||||||
|
<option value="">{t('overview.bookings.noTable')}</option>
|
||||||
|
{zones.map(z => (
|
||||||
|
<optgroup key={z.zone} label={z.zone}>
|
||||||
|
{z.tables.map(tb => <option key={tb.id} value={tb.id}>{tableName(tb)}</option>)}
|
||||||
|
</optgroup>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
|
<Field label={t('overview.bookings.phone')}><Input type="tel" value={form.phone} onChange={e => set('phone', e.target.value)} /></Field>
|
||||||
|
<Field label={t('overview.bookings.email')}><Input type="email" value={form.email} onChange={e => set('email', e.target.value)} /></Field>
|
||||||
|
</div>
|
||||||
|
<Field label={t('overview.bookings.note')} hint={t('overview.bookings.noteHint')}>
|
||||||
|
<Textarea rows={2} value={form.note} onChange={e => set('note', e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
</form>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
// The day summary (plan step 6.2), opened from the overview as "Day stats" (to look) or "Close
|
||||||
|
// the day" (adds the cash count and the checks). Closing: count the drawer (optional), then
|
||||||
|
// the checks: tables still open (with unpaid lines or not) and shifts still running. With open
|
||||||
|
// tables the close is forced: they are closed, unpaid amounts are lost, running shifts end.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, EmptyState, Spinner, cx } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { CashTab, ChecksTab, MoneyTab, PrintersTab, StaffTab, ZonesTab } from './DaySummaryTabs'
|
||||||
|
import { Pill } from './parts'
|
||||||
|
|
||||||
|
export default function DaySummaryDialog({ dayId, closing = false, onClose, onClosed }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatDateTime } = useFormat()
|
||||||
|
const [tab, setTab] = useState('money')
|
||||||
|
const [counted, setCounted] = useState('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const { data, isPending, error } = useLiveQuery({
|
||||||
|
queryKey: ['day-summary', dayId ?? 'current'],
|
||||||
|
queryFn: () => client.get('/api/business-day/summary', { params: dayId ? { day_id: dayId } : {} }).then(r => r.data),
|
||||||
|
events: closing ? ['order_updated', 'order_paid', 'order_closed'] : [],
|
||||||
|
refetchInterval: closing ? 15_000 : false,
|
||||||
|
})
|
||||||
|
const countedValue = counted.trim() === '' ? null : parseNumber(counted)
|
||||||
|
|
||||||
|
async function closeDay() {
|
||||||
|
setBusy(true)
|
||||||
|
try {
|
||||||
|
const body = { force: data.checks.open_orders > 0 }
|
||||||
|
if (countedValue != null && Number.isFinite(countedValue)) body.store_closing_cash = countedValue
|
||||||
|
await client.post('/api/business-day/close', body)
|
||||||
|
onClosed?.()
|
||||||
|
} catch (err) {
|
||||||
|
if (err.xenia?.code === 'business_day.orders_open') setTab('checks')
|
||||||
|
toast.error(errorMessage(err, t))
|
||||||
|
} finally { setBusy(false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ id: 'money', label: t('overview.day.tab.money') },
|
||||||
|
{ id: 'staff', label: t('overview.day.tab.staff'), badge: data?.waiters?.length },
|
||||||
|
{ id: 'zones', label: t('overview.day.tab.zones'), badge: data?.zones?.length },
|
||||||
|
{ id: 'printers', label: t('overview.day.tab.printers'), badge: data?.printers?.length },
|
||||||
|
...(closing ? [
|
||||||
|
{ id: 'cash', label: t('overview.day.tab.cash') },
|
||||||
|
{ id: 'checks', label: t('overview.day.tab.checks'), badge: data?.checks ? data.checks.open_orders + data.checks.active_shifts : null, warn: data?.checks?.with_unpaid_items > 0 },
|
||||||
|
] : []),
|
||||||
|
]
|
||||||
|
|
||||||
|
const footer = closing && data && tab !== 'checks' && (<>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||||
|
{tab !== 'cash'
|
||||||
|
? <Button onClick={() => setTab('cash')} data-testid="day-to-cash">{t('overview.day.toCash')}</Button>
|
||||||
|
: <Button onClick={() => setTab('checks')} data-testid="day-to-checks">{t('overview.day.toChecks')}</Button>}
|
||||||
|
</>)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open size="lg" onClose={onClose} footer={footer || undefined}
|
||||||
|
title={closing ? t('overview.day.closeTitle') : t('overview.day.statsTitle')}
|
||||||
|
description={data && <span className="inline-flex items-center gap-2">
|
||||||
|
<Pill tone={data.status === 'open' ? 'success' : 'neutral'}>{data.status === 'open' ? t('overview.day.open') : t('overview.day.closedState')}</Pill>
|
||||||
|
{t('overview.day.openedAt', { time: formatDateTime(data.opened_at, 'datetimeShort') })}
|
||||||
|
</span>}>
|
||||||
|
<div className="grid gap-4" data-testid="day-summary">
|
||||||
|
<div className="flex gap-1 overflow-x-auto border-b border-line -mx-1 px-1" role="tablist">
|
||||||
|
{tabs.map(tb => (
|
||||||
|
<button key={tb.id} type="button" role="tab" aria-selected={tab === tb.id} onClick={() => setTab(tb.id)} data-testid={`day-tab-${tb.id}`}
|
||||||
|
className={cx('flex items-center gap-1.5 px-3 py-2 -mb-px border-b-2 text-label whitespace-nowrap transition-colors duration-fast',
|
||||||
|
tab === tb.id ? 'border-accent text-ink font-semibold' : 'border-transparent text-ink-2 hover:text-ink')}>
|
||||||
|
{tb.label}
|
||||||
|
{tb.badge != null && <span className={cx('min-w-5 px-1 rounded-full text-caption font-bold tabular-nums', tb.warn ? 'bg-danger-soft text-danger-ink' : 'bg-surface-2 text-ink-2')}>{tb.badge}</span>}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{isPending && <div className="py-10 flex justify-center"><Spinner /></div>}
|
||||||
|
{error && <EmptyState compact title={errorMessage(error, t)} />}
|
||||||
|
{data && (<>
|
||||||
|
{tab === 'money' && <MoneyTab data={data} />}
|
||||||
|
{tab === 'staff' && <StaffTab data={data} />}
|
||||||
|
{tab === 'zones' && <ZonesTab data={data} />}
|
||||||
|
{tab === 'printers' && <PrintersTab data={data} />}
|
||||||
|
{tab === 'cash' && <CashTab data={data} counted={counted} onCounted={setCounted} value={countedValue} />}
|
||||||
|
{tab === 'checks' && <ChecksTab data={data} open={data.status === 'open'} closing={busy} onClose={closeDay} />}
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,289 @@
|
|||||||
|
// The tabs of the day summary (plan step 6.2): the day's money from sales to the estimated net
|
||||||
|
// result, each person's work and money, the zones and the printers; when closing, the cash count
|
||||||
|
// and the checks before the day closes.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { ChevronDown, Printer } from 'lucide-react'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, EmptyState, Field, InfoTip, Input, cx } from '@xenia/ui'
|
||||||
|
import { PAY_METHODS, cashCheck, paymentTotals } from './overviewLogic'
|
||||||
|
import { Avatar, Figure, Money, Pill, SplitBar } from './parts'
|
||||||
|
import { SOFT } from './tones'
|
||||||
|
|
||||||
|
const PAY_TONE = { cash: 'success', card: 'info', transfer: 'accent', treat: 'warning', other: 'neutral' }
|
||||||
|
|
||||||
|
function usePayParts() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
return w => PAY_METHODS.map(k => ({ key: k, tone: PAY_TONE[k], label: t(`overview.pay.${k}`), value: w[k] || 0 }))
|
||||||
|
}
|
||||||
|
|
||||||
|
function Row({ label, value, tone, warn, indent, sub, info }) {
|
||||||
|
return (
|
||||||
|
<div className={cx('flex items-baseline justify-between gap-3 py-1', indent && 'pl-4 text-label')}>
|
||||||
|
<span className={cx('flex-1 flex items-center gap-1', warn ? 'text-warning-ink' : indent ? 'text-ink-2' : 'text-ink')}>{label}{info}</span>
|
||||||
|
<span className="text-right grid">
|
||||||
|
<span className={cx('font-semibold tabular-nums', tone ?? 'text-ink')}>{value}</span>
|
||||||
|
{sub && <span className="text-caption text-ink-3">{sub}</span>}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Section({ title, children, shaded }) {
|
||||||
|
return (
|
||||||
|
<div className={cx('px-4 py-3 border-b border-line last:border-b-0', shaded && 'bg-surface-2')}>
|
||||||
|
<div className="text-caption font-semibold uppercase tracking-wide text-ink-3 mb-1">{title}</div>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MoneyTab({ data }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatMoney, formatDateTime } = useFormat()
|
||||||
|
const pay = usePayParts()
|
||||||
|
const staff = data.waiters.filter(w => w.role === 'waiter')
|
||||||
|
const sign = v => (v >= 0 ? 'text-success-ink' : 'text-danger-ink')
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4" data-testid="day-money">
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
||||||
|
<Figure label={t('overview.day.revenue')}><Money value={data.total_revenue} /></Figure>
|
||||||
|
<Figure label={t('overview.day.orders')}>{data.total_orders}</Figure>
|
||||||
|
<Figure label={t('overview.day.items')}>{data.total_items_ordered}</Figure>
|
||||||
|
<Figure label={t('overview.day.waiters')}>{staff.length}</Figure>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-6">
|
||||||
|
<Figure label={t('overview.day.opened')}>{formatDateTime(data.opened_at, 'datetimeShort')}</Figure>
|
||||||
|
<Figure label={t('overview.day.closed')}>{data.closed_at ? formatDateTime(data.closed_at, 'datetimeShort') : <span className="text-success-ink">{t('overview.day.stillOpen')}</span>}</Figure>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-card border border-line overflow-hidden">
|
||||||
|
<Section title={t('overview.day.sales')} shaded>
|
||||||
|
<Row label={t('overview.day.salesTotal')} value={formatMoney(data.total_revenue)} />
|
||||||
|
{data.tabbed_revenue > 0 && <Row indent label={t('overview.day.onTabs')} value={`− ${formatMoney(data.tabbed_revenue)}`} tone="text-warning-ink"
|
||||||
|
info={<InfoTip>{t('overview.day.onTabsTip')}</InfoTip>} />}
|
||||||
|
<Row label={t('overview.day.taken')} value={formatMoney(data.total_revenue - (data.tabbed_revenue || 0))} tone="text-success-ink" />
|
||||||
|
</Section>
|
||||||
|
<Section title={t('overview.day.cogs')}>
|
||||||
|
<Row label={t('overview.day.cogsKnown')} value={formatMoney(data.cogs_trackable)} info={<InfoTip>{t('overview.day.cogsTip')}</InfoTip>} />
|
||||||
|
{data.cogs_has_gap && <Row indent warn label={t('overview.day.uncosted', { count: data.cogs_uncosted_count, revenue: formatMoney(data.cogs_uncosted_revenue) })} value="?" />}
|
||||||
|
<Row label={t('overview.day.gross')} value={formatMoney(data.gross_profit)} tone={sign(data.gross_profit)} warn={data.cogs_has_gap}
|
||||||
|
sub={data.cogs_has_gap ? t('overview.day.partial') : undefined} />
|
||||||
|
</Section>
|
||||||
|
<Section title={t('overview.day.labour')}>
|
||||||
|
<Row label={t('overview.day.labourCost')} value={formatMoney(data.total_labor_cost)} />
|
||||||
|
{data.labor_untracked_shifts > 0 && <Row indent warn label={t('overview.day.noRate', { count: data.labor_untracked_shifts })} value="?" />}
|
||||||
|
</Section>
|
||||||
|
{data.waste_item_count > 0 && (
|
||||||
|
<Section title={t('overview.day.waste')}>
|
||||||
|
<Row label={t('overview.day.wasteEntries', { count: data.waste_item_count })} value={formatMoney(data.waste_estimated_cost)} tone="text-warning-ink" />
|
||||||
|
</Section>
|
||||||
|
)}
|
||||||
|
{data.expenses_total > 0 && (
|
||||||
|
<Section title={t('overview.day.expenses')}>
|
||||||
|
<Row label={t('overview.day.expensesTotal')} value={formatMoney(data.expenses_total)} />
|
||||||
|
<Row indent label={t('overview.day.expensesPaid')} value={formatMoney(data.expenses_paid_today)} />
|
||||||
|
{data.expenses_due > 0 && <Row indent warn label={t('overview.day.expensesDue')} value={formatMoney(data.expenses_due)} tone="text-danger-ink" />}
|
||||||
|
</Section>
|
||||||
|
)}
|
||||||
|
<Section shaded title={t('overview.day.net')}>
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<span className="text-label text-ink-2 flex items-center gap-1">{t('overview.day.netHint')}<InfoTip>{t('overview.day.netTip')}</InfoTip></span>
|
||||||
|
<span className={cx('text-title font-bold tabular-nums', sign(data.net_estimate))} data-testid="day-net">{formatMoney(data.net_estimate)}</span>
|
||||||
|
</div>
|
||||||
|
{data.net_has_unknowns && <p className="text-caption text-warning-ink mt-1">{t('overview.day.netPartial')}</p>}
|
||||||
|
</Section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{t('overview.day.payments')}</span>
|
||||||
|
{data.total_revenue > 0 ? <SplitBar parts={pay(paymentTotals(data.waiters))} /> : <span className="text-label text-ink-3">—</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data.store_closing_cash != null && (
|
||||||
|
<div className="rounded-card border border-line px-4 py-3">
|
||||||
|
<div className="text-caption font-semibold uppercase tracking-wide text-ink-3 mb-1">{t('overview.day.drawer')}</div>
|
||||||
|
<Row label={t('overview.day.drawerExpected')} value={formatMoney(data.store_expected_closing)} />
|
||||||
|
<Row label={t('overview.day.drawerCounted')} value={formatMoney(data.store_closing_cash)} />
|
||||||
|
<Row label={t('overview.day.drawerDiff')} warn={data.store_cash_discrepancy !== 0}
|
||||||
|
value={data.store_cash_discrepancy === 0 ? t('overview.cash.even') : formatMoney(data.store_cash_discrepancy)}
|
||||||
|
tone={data.store_cash_discrepancy === 0 ? 'text-success-ink' : 'text-danger-ink'} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StaffTab({ data }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime } = useFormat()
|
||||||
|
const pay = usePayParts()
|
||||||
|
const [open, setOpen] = useState(null)
|
||||||
|
if (data.waiters.length === 0) return <EmptyState compact title={t('overview.day.noStaff')} />
|
||||||
|
return (
|
||||||
|
<div className="grid gap-2" data-testid="day-staff">
|
||||||
|
{data.waiters.map(w => {
|
||||||
|
const shown = open === w.waiter_id
|
||||||
|
const role = w.role === 'waiter' ? 'waiter' : 'manager'
|
||||||
|
return (
|
||||||
|
<div key={w.waiter_id} className="rounded-card border border-line overflow-hidden">
|
||||||
|
<button type="button" onClick={() => setOpen(shown ? null : w.waiter_id)} aria-expanded={shown}
|
||||||
|
className="w-full flex flex-wrap items-center gap-3 px-4 py-3 text-left bg-surface hover:bg-surface-2">
|
||||||
|
<Avatar name={w.waiter_name} />
|
||||||
|
<span className="flex-1 min-w-32 grid">
|
||||||
|
<span className="text-body font-semibold text-ink">{w.waiter_name}</span>
|
||||||
|
<Pill tone={role === 'waiter' ? 'info' : 'accent'} className="justify-self-start">{t(`overview.day.role.${role}`)}</Pill>
|
||||||
|
</span>
|
||||||
|
<Figure label={t('overview.day.ordersOpened')}>{w.orders_opened}</Figure>
|
||||||
|
<Figure label={t('overview.day.tablesServed')}>{w.tables_served ?? 0}</Figure>
|
||||||
|
<Figure label={t('overview.day.itemsPaid')}>{w.items_paid}</Figure>
|
||||||
|
<Figure label={t('overview.day.collected')}><Money value={w.total_collected} className="text-success-ink" /></Figure>
|
||||||
|
<ChevronDown size={16} className={cx('text-ink-3 transition-transform duration-base', shown && 'rotate-180')} aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
{shown && (
|
||||||
|
<div className="border-t border-line bg-surface-2 p-4 grid gap-3">
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
||||||
|
<Figure label={t('overview.day.shiftStart')}>{w.shift_started_at ? formatTime(w.shift_started_at) : '—'}</Figure>
|
||||||
|
<Figure label={t('overview.day.shiftEnd')}>{w.shift_ended_at ? formatTime(w.shift_ended_at) : <span className="text-success-ink">{t('overview.day.shiftRunning')}</span>}</Figure>
|
||||||
|
<Figure label={t('overview.day.rate')}>{w.hourly_rate_snapshot != null ? <Money value={w.hourly_rate_snapshot} /> : '—'}</Figure>
|
||||||
|
<Figure label={t('overview.day.payNow')}>{w.shift_pay != null ? <Money value={w.shift_pay} /> : <span className="text-ink-3">{t('overview.day.notTracked')}</span>}</Figure>
|
||||||
|
<Figure label={t('overview.day.startCash')}>{w.starting_cash != null ? <Money value={w.starting_cash} /> : '—'}</Figure>
|
||||||
|
<Figure label={t('overview.day.drawerNow')}><Money value={(w.starting_cash ?? 0) + (w.total_collected ?? 0)} className="text-accent-ink" /></Figure>
|
||||||
|
</div>
|
||||||
|
{w.total_collected > 0 && <SplitBar parts={pay(w)} />}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ZonesTab({ data }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const max = Math.max(1, ...data.zones.map(z => z.revenue))
|
||||||
|
if (data.zones.length === 0) return <EmptyState compact title={t('overview.day.noZones')} />
|
||||||
|
return (
|
||||||
|
<div className="grid gap-2" data-testid="day-zones">
|
||||||
|
{data.zones.map(z => (
|
||||||
|
<div key={z.group_id} className="rounded-card border border-line p-4 grid gap-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{/* a zone's colour is the venue's choice (data), not styling */}
|
||||||
|
<span className={cx('w-3 h-3 rounded-sm shrink-0', !z.color && 'bg-ink-3')} style={z.color ? { background: z.color } : undefined} aria-hidden="true" />
|
||||||
|
<span className="flex-1 text-body font-semibold text-ink">{z.group_name}</span>
|
||||||
|
<Money value={z.revenue} className="text-title font-bold text-ink" />
|
||||||
|
</div>
|
||||||
|
<div className="h-1.5 rounded-full bg-surface-2 overflow-hidden">
|
||||||
|
<div className={cx('h-full rounded-full', !z.color && 'bg-ink-3')} style={{ width: `${Math.round((z.revenue / max) * 100)}%`, ...(z.color ? { background: z.color } : {}) }} />
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-6">
|
||||||
|
<Figure label={t('overview.day.orders')}>{z.orders}</Figure>
|
||||||
|
<Figure label={t('overview.day.items')}>{z.items}</Figure>
|
||||||
|
{z.orders > 0 && <Figure label={t('overview.day.perOrder')}><Money value={z.revenue / z.orders} /></Figure>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PrintersTab({ data }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
if (data.printers.length === 0) return <EmptyState compact title={t('overview.day.noPrints')} />
|
||||||
|
return (
|
||||||
|
<div className="grid gap-2" data-testid="day-printers">
|
||||||
|
{data.printers.map(p => {
|
||||||
|
const rate = p.jobs > 0 ? Math.round((p.success / p.jobs) * 100) : 0
|
||||||
|
return (
|
||||||
|
<div key={p.printer_id} className="rounded-card border border-line p-4 grid gap-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<span className="w-9 h-9 grid place-items-center rounded-control bg-surface-2 text-ink-2"><Printer size={18} aria-hidden="true" /></span>
|
||||||
|
<span className="flex-1 grid">
|
||||||
|
<span className="text-body font-semibold text-ink">{p.printer_name}</span>
|
||||||
|
<span className="text-caption text-ink-3">{p.ip_address}</span>
|
||||||
|
</span>
|
||||||
|
<span className="grid text-right">
|
||||||
|
<Money value={p.items_value} className="text-title font-bold text-ink" />
|
||||||
|
<span className="text-caption text-ink-3">{t('overview.day.printedValue')}</span>
|
||||||
|
</span>
|
||||||
|
<Pill tone={rate === 100 ? 'success' : rate >= 80 ? 'warning' : 'danger'}>{rate}%</Pill>
|
||||||
|
</div>
|
||||||
|
<div className="flex h-1.5 rounded-full bg-surface-2 overflow-hidden">
|
||||||
|
<div className="bg-success" style={{ flex: p.success }} />
|
||||||
|
<div className="bg-danger" style={{ flex: p.failed }} />
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-6">
|
||||||
|
<Figure label={t('overview.day.jobs')}>{p.jobs}</Figure>
|
||||||
|
<Figure label={t('overview.day.jobsOk')}>{p.success}</Figure>
|
||||||
|
{p.failed > 0 && <Figure label={t('overview.day.jobsFailed')}><span className="text-danger-ink">{p.failed}</span></Figure>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CashTab({ data, counted, onCounted, value }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatMoney } = useFormat()
|
||||||
|
const expected = data.store_expected_closing ?? 0
|
||||||
|
const check = cashCheck(value, expected)
|
||||||
|
const tone = check ? (check.state === 'even' ? 'success' : 'danger') : null
|
||||||
|
return (
|
||||||
|
<div className="grid gap-4" data-testid="day-cash">
|
||||||
|
<div className="rounded-card border border-line bg-surface-2 px-4 py-3">
|
||||||
|
<div className="text-caption font-semibold uppercase tracking-wide text-ink-3 mb-1">{t('overview.day.takings')}</div>
|
||||||
|
<Row label={t('overview.day.staffTook')} value={formatMoney(data.total_waiter_collected)} />
|
||||||
|
{data.store_opening_cash != null && <Row label={t('overview.day.openingCash')} value={formatMoney(data.store_opening_cash)} />}
|
||||||
|
<div className="border-t border-line mt-1 pt-1">
|
||||||
|
<Row label={t('overview.day.drawerExpected')} value={formatMoney(expected)} info={<InfoTip>{t('overview.day.drawerExpectedTip')}</InfoTip>} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Field label={t('overview.day.countDrawer')} hint={t('overview.day.countHint')}>
|
||||||
|
<Input inputMode="decimal" value={counted} onChange={e => onCounted(e.target.value)} placeholder="0" data-testid="day-counted" />
|
||||||
|
</Field>
|
||||||
|
{check && (
|
||||||
|
<div className={cx('rounded-card border p-3 grid gap-1', SOFT[tone])} data-testid="day-check" data-state={check.state}>
|
||||||
|
<span className="font-semibold">{t(`overview.cash.${check.state}`)}{check.state !== 'even' && ` ${formatMoney(Math.abs(check.diff))}`}</span>
|
||||||
|
<span className="text-label">{t(`overview.day.cash.${check.state}`, { amount: formatMoney(Math.abs(check.diff)) })}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check({ ok, warn, title, children, testId }) {
|
||||||
|
return (
|
||||||
|
<div className={cx('rounded-card border p-4 flex items-start gap-3', ok ? 'border-success bg-success-soft' : warn ? 'border-warning bg-warning-soft' : 'border-danger bg-danger-soft')} data-testid={testId} data-ok={ok}>
|
||||||
|
<span className="text-title" aria-hidden="true">{ok ? '✓' : '!'}</span>
|
||||||
|
<span className="grid"><span className="text-body font-semibold text-ink">{title}</span><span className="text-label">{children}</span></span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ChecksTab({ data, open, closing, onClose }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { checks } = data
|
||||||
|
const tables = checks.open_orders
|
||||||
|
const unpaid = checks.with_unpaid_items > 0
|
||||||
|
const shifts = checks.active_shifts
|
||||||
|
return (
|
||||||
|
<div className="grid gap-3" data-testid="day-checks">
|
||||||
|
<Check ok={tables === 0} title={t('overview.day.openTables')} testId="check-tables">
|
||||||
|
{tables === 0 ? t('overview.day.allClosed') : t('overview.day.stillOpenTables', { count: tables }) + (unpaid ? ` · ${t('overview.day.withUnpaid', { count: checks.with_unpaid_items })}` : '')}
|
||||||
|
</Check>
|
||||||
|
<Check ok={shifts === 0} warn title={t('overview.day.activeShifts')} testId="check-shifts">
|
||||||
|
{shifts === 0 ? t('overview.day.noShifts') : t('overview.day.shiftsWillEnd', { count: shifts })}
|
||||||
|
</Check>
|
||||||
|
<p className={cx('rounded-card p-3 text-label', tables === 0 ? SOFT.success : unpaid ? SOFT.danger : SOFT.warning)}>
|
||||||
|
{tables === 0 ? t('overview.day.ready') : unpaid ? t('overview.day.unpaidWarning') : t('overview.day.autoClose')}
|
||||||
|
</p>
|
||||||
|
{open && (
|
||||||
|
<Button size="lg" variant={unpaid ? 'danger' : 'primary'} loading={closing} onClick={onClose} data-testid="day-close-confirm">
|
||||||
|
{unpaid ? t('overview.day.forceClose') : t('overview.day.closeNow')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
// Messages to the staff's phones (plan step 6.2): the latest ones with who they went to and how
|
||||||
|
// many have read them; "New" writes one to everyone or to chosen waiters, optionally about some
|
||||||
|
// tables, from a quick template or typed. The shift list's message button opens the same
|
||||||
|
// dialog with that waiter chosen.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { MessageSquare, Plus, Send } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, EmptyState, Field, Textarea } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { messageAcks, messageTargets, tableName } from './overviewLogic'
|
||||||
|
import { Card, Pill } from './parts'
|
||||||
|
|
||||||
|
const useTemplates = () => useLiveQuery({
|
||||||
|
queryKey: ['quick-templates'], queryFn: () => client.get('/api/notifications/templates').then(r => r.data), staleTime: 60_000,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default function MessagesCard({ staff, tables }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime } = useFormat()
|
||||||
|
const [composing, setComposing] = useState(false)
|
||||||
|
const { data: messages = [] } = useLiveQuery({
|
||||||
|
queryKey: ['messages-all'],
|
||||||
|
queryFn: () => client.get('/api/notifications/all', { params: { limit: 20 } }).then(r => r.data),
|
||||||
|
events: ['message_sent'],
|
||||||
|
refetchInterval: 30_000, // reads (acks) send no event
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title={t('overview.messages.title')} testId="messages-card"
|
||||||
|
action={<Button size="sm" variant="secondary" icon={<Plus size={16} />} onClick={() => setComposing(true)} data-testid="message-new">{t('overview.messages.new')}</Button>}>
|
||||||
|
{messages.length === 0 ? <EmptyState compact icon={<MessageSquare size={24} />} title={t('overview.messages.none')} /> : (
|
||||||
|
<ul className="max-h-80 overflow-y-auto divide-y divide-line">
|
||||||
|
{messages.map(m => {
|
||||||
|
const to = messageTargets(m, staff)
|
||||||
|
const acks = messageAcks(m, staff.length)
|
||||||
|
return (
|
||||||
|
<li key={m.id} className="flex items-start gap-3 px-4 py-2.5" data-testid="message-row">
|
||||||
|
<span className="flex-1 min-w-0 grid">
|
||||||
|
<span className="text-body font-semibold text-ink">{m.body}</span>
|
||||||
|
<span className="text-caption text-ink-3">{t('overview.messages.to', { who: to ? to.join(', ') : t('overview.messages.everyone'), time: formatTime(m.created_at) })}</span>
|
||||||
|
</span>
|
||||||
|
<Pill tone={acks.all ? 'success' : 'warning'} title={t('overview.messages.readBy')}>{t('overview.messages.read', { read: acks.read, of: acks.of })}</Pill>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
{composing && <ComposeDialog staff={staff} tables={tables} onClose={() => setComposing(false)} />}
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Write a message; `to` preselects one waiter ({ id, name }) and hides the pickers. */
|
||||||
|
export function ComposeDialog({ staff = [], tables = [], to, onClose }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const { data: templates = [] } = useTemplates()
|
||||||
|
const [waiters, setWaiters] = useState(to ? [to.id] : []) // [] = everyone
|
||||||
|
const [tableIds, setTableIds] = useState([])
|
||||||
|
const [body, setBody] = useState('')
|
||||||
|
const send = useMutation({
|
||||||
|
mutationFn: payload => client.post('/api/notifications/send', payload),
|
||||||
|
onSuccess: () => { toast.success(t('overview.messages.sent')); qc.invalidateQueries({ queryKey: ['messages-all'] }); onClose() },
|
||||||
|
onError: err => toast.error(errorMessage(err, t)),
|
||||||
|
})
|
||||||
|
const toggle = (list, set, id) => set(list.includes(id) ? list.filter(x => x !== id) : [...list, id])
|
||||||
|
const chip = on => (on ? 'primary' : 'secondary')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open onClose={onClose} title={to ? t('overview.messages.toOne', { name: to.name }) : t('overview.messages.newTitle')}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||||
|
<Button icon={<Send size={16} />} disabled={!body.trim()} loading={send.isPending} data-testid="message-send"
|
||||||
|
onClick={() => send.mutate({ body: body.trim(), target_waiter_ids: waiters, table_ids: tableIds })}>{t('overview.messages.send')}</Button>
|
||||||
|
</>}>
|
||||||
|
<div className="grid gap-4">
|
||||||
|
{!to && (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<span className="text-label font-semibold text-ink-2">{t('overview.messages.recipients')} {waiters.length === 0 && <span className="text-accent-ink">{t('overview.messages.allOfThem')}</span>}</span>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{staff.map(w => <Button key={w.id} size="sm" variant={chip(waiters.includes(w.id))} onClick={() => toggle(waiters, setWaiters, w.id)}>{w.nickname || w.full_name || w.username}</Button>)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!to && tables.length > 0 && (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<span className="text-label font-semibold text-ink-2">{t('overview.messages.tables')}</span>
|
||||||
|
<div className="flex flex-wrap gap-1.5 max-h-24 overflow-y-auto">
|
||||||
|
{tables.map(tb => <Button key={tb.id} size="sm" variant={chip(tableIds.includes(tb.id))} onClick={() => toggle(tableIds, setTableIds, tb.id)}>{tableName(tb)}</Button>)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{templates.length > 0 && (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<span className="text-label font-semibold text-ink-2">{t('overview.messages.quick')}</span>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{templates.map(tp => <Button key={tp.id} size="sm" variant={chip(body === tp.body)} onClick={() => setBody(tp.body)}>{tp.body}</Button>)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Field label={t('overview.messages.text')}>
|
||||||
|
<Textarea rows={3} value={body} onChange={e => setBody(e.target.value)} data-testid="message-body" />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Notes and to-dos at a glance (plan step 6.2): how many notes and open to-dos, the pinned
|
||||||
|
// count; a click opens Notes, resting the pointer on it for a second previews the pinned notes,
|
||||||
|
// the urgent to-dos and the latest notes.
|
||||||
|
import { useRef, useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { ArrowRight, CheckSquare, FileText, Pin, Square } from 'lucide-react'
|
||||||
|
import { useTranslation } from '@xenia/i18n'
|
||||||
|
import { cx } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { notesPreview } from './overviewLogic'
|
||||||
|
import { Pill } from './parts'
|
||||||
|
|
||||||
|
export default function NotesCard() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const timer = useRef(null)
|
||||||
|
const [preview, setPreview] = useState(false)
|
||||||
|
const { data: notes = [] } = useLiveQuery({ queryKey: ['notes'], queryFn: () => client.get('/api/notes/').then(r => r.data), refetchInterval: 60_000 })
|
||||||
|
const { data: todos = [] } = useLiveQuery({ queryKey: ['todos'], queryFn: () => client.get('/api/notes/todos').then(r => r.data), refetchInterval: 60_000 })
|
||||||
|
const items = notesPreview(notes, todos)
|
||||||
|
const pinned = notes.filter(n => n.is_pinned).length
|
||||||
|
|
||||||
|
const enter = () => { clearTimeout(timer.current); timer.current = setTimeout(() => setPreview(true), 1000) }
|
||||||
|
const leave = () => { clearTimeout(timer.current); setPreview(false) }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative" onMouseEnter={enter} onMouseLeave={leave}>
|
||||||
|
<button type="button" onClick={() => navigate('/notes')} onFocus={() => setPreview(true)} onBlur={leave}
|
||||||
|
className="w-full flex items-center gap-3 p-4 rounded-card border border-line bg-surface shadow-raised text-left hover:shadow-popover transition-shadow duration-fast"
|
||||||
|
data-testid="notes-card">
|
||||||
|
<span className="flex-1 min-w-0 grid">
|
||||||
|
<span className="text-body-lg font-semibold text-ink">{t('overview.notes.title')}</span>
|
||||||
|
<span className="text-label text-ink-3">{t('overview.notes.counts', { notes: notes.length, todos: todos.filter(x => !x.is_done).length })}</span>
|
||||||
|
</span>
|
||||||
|
{pinned > 0 && <Pill tone="warning"><Pin size={12} aria-hidden="true" />{pinned}</Pill>}
|
||||||
|
<ArrowRight size={16} className="text-ink-3" aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
{preview && items.length > 0 && (
|
||||||
|
<ul className="absolute top-full inset-x-0 mt-1.5 z-popover rounded-card border border-line bg-surface shadow-popover divide-y divide-line overflow-hidden">
|
||||||
|
{items.map(item => {
|
||||||
|
const Icon = item.kind === 'todo' ? (item.is_done ? CheckSquare : Square) : item.is_pinned ? Pin : FileText
|
||||||
|
return (
|
||||||
|
<li key={`${item.kind}-${item.id}`} className="flex items-start gap-2 px-4 py-2.5">
|
||||||
|
<Icon size={14} className="mt-0.5 shrink-0 text-ink-3" aria-hidden="true" />
|
||||||
|
<span className={cx('text-label text-ink line-clamp-2', item.is_done && 'line-through opacity-50')}>{item.body}</span>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
// A table's order at a glance, opened from the overview's table chips and the waiting prints
|
||||||
|
// (plan step 6.2): its lines with price changes, pay a line or everything, close or cancel it
|
||||||
|
// (a cancel asks whether to print a cancellation ticket), print it on a chosen printer, or open
|
||||||
|
// the full order page.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { ArrowRight, Printer, X } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, EmptyState, IconButton, Select, Spinner, cx } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { lineTotal, orderTotal } from './overviewLogic'
|
||||||
|
import { Money, Pill } from './parts'
|
||||||
|
import { useDuration } from './hooks'
|
||||||
|
|
||||||
|
const ORDER_EVENTS = ['order_updated', 'order_paid', 'order_closed', 'order_refunded']
|
||||||
|
const STATUS_TONE = { open: 'success', partially_paid: 'info', paid: 'accent', closed: 'neutral', cancelled: 'danger' }
|
||||||
|
const EVENT_TONE = { waiter_discount: 'text-accent-ink', free_item_added: 'text-success-ink', modifier_applied: 'text-info-ink' }
|
||||||
|
|
||||||
|
export default function OrderDialog({ orderId, tableName, onClose, onOpenFull }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime, formatMoney } = useFormat()
|
||||||
|
const since = useDuration()
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const [confirm, setConfirm] = useState(null) // { kind: 'cancelItem', itemId } | { kind: 'cancelOrder' } | { kind: 'close' }
|
||||||
|
const [printCancel, setPrintCancel] = useState(null) // the same, after "yes": ask about the ticket
|
||||||
|
const [printerId, setPrinterId] = useState('')
|
||||||
|
|
||||||
|
const { data: order, isPending } = useLiveQuery({
|
||||||
|
queryKey: ['order', orderId],
|
||||||
|
queryFn: () => client.get(`/api/orders/${orderId}`).then(r => r.data),
|
||||||
|
events: ORDER_EVENTS,
|
||||||
|
})
|
||||||
|
const { data: staff = [] } = useLiveQuery({ queryKey: ['waiters'], queryFn: () => client.get('/api/waiters/').then(r => r.data), staleTime: 60_000 })
|
||||||
|
const { data: printers = [] } = useLiveQuery({ queryKey: ['printers'], queryFn: () => client.get('/api/system/printers').then(r => r.data), staleTime: 60_000 })
|
||||||
|
const { data: priceEvents = [] } = useLiveQuery({
|
||||||
|
queryKey: ['price-events', orderId],
|
||||||
|
queryFn: () => client.get(`/api/pricing/events/order/${orderId}`).then(r => r.data),
|
||||||
|
events: ['order_updated'],
|
||||||
|
})
|
||||||
|
const eventsOf = id => priceEvents.filter(ev => ev.order_item_id === id)
|
||||||
|
const nameOf = id => { const w = staff.find(x => x.id === id); return w ? (w.nickname || w.full_name || w.username) : `#${id}` }
|
||||||
|
|
||||||
|
const refresh = () => {
|
||||||
|
qc.invalidateQueries({ queryKey: ['order', orderId] })
|
||||||
|
qc.invalidateQueries({ queryKey: ['orders-active'] })
|
||||||
|
}
|
||||||
|
const run = (fn, done, after) => ({
|
||||||
|
mutationFn: fn,
|
||||||
|
onSuccess: () => { toast.success(done); refresh(); after?.() },
|
||||||
|
onError: err => toast.error(errorMessage(err, t)),
|
||||||
|
})
|
||||||
|
const pay = useMutation(run(ids => client.post(`/api/orders/${orderId}/pay`, { item_ids: ids }), t('overview.order.paidDone')))
|
||||||
|
const cancelItem = useMutation(run(({ itemId, print }) => client.delete(`/api/orders/${orderId}/items/${itemId}`, { params: { print_cancellation: print } }), t('overview.order.lineCancelled')))
|
||||||
|
const cancelOrder = useMutation(run(({ print }) => client.delete(`/api/orders/${orderId}`, { params: { print_cancellation: print } }), t('overview.order.cancelled'), onClose))
|
||||||
|
const close = useMutation(run(() => client.post(`/api/orders/${orderId}/close`), t('overview.order.closed'), onClose))
|
||||||
|
const print = useMutation(run(pid => client.post(`/api/orders/${orderId}/print`, { printer_id: pid }), t('overview.order.printing')))
|
||||||
|
|
||||||
|
const isOpen = order ? ['open', 'partially_paid'].includes(order.status) : false
|
||||||
|
const active = order ? order.items.filter(i => i.status === 'active') : []
|
||||||
|
|
||||||
|
const confirmed = () => {
|
||||||
|
const c = confirm
|
||||||
|
setConfirm(null)
|
||||||
|
if (c.kind === 'close') close.mutate()
|
||||||
|
else setPrintCancel(c)
|
||||||
|
}
|
||||||
|
const cancelWith = printIt => {
|
||||||
|
const c = printCancel
|
||||||
|
setPrintCancel(null)
|
||||||
|
if (c.kind === 'cancelItem') cancelItem.mutate({ itemId: c.itemId, print: printIt })
|
||||||
|
else cancelOrder.mutate({ print: printIt })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open size="lg" onClose={onClose}
|
||||||
|
title={<span className="flex flex-wrap items-center gap-2">
|
||||||
|
{t('overview.order.title', { table: tableName })}
|
||||||
|
{order && <Pill tone={STATUS_TONE[order.status] ?? 'neutral'}>{t(`overview.orderStatus.${order.status}`, { defaultValue: order.status })}</Pill>}
|
||||||
|
{order && <Money value={orderTotal(order.items)} className="ml-auto text-title font-semibold text-ink" data-testid="order-total" />}
|
||||||
|
</span>}
|
||||||
|
description={order ? t('overview.order.sub', { id: order.id, time: formatTime(order.opened_at), since: since(order.opened_at) }) : undefined}
|
||||||
|
footer={order && <div className="flex flex-wrap items-center gap-2 w-full">
|
||||||
|
{isOpen && active.length > 0 && <Button onClick={() => pay.mutate(active.map(i => i.id))} loading={pay.isPending} data-testid="order-pay-all">{t('overview.order.payAll')}</Button>}
|
||||||
|
{isOpen && <Button variant="secondary" onClick={() => setConfirm({ kind: 'close' })}>{t('overview.order.close')}</Button>}
|
||||||
|
{isOpen && <Button variant="danger" onClick={() => setConfirm({ kind: 'cancelOrder' })}>{t('overview.order.cancel')}</Button>}
|
||||||
|
<span className="flex-1" />
|
||||||
|
{printers.length > 0 && (
|
||||||
|
<span className="flex items-center gap-2">
|
||||||
|
<Select size="sm" value={printerId} onChange={e => setPrinterId(e.target.value)} aria-label={t('overview.order.printer')}
|
||||||
|
placeholder={t('overview.order.printer')} options={printers.map(p => ({ value: String(p.id), label: p.name }))} />
|
||||||
|
<Button size="sm" variant="secondary" icon={<Printer size={16} />} disabled={!printerId} loading={print.isPending}
|
||||||
|
onClick={() => print.mutate(Number(printerId))}>{t('overview.order.print')}</Button>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<Button size="sm" variant="ghost" iconEnd={<ArrowRight size={16} />} onClick={onOpenFull}>{t('overview.order.full')}</Button>
|
||||||
|
</div>}>
|
||||||
|
{isPending && <div className="py-10 flex justify-center"><Spinner /></div>}
|
||||||
|
{order && (
|
||||||
|
<div className="grid gap-3 -mx-2" data-testid="order-dialog">
|
||||||
|
{order.waiters.length > 0 && (
|
||||||
|
<div className="flex flex-wrap items-center gap-2 px-2">
|
||||||
|
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{t('overview.order.staff')}</span>
|
||||||
|
{order.waiters.map(w => <Pill key={w.waiter_id} tone="accent">{nameOf(w.waiter_id)}</Pill>)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{order.items.length === 0 ? <EmptyState compact title={t('overview.order.empty')} /> : (
|
||||||
|
<ul className="divide-y divide-line">
|
||||||
|
{order.items.map(item => {
|
||||||
|
const evs = eventsOf(item.id).filter(ev => EVENT_TONE[ev.event_type])
|
||||||
|
const cancelled = item.status === 'cancelled'
|
||||||
|
return (
|
||||||
|
<li key={item.id} className={cx('px-2 py-2', cancelled && 'opacity-50')} data-testid="order-line">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className={cx('flex-1 min-w-0', cancelled && 'line-through')}>
|
||||||
|
<div className="flex flex-wrap items-center gap-1.5 text-body font-semibold text-ink">
|
||||||
|
{item.product?.name ?? `#${item.product_id}`}
|
||||||
|
<span className="font-normal text-ink-3">×{item.quantity}</span>
|
||||||
|
{item.deal_id && <Pill tone="accent">{t('overview.order.free')}</Pill>}
|
||||||
|
</div>
|
||||||
|
{item.notes && <div className="text-caption text-ink-3">{item.notes}</div>}
|
||||||
|
{item.paid_by && <div className="text-caption font-semibold text-success-ink">{t('overview.order.linePaid')}</div>}
|
||||||
|
</div>
|
||||||
|
<Money value={lineTotal(item)} className={cx('text-body font-semibold min-w-16 text-right', item.price_adjustment ? 'text-info-ink' : 'text-ink')} />
|
||||||
|
{isOpen && item.status === 'active' && (<>
|
||||||
|
<Button size="sm" variant="secondary" onClick={() => pay.mutate([item.id])}>{t('overview.order.pay')}</Button>
|
||||||
|
<IconButton size="sm" variant="ghost" label={t('overview.order.cancelLine')} onClick={() => setConfirm({ kind: 'cancelItem', itemId: item.id })}><X size={16} /></IconButton>
|
||||||
|
</>)}
|
||||||
|
</div>
|
||||||
|
{evs.map((ev, i) => (
|
||||||
|
<div key={i} className={cx('flex items-center gap-2 pl-4 text-caption', EVENT_TONE[ev.event_type])}>
|
||||||
|
<span aria-hidden="true">↳</span>
|
||||||
|
<span className="flex-1">{ev.modifier_name || ev.deal_name || t(`overview.order.event.${ev.event_type}`)}</span>
|
||||||
|
{ev.delta_amount != null && <span className="font-semibold">{formatMoney(ev.delta_amount, { signDisplay: 'exceptZero' })}</span>}
|
||||||
|
{ev.price_after != null && <span className="text-ink-3">→ {formatMoney(ev.price_after)}</span>}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{confirm && (
|
||||||
|
<Dialog open size="sm" onClose={() => setConfirm(null)} title={t(`overview.order.confirm.${confirm.kind}`)}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={() => setConfirm(null)}>{t('overview.back')}</Button>
|
||||||
|
<Button variant={confirm.kind === 'close' ? 'primary' : 'danger'} onClick={confirmed} data-testid="order-confirm">
|
||||||
|
{confirm.kind === 'close' ? t('overview.order.close') : t('overview.order.cancel')}
|
||||||
|
</Button>
|
||||||
|
</>}>
|
||||||
|
{confirm.kind === 'cancelOrder' && <p>{t('overview.order.confirm.cancelOrderBody')}</p>}
|
||||||
|
</Dialog>
|
||||||
|
)}
|
||||||
|
{printCancel && (
|
||||||
|
<Dialog open size="sm" onClose={() => setPrintCancel(null)} title={t('overview.order.printCancel')}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={() => cancelWith(false)} data-testid="cancel-no-print">{t('overview.order.printCancelNo')}</Button>
|
||||||
|
<Button variant="danger" icon={<Printer size={16} />} onClick={() => cancelWith(true)}>{t('overview.order.printCancelYes')}</Button>
|
||||||
|
</>}>
|
||||||
|
<p>{t('overview.order.printCancelBody')}</p>
|
||||||
|
</Dialog>
|
||||||
|
)}
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
// The overview, the manager's landing page (/dashboard; plan step 6.2, was DashboardPage).
|
||||||
|
// Top: the business day (open / closed, since when), its stats and close, opening it (refused
|
||||||
|
// when the license is locked or expired), and hiding the amounts (privacy, kept per browser).
|
||||||
|
// Then the day's figures, the waiters on shift, the tables now, revenue per hour and orders
|
||||||
|
// waiting to print on the left; notes, bookings and staff messages on the right (each only when
|
||||||
|
// its module is on). Orders and tables refresh from the live events; the day and the shifts
|
||||||
|
// (which send none) every 15 seconds.
|
||||||
|
import { useContext, useState } from 'react'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { BarChart3, Eye, EyeOff, Lock, Play, Power } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useModule } from '@xenia/access'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, IconButton, Spinner, cx } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { LicenseContext } from '../../layouts/AppLayout'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import BookingsCard, { BookingDialog } from './BookingsCard'
|
||||||
|
import DaySummaryDialog from './DaySummaryDialog'
|
||||||
|
import MessagesCard, { ComposeDialog } from './MessagesCard'
|
||||||
|
import NotesCard from './NotesCard'
|
||||||
|
import OrderDialog from './OrderDialog'
|
||||||
|
import PendingPrints from './PendingPrints'
|
||||||
|
import ShiftDialog from './ShiftDialog'
|
||||||
|
import ShiftsCard from './ShiftsCard'
|
||||||
|
import TablesCard from './TablesCard'
|
||||||
|
import { dayKpis, dayOrders, hourBuckets, orderPairs, tableCards } from './overviewLogic'
|
||||||
|
import { Card, HourBars, Money, Pill } from './parts'
|
||||||
|
import { SOLID } from './tones'
|
||||||
|
import { useDuration, useHourOf } from './hooks'
|
||||||
|
|
||||||
|
const ORDER_EVENTS = ['order_updated', 'order_paid', 'order_closed', 'order_refunded', 'table_list_changed', 'table_flags_changed']
|
||||||
|
const PRIVACY_KEY = 'privacyMode'
|
||||||
|
const readPrivacy = () => { try { return localStorage.getItem(PRIVACY_KEY) === 'true' } catch { return false } }
|
||||||
|
|
||||||
|
export default function OverviewPage() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatDateTime, formatTime } = useFormat()
|
||||||
|
const since = useDuration()
|
||||||
|
const hourOf = useHourOf()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const license = useContext(LicenseContext)
|
||||||
|
const notesOn = useModule('notes')
|
||||||
|
const bookingsOn = useModule('reservations')
|
||||||
|
const chatOn = useModule('chat')
|
||||||
|
|
||||||
|
const [hidden, setHidden] = useState(readPrivacy)
|
||||||
|
const [order, setOrder] = useState(null) // { id, table }
|
||||||
|
const [shift, setShift] = useState(null) // { shift, mode: 'stats' | 'close' }
|
||||||
|
const [shiftBusy, setShiftBusy] = useState(false)
|
||||||
|
const [message, setMessage] = useState(null) // { id, name }
|
||||||
|
const [summary, setSummary] = useState(null) // 'view' | 'close'
|
||||||
|
const [newBooking, setNewBooking] = useState(false)
|
||||||
|
const [blocked, setBlocked] = useState(null) // an error code: license.locked | license.expired
|
||||||
|
const [opening, setOpening] = useState(false)
|
||||||
|
|
||||||
|
const { data: day, isPending: dayPending } = useLiveQuery({
|
||||||
|
queryKey: ['business-day'], queryFn: () => client.get('/api/business-day/current').then(r => r.data), refetchInterval: 15_000,
|
||||||
|
})
|
||||||
|
const { data: shifts = [] } = useLiveQuery({
|
||||||
|
queryKey: ['active-shifts'], queryFn: () => client.get('/api/shifts/', { params: { active_only: true } }).then(r => r.data.shifts ?? []), refetchInterval: 15_000,
|
||||||
|
})
|
||||||
|
const { data: staff = [] } = useLiveQuery({ queryKey: ['waiters'], queryFn: () => client.get('/api/waiters/').then(r => r.data), staleTime: 60_000 })
|
||||||
|
const { data: tables = [], isPending: tablesPending } = useLiveQuery({
|
||||||
|
queryKey: ['tables'], queryFn: () => client.get('/api/tables/').then(r => r.data), events: ORDER_EVENTS, refetchInterval: 60_000,
|
||||||
|
})
|
||||||
|
const { data: orders = [], isPending: ordersPending } = useLiveQuery({
|
||||||
|
queryKey: ['orders-active'], queryFn: () => client.get('/api/orders/').then(r => r.data), events: ORDER_EVENTS, refetchInterval: 60_000,
|
||||||
|
})
|
||||||
|
|
||||||
|
const dayOpen = !!day
|
||||||
|
const cards = tableCards(tables, orders)
|
||||||
|
const waiting = cards.filter(c => c.pendingPrint)
|
||||||
|
const today = dayOrders(orders, day?.opened_at)
|
||||||
|
const k = dayKpis({ cards, orders: today, shifts })
|
||||||
|
const idle = staff.filter(w => w.role === 'waiter' && !shifts.some(s => s.waiter_id === w.id))
|
||||||
|
const nowHour = hourOf(new Date().toISOString())
|
||||||
|
|
||||||
|
const togglePrivacy = () => setHidden(h => {
|
||||||
|
try { localStorage.setItem(PRIVACY_KEY, String(!h)) } catch { /* private window: this visit only */ }
|
||||||
|
return !h
|
||||||
|
})
|
||||||
|
const refreshDay = () => ['business-day', 'active-shifts', 'orders-active', 'tables', 'messages-all', 'day-summary']
|
||||||
|
.forEach(key => qc.invalidateQueries({ queryKey: [key] }))
|
||||||
|
|
||||||
|
async function openDay() {
|
||||||
|
if (license?.isBlocked) { setBlocked(license.lock_reason === 'admin' ? 'license.locked' : 'license.expired'); return }
|
||||||
|
setOpening(true)
|
||||||
|
try {
|
||||||
|
await client.post('/api/business-day/open', {})
|
||||||
|
toast.success(t('overview.dayOpened'))
|
||||||
|
refreshDay()
|
||||||
|
} catch (err) {
|
||||||
|
const code = err.xenia?.code
|
||||||
|
if (code === 'license.locked' || code === 'license.expired') setBlocked(code)
|
||||||
|
else toast.error(errorMessage(err, t))
|
||||||
|
} finally { setOpening(false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startShift(waiterId, startingCash) {
|
||||||
|
await client.post('/api/shifts/manager/start', { waiter_id: waiterId, starting_cash: startingCash })
|
||||||
|
toast.success(t('overview.shifts.started'))
|
||||||
|
qc.invalidateQueries({ queryKey: ['active-shifts'] })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function endShift(notes, countedCash) {
|
||||||
|
setShiftBusy(true)
|
||||||
|
try {
|
||||||
|
await client.post(`/api/shifts/manager/end/${shift.shift.id}`, { notes: notes || null, counted_cash_end: countedCash ?? null })
|
||||||
|
toast.success(t('overview.shifts.ended', { name: shift.shift.waiter_name }))
|
||||||
|
setShift(null)
|
||||||
|
qc.invalidateQueries({ queryKey: ['active-shifts'] })
|
||||||
|
} catch (err) {
|
||||||
|
toast.error(errorMessage(err, t))
|
||||||
|
} finally { setShiftBusy(false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tablesPending || ordersPending || dayPending) return <div className="p-6 flex justify-center"><Spinner /></div>
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-4 md:p-6 grid gap-5" data-testid="overview">
|
||||||
|
<header className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<div className="grid gap-1">
|
||||||
|
<Pill tone={dayOpen ? 'success' : 'neutral'} className="justify-self-start uppercase tracking-wide" data-testid="day-state" data-open={dayOpen}>
|
||||||
|
<span className={cx('w-1.5 h-1.5 rounded-full', dayOpen ? SOLID.success : SOLID.neutral)} aria-hidden="true" />
|
||||||
|
{dayOpen ? t('overview.dayOpen') : t('overview.dayClosed')}
|
||||||
|
</Pill>
|
||||||
|
<span className="text-label text-ink-2">
|
||||||
|
{formatDateTime(new Date(), { weekday: 'long', day: 'numeric', month: 'long' })}
|
||||||
|
{dayOpen && ` · ${t('overview.daySince', { time: formatTime(day.opened_at), length: since(day.opened_at) })}`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<IconButton variant={hidden ? 'primary' : 'secondary'} label={hidden ? t('overview.showAmounts') : t('overview.hideAmounts')} onClick={togglePrivacy} aria-pressed={hidden} data-testid="privacy">
|
||||||
|
{hidden ? <EyeOff size={18} /> : <Eye size={18} />}
|
||||||
|
</IconButton>
|
||||||
|
{dayOpen ? (<>
|
||||||
|
<Button variant="secondary" icon={<BarChart3 size={16} />} onClick={() => setSummary('view')} data-testid="day-stats">{t('overview.dayStats')}</Button>
|
||||||
|
<Button variant="danger" icon={<Power size={16} />} onClick={() => setSummary('close')} data-testid="day-close">{t('overview.closeDay')}</Button>
|
||||||
|
</>) : (
|
||||||
|
<Button icon={<Play size={16} />} loading={opening} onClick={openDay} data-testid="day-open">{t('overview.openDay')}</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="grid gap-3 grid-cols-[repeat(auto-fit,minmax(12rem,1fr))]" data-testid="kpis">
|
||||||
|
<Kpi label={t('overview.kpi.revenue')} sub={<>{t('overview.kpi.orders', { count: k.orders })} · {t('overview.kpi.avg')} <Money value={k.avgTicket} hidden={hidden} /></>}>
|
||||||
|
<Money value={k.revenue} hidden={hidden} data-testid="kpi-revenue" />
|
||||||
|
</Kpi>
|
||||||
|
<Kpi label={t('overview.kpi.tables')} sub={t('overview.kpi.tablesSub', { free: k.free, partly: k.partly })} pct={k.occupiedPct}>
|
||||||
|
<span data-testid="kpi-tables">{k.occupied} / {k.tables}</span>
|
||||||
|
</Kpi>
|
||||||
|
<Kpi label={t('overview.kpi.shifts')} sub={shifts.length ? shifts.map(s => s.waiter_name.split(' ')[0]).join(', ') : t('overview.shifts.none')}>{k.shifts}</Kpi>
|
||||||
|
<Kpi label={t('overview.kpi.collected')} sub={t('overview.kpi.collectedSub', { count: k.shifts })}><Money value={k.collected} hidden={hidden} /></Kpi>
|
||||||
|
{waiting.length > 0 && <Kpi tone="warning" label={t('overview.kpi.prints')} sub={t('overview.kpi.printsSub')}>{waiting.length}</Kpi>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-5 lg:grid-cols-[13fr_7fr] items-start">
|
||||||
|
<div className="grid gap-5 min-w-0">
|
||||||
|
<ShiftsCard shifts={shifts} idle={idle} dayOpen={dayOpen} hidden={hidden} canMessage={chatOn}
|
||||||
|
onStart={startShift}
|
||||||
|
onEnd={s => setShift({ shift: s, mode: 'close' })}
|
||||||
|
onStats={s => setShift({ shift: s, mode: 'stats' })}
|
||||||
|
onMessage={s => setMessage({ id: s.waiter_id, name: s.waiter_name })} />
|
||||||
|
<TablesCard cards={cards} onOpen={(id, table) => setOrder({ id, table })} />
|
||||||
|
<Card title={t('overview.revenueByHour')} testId="revenue-chart">
|
||||||
|
<div className="p-4"><HourBars buckets={hourBuckets(orderPairs(today), hourOf)} current={nowHour} /></div>
|
||||||
|
</Card>
|
||||||
|
<PendingPrints cards={waiting} onOpen={(id, table) => setOrder({ id, table })} />
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-5 min-w-0">
|
||||||
|
{notesOn && <NotesCard />}
|
||||||
|
{bookingsOn && <BookingsCard tables={tables} onNew={() => setNewBooking(true)} />}
|
||||||
|
{chatOn && <MessagesCard staff={staff} tables={tables} />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{order && <OrderDialog orderId={order.id} tableName={order.table} onClose={() => setOrder(null)}
|
||||||
|
onOpenFull={() => { navigate(`/orders/${order.id}`); setOrder(null) }} />}
|
||||||
|
{shift && <ShiftDialog shift={shift.shift} mode={shift.mode} busy={shiftBusy} onClose={() => setShift(null)} onConfirm={endShift} />}
|
||||||
|
{message && <ComposeDialog to={message} onClose={() => setMessage(null)} />}
|
||||||
|
{summary && <DaySummaryDialog closing={summary === 'close'} onClose={() => setSummary(null)}
|
||||||
|
onClosed={() => { toast.success(t('overview.dayClosedDone')); refreshDay(); setSummary(null) }} />}
|
||||||
|
{newBooking && <BookingDialog tables={tables} onClose={() => setNewBooking(false)}
|
||||||
|
onSaved={() => { setNewBooking(false); qc.invalidateQueries({ queryKey: ['reservations'] }); qc.invalidateQueries({ queryKey: ['tables'] }) }} />}
|
||||||
|
{blocked && (
|
||||||
|
<Dialog open size="sm" onClose={() => setBlocked(null)} title={t(blocked === 'license.locked' ? 'overview.locked' : 'overview.expired')}
|
||||||
|
footer={<Button variant="secondary" onClick={() => setBlocked(null)}>{t('overview.close')}</Button>}>
|
||||||
|
<div className="flex items-start gap-3" data-testid="license-block" data-code={blocked}>
|
||||||
|
<Lock size={20} className={blocked === 'license.locked' ? 'text-danger' : 'text-warning'} aria-hidden="true" />
|
||||||
|
<p>{t(`errors:${blocked}`)} {t('overview.blockedHelp')}</p>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Kpi({ label, sub, pct, tone, children }) {
|
||||||
|
return (
|
||||||
|
<div className={cx('rounded-card border bg-surface shadow-raised p-4 grid gap-1 content-start', tone === 'warning' ? 'border-warning' : 'border-line')}>
|
||||||
|
<span className="text-caption font-semibold uppercase tracking-wide text-ink-2">{label}</span>
|
||||||
|
<span className="text-display font-bold tabular-nums text-ink leading-tight">{children}</span>
|
||||||
|
{sub && <span className="text-label text-ink-2">{sub}</span>}
|
||||||
|
{pct != null && (
|
||||||
|
<div className="mt-1 h-1.5 rounded-full bg-surface-2 overflow-hidden">
|
||||||
|
<div className="h-full rounded-full bg-accent transition-[width] duration-base" style={{ width: `${Math.min(100, pct)}%` }} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// Orders with lines that haven't printed (plan step 6.2): which table, since when, how many
|
||||||
|
// retries, the lines waiting; print one again or all of them, or open the order.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { Printer } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { printRetries, tableName } from './overviewLogic'
|
||||||
|
import { Card, Pill } from './parts'
|
||||||
|
|
||||||
|
export default function PendingPrints({ cards, onOpen }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime } = useFormat()
|
||||||
|
const qc = useQueryClient()
|
||||||
|
const [busy, setBusy] = useState(null) // an order id, or 'all'
|
||||||
|
|
||||||
|
if (cards.length === 0) return null
|
||||||
|
|
||||||
|
async function retry(orderId) {
|
||||||
|
try {
|
||||||
|
const res = await client.post(`/api/orders/${orderId}/retry-print`)
|
||||||
|
const failed = (res.data.print_results ?? []).filter(r => !r.success).map(r => r.printer_name)
|
||||||
|
if (failed.length) toast.error(t('overview.prints.failed', { printers: failed.join(', ') }))
|
||||||
|
else toast.success(t('overview.prints.done'))
|
||||||
|
} catch (err) {
|
||||||
|
toast.error(errorMessage(err, t))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function run(id, fn) {
|
||||||
|
setBusy(id)
|
||||||
|
try { await fn() } finally {
|
||||||
|
setBusy(null)
|
||||||
|
qc.invalidateQueries({ queryKey: ['orders-active'] })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card tone="warning" testId="pending-prints"
|
||||||
|
title={<span className="grid">
|
||||||
|
<span>{t('overview.prints.title')}</span>
|
||||||
|
<span className="text-label font-normal">{t('overview.prints.count', { count: cards.length })}</span>
|
||||||
|
</span>}
|
||||||
|
action={<Button size="sm" variant="secondary" icon={<Printer size={16} />} loading={busy === 'all'} disabled={busy != null}
|
||||||
|
onClick={() => run('all', async () => { for (const c of cards) await retry(c.order.id) })}>{t('overview.prints.all')}</Button>}>
|
||||||
|
<ul className="divide-y divide-line">
|
||||||
|
{cards.map(({ table, order }) => {
|
||||||
|
const waiting = order.items.filter(i => i.status === 'active' && !i.printed)
|
||||||
|
const retries = printRetries(order)
|
||||||
|
return (
|
||||||
|
<li key={order.id} className="flex items-center gap-3 px-4 py-2.5" data-testid="pending-print">
|
||||||
|
<span className="w-10 h-10 shrink-0 grid place-items-center rounded-control bg-warning-soft text-warning-ink text-label font-bold">{tableName(table)}</span>
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex flex-wrap items-center gap-2 text-label">
|
||||||
|
<span className="font-semibold text-ink">#{order.id}</span>
|
||||||
|
{order.opened_at && <span className="text-ink-2">{formatTime(order.opened_at)}</span>}
|
||||||
|
{retries > 0 && <Pill tone="warning">{t('overview.prints.retries', { count: retries })}</Pill>}
|
||||||
|
</div>
|
||||||
|
<div className="text-caption text-ink-2 truncate">
|
||||||
|
{t('overview.prints.lines', { count: waiting.length })} · {waiting.map(i => i.product?.name || `#${i.product_id}`).join(', ')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button size="sm" variant="ghost" onClick={() => onOpen(order.id, tableName(table))}>{t('overview.prints.open')}</Button>
|
||||||
|
<Button size="sm" variant="secondary" loading={busy === order.id} disabled={busy != null}
|
||||||
|
onClick={() => run(order.id, () => retry(order.id))}>{t('overview.prints.print')}</Button>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,206 @@
|
|||||||
|
// A waiter's shift, from the overview's shift list (plan step 6.2): its money (what should be in
|
||||||
|
// the drawer: the starting cash + cash taken), the cash / card split, sales per hour and counts,
|
||||||
|
// and every line of the shift with who ordered and who took the money (filters). In "close"
|
||||||
|
// mode it ends the shift: notes, then the cash the waiter hands over, compared with what was
|
||||||
|
// expected (short / over / even), then "End the shift".
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { useTranslation, useFormat, parseNumber } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, Field, Input, Spinner, Textarea, cx } from '@xenia/ui'
|
||||||
|
import client from '../../api/client'
|
||||||
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
||||||
|
import { ITEM_KINDS, cashCheck, hourBuckets, itemKind, itemShown, quickAmounts, shiftCounts, shiftMoney, shiftPairs } from './overviewLogic'
|
||||||
|
import { Avatar, Figure, HourBars, Money, Pill, SplitBar } from './parts'
|
||||||
|
import { SOFT } from './tones'
|
||||||
|
import { useDuration, useHourOf } from './hooks'
|
||||||
|
|
||||||
|
const KIND_TONE = { both: 'success', paid: 'info', ordered: 'warning', unpaid: 'warning', cancelled: 'danger', anomaly: 'danger' }
|
||||||
|
const CHECK_TONE = { even: 'success', over: 'success', short: 'danger' }
|
||||||
|
|
||||||
|
export default function ShiftDialog({ shift, mode, onClose, onConfirm, busy }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime, formatMoney } = useFormat()
|
||||||
|
const since = useDuration()
|
||||||
|
const hourOf = useHourOf()
|
||||||
|
const [screen, setScreen] = useState('overview') // overview | lines
|
||||||
|
const [step, setStep] = useState(1) // close mode: 1 review + notes, 2 cash handover
|
||||||
|
const [notes, setNotes] = useState('')
|
||||||
|
const [counted, setCounted] = useState('')
|
||||||
|
const [kind, setKind] = useState('all')
|
||||||
|
const [payment, setPayment] = useState('any')
|
||||||
|
|
||||||
|
const { data: summary, isPending } = useLiveQuery({
|
||||||
|
queryKey: ['shift-summary', shift.id],
|
||||||
|
queryFn: () => client.get(`/api/shifts/${shift.id}/summary`).then(r => r.data),
|
||||||
|
events: ['order_paid', 'order_updated'],
|
||||||
|
})
|
||||||
|
const data = summary || shift
|
||||||
|
const money = shiftMoney(data)
|
||||||
|
const counts = shiftCounts(summary)
|
||||||
|
const countedValue = counted === '' ? null : parseNumber(counted)
|
||||||
|
const check = cashCheck(countedValue, money.expected)
|
||||||
|
const waiterId = shift.waiter_id ?? summary?.waiter_id
|
||||||
|
const closing = mode === 'close'
|
||||||
|
|
||||||
|
const footer = !closing ? (<>
|
||||||
|
<span className="flex-1 text-caption text-ink-3">{t('overview.shift.live')}</span>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.close')}</Button>
|
||||||
|
</>) : step === 1 ? (<>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||||
|
<span className="flex-1 text-caption text-ink-3">{t('overview.shift.checkFirst')}</span>
|
||||||
|
<Button onClick={() => { setScreen('overview'); setStep(2) }} data-testid="shift-next">{t('overview.shift.toHandover')}</Button>
|
||||||
|
</>) : (<>
|
||||||
|
<Button variant="secondary" onClick={() => setStep(1)}>{t('overview.back')}</Button>
|
||||||
|
<span className="flex-1" />
|
||||||
|
<Button variant="danger" loading={busy} data-testid="shift-end-confirm"
|
||||||
|
onClick={() => onConfirm(notes, countedValue != null && Number.isFinite(countedValue) ? countedValue : null)}>{t('overview.shift.endNow')}</Button>
|
||||||
|
</>)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open size="lg" onClose={onClose} footer={footer}
|
||||||
|
title={<span className="flex items-center gap-3">
|
||||||
|
<Avatar name={shift.waiter_name} url={shift.avatar_url} size="lg" />
|
||||||
|
<span className="grid">
|
||||||
|
<span className="flex items-center gap-2">{shift.waiter_name}
|
||||||
|
<Pill tone={closing ? 'warning' : 'success'}>{closing ? t('overview.shift.closing') : t('overview.shift.running')}</Pill>
|
||||||
|
</span>
|
||||||
|
<span className="text-caption font-normal text-ink-3">{t('overview.shift.number', { id: shift.id })}</span>
|
||||||
|
</span>
|
||||||
|
</span>}>
|
||||||
|
<div className="grid gap-4" data-testid="shift-dialog">
|
||||||
|
<div className="flex flex-wrap items-center gap-4">
|
||||||
|
<Figure label={t('overview.shift.start')}>{formatTime(shift.started_at)}</Figure>
|
||||||
|
<Figure label={t('overview.shift.length')}>{since(shift.started_at)}</Figure>
|
||||||
|
<span className="flex-1" />
|
||||||
|
<div className="flex gap-1" role="tablist">
|
||||||
|
{['overview', 'lines'].map(s => (
|
||||||
|
<Button key={s} size="sm" variant={screen === s ? 'primary' : 'secondary'} role="tab" aria-selected={screen === s}
|
||||||
|
onClick={() => setScreen(s)} data-testid={`shift-tab-${s}`}>{t(`overview.shift.tab.${s}`)}</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{screen === 'overview' && (<>
|
||||||
|
<div className={cx('rounded-card border p-4 flex flex-wrap items-center justify-between gap-3', SOFT.success, 'border-success')}>
|
||||||
|
<div className="grid">
|
||||||
|
<span className="text-caption font-semibold uppercase tracking-wide">{t('overview.shift.expected')}</span>
|
||||||
|
<Money value={money.expected} className="text-display font-bold text-ink" data-testid="shift-expected" />
|
||||||
|
</div>
|
||||||
|
<div className="text-label text-right">
|
||||||
|
{t('overview.shift.startCash')} <Money value={money.start} className="font-semibold text-ink" /><br />
|
||||||
|
+ {t('overview.shift.cashSales')} <Money value={money.cash} className="font-semibold text-ink" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-3 gap-3">
|
||||||
|
<Figure label={t('overview.shift.startCash')} sub={t('overview.shift.startCashHint')}><Money value={money.start} /></Figure>
|
||||||
|
<Figure label={t('overview.shift.cashSales')} sub={t('overview.shift.cashSalesHint')}><Money value={money.cash} /></Figure>
|
||||||
|
<Figure label={t('overview.shift.turnover')} sub={t('overview.shift.turnoverHint')}><Money value={money.total} /></Figure>
|
||||||
|
</div>
|
||||||
|
{money.total > 0 && <SplitBar parts={[
|
||||||
|
{ key: 'cash', tone: 'success', label: t('overview.pay.cash'), value: money.cash },
|
||||||
|
{ key: 'card', tone: 'info', label: t('overview.pay.card'), value: money.card },
|
||||||
|
]} />}
|
||||||
|
{summary && shiftPairs(summary).length > 0 && (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{t('overview.shift.perHour')}</span>
|
||||||
|
<HourBars buckets={hourBuckets(shiftPairs(summary), hourOf, { from: 24, to: -1 })} height="h-16" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="grid grid-cols-4 gap-3 rounded-card border border-line p-3">
|
||||||
|
<Figure label={t('overview.shift.items')}>{counts.items}</Figure>
|
||||||
|
<Figure label={t('overview.shift.tables')}>{counts.tables}</Figure>
|
||||||
|
<Figure label={t('overview.shift.orders')}>{counts.orders}</Figure>
|
||||||
|
<Figure label={t('overview.shift.pay')} sub={data.hourly_rate_snapshot ? t('overview.shift.perHourRate', { rate: formatMoney(data.hourly_rate_snapshot) }) : null}>
|
||||||
|
{data.shift_pay != null ? <Money value={data.shift_pay} /> : '—'}
|
||||||
|
</Figure>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{closing && step === 1 && (
|
||||||
|
<Field label={t('overview.shift.notes')} hint={t('overview.shift.notesHint')}>
|
||||||
|
<Textarea rows={2} value={notes} onChange={e => setNotes(e.target.value)} />
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
{closing && step === 2 && (
|
||||||
|
<div className="grid gap-3">
|
||||||
|
<h3 className="text-title font-semibold text-ink">{t('overview.shift.handover')}</h3>
|
||||||
|
<Field label={t('overview.shift.counted')} hint={t('overview.shift.countedHint')}>
|
||||||
|
<Input inputMode="decimal" autoFocus value={counted} onChange={e => setCounted(e.target.value)}
|
||||||
|
placeholder={String(money.expected.toFixed(2))} data-testid="shift-counted" />
|
||||||
|
</Field>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{quickAmounts(money.expected).map(v => (
|
||||||
|
<Button key={v} size="sm" variant="secondary" onClick={() => setCounted(v.toFixed(2))}>
|
||||||
|
{v === money.expected ? <>{t('overview.shift.exact')} <Money value={v} /></> : <Money value={v} />}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{check && (
|
||||||
|
<div className={cx('rounded-card border p-3 flex items-center justify-between gap-3', SOFT[CHECK_TONE[check.state]])} data-testid="shift-check" data-state={check.state}>
|
||||||
|
<span className="font-semibold">{t(`overview.cash.${check.state}`)}</span>
|
||||||
|
<Money value={check.diff} className="text-title font-bold" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>)}
|
||||||
|
|
||||||
|
{screen === 'lines' && (
|
||||||
|
<div className="grid gap-3">
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{['all', ...ITEM_KINDS].map(k => (
|
||||||
|
<Button key={k} size="sm" variant={kind === k ? 'primary' : 'secondary'} onClick={() => setKind(k)}>{t(`overview.shift.kind.${k}`)}</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{['any', 'cash', 'card'].map(p => (
|
||||||
|
<Button key={p} size="sm" variant={payment === p ? 'primary' : 'ghost'} onClick={() => setPayment(p)}>{t(`overview.pay.${p}`)}</Button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{isPending && <div className="py-8 flex justify-center"><Spinner /></div>}
|
||||||
|
{summary && summary.orders.length === 0 && <p className="text-label text-ink-3 text-center py-6">{t('overview.shift.noLines')}</p>}
|
||||||
|
{summary?.orders.map(o => <OrderLines key={o.order_id} order={o} waiterId={waiterId} kind={kind} payment={payment} />)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{isPending && screen === 'overview' && <span className="sr-only">{t('overview.loading')}</span>}
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function OrderLines({ order, waiterId, kind, payment }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime } = useFormat()
|
||||||
|
const items = order.items.filter(i => itemShown(i, waiterId, kind, payment))
|
||||||
|
if (items.length === 0) return null
|
||||||
|
const paid = items.filter(i => i.status === 'paid').reduce((s, i) => s + i.subtotal, 0)
|
||||||
|
return (
|
||||||
|
<div className="rounded-card border border-line overflow-hidden">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-2 px-3 py-2 bg-surface-2 text-label">
|
||||||
|
<span className="font-semibold text-ink">{t('overview.shift.order', { id: order.order_id })}{order.table_name && <span className="font-normal text-ink-3"> · {order.table_name}</span>}</span>
|
||||||
|
<span className="flex items-center gap-3">
|
||||||
|
{order.opener_name && <span className="text-ink-2">{t('overview.shift.openedBy', { name: order.opener_name })}{order.opened_at && ` · ${formatTime(order.opened_at)}`}</span>}
|
||||||
|
{paid > 0 && <Money value={paid} className="font-semibold text-success-ink" />}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<ul className="divide-y divide-line">
|
||||||
|
{items.map(item => {
|
||||||
|
const k = itemKind(item, waiterId)
|
||||||
|
const cancelled = item.status === 'cancelled'
|
||||||
|
return (
|
||||||
|
<li key={item.id} className="px-3 py-2 grid gap-1" data-testid="shift-line" data-kind={k}>
|
||||||
|
<div className="flex items-baseline justify-between gap-2">
|
||||||
|
<span className={cx('text-body font-semibold', cancelled ? 'text-danger-ink' : 'text-ink')}>{item.product_name} <span className="font-normal text-ink-3">×{item.quantity}</span></span>
|
||||||
|
<Money value={item.subtotal} className={cx('font-semibold', cancelled && 'line-through text-danger-ink')} />
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-caption text-ink-2">
|
||||||
|
<span>{t('overview.shift.orderedBy', { name: item.added_by_name ?? '—' })}</span>
|
||||||
|
{!cancelled && <span>{t('overview.shift.paidTo', { name: item.paid_by_name ?? '—' })}</span>}
|
||||||
|
{!cancelled && item.payment_method && <Pill tone={item.payment_method === 'card' ? 'info' : 'success'}>{t(`overview.pay.${item.payment_method}`, { defaultValue: item.payment_method })}</Pill>}
|
||||||
|
<Pill tone={KIND_TONE[k]}>{t(`overview.shift.kind.${k}`)}</Pill>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
// The waiters on shift now (plan step 6.2): since when, what they took in, a break in progress;
|
||||||
|
// message one of them, look at their shift, or end it. "Start" puts a waiter without a shift
|
||||||
|
// on one (with the cash they start with) while the day is open.
|
||||||
|
import { useState } from 'react'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import { BarChart3, Coffee, MessageSquare, Plus } from 'lucide-react'
|
||||||
|
import { errorMessage } from '@xenia/api'
|
||||||
|
import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, cx } from '@xenia/ui'
|
||||||
|
import { Avatar, Card, Money, Pill } from './parts'
|
||||||
|
import { useDuration } from './hooks'
|
||||||
|
|
||||||
|
export default function ShiftsCard({ shifts, idle, dayOpen, hidden, onStart, onEnd, onStats, onMessage, canMessage }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatTime } = useFormat()
|
||||||
|
const since = useDuration()
|
||||||
|
const [starting, setStarting] = useState(false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title={t('overview.shifts.title')} testId="shifts-card"
|
||||||
|
action={dayOpen && idle.length > 0 && <Button size="sm" variant="secondary" icon={<Plus size={16} />} onClick={() => setStarting(true)} data-testid="shift-start">{t('overview.shifts.start')}</Button>}>
|
||||||
|
<div className="p-3 grid gap-2">
|
||||||
|
{shifts.length === 0 ? <EmptyState compact title={t('overview.shifts.none')} /> : shifts.map(s => {
|
||||||
|
const onBreak = Array.isArray(s.breaks) ? s.breaks.find(b => !b.ended_at) : null
|
||||||
|
return (
|
||||||
|
<div key={s.id} className={cx('flex items-center gap-3 p-2.5 rounded-card border', onBreak ? 'border-warning bg-warning-soft' : 'border-line bg-surface-2')} data-testid="shift-row">
|
||||||
|
<Avatar name={s.waiter_name} url={s.avatar_url} />
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<span className="text-body font-semibold text-ink">{s.waiter_name}</span>
|
||||||
|
{onBreak && <Pill tone="warning"><Coffee size={12} aria-hidden="true" />{t('overview.shifts.onBreak', { since: since(onBreak.started_at) })}</Pill>}
|
||||||
|
</div>
|
||||||
|
<div className="text-caption text-ink-2">
|
||||||
|
{t('overview.shifts.since', { time: formatTime(s.started_at), length: since(s.started_at) })}
|
||||||
|
{s.total_collected > 0 && <> · <Money value={s.total_collected} hidden={hidden} className="font-semibold text-success-ink" /></>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{canMessage && <IconButton size="sm" variant="secondary" label={t('overview.shifts.message')} onClick={() => onMessage(s)}><MessageSquare size={16} /></IconButton>}
|
||||||
|
<IconButton size="sm" variant="secondary" label={t('overview.shifts.stats')} onClick={() => onStats(s)} data-testid="shift-stats"><BarChart3 size={16} /></IconButton>
|
||||||
|
<Button size="sm" variant="danger" onClick={() => onEnd(s)} data-testid="shift-end">{t('overview.shifts.end')}</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{starting && <StartShiftDialog waiters={idle} onClose={() => setStarting(false)} onStart={onStart} />}
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function StartShiftDialog({ waiters, onClose, onStart }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const [waiterId, setWaiterId] = useState('')
|
||||||
|
const [cash, setCash] = useState('')
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const [error, setError] = useState(null)
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!waiterId) { setError(t('overview.shifts.pickWaiter')); return }
|
||||||
|
const amount = cash.trim() === '' ? null : parseNumber(cash)
|
||||||
|
if (amount != null && !Number.isFinite(amount)) { setError(t('overview.shifts.badAmount')); return }
|
||||||
|
setBusy(true)
|
||||||
|
try {
|
||||||
|
await onStart(Number(waiterId), amount)
|
||||||
|
onClose()
|
||||||
|
} catch (err) {
|
||||||
|
toast.error(errorMessage(err, t))
|
||||||
|
} finally { setBusy(false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open size="sm" onClose={onClose} title={t('overview.shifts.startTitle')}
|
||||||
|
footer={<>
|
||||||
|
<Button variant="secondary" onClick={onClose}>{t('overview.back')}</Button>
|
||||||
|
<Button onClick={submit} loading={busy} data-testid="shift-start-confirm">{t('overview.shifts.startNow')}</Button>
|
||||||
|
</>}>
|
||||||
|
<div className="grid gap-3">
|
||||||
|
<Field label={t('overview.shifts.waiter')} error={error && !waiterId ? error : undefined}>
|
||||||
|
<Select value={waiterId} onChange={e => { setWaiterId(e.target.value); setError(null) }} placeholder={t('overview.shifts.pick')}
|
||||||
|
options={waiters.map(w => ({ value: String(w.id), label: w.full_name || w.username }))} data-testid="shift-start-waiter" />
|
||||||
|
</Field>
|
||||||
|
<Field label={t('overview.shifts.startCash')} hint={t('overview.shifts.startCashHint')} error={error && waiterId ? error : undefined}>
|
||||||
|
<Input inputMode="decimal" value={cash} onChange={e => { setCash(e.target.value); setError(null) }} placeholder="0" />
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// The tables now (plan step 6.2): a chip per table in its state's colour (open, partly paid,
|
||||||
|
// paid, free) with a count per state; a table with an order opens it at a glance.
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import { ArrowRight } from 'lucide-react'
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { Button, cx } from '@xenia/ui'
|
||||||
|
import { TABLE_STATES, orderTotal, tableName } from './overviewLogic'
|
||||||
|
import { Card } from './parts'
|
||||||
|
import { SOFT, SOLID } from './tones'
|
||||||
|
|
||||||
|
const STATE_TONE = { open: 'success', partially_paid: 'info', paid: 'accent', free: 'neutral' }
|
||||||
|
|
||||||
|
export default function TablesCard({ cards, onOpen }) {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
const { formatMoney } = useFormat()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const shown = TABLE_STATES.filter(s => s !== 'paid' || cards.some(c => c.state === 'paid'))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title={t('overview.tables.title')} testId="tables-card"
|
||||||
|
action={<Button size="sm" variant="ghost" iconEnd={<ArrowRight size={16} />} onClick={() => navigate('/tables')}>{t('overview.tables.all')}</Button>}>
|
||||||
|
<div className="p-4 grid gap-3">
|
||||||
|
<div className="grid gap-2 grid-cols-[repeat(auto-fill,minmax(3.5rem,1fr))]">
|
||||||
|
{cards.map(({ table, order, state }) => (
|
||||||
|
<button key={table.id} type="button" disabled={!order}
|
||||||
|
onClick={order ? () => onOpen(order.id, tableName(table)) : undefined}
|
||||||
|
title={order ? `${tableName(table)} · ${formatMoney(orderTotal(order.items))}` : tableName(table)}
|
||||||
|
aria-label={`${tableName(table)}: ${t(`overview.tableState.${state}`)}`}
|
||||||
|
className={cx('aspect-square min-h-[3.25rem] rounded-control border border-line text-label font-bold tabular-nums transition-transform duration-fast',
|
||||||
|
SOFT[STATE_TONE[state]], order && 'hover:-translate-y-0.5 hover:shadow-raised cursor-pointer')}
|
||||||
|
data-testid="table-chip" data-state={state}>
|
||||||
|
{tableName(table)}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{shown.map(s => (
|
||||||
|
<span key={s} className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-surface-2 text-label font-semibold text-ink-2">
|
||||||
|
<span className={cx('w-2 h-2 rounded-full', SOLID[STATE_TONE[s]])} aria-hidden="true" />
|
||||||
|
{t(`overview.tableState.${s}`)}
|
||||||
|
<span className="tabular-nums text-ink">{cards.filter(c => c.state === s).length}</span>
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// The overview's small formatting hooks (plan step 6.2).
|
||||||
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||||
|
import { durationParts } from './overviewLogic'
|
||||||
|
|
||||||
|
/** "1 h 20 min" since a moment (updates when the page re-renders). */
|
||||||
|
export function useDuration() {
|
||||||
|
const { t } = useTranslation('manager')
|
||||||
|
return (from, now) => {
|
||||||
|
const d = durationParts(from, now)
|
||||||
|
if (!d) return '—'
|
||||||
|
if (d.h === 0) return t('overview.duration.m', { m: d.m })
|
||||||
|
return d.m === 0 ? t('overview.duration.h', { h: d.h }) : t('overview.duration.hm', { h: d.h, m: d.m })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The venue-time hour (0–23) of a timestamp. */
|
||||||
|
export function useHourOf() {
|
||||||
|
const { formatDateTime } = useFormat()
|
||||||
|
return iso => Number(formatDateTime(iso, { hour: '2-digit', hourCycle: 'h23' }))
|
||||||
|
}
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
// The overview's arithmetic (plan step 6.2), kept out of the components so it is unit-tested
|
||||||
|
// (tests/overview.test.mjs). No React, no texts: the components translate the keys returned here.
|
||||||
|
|
||||||
|
/** What a line costs: (unit price + by-hand change) × quantity. */
|
||||||
|
export const lineTotal = item => ((item.unit_price ?? 0) + (item.price_adjustment ?? 0)) * (item.quantity ?? 1)
|
||||||
|
|
||||||
|
/** An order's total without its cancelled lines. */
|
||||||
|
export const orderTotal = (items = []) => items.filter(i => i.status !== 'cancelled').reduce((s, i) => s + lineTotal(i), 0)
|
||||||
|
|
||||||
|
export const tableName = table => table?.label || (table?.number != null ? `T${table.number}` : '')
|
||||||
|
|
||||||
|
/** The table states the overview shows, in legend order. */
|
||||||
|
export const TABLE_STATES = ['open', 'partially_paid', 'paid', 'free']
|
||||||
|
const LIVE = ['open', 'partially_paid', 'paid']
|
||||||
|
|
||||||
|
/** Each table with its live order (open, partly paid or paid but not closed) and whether a line waits to print. */
|
||||||
|
export function tableCards(tables = [], orders = []) {
|
||||||
|
return tables.map(table => {
|
||||||
|
const order = orders.find(o => o.table_id === table.id && LIVE.includes(o.status)) ?? null
|
||||||
|
return {
|
||||||
|
table,
|
||||||
|
order,
|
||||||
|
state: order ? order.status : 'free',
|
||||||
|
pendingPrint: !!order && order.items.some(i => i.status === 'active' && !i.printed),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Orders opened since the business day opened (all of them when no day is open). */
|
||||||
|
export function dayOrders(orders = [], openedAt) {
|
||||||
|
if (!openedAt) return orders
|
||||||
|
const from = new Date(openedAt).getTime()
|
||||||
|
return orders.filter(o => new Date(o.opened_at).getTime() >= from)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The numbers across the top of the overview. */
|
||||||
|
export function dayKpis({ cards = [], orders = [], shifts = [] }) {
|
||||||
|
const revenue = orders.reduce((s, o) => s + orderTotal(o.items), 0)
|
||||||
|
const paid = orders.filter(o => o.items.some(i => i.paid_by)).length
|
||||||
|
const count = state => cards.filter(c => c.state === state).length
|
||||||
|
const open = count('open')
|
||||||
|
const partly = count('partially_paid')
|
||||||
|
return {
|
||||||
|
revenue,
|
||||||
|
orders: orders.length,
|
||||||
|
avgTicket: paid ? revenue / paid : 0,
|
||||||
|
tables: cards.length,
|
||||||
|
occupied: open + partly,
|
||||||
|
partly,
|
||||||
|
free: count('free'),
|
||||||
|
occupiedPct: cards.length ? ((open + partly) / cards.length) * 100 : 0,
|
||||||
|
shifts: shifts.length,
|
||||||
|
collected: shifts.reduce((s, sh) => s + (sh.total_collected || 0), 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money per hour of the day. `hourOf(iso)` gives the venue-time hour (0–23); `pick(entry)`
|
||||||
|
* gives [iso, amount] pairs to count. The range covers [from, to] and any hour that has money.
|
||||||
|
*/
|
||||||
|
export function hourBuckets(pairs, hourOf, { from = 10, to = 23 } = {}) {
|
||||||
|
const sums = new Map()
|
||||||
|
for (const [iso, amount] of pairs) {
|
||||||
|
if (!iso) continue
|
||||||
|
const h = hourOf(iso)
|
||||||
|
if (!Number.isInteger(h)) continue
|
||||||
|
sums.set(h, (sums.get(h) || 0) + amount)
|
||||||
|
}
|
||||||
|
const hours = [...sums.keys()]
|
||||||
|
const lo = Math.min(from, ...hours)
|
||||||
|
const hi = Math.max(to, ...hours)
|
||||||
|
const out = []
|
||||||
|
for (let h = lo; h <= hi; h++) out.push({ hour: h, value: sums.get(h) || 0 })
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Revenue by the hour its order opened. */
|
||||||
|
export const orderPairs = (orders = []) => orders.map(o => [o.opened_at, orderTotal(o.items)])
|
||||||
|
|
||||||
|
/** A shift's paid lines by the hour they were paid (from GET /api/shifts/{id}/summary). */
|
||||||
|
export const shiftPairs = (summary) => (summary?.orders ?? []).flatMap(o =>
|
||||||
|
o.items.filter(i => i.status === 'paid' && i.paid_at).map(i => [i.paid_at, i.subtotal]))
|
||||||
|
|
||||||
|
/** The shift's own counts for the review: paid items, tables, orders. */
|
||||||
|
export function shiftCounts(summary) {
|
||||||
|
const orders = summary?.orders ?? []
|
||||||
|
return {
|
||||||
|
items: orders.reduce((s, o) => s + o.items.filter(i => i.status === 'paid').reduce((n, i) => n + i.quantity, 0), 0),
|
||||||
|
tables: new Set(orders.filter(o => o.table_id).map(o => o.table_id)).size,
|
||||||
|
orders: orders.length,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The shift's money: what it started with, took in cash / card, and what should be in the drawer. */
|
||||||
|
export function shiftMoney(data = {}) {
|
||||||
|
const cash = data.cash_sales ?? data.total_collected ?? 0
|
||||||
|
const card = data.card_sales ?? 0
|
||||||
|
const start = data.starting_cash ?? 0
|
||||||
|
const total = cash + card
|
||||||
|
const cashPct = total > 0 ? Math.round((cash / total) * 100) : 0
|
||||||
|
return { cash, card, start, total, expected: start + cash, cashPct, cardPct: total > 0 ? 100 - cashPct : 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How a line of a waiter's shift is counted, seen from that waiter:
|
||||||
|
* both (ordered and took the money), paid (only took the money), ordered (someone else took it),
|
||||||
|
* unpaid (ordered, not paid yet), cancelled, anomaly (neither: shouldn't happen).
|
||||||
|
*/
|
||||||
|
export function itemKind(item, waiterId) {
|
||||||
|
if (item.status === 'cancelled') return 'cancelled'
|
||||||
|
const mine = item.added_by_id === waiterId
|
||||||
|
const toMe = item.paid_by_id === waiterId
|
||||||
|
const paid = item.status === 'paid'
|
||||||
|
if (mine && toMe && paid) return 'both'
|
||||||
|
if (!mine && toMe && paid) return 'paid'
|
||||||
|
if (mine && paid && !toMe) return 'ordered'
|
||||||
|
if (mine && !paid) return 'unpaid'
|
||||||
|
return 'anomaly'
|
||||||
|
}
|
||||||
|
export const ITEM_KINDS = ['both', 'paid', 'ordered', 'unpaid', 'cancelled']
|
||||||
|
|
||||||
|
/** Whether a shift line passes the review's filters (kind 'all' | one of ITEM_KINDS; payment 'any' | 'cash' | 'card'). */
|
||||||
|
export function itemShown(item, waiterId, kind = 'all', payment = 'any') {
|
||||||
|
if (kind !== 'all' && itemKind(item, waiterId) !== kind) return false
|
||||||
|
if (item.status === 'cancelled' || payment === 'any') return true
|
||||||
|
return (item.payment_method || 'cash') === payment
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Counted cash against what was expected: null until something is typed. */
|
||||||
|
export function cashCheck(counted, expected) {
|
||||||
|
if (counted == null || !Number.isFinite(counted)) return null
|
||||||
|
const diff = Math.round((counted - expected) * 100) / 100
|
||||||
|
return { diff, state: diff < -0.005 ? 'short' : diff > 0.005 ? 'over' : 'even' }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One-tap amounts for counting a drawer: exactly the expected amount, and the tens around it. */
|
||||||
|
export function quickAmounts(expected) {
|
||||||
|
return [expected, Math.floor(expected / 10) * 10, Math.ceil(expected / 10) * 10]
|
||||||
|
.filter((v, i, a) => a.indexOf(v) === i)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whole hours and minutes from `from` to `now` (ms or ISO). */
|
||||||
|
export function durationParts(from, now = Date.now()) {
|
||||||
|
if (from == null || from === '') return null
|
||||||
|
const mins = Math.max(0, Math.floor((now - new Date(from).getTime()) / 60000))
|
||||||
|
return { h: Math.floor(mins / 60), m: mins % 60, mins }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A person's initials for an avatar: "Maria Papa" → "MP". */
|
||||||
|
export function initials(name = '') {
|
||||||
|
const parts = name.trim().split(/\s+/).filter(Boolean)
|
||||||
|
if (parts.length >= 2) return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase()
|
||||||
|
return (parts[0] ?? '?').slice(0, 2).toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A steady tone per name (the same person always gets the same avatar colour). */
|
||||||
|
export const TONES = ['accent', 'success', 'info', 'warning', 'danger']
|
||||||
|
export function toneOf(name = '') {
|
||||||
|
let h = 0
|
||||||
|
for (let i = 0; i < name.length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0
|
||||||
|
return TONES[h % TONES.length]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The payment methods the day summary splits money by, in this order. */
|
||||||
|
export const PAY_METHODS = ['cash', 'card', 'transfer', 'treat', 'other']
|
||||||
|
|
||||||
|
/** The day's money per payment method, added up over the staff rows. */
|
||||||
|
export function paymentTotals(staff = []) {
|
||||||
|
const out = Object.fromEntries(PAY_METHODS.map(k => [k, 0]))
|
||||||
|
for (const w of staff) for (const k of PAY_METHODS) out[k] += w[k] || 0
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A list field that may come as JSON text (older rows) or as a list. */
|
||||||
|
export function listField(value) {
|
||||||
|
if (Array.isArray(value)) return value
|
||||||
|
try { return JSON.parse(value || '[]') } catch { return [] }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Who a staff message went to: null = everyone, else the names. */
|
||||||
|
export function messageTargets(msg, staff = []) {
|
||||||
|
const ids = listField(msg.target_waiter_ids)
|
||||||
|
if (ids.length === 0) return null
|
||||||
|
return ids.map(id => {
|
||||||
|
const w = staff.find(x => x.id === id)
|
||||||
|
return w ? (w.nickname || w.full_name || w.username) : `#${id}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How many have read a message, of how many it was meant for. */
|
||||||
|
export function messageAcks(msg, staffCount) {
|
||||||
|
const read = listField(msg.acked_by).length
|
||||||
|
const of = listField(msg.target_waiter_ids).length || staffCount
|
||||||
|
return { read, of, all: read >= of }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What the notes card previews: pinned notes, urgent todos, then the latest notes; six at most. */
|
||||||
|
export function notesPreview(notes = [], todos = []) {
|
||||||
|
return [
|
||||||
|
...notes.filter(n => n.is_pinned).map(n => ({ ...n, kind: 'note' })),
|
||||||
|
...todos.filter(t => !t.is_done && t.priority === 'high').map(t => ({ ...t, kind: 'todo' })),
|
||||||
|
...notes.filter(n => !n.is_pinned).slice(0, 3).map(n => ({ ...n, kind: 'note' })),
|
||||||
|
].slice(0, 6)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The highest retry count among an order's waiting print jobs. */
|
||||||
|
export function printRetries(order) {
|
||||||
|
const waiting = (order.print_jobs ?? []).filter(j => j.status === 'pending').map(j => j.retry_count || 0)
|
||||||
|
return waiting.length ? Math.max(...waiting) : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The venue's wall clock for a moment, as a datetime-local value ("YYYY-MM-DDTHH:mm").
|
||||||
|
* Bookings are typed in venue time; the backend reads a time without an offset as venue time (D-11).
|
||||||
|
*/
|
||||||
|
export function venueWallClock(date, timeZone) {
|
||||||
|
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||||
|
timeZone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
|
||||||
|
}).formatToParts(date)
|
||||||
|
const get = type => parts.find(p => p.type === type).value
|
||||||
|
return `${get('year')}-${get('month')}-${get('day')}T${get('hour')}:${get('minute')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The quick "in …" buttons of the booking time: minutes or days from now. */
|
||||||
|
export const BOOKING_OFFSETS = [
|
||||||
|
{ mins: 30 }, { mins: 60 }, { mins: 120 }, { mins: 180 }, { mins: 300 },
|
||||||
|
{ days: 1 }, { days: 2 }, { days: 7 },
|
||||||
|
]
|
||||||
|
export function offsetFrom(now, { mins, days }) {
|
||||||
|
return new Date(now.getTime() + (mins ? mins * 60_000 : days * 86_400_000))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A booking form → the API body (empty texts as null; the time as venue wall clock with seconds). */
|
||||||
|
export function bookingBody(form) {
|
||||||
|
const text = v => (v ?? '').trim() || null
|
||||||
|
return {
|
||||||
|
guest_name: form.guest_name.trim(),
|
||||||
|
party_size: Number(form.party_size),
|
||||||
|
phone: text(form.phone),
|
||||||
|
email: text(form.email),
|
||||||
|
note: text(form.note),
|
||||||
|
table_id: form.table_id ?? null,
|
||||||
|
reserved_for: `${form.reserved_for}:00`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tables grouped by their zone for a picker; `none` is the label of tables without a zone. */
|
||||||
|
export function tablesByZone(tables = [], none = '') {
|
||||||
|
const groups = new Map()
|
||||||
|
for (const t of tables) {
|
||||||
|
const key = t.group?.name || none
|
||||||
|
if (!groups.has(key)) groups.set(key, [])
|
||||||
|
groups.get(key).push(t)
|
||||||
|
}
|
||||||
|
return [...groups.entries()].map(([zone, list]) => ({ zone, tables: list }))
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
// Small building blocks shared by the overview's cards and dialogs (plan step 6.2).
|
||||||
|
import { useFormat } from '@xenia/i18n'
|
||||||
|
import { cx } from '@xenia/ui'
|
||||||
|
import { initials, toneOf } from './overviewLogic'
|
||||||
|
import { BORDER, SOFT, SOLID } from './tones'
|
||||||
|
|
||||||
|
/** A card of the overview: a title row (with an optional action) over its content. */
|
||||||
|
export function Card({ title, info, action, children, className, testId, tone }) {
|
||||||
|
return (
|
||||||
|
<section className={cx('rounded-card border bg-surface shadow-raised overflow-hidden', tone ? BORDER[tone] : 'border-line', className)} data-testid={testId}>
|
||||||
|
{(title || action) && (
|
||||||
|
<header className={cx('flex items-center gap-2 px-4 py-3 border-b', tone ? `${SOFT[tone]} ${BORDER[tone]}` : 'border-line')}>
|
||||||
|
<h2 className="flex-1 min-w-0 text-body-lg font-semibold flex items-center gap-1">{title}{info}</h2>
|
||||||
|
{action}
|
||||||
|
</header>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A small label in a tone. */
|
||||||
|
export function Pill({ tone = 'neutral', children, className, ...rest }) {
|
||||||
|
return <span className={cx('inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-caption font-semibold whitespace-nowrap', SOFT[tone], className)} {...rest}>{children}</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** An amount of money; blurred while the overview hides amounts (privacy). */
|
||||||
|
export function Money({ value, hidden = false, className, ...rest }) {
|
||||||
|
const { formatMoney } = useFormat()
|
||||||
|
return (
|
||||||
|
<span className={cx('tabular-nums transition-[filter] duration-base', hidden && 'blur-sm select-none', className)} aria-hidden={hidden || undefined} {...rest}>
|
||||||
|
{formatMoney(value ?? 0)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A person's photo, or their initials on a steady colour. */
|
||||||
|
export function Avatar({ name = '', url, size = 'md' }) {
|
||||||
|
const box = size === 'lg' ? 'w-11 h-11 text-body' : 'w-9 h-9 text-label'
|
||||||
|
if (url) return <img src={url} alt="" className={cx(box, 'rounded-full object-cover shrink-0')} />
|
||||||
|
return <span className={cx(box, 'rounded-full shrink-0 grid place-items-center font-bold', SOFT[toneOf(name)])} aria-hidden="true">{initials(name)}</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bars of money per hour; the current hour stands out, later hours are faint. */
|
||||||
|
export function HourBars({ buckets, current, height = 'h-24', testId }) {
|
||||||
|
const { formatMoney } = useFormat()
|
||||||
|
const max = Math.max(1, ...buckets.map(b => b.value))
|
||||||
|
return (
|
||||||
|
<div className={cx('flex items-end gap-1', height)} data-testid={testId}>
|
||||||
|
{buckets.map(({ hour, value }) => {
|
||||||
|
const now = hour === current
|
||||||
|
const later = current != null && hour > current
|
||||||
|
return (
|
||||||
|
<div key={hour} className="flex-1 h-full flex flex-col items-center gap-1">
|
||||||
|
<div className="flex-1 w-full flex items-end">
|
||||||
|
<div title={`${hour}:00 · ${formatMoney(value)}`}
|
||||||
|
className={cx('w-full rounded-sm transition-[height] duration-base', now ? 'bg-accent' : later ? 'bg-surface-3' : value > 0 ? 'bg-accent-soft' : 'bg-surface-2')}
|
||||||
|
style={{ height: value > 0 ? `${Math.max(4, (value / max) * 100)}%` : '3px' }} />
|
||||||
|
</div>
|
||||||
|
<span className={cx('text-caption tabular-nums', now ? 'text-accent-ink font-bold' : 'text-ink-3')}>{hour}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A label over a value, the overview's small figure. */
|
||||||
|
export function Figure({ label, children, sub, className }) {
|
||||||
|
return (
|
||||||
|
<div className={cx('grid gap-0.5', className)}>
|
||||||
|
<span className="text-caption font-semibold uppercase tracking-wide text-ink-3">{label}</span>
|
||||||
|
<span className="text-title font-semibold tabular-nums text-ink">{children}</span>
|
||||||
|
{sub && <span className="text-caption text-ink-3">{sub}</span>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cash against card as one split bar with its legend. */
|
||||||
|
export function SplitBar({ parts, hidden }) {
|
||||||
|
const total = parts.reduce((s, p) => s + p.value, 0)
|
||||||
|
if (!total) return null
|
||||||
|
return (
|
||||||
|
<div className="grid gap-2">
|
||||||
|
<div className="flex h-3 rounded-full overflow-hidden gap-0.5">
|
||||||
|
{parts.filter(p => p.value > 0).map(p => <div key={p.key} className={SOLID[p.tone]} style={{ flex: p.value }} />)}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-x-4 gap-y-1">
|
||||||
|
{parts.filter(p => p.value > 0).map(p => (
|
||||||
|
<span key={p.key} className="inline-flex items-center gap-1.5 text-label text-ink-2">
|
||||||
|
<span className={cx('w-2.5 h-2.5 rounded-sm', SOLID[p.tone])} aria-hidden="true" />
|
||||||
|
{p.label} <Money value={p.value} hidden={hidden} className="font-semibold text-ink" />
|
||||||
|
<span className="text-caption text-ink-3">{Math.round((p.value / total) * 100)}%</span>
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// The overview's tones as whole Tailwind class names (plan step 6.2).
|
||||||
|
// Tailwind needs whole class names in the source, so tones map to fixed strings.
|
||||||
|
export const SOFT = {
|
||||||
|
accent: 'bg-accent-soft text-accent-ink',
|
||||||
|
success: 'bg-success-soft text-success-ink',
|
||||||
|
info: 'bg-info-soft text-info-ink',
|
||||||
|
warning: 'bg-warning-soft text-warning-ink',
|
||||||
|
danger: 'bg-danger-soft text-danger-ink',
|
||||||
|
neutral: 'bg-surface-2 text-ink-2',
|
||||||
|
}
|
||||||
|
export const SOLID = {
|
||||||
|
accent: 'bg-accent', success: 'bg-success', info: 'bg-info', warning: 'bg-warning', danger: 'bg-danger', neutral: 'bg-ink-3',
|
||||||
|
}
|
||||||
|
export const BORDER = {
|
||||||
|
accent: 'border-accent', success: 'border-success', info: 'border-info', warning: 'border-warning', danger: 'border-danger', neutral: 'border-line',
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
// The overview's arithmetic and the online orders' steps (plan step 6.2).
|
||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import {
|
||||||
|
bookingBody, cashCheck, dayKpis, dayOrders, durationParts, hourBuckets, initials, itemKind, itemShown,
|
||||||
|
messageAcks, messageTargets, notesPreview, orderPairs, orderTotal, paymentTotals, printRetries, quickAmounts,
|
||||||
|
shiftCounts, shiftMoney, tableCards, tableName, tablesByZone, toneOf, TONES, venueWallClock,
|
||||||
|
} from '../src/pages/overview/overviewLogic.js'
|
||||||
|
import { onlineKind, onlineNextStep } from '../src/pages/online/onlineOrdersLogic.js'
|
||||||
|
|
||||||
|
const item = (o = {}) => ({ status: 'active', unit_price: 3, price_adjustment: 0, quantity: 2, printed: true, ...o })
|
||||||
|
|
||||||
|
test('an order total leaves out cancelled lines and counts by-hand changes', () => {
|
||||||
|
assert.equal(orderTotal([item(), item({ price_adjustment: -1 }), item({ status: 'cancelled' })]), 6 + 4)
|
||||||
|
assert.equal(orderTotal(), 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('tables get their live order, state and waiting prints; KPIs add up', () => {
|
||||||
|
const tables = [{ id: 1, number: 1 }, { id: 2, label: 'Bar' }, { id: 3, number: 3 }]
|
||||||
|
const orders = [
|
||||||
|
{ id: 10, table_id: 1, status: 'open', opened_at: '2026-11-18T09:00:00Z', items: [item({ printed: false })] },
|
||||||
|
{ id: 11, table_id: 2, status: 'partially_paid', opened_at: '2026-11-18T11:00:00Z', items: [item({ paid_by: 4 })] },
|
||||||
|
{ id: 12, table_id: 3, status: 'closed', opened_at: '2026-11-18T11:00:00Z', items: [item()] },
|
||||||
|
]
|
||||||
|
const cards = tableCards(tables, orders)
|
||||||
|
assert.deepEqual(cards.map(c => c.state), ['open', 'partially_paid', 'free'])
|
||||||
|
assert.deepEqual(cards.map(c => c.pendingPrint), [true, false, false])
|
||||||
|
assert.equal(tableName(tables[0]), 'T1')
|
||||||
|
assert.equal(tableName(tables[1]), 'Bar')
|
||||||
|
|
||||||
|
const today = dayOrders(orders, '2026-11-18T10:00:00Z')
|
||||||
|
assert.deepEqual(today.map(o => o.id), [11, 12])
|
||||||
|
assert.equal(dayOrders(orders, null).length, 3)
|
||||||
|
const k = dayKpis({ cards, orders: today, shifts: [{ total_collected: 5 }, { total_collected: 7.5 }] })
|
||||||
|
assert.equal(k.revenue, 12)
|
||||||
|
assert.equal(k.avgTicket, 12) // one order with a paid line
|
||||||
|
assert.equal(k.occupied, 2)
|
||||||
|
assert.equal(k.free, 1)
|
||||||
|
assert.equal(Math.round(k.occupiedPct), 67)
|
||||||
|
assert.equal(k.collected, 12.5)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('money per hour covers the usual hours and any hour with money', () => {
|
||||||
|
const hourOf = iso => new Date(iso).getUTCHours()
|
||||||
|
const b = hourBuckets(orderPairs([
|
||||||
|
{ opened_at: '2026-11-18T08:30:00Z', items: [item()] },
|
||||||
|
{ opened_at: '2026-11-18T12:10:00Z', items: [item(), item()] },
|
||||||
|
]), hourOf)
|
||||||
|
assert.equal(b[0].hour, 8)
|
||||||
|
assert.equal(b.at(-1).hour, 23)
|
||||||
|
assert.equal(b.find(x => x.hour === 12).value, 12)
|
||||||
|
assert.equal(b.find(x => x.hour === 9).value, 0)
|
||||||
|
// a shift's bars: only the hours with money
|
||||||
|
assert.deepEqual(hourBuckets([['2026-11-18T19:00:00Z', 4]], hourOf, { from: 24, to: -1 }), [{ hour: 19, value: 4 }])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('a shift\'s money, counts and its lines seen from the waiter', () => {
|
||||||
|
assert.deepEqual(shiftMoney({ starting_cash: 20, cash_sales: 30, card_sales: 10 }),
|
||||||
|
{ cash: 30, card: 10, start: 20, total: 40, expected: 50, cashPct: 75, cardPct: 25 })
|
||||||
|
assert.equal(shiftMoney({}).cardPct, 0)
|
||||||
|
const summary = { orders: [
|
||||||
|
{ table_id: 1, items: [{ status: 'paid', quantity: 2 }, { status: 'cancelled', quantity: 5 }] },
|
||||||
|
{ table_id: 1, items: [{ status: 'paid', quantity: 1 }] },
|
||||||
|
{ table_id: null, items: [] },
|
||||||
|
] }
|
||||||
|
assert.deepEqual(shiftCounts(summary), { items: 3, tables: 1, orders: 3 })
|
||||||
|
|
||||||
|
const me = 7
|
||||||
|
assert.equal(itemKind({ status: 'paid', added_by_id: me, paid_by_id: me }, me), 'both')
|
||||||
|
assert.equal(itemKind({ status: 'paid', added_by_id: 2, paid_by_id: me }, me), 'paid')
|
||||||
|
assert.equal(itemKind({ status: 'paid', added_by_id: me, paid_by_id: 2 }, me), 'ordered')
|
||||||
|
assert.equal(itemKind({ status: 'active', added_by_id: me }, me), 'unpaid')
|
||||||
|
assert.equal(itemKind({ status: 'cancelled' }, me), 'cancelled')
|
||||||
|
assert.equal(itemKind({ status: 'active', added_by_id: 2 }, me), 'anomaly')
|
||||||
|
const card = { status: 'paid', added_by_id: me, paid_by_id: me, payment_method: 'card' }
|
||||||
|
assert.equal(itemShown(card, me, 'both', 'card'), true)
|
||||||
|
assert.equal(itemShown(card, me, 'both', 'cash'), false)
|
||||||
|
assert.equal(itemShown({ ...card, payment_method: null }, me, 'all', 'cash'), true) // no method = cash
|
||||||
|
assert.equal(itemShown({ status: 'cancelled' }, me, 'all', 'card'), true) // cancelled lines ignore the method
|
||||||
|
assert.equal(itemShown(card, me, 'unpaid', 'any'), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('counting cash: short, over, even (to the cent)', () => {
|
||||||
|
assert.equal(cashCheck(null, 50), null)
|
||||||
|
assert.equal(cashCheck(NaN, 50), null)
|
||||||
|
assert.deepEqual(cashCheck(50, 50), { diff: 0, state: 'even' })
|
||||||
|
assert.deepEqual(cashCheck(45.5, 50), { diff: -4.5, state: 'short' })
|
||||||
|
assert.deepEqual(cashCheck(50.1, 50), { diff: 0.1, state: 'over' })
|
||||||
|
assert.deepEqual(quickAmounts(47.3), [47.3, 40, 50])
|
||||||
|
assert.deepEqual(quickAmounts(50), [50])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('people: durations, initials, a steady tone', () => {
|
||||||
|
assert.deepEqual(durationParts(0, 95 * 60000), { h: 1, m: 35, mins: 95 })
|
||||||
|
assert.equal(durationParts(null), null)
|
||||||
|
assert.equal(initials('Maria Papadopoulou'), 'MP')
|
||||||
|
assert.equal(initials('nikos'), 'NI')
|
||||||
|
assert.equal(initials(''), '?')
|
||||||
|
assert.equal(toneOf('Maria'), toneOf('Maria'))
|
||||||
|
assert.ok(TONES.includes(toneOf('Giorgos')))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the day\'s payments, messages, notes, print retries', () => {
|
||||||
|
assert.deepEqual(paymentTotals([{ cash: 5, card: 2 }, { cash: 1, treat: 3 }]), { cash: 6, card: 2, transfer: 0, treat: 3, other: 0 })
|
||||||
|
const staff = [{ id: 1, nickname: 'Mary' }, { id: 2, username: 'nick' }]
|
||||||
|
assert.equal(messageTargets({ target_waiter_ids: '[]' }, staff), null)
|
||||||
|
assert.deepEqual(messageTargets({ target_waiter_ids: [1, 9] }, staff), ['Mary', '#9'])
|
||||||
|
assert.deepEqual(messageAcks({ target_waiter_ids: '[]', acked_by: '[1,2]' }, 2), { read: 2, of: 2, all: true })
|
||||||
|
assert.deepEqual(messageAcks({ target_waiter_ids: [1], acked_by: 'bad json' }, 2), { read: 0, of: 1, all: false })
|
||||||
|
const notes = [{ id: 1, is_pinned: true }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]
|
||||||
|
const todos = [{ id: 9, priority: 'high' }, { id: 8, priority: 'high', is_done: true }, { id: 7, priority: 'low' }]
|
||||||
|
assert.deepEqual(notesPreview(notes, todos).map(x => `${x.kind}${x.id}`), ['note1', 'todo9', 'note2', 'note3', 'note4'])
|
||||||
|
assert.equal(printRetries({ print_jobs: [{ status: 'pending', retry_count: 2 }, { status: 'done', retry_count: 9 }] }), 2)
|
||||||
|
assert.equal(printRetries({}), 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('bookings are typed in venue time', () => {
|
||||||
|
// 18 Nov 2026 10:00 UTC is 12:00 in Athens (EET, +2)
|
||||||
|
assert.equal(venueWallClock(new Date('2026-11-18T10:00:00Z'), 'Europe/Athens'), '2026-11-18T12:00')
|
||||||
|
assert.equal(venueWallClock(new Date('2026-07-01T23:30:00Z'), 'Europe/Athens'), '2026-07-02T02:30')
|
||||||
|
assert.deepEqual(bookingBody({ guest_name: ' Eleni ', party_size: '4', phone: ' ', email: '', note: 'window', table_id: 3, reserved_for: '2026-11-18T21:00' }),
|
||||||
|
{ guest_name: 'Eleni', party_size: 4, phone: null, email: null, note: 'window', table_id: 3, reserved_for: '2026-11-18T21:00:00' })
|
||||||
|
const zones = tablesByZone([{ id: 1, group: { name: 'Garden' } }, { id: 2 }, { id: 3, group: { name: 'Garden' } }], 'No zone')
|
||||||
|
assert.deepEqual(zones.map(z => [z.zone, z.tables.map(t => t.id)]), [['Garden', [1, 3]], ['No zone', [2]]])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('online orders move on step by step', () => {
|
||||||
|
const o = (status, type = 'takeaway') => ({ online_status: status, online_order_type: type })
|
||||||
|
assert.equal(onlineNextStep(o('pending_acceptance')), null) // accept / refuse first
|
||||||
|
assert.equal(onlineNextStep(o('accepted')), 'preparing')
|
||||||
|
assert.equal(onlineNextStep(o('preparing')), 'ready')
|
||||||
|
assert.equal(onlineNextStep(o('preparing', 'delivery')), 'out_for_delivery')
|
||||||
|
assert.equal(onlineNextStep(o('out_for_delivery', 'delivery')), 'delivered')
|
||||||
|
assert.equal(onlineNextStep(o('delivered')), null)
|
||||||
|
assert.equal(onlineKind(o('x', null)), 'dine_in')
|
||||||
|
assert.equal(onlineKind(o('x', 'delivery')), 'delivery')
|
||||||
|
})
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
{
|
{
|
||||||
"_comment": "Plan step 6.1: what is on the v2 rules. `paths` (files or folders): `npm run lint` checks them, and tests/v2-guards.test.mjs refuses Greek and colour literals in them. `strict`: also no setState in effects (data loads with useLiveQuery / react-query). Each phase 6 step adds what it converted; 6.14 ends with `src`.",
|
"_comment": "Plan step 6.1: what is on the v2 rules. `paths` (files or folders): `npm run lint` checks them, and tests/v2-guards.test.mjs refuses Greek and colour literals in them. `strict`: also no setState in effects (data loads with useLiveQuery / react-query). Each phase 6 step adds what it converted; 6.14 ends with `src`.",
|
||||||
"paths": [
|
"paths": [
|
||||||
"src/shell", "src/live", "src/pages/platform", "src/pages/online", "src/pages/media", "src/pages/signage",
|
"src/shell", "src/live", "src/pages/platform", "src/pages/online", "src/pages/media", "src/pages/signage", "src/pages/staff", "src/pages/Settings/sections", "src/pages/LoginPage.jsx", "src/components/NotificationBell.jsx", "src/components/PhoneListener.jsx", "src/pages/PhonePage.jsx", "src/store/phoneStore.js", "src/components/UserMenuButton.jsx", "src/pages/reports/operations/LogsPanel.jsx", "src/api/client.js", "src/store/authStore.js", "src/main.jsx", "src/pages/overview", "src/hooks"
|
||||||
"src/pages/staff", "src/pages/Settings/sections", "src/pages/LoginPage.jsx", "src/components/NotificationBell.jsx",
|
|
||||||
"src/components/PhoneListener.jsx", "src/pages/PhonePage.jsx", "src/store/phoneStore.js", "src/components/UserMenuButton.jsx",
|
|
||||||
"src/pages/reports/operations/LogsPanel.jsx", "src/api/client.js", "src/store/authStore.js", "src/main.jsx"
|
|
||||||
],
|
],
|
||||||
"strict": ["src/live", "src/pages/staff/SessionsPage.jsx"]
|
"strict": [
|
||||||
|
"src/live", "src/pages/staff/SessionsPage.jsx", "src/pages/overview", "src/pages/online/OnlineOrdersPage.jsx", "src/hooks"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -573,7 +573,44 @@
|
|||||||
"onlineOrders": {
|
"onlineOrders": {
|
||||||
"for": "Για {{when}}",
|
"for": "Για {{when}}",
|
||||||
"asap": "Το συντομότερο",
|
"asap": "Το συντομότερο",
|
||||||
"priceDiff": "Χρεώθηκε {{charged}} online· με τις τωρινές τιμές του καταστήματος θα ήταν {{here}}. Ο πελάτης πληρώνει όσο χρεώθηκε."
|
"priceDiff": "Χρεώθηκε {{charged}} online· με τις τωρινές τιμές του καταστήματος θα ήταν {{here}}. Ο πελάτης πληρώνει όσο χρεώθηκε.",
|
||||||
|
"tab": {
|
||||||
|
"incoming": "Εισερχόμενες",
|
||||||
|
"active": "Ενεργές",
|
||||||
|
"history": "Ιστορικό"
|
||||||
|
},
|
||||||
|
"refresh": "Ανανέωση",
|
||||||
|
"empty": {
|
||||||
|
"incoming": "Δεν υπάρχουν εισερχόμενες παραγγελίες.",
|
||||||
|
"active": "Δεν υπάρχουν ενεργές παραγγελίες.",
|
||||||
|
"history": "Δεν υπάρχει ιστορικό παραγγελιών."
|
||||||
|
},
|
||||||
|
"kind": {
|
||||||
|
"delivery": "Delivery",
|
||||||
|
"takeaway": "Takeaway",
|
||||||
|
"dine_in": "Στο κατάστημα"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"pending_acceptance": "Αναμονή",
|
||||||
|
"accepted": "Αποδεκτή",
|
||||||
|
"preparing": "Προετοιμασία",
|
||||||
|
"ready": "Έτοιμη",
|
||||||
|
"out_for_delivery": "Σε παράδοση",
|
||||||
|
"delivered": "Παραδόθηκε",
|
||||||
|
"rejected": "Απορρίφθηκε"
|
||||||
|
},
|
||||||
|
"next": {
|
||||||
|
"preparing": "Προετοιμασία",
|
||||||
|
"ready": "Έτοιμη",
|
||||||
|
"out_for_delivery": "Εξωτερική παράδοση",
|
||||||
|
"delivered": "Παραδόθηκε"
|
||||||
|
},
|
||||||
|
"total": "Σύνολο",
|
||||||
|
"accept": "Αποδοχή",
|
||||||
|
"reject": "Απόρριψη",
|
||||||
|
"rejectReason": "Λόγος απόρριψης (προαιρετικό)",
|
||||||
|
"rejectHint": "Τον βλέπει ο πελάτης.",
|
||||||
|
"rejectNow": "Επιβεβαίωση"
|
||||||
},
|
},
|
||||||
"feeProduct": {
|
"feeProduct": {
|
||||||
"title": "Τα μεταφορικά στην απόδειξη",
|
"title": "Τα μεταφορικά στην απόδειξη",
|
||||||
@@ -1123,5 +1160,368 @@
|
|||||||
"refresh": "Ενημέρωση τώρα",
|
"refresh": "Ενημέρωση τώρα",
|
||||||
"forget": "Αφαίρεση πόλης"
|
"forget": "Αφαίρεση πόλης"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"overview": {
|
||||||
|
"back": "Άκυρο",
|
||||||
|
"close": "Κλείσιμο",
|
||||||
|
"save": "Αποθήκευση",
|
||||||
|
"loading": "Φόρτωση…",
|
||||||
|
"dayOpen": "Ημέρα ανοιχτή",
|
||||||
|
"dayClosed": "Ημέρα κλειστή",
|
||||||
|
"daySince": "από {{time}} · {{length}}",
|
||||||
|
"openDay": "Άνοιγμα ημέρας",
|
||||||
|
"dayOpened": "Η ημέρα άνοιξε",
|
||||||
|
"dayStats": "Στατιστικά ημέρας",
|
||||||
|
"closeDay": "Κλείσιμο ημέρας",
|
||||||
|
"dayClosedDone": "Η ημέρα έκλεισε",
|
||||||
|
"hideAmounts": "Απόκρυψη ποσών",
|
||||||
|
"showAmounts": "Εμφάνιση ποσών",
|
||||||
|
"locked": "Σύστημα κλειδωμένο",
|
||||||
|
"expired": "Η άδεια χρήσης έληξε",
|
||||||
|
"blockedHelp": "Η ημέρα δεν μπορεί να ανοίξει μέχρι να λυθεί αυτό.",
|
||||||
|
"revenueByHour": "Έσοδα ανά ώρα",
|
||||||
|
"duration": {
|
||||||
|
"m": "{{m}}λ",
|
||||||
|
"h": "{{h}}ω",
|
||||||
|
"hm": "{{h}}ω {{m}}λ"
|
||||||
|
},
|
||||||
|
"kpi": {
|
||||||
|
"revenue": "Έσοδα ημέρας",
|
||||||
|
"orders_one": "{{count}} παραγγελία",
|
||||||
|
"orders_other": "{{count}} παραγγελίες",
|
||||||
|
"avg": "μ.ο.",
|
||||||
|
"tables": "Τραπέζια σε χρήση",
|
||||||
|
"tablesSub": "{{free}} ελεύθερα · {{partly}} μερική πληρ.",
|
||||||
|
"shifts": "Βάρδιες ενεργές",
|
||||||
|
"collected": "Είσπραξη βαρδιών",
|
||||||
|
"collectedSub_one": "Σύνολο από {{count}} βάρδια",
|
||||||
|
"collectedSub_other": "Σύνολο από {{count}} βάρδιες",
|
||||||
|
"prints": "Εκκρεμείς εκτυπώσεις",
|
||||||
|
"printsSub": "Απαιτείται προσοχή"
|
||||||
|
},
|
||||||
|
"shifts": {
|
||||||
|
"title": "Βάρδιες σε εξέλιξη",
|
||||||
|
"start": "Έναρξη",
|
||||||
|
"none": "Κανένας σερβιτόρος σε βάρδια",
|
||||||
|
"onBreak": "Διάλειμμα · {{since}}",
|
||||||
|
"since": "από {{time}} · {{length}}",
|
||||||
|
"message": "Αποστολή μηνύματος",
|
||||||
|
"stats": "Στατιστικά βάρδιας",
|
||||||
|
"end": "Τέλος",
|
||||||
|
"startTitle": "Έναρξη βάρδιας",
|
||||||
|
"waiter": "Σερβιτόρος",
|
||||||
|
"pick": "Επιλέξτε…",
|
||||||
|
"pickWaiter": "Επιλέξτε σερβιτόρο",
|
||||||
|
"startCash": "Αρχικά μετρητά",
|
||||||
|
"startCashHint": "Τα ρέστα με τα οποία ξεκινά ο σερβιτόρος. Αφήστε το κενό αν δεν έχει.",
|
||||||
|
"badAmount": "Γράψτε ένα ποσό, π.χ. 50 ή 50,00",
|
||||||
|
"startNow": "Έναρξη",
|
||||||
|
"started": "Η βάρδια ξεκίνησε",
|
||||||
|
"ended": "Η βάρδια του/της {{name}} έκλεισε"
|
||||||
|
},
|
||||||
|
"shift": {
|
||||||
|
"running": "Σε εξέλιξη",
|
||||||
|
"closing": "Κλείσιμο",
|
||||||
|
"number": "Βάρδια #{{id}}",
|
||||||
|
"start": "Έναρξη",
|
||||||
|
"length": "Διάρκεια",
|
||||||
|
"tab": {
|
||||||
|
"overview": "Επισκόπηση",
|
||||||
|
"lines": "Λεπτομέρειες"
|
||||||
|
},
|
||||||
|
"expected": "Αναμενόμενο στο ταμείο",
|
||||||
|
"startCash": "Αρχικό ταμείο",
|
||||||
|
"startCashHint": "με τι ξεκίνησε",
|
||||||
|
"cashSales": "Μετρητά πωλήσεων",
|
||||||
|
"cashSalesHint": "είσπραξη σε μετρητά",
|
||||||
|
"turnover": "Συνολικός τζίρος",
|
||||||
|
"turnoverHint": "μετρητά + κάρτα",
|
||||||
|
"perHour": "Πωλήσεις ανά ώρα",
|
||||||
|
"items": "Είδη",
|
||||||
|
"tables": "Τραπέζια",
|
||||||
|
"orders": "Παραγγελίες",
|
||||||
|
"pay": "Αμοιβή",
|
||||||
|
"perHourRate": "{{rate}}/ώρα",
|
||||||
|
"notes": "Σημειώσεις (προαιρετικό)",
|
||||||
|
"notesHint": "π.χ. παρατηρήσεις για τη βάρδια, βλάβες, ελλείψεις…",
|
||||||
|
"handover": "Πόσα μετρητά παραδίδει ο σερβιτόρος;",
|
||||||
|
"counted": "Μετρητά που παραδίδονται",
|
||||||
|
"countedHint": "Συγκρίνεται με το αναμενόμενο. Αφήστε το κενό για να παραλείψετε τη μέτρηση.",
|
||||||
|
"exact": "Ακριβές",
|
||||||
|
"live": "Ζωντανή προβολή: η βάρδια συνεχίζεται",
|
||||||
|
"checkFirst": "Επιβεβαίωσε τα ποσά πριν το κλείσιμο",
|
||||||
|
"toHandover": "Παράδοση μετρητών",
|
||||||
|
"endNow": "Οριστικό κλείσιμο",
|
||||||
|
"noLines": "Δεν υπάρχουν αντικείμενα για αυτή τη βάρδια",
|
||||||
|
"order": "Παραγγελία #{{id}}",
|
||||||
|
"openedBy": "Άνοιξε: {{name}}",
|
||||||
|
"orderedBy": "Παρήγγειλε: {{name}}",
|
||||||
|
"paidTo": "Πληρώθηκε: {{name}}",
|
||||||
|
"kind": {
|
||||||
|
"all": "Όλα",
|
||||||
|
"both": "Πλήρης",
|
||||||
|
"paid": "Μόνο πληρώθηκε",
|
||||||
|
"ordered": "Μόνο παρήγγειλε",
|
||||||
|
"unpaid": "Ανοιχτό",
|
||||||
|
"cancelled": "Ακυρώθηκε",
|
||||||
|
"anomaly": "Πρόβλημα"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cash": {
|
||||||
|
"even": "Ισοσκελισμένο",
|
||||||
|
"short": "Έλλειμμα",
|
||||||
|
"over": "Πλεόνασμα"
|
||||||
|
},
|
||||||
|
"pay": {
|
||||||
|
"any": "Κάθε τρόπος",
|
||||||
|
"cash": "Μετρητά",
|
||||||
|
"card": "Κάρτα",
|
||||||
|
"transfer": "Τρ. μεταφορά",
|
||||||
|
"treat": "Κεράστηκε",
|
||||||
|
"other": "Άλλο"
|
||||||
|
},
|
||||||
|
"tables": {
|
||||||
|
"title": "Τραπέζια τώρα",
|
||||||
|
"all": "Πλήρης εικόνα"
|
||||||
|
},
|
||||||
|
"tableState": {
|
||||||
|
"open": "Ανοιχτό",
|
||||||
|
"partially_paid": "Μερική πληρ.",
|
||||||
|
"paid": "Πληρωμένο",
|
||||||
|
"free": "Ελεύθερο"
|
||||||
|
},
|
||||||
|
"order": {
|
||||||
|
"title": "Τραπέζι {{table}}",
|
||||||
|
"sub": "Παραγγελία #{{id}} · από {{time}} · {{since}}",
|
||||||
|
"staff": "Προσωπικό",
|
||||||
|
"empty": "Κανένα αντικείμενο.",
|
||||||
|
"free": "ΔΩΡΕΑΝ",
|
||||||
|
"linePaid": "Πληρώθηκε",
|
||||||
|
"pay": "Πληρωμή",
|
||||||
|
"payAll": "Πληρωμή όλων",
|
||||||
|
"cancelLine": "Ακύρωση αντικειμένου",
|
||||||
|
"close": "Κλείσιμο",
|
||||||
|
"cancel": "Ακύρωση",
|
||||||
|
"printer": "Εκτυπωτής…",
|
||||||
|
"print": "Εκτύπωση",
|
||||||
|
"full": "Πλήρης εικόνα",
|
||||||
|
"paidDone": "Πληρώθηκε",
|
||||||
|
"lineCancelled": "Το αντικείμενο ακυρώθηκε",
|
||||||
|
"cancelled": "Η παραγγελία ακυρώθηκε",
|
||||||
|
"closed": "Η παραγγελία έκλεισε",
|
||||||
|
"printing": "Αποστολή στον εκτυπωτή…",
|
||||||
|
"confirm": {
|
||||||
|
"cancelItem": "Ακύρωση αντικειμένου;",
|
||||||
|
"cancelOrder": "Ακύρωση παραγγελίας;",
|
||||||
|
"close": "Κλείσιμο παραγγελίας;",
|
||||||
|
"cancelOrderBody": "Η παραγγελία θα ακυρωθεί οριστικά."
|
||||||
|
},
|
||||||
|
"printCancel": "Εκτύπωση ακύρωσης;",
|
||||||
|
"printCancelBody": "Θέλετε να σταλεί ακυρωτικό ticket στον εκτυπωτή;",
|
||||||
|
"printCancelNo": "Όχι, απλή ακύρωση",
|
||||||
|
"printCancelYes": "Ναι, εκτύπωση",
|
||||||
|
"event": {
|
||||||
|
"waiter_discount": "Έκπτωση",
|
||||||
|
"free_item_added": "Δωρεάν",
|
||||||
|
"modifier_applied": "Τροποποιητής"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"orderStatus": {
|
||||||
|
"open": "Ανοιχτή",
|
||||||
|
"partially_paid": "Μερικώς πληρωμένη",
|
||||||
|
"paid": "Πληρωμένη",
|
||||||
|
"closed": "Κλειστή",
|
||||||
|
"cancelled": "Ακυρωμένη"
|
||||||
|
},
|
||||||
|
"prints": {
|
||||||
|
"title": "Εκκρεμείς εκτυπώσεις",
|
||||||
|
"count_one": "{{count}} παραγγελία δεν έχει σταλεί",
|
||||||
|
"count_other": "{{count}} παραγγελίες δεν έχουν σταλεί",
|
||||||
|
"all": "Αποστολή όλων",
|
||||||
|
"retries_one": "{{count}} επανάληψη",
|
||||||
|
"retries_other": "{{count}} επαναλήψεις",
|
||||||
|
"lines_one": "{{count}} αντ. εκκρεμεί",
|
||||||
|
"lines_other": "{{count}} αντ. εκκρεμούν",
|
||||||
|
"open": "Λεπτομέρειες",
|
||||||
|
"print": "Εκτύπωση",
|
||||||
|
"done": "Εκτυπώθηκε επιτυχώς",
|
||||||
|
"failed": "Αποτυχία: {{printers}}"
|
||||||
|
},
|
||||||
|
"notes": {
|
||||||
|
"title": "Σημειώσεις & εργασίες",
|
||||||
|
"counts": "{{notes}} σημειώσεις · {{todos}} εκκρεμείς εργασίες"
|
||||||
|
},
|
||||||
|
"bookings": {
|
||||||
|
"upcoming": "Επερχόμενες",
|
||||||
|
"history": "Ιστορικό",
|
||||||
|
"new": "Νέα",
|
||||||
|
"noneUpcoming": "Καμία επερχόμενη κράτηση",
|
||||||
|
"noneHistory": "Κανένα ιστορικό",
|
||||||
|
"status": {
|
||||||
|
"requested": "Αίτημα online",
|
||||||
|
"pending": "Αναμονή",
|
||||||
|
"arrived": "Έφτασε",
|
||||||
|
"cancelled": "Ακυρώθηκε",
|
||||||
|
"no_show": "Δεν ήρθε",
|
||||||
|
"declined": "Απορρίφθηκε"
|
||||||
|
},
|
||||||
|
"edit": "Επεξεργασία",
|
||||||
|
"confirm": "Επιβεβαίωση",
|
||||||
|
"decline": "Απόρριψη",
|
||||||
|
"arrived": "Έφτασε",
|
||||||
|
"cancel": "Ακύρωση",
|
||||||
|
"declineTitle": "Απόρριψη κράτησης",
|
||||||
|
"declineDefault": "Δεν υπάρχει διαθεσιμότητα εκείνη την ώρα",
|
||||||
|
"reason": "Λόγος",
|
||||||
|
"reasonHint": "Τον βλέπει ο πελάτης.",
|
||||||
|
"newTitle": "Νέα κράτηση",
|
||||||
|
"editTitle": "Επεξεργασία κράτησης",
|
||||||
|
"name": "Όνομα",
|
||||||
|
"nameNeeded": "Εισάγετε όνομα",
|
||||||
|
"people": "Άτομα",
|
||||||
|
"peopleNeeded": "Τουλάχιστον 1",
|
||||||
|
"when": "Ημερομηνία & ώρα",
|
||||||
|
"whenHint": "Στην ώρα του καταστήματος.",
|
||||||
|
"inMinutes_one": "+{{count}}λ",
|
||||||
|
"inMinutes_other": "+{{count}}λ",
|
||||||
|
"inHours_one": "+{{count}}ω",
|
||||||
|
"inHours_other": "+{{count}}ω",
|
||||||
|
"inDays_one": "+{{count}} μέρα",
|
||||||
|
"inDays_other": "+{{count}} μέρες",
|
||||||
|
"table": "Τραπέζι (προαιρετικό)",
|
||||||
|
"noTable": "Χωρίς τραπέζι",
|
||||||
|
"noZone": "Χωρίς ζώνη",
|
||||||
|
"phone": "Τηλέφωνο",
|
||||||
|
"email": "Email",
|
||||||
|
"note": "Σημείωση",
|
||||||
|
"noteHint": "Εσωτερική σημείωση για το προσωπικό.",
|
||||||
|
"create": "Δημιουργία",
|
||||||
|
"created": "Η κράτηση δημιουργήθηκε",
|
||||||
|
"saved": "Αποθηκεύτηκε"
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"title": "Μηνύματα",
|
||||||
|
"new": "Νέο",
|
||||||
|
"none": "Δεν υπάρχουν μηνύματα ακόμα",
|
||||||
|
"to": "Προς: {{who}} · {{time}}",
|
||||||
|
"everyone": "Όλοι",
|
||||||
|
"read": "{{read}}/{{of}} διαβάστηκε",
|
||||||
|
"readBy": "Πόσοι το διάβασαν",
|
||||||
|
"newTitle": "Νέο μήνυμα",
|
||||||
|
"toOne": "Μήνυμα σε {{name}}",
|
||||||
|
"recipients": "Παραλήπτες",
|
||||||
|
"allOfThem": "(όλοι)",
|
||||||
|
"tables": "Σχετικά τραπέζια (προαιρετικό)",
|
||||||
|
"quick": "Γρήγορα μηνύματα",
|
||||||
|
"text": "Μήνυμα",
|
||||||
|
"send": "Αποστολή",
|
||||||
|
"sent": "Εστάλη"
|
||||||
|
},
|
||||||
|
"day": {
|
||||||
|
"statsTitle": "Στατιστικά ημέρας",
|
||||||
|
"closeTitle": "Κλείσιμο εργάσιμης ημέρας",
|
||||||
|
"open": "Ημέρα ενεργή",
|
||||||
|
"closedState": "Κλειστή",
|
||||||
|
"openedAt": "Άνοιγμα {{time}}",
|
||||||
|
"tab": {
|
||||||
|
"money": "Επισκόπηση",
|
||||||
|
"staff": "Προσωπικό",
|
||||||
|
"zones": "Ζώνες",
|
||||||
|
"printers": "Εκτυπωτές",
|
||||||
|
"cash": "Ταμείο",
|
||||||
|
"checks": "Έλεγχοι"
|
||||||
|
},
|
||||||
|
"toCash": "Μέτρηση ταμείου",
|
||||||
|
"toChecks": "Προχωρήστε στους ελέγχους",
|
||||||
|
"revenue": "Συνολικά έσοδα",
|
||||||
|
"orders": "Παραγγελίες",
|
||||||
|
"items": "Αντικείμενα",
|
||||||
|
"waiters": "Σερβιτόροι",
|
||||||
|
"opened": "Άνοιγμα",
|
||||||
|
"closed": "Κλείσιμο",
|
||||||
|
"stillOpen": "Ημέρα ενεργή",
|
||||||
|
"sales": "Έσοδα",
|
||||||
|
"salesTotal": "Σύνολο πωλήσεων",
|
||||||
|
"onTabs": "Καρτέλες (μη εισπραχθέντα)",
|
||||||
|
"onTabsTip": "Πωλήσεις σε καρτέλες πελατών: μετράνε ως πωλήσεις, τα χρήματα έρχονται όταν εξοφληθεί η καρτέλα.",
|
||||||
|
"taken": "Καθαρά εισπραχθέντα",
|
||||||
|
"cogs": "Κόστος πωληθέντων",
|
||||||
|
"cogsKnown": "Κόστος καταγεγραμμένων",
|
||||||
|
"cogsTip": "Πόσο κόστισαν στο κατάστημα τα είδη που πουλήθηκαν, από τα κόστη των προϊόντων (όπως ήταν τη στιγμή της πώλησης).",
|
||||||
|
"uncosted_one": "{{count}} αντ. χωρίς κόστος ({{revenue}} έσοδα)",
|
||||||
|
"uncosted_other": "{{count}} αντ. χωρίς κόστος ({{revenue}} έσοδα)",
|
||||||
|
"gross": "Μικτό κέρδος",
|
||||||
|
"partial": "Μερικό: υπάρχουν αντ. χωρίς κόστος",
|
||||||
|
"labour": "Μισθοδοσία",
|
||||||
|
"labourCost": "Κόστος εργασίας (καταγεγρ.)",
|
||||||
|
"noRate_one": "{{count}} βάρδια χωρίς ωριαία αμοιβή",
|
||||||
|
"noRate_other": "{{count}} βάρδιες χωρίς ωριαία αμοιβή",
|
||||||
|
"waste": "Απόβλητα",
|
||||||
|
"wasteEntries_one": "{{count}} καταχώρηση",
|
||||||
|
"wasteEntries_other": "{{count}} καταχωρήσεις",
|
||||||
|
"expenses": "Έξοδα (σήμερα)",
|
||||||
|
"expensesTotal": "Σύνολο εξόδων",
|
||||||
|
"expensesPaid": "Πληρωμένα σήμερα",
|
||||||
|
"expensesDue": "Ακόμη οφείλονται",
|
||||||
|
"net": "Εκτιμώμενο καθαρό αποτέλεσμα",
|
||||||
|
"netHint": "Εισπράξεις − κόστος − μισθοί − απόβλητα − έξοδα",
|
||||||
|
"netTip": "Εκτίμηση: γνωρίζει μόνο τα κόστη και τους μισθούς που έχουν καταχωρηθεί στο σύστημα.",
|
||||||
|
"netPartial": "Μερικό: υπάρχουν άγνωστα κόστη",
|
||||||
|
"payments": "Κατανομή πληρωμών",
|
||||||
|
"drawer": "Ταμείο",
|
||||||
|
"drawerExpected": "Αναμενόμενο ταμείο",
|
||||||
|
"drawerExpectedTip": "Το αρχικό ταμείο συν όσα εισέπραξε το προσωπικό σε μετρητά.",
|
||||||
|
"drawerCounted": "Μετρημένο ταμείο",
|
||||||
|
"drawerDiff": "Διαφορά",
|
||||||
|
"noStaff": "Δεν βρέθηκαν σερβιτόροι",
|
||||||
|
"role": {
|
||||||
|
"waiter": "Σερβιτόρος",
|
||||||
|
"manager": "Διευθυντής"
|
||||||
|
},
|
||||||
|
"ordersOpened": "Παραγγελίες",
|
||||||
|
"tablesServed": "Εξ. τραπεζιών",
|
||||||
|
"itemsPaid": "Αντικ. εισπρ.",
|
||||||
|
"collected": "Είσπραξη",
|
||||||
|
"shiftStart": "Έναρξη βάρδιας",
|
||||||
|
"shiftEnd": "Λήξη βάρδιας",
|
||||||
|
"shiftRunning": "Βάρδια ενεργή",
|
||||||
|
"rate": "Μισθός / ώρα",
|
||||||
|
"payNow": "Μισθός (έως τώρα)",
|
||||||
|
"notTracked": "Δεν παρακολ.",
|
||||||
|
"startCash": "Αρχικά μετρητά",
|
||||||
|
"drawerNow": "Ταμείο τώρα",
|
||||||
|
"noZones": "Δεν βρέθηκαν ζώνες",
|
||||||
|
"perOrder": "Μ.Ο./παραγ.",
|
||||||
|
"noPrints": "Δεν βρέθηκαν δεδομένα εκτύπωσης",
|
||||||
|
"printedValue": "αξία εκτυπ.",
|
||||||
|
"jobs": "Εργασίες",
|
||||||
|
"jobsOk": "Επιτυχείς",
|
||||||
|
"jobsFailed": "Αποτυχίες",
|
||||||
|
"takings": "Σύνοψη εισπράξεων βάρδιας",
|
||||||
|
"staffTook": "Σύνολο εισπράξεων σερβιτόρων",
|
||||||
|
"openingCash": "Αρχικό ταμείο",
|
||||||
|
"countDrawer": "Μετρήστε το ταμείο: πόσα μετρητά υπάρχουν;",
|
||||||
|
"countHint": "Προαιρετικό. Αν παραλείψετε τη μέτρηση, η επαλήθευση δεν θα καταγραφεί.",
|
||||||
|
"cash": {
|
||||||
|
"even": "Το φυσικό ταμείο συμφωνεί με τις καταγεγραμμένες εισπράξεις.",
|
||||||
|
"short": "Το ταμείο έχει {{amount}} λιγότερα από το αναμενόμενο. Το κενό δεν αποδίδεται σε κάποιον σερβιτόρο συγκεκριμένα.",
|
||||||
|
"over": "Το ταμείο έχει {{amount}} περισσότερα από το αναμενόμενο."
|
||||||
|
},
|
||||||
|
"openTables": "Ανοιχτά τραπέζια",
|
||||||
|
"allClosed": "Όλα τα τραπέζια έχουν κλείσει",
|
||||||
|
"stillOpenTables_one": "{{count}} τραπέζι ακόμα ανοιχτό",
|
||||||
|
"stillOpenTables_other": "{{count}} τραπέζια ακόμα ανοιχτά",
|
||||||
|
"withUnpaid_one": "{{count}} με απλήρωτα αντικείμενα",
|
||||||
|
"withUnpaid_other": "{{count}} με απλήρωτα αντικείμενα",
|
||||||
|
"activeShifts": "Ενεργές βάρδιες",
|
||||||
|
"noShifts": "Δεν υπάρχουν ενεργές βάρδιες",
|
||||||
|
"shiftsWillEnd_one": "{{count}} βάρδια ακόμα ενεργή: θα κλείσει αυτόματα",
|
||||||
|
"shiftsWillEnd_other": "{{count}} βάρδιες ακόμα ενεργές: θα κλείσουν αυτόματα",
|
||||||
|
"ready": "Ο έλεγχος πέρασε: η ημέρα είναι έτοιμη να κλείσει.",
|
||||||
|
"unpaidWarning": "Προσοχή: υπάρχουν απλήρωτα αντικείμενα. Αν κλείσετε αναγκαστικά, τα απλήρωτα ποσά δεν θα καταγραφούν στις αναφορές.",
|
||||||
|
"autoClose": "Υπάρχουν ανοιχτά τραπέζια χωρίς απλήρωτα αντικείμενα. Θα κλείσουν αυτόματα.",
|
||||||
|
"forceClose": "Αναγκαστικό κλείσιμο",
|
||||||
|
"closeNow": "Κλείσε ημέρα"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -573,7 +573,44 @@
|
|||||||
"onlineOrders": {
|
"onlineOrders": {
|
||||||
"for": "For {{when}}",
|
"for": "For {{when}}",
|
||||||
"asap": "As soon as possible",
|
"asap": "As soon as possible",
|
||||||
"priceDiff": "Charged {{charged}} online; at the venue's prices now it would be {{here}}. The customer pays what they were charged."
|
"priceDiff": "Charged {{charged}} online; at the venue's prices now it would be {{here}}. The customer pays what they were charged.",
|
||||||
|
"tab": {
|
||||||
|
"incoming": "New",
|
||||||
|
"active": "In progress",
|
||||||
|
"history": "History"
|
||||||
|
},
|
||||||
|
"refresh": "Refresh",
|
||||||
|
"empty": {
|
||||||
|
"incoming": "No new online orders.",
|
||||||
|
"active": "No orders in progress.",
|
||||||
|
"history": "No past orders."
|
||||||
|
},
|
||||||
|
"kind": {
|
||||||
|
"delivery": "Delivery",
|
||||||
|
"takeaway": "Takeaway",
|
||||||
|
"dine_in": "Eat in"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"pending_acceptance": "Waiting",
|
||||||
|
"accepted": "Accepted",
|
||||||
|
"preparing": "Preparing",
|
||||||
|
"ready": "Ready",
|
||||||
|
"out_for_delivery": "Out for delivery",
|
||||||
|
"delivered": "Delivered",
|
||||||
|
"rejected": "Refused"
|
||||||
|
},
|
||||||
|
"next": {
|
||||||
|
"preparing": "Preparing",
|
||||||
|
"ready": "Ready",
|
||||||
|
"out_for_delivery": "Out for delivery",
|
||||||
|
"delivered": "Delivered"
|
||||||
|
},
|
||||||
|
"total": "Total",
|
||||||
|
"accept": "Accept",
|
||||||
|
"reject": "Refuse",
|
||||||
|
"rejectReason": "Reason (optional)",
|
||||||
|
"rejectHint": "The customer sees it.",
|
||||||
|
"rejectNow": "Refuse the order"
|
||||||
},
|
},
|
||||||
"feeProduct": {
|
"feeProduct": {
|
||||||
"title": "The fee on the receipt",
|
"title": "The fee on the receipt",
|
||||||
@@ -1123,5 +1160,368 @@
|
|||||||
"refresh": "Fetch now",
|
"refresh": "Fetch now",
|
||||||
"forget": "Remove the town"
|
"forget": "Remove the town"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"overview": {
|
||||||
|
"back": "Back",
|
||||||
|
"close": "Close",
|
||||||
|
"save": "Save",
|
||||||
|
"loading": "Loading…",
|
||||||
|
"dayOpen": "Day open",
|
||||||
|
"dayClosed": "Day closed",
|
||||||
|
"daySince": "since {{time}} · {{length}}",
|
||||||
|
"openDay": "Open the day",
|
||||||
|
"dayOpened": "The day is open",
|
||||||
|
"dayStats": "Day stats",
|
||||||
|
"closeDay": "Close the day",
|
||||||
|
"dayClosedDone": "The day is closed",
|
||||||
|
"hideAmounts": "Hide amounts",
|
||||||
|
"showAmounts": "Show amounts",
|
||||||
|
"locked": "System locked",
|
||||||
|
"expired": "License expired",
|
||||||
|
"blockedHelp": "The day can't open until this is sorted out.",
|
||||||
|
"revenueByHour": "Revenue per hour",
|
||||||
|
"duration": {
|
||||||
|
"m": "{{m}} min",
|
||||||
|
"h": "{{h}} h",
|
||||||
|
"hm": "{{h}} h {{m}} min"
|
||||||
|
},
|
||||||
|
"kpi": {
|
||||||
|
"revenue": "Revenue today",
|
||||||
|
"orders_one": "{{count}} order",
|
||||||
|
"orders_other": "{{count}} orders",
|
||||||
|
"avg": "avg.",
|
||||||
|
"tables": "Tables in use",
|
||||||
|
"tablesSub": "{{free}} free · {{partly}} partly paid",
|
||||||
|
"shifts": "Shifts running",
|
||||||
|
"collected": "Taken by the shifts",
|
||||||
|
"collectedSub_one": "Total of {{count}} shift",
|
||||||
|
"collectedSub_other": "Total of {{count}} shifts",
|
||||||
|
"prints": "Waiting to print",
|
||||||
|
"printsSub": "Needs attention"
|
||||||
|
},
|
||||||
|
"shifts": {
|
||||||
|
"title": "Shifts running",
|
||||||
|
"start": "Start",
|
||||||
|
"none": "No waiter on shift",
|
||||||
|
"onBreak": "On a break · {{since}}",
|
||||||
|
"since": "since {{time}} · {{length}}",
|
||||||
|
"message": "Send a message",
|
||||||
|
"stats": "Shift stats",
|
||||||
|
"end": "End",
|
||||||
|
"startTitle": "Start a shift",
|
||||||
|
"waiter": "Waiter",
|
||||||
|
"pick": "Choose…",
|
||||||
|
"pickWaiter": "Choose a waiter",
|
||||||
|
"startCash": "Starting cash",
|
||||||
|
"startCashHint": "The change the waiter starts with. Leave it empty for none.",
|
||||||
|
"badAmount": "Type an amount, e.g. 50 or 50,00",
|
||||||
|
"startNow": "Start",
|
||||||
|
"started": "The shift started",
|
||||||
|
"ended": "{{name}}'s shift ended"
|
||||||
|
},
|
||||||
|
"shift": {
|
||||||
|
"running": "Running",
|
||||||
|
"closing": "Ending",
|
||||||
|
"number": "Shift #{{id}}",
|
||||||
|
"start": "Started",
|
||||||
|
"length": "Length",
|
||||||
|
"tab": {
|
||||||
|
"overview": "Overview",
|
||||||
|
"lines": "Details"
|
||||||
|
},
|
||||||
|
"expected": "Expected in the drawer",
|
||||||
|
"startCash": "Starting cash",
|
||||||
|
"startCashHint": "what it started with",
|
||||||
|
"cashSales": "Cash sales",
|
||||||
|
"cashSalesHint": "taken in cash",
|
||||||
|
"turnover": "Turnover",
|
||||||
|
"turnoverHint": "cash + card",
|
||||||
|
"perHour": "Sales per hour",
|
||||||
|
"items": "Items",
|
||||||
|
"tables": "Tables",
|
||||||
|
"orders": "Orders",
|
||||||
|
"pay": "Pay",
|
||||||
|
"perHourRate": "{{rate}} / hour",
|
||||||
|
"notes": "Notes (optional)",
|
||||||
|
"notesHint": "e.g. remarks about the shift, breakages, shortages…",
|
||||||
|
"handover": "How much cash does the waiter hand over?",
|
||||||
|
"counted": "Cash handed over",
|
||||||
|
"countedHint": "Compared with what was expected. Leave it empty to skip the count.",
|
||||||
|
"exact": "Exactly",
|
||||||
|
"live": "Live view: the shift goes on",
|
||||||
|
"checkFirst": "Check the amounts before ending",
|
||||||
|
"toHandover": "Cash handover",
|
||||||
|
"endNow": "End the shift",
|
||||||
|
"noLines": "Nothing in this shift yet",
|
||||||
|
"order": "Order #{{id}}",
|
||||||
|
"openedBy": "Opened by {{name}}",
|
||||||
|
"orderedBy": "Ordered by {{name}}",
|
||||||
|
"paidTo": "Paid to {{name}}",
|
||||||
|
"kind": {
|
||||||
|
"all": "All",
|
||||||
|
"both": "Complete",
|
||||||
|
"paid": "Only took the money",
|
||||||
|
"ordered": "Only ordered",
|
||||||
|
"unpaid": "Open",
|
||||||
|
"cancelled": "Cancelled",
|
||||||
|
"anomaly": "Problem"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cash": {
|
||||||
|
"even": "Balanced",
|
||||||
|
"short": "Short",
|
||||||
|
"over": "Over"
|
||||||
|
},
|
||||||
|
"pay": {
|
||||||
|
"any": "Any method",
|
||||||
|
"cash": "Cash",
|
||||||
|
"card": "Card",
|
||||||
|
"transfer": "Bank transfer",
|
||||||
|
"treat": "On the house",
|
||||||
|
"other": "Other"
|
||||||
|
},
|
||||||
|
"tables": {
|
||||||
|
"title": "Tables now",
|
||||||
|
"all": "All tables"
|
||||||
|
},
|
||||||
|
"tableState": {
|
||||||
|
"open": "Open",
|
||||||
|
"partially_paid": "Partly paid",
|
||||||
|
"paid": "Paid",
|
||||||
|
"free": "Free"
|
||||||
|
},
|
||||||
|
"order": {
|
||||||
|
"title": "Table {{table}}",
|
||||||
|
"sub": "Order #{{id}} · since {{time}} · {{since}}",
|
||||||
|
"staff": "Staff",
|
||||||
|
"empty": "No items.",
|
||||||
|
"free": "FREE",
|
||||||
|
"linePaid": "Paid",
|
||||||
|
"pay": "Pay",
|
||||||
|
"payAll": "Pay everything",
|
||||||
|
"cancelLine": "Cancel this line",
|
||||||
|
"close": "Close",
|
||||||
|
"cancel": "Cancel",
|
||||||
|
"printer": "Printer…",
|
||||||
|
"print": "Print",
|
||||||
|
"full": "Full view",
|
||||||
|
"paidDone": "Paid",
|
||||||
|
"lineCancelled": "Line cancelled",
|
||||||
|
"cancelled": "Order cancelled",
|
||||||
|
"closed": "Order closed",
|
||||||
|
"printing": "Sent to the printer…",
|
||||||
|
"confirm": {
|
||||||
|
"cancelItem": "Cancel this line?",
|
||||||
|
"cancelOrder": "Cancel the order?",
|
||||||
|
"close": "Close the order?",
|
||||||
|
"cancelOrderBody": "The order will be cancelled for good."
|
||||||
|
},
|
||||||
|
"printCancel": "Print a cancellation?",
|
||||||
|
"printCancelBody": "Send a cancellation ticket to the printer?",
|
||||||
|
"printCancelNo": "No, just cancel",
|
||||||
|
"printCancelYes": "Yes, print",
|
||||||
|
"event": {
|
||||||
|
"waiter_discount": "Discount",
|
||||||
|
"free_item_added": "Free",
|
||||||
|
"modifier_applied": "Price change"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"orderStatus": {
|
||||||
|
"open": "Open",
|
||||||
|
"partially_paid": "Partly paid",
|
||||||
|
"paid": "Paid",
|
||||||
|
"closed": "Closed",
|
||||||
|
"cancelled": "Cancelled"
|
||||||
|
},
|
||||||
|
"prints": {
|
||||||
|
"title": "Waiting to print",
|
||||||
|
"count_one": "{{count}} order hasn't printed",
|
||||||
|
"count_other": "{{count}} orders haven't printed",
|
||||||
|
"all": "Print all",
|
||||||
|
"retries_one": "{{count}} retry",
|
||||||
|
"retries_other": "{{count}} retries",
|
||||||
|
"lines_one": "{{count}} line waiting",
|
||||||
|
"lines_other": "{{count}} lines waiting",
|
||||||
|
"open": "Details",
|
||||||
|
"print": "Print",
|
||||||
|
"done": "Printed",
|
||||||
|
"failed": "Didn't print: {{printers}}"
|
||||||
|
},
|
||||||
|
"notes": {
|
||||||
|
"title": "Notes & to-dos",
|
||||||
|
"counts": "{{notes}} notes · {{todos}} open to-dos"
|
||||||
|
},
|
||||||
|
"bookings": {
|
||||||
|
"upcoming": "Upcoming",
|
||||||
|
"history": "History",
|
||||||
|
"new": "New",
|
||||||
|
"noneUpcoming": "No upcoming bookings",
|
||||||
|
"noneHistory": "No history",
|
||||||
|
"status": {
|
||||||
|
"requested": "Online request",
|
||||||
|
"pending": "Waiting",
|
||||||
|
"arrived": "Arrived",
|
||||||
|
"cancelled": "Cancelled",
|
||||||
|
"no_show": "Didn't come",
|
||||||
|
"declined": "Declined"
|
||||||
|
},
|
||||||
|
"edit": "Edit",
|
||||||
|
"confirm": "Confirm",
|
||||||
|
"decline": "Decline",
|
||||||
|
"arrived": "Arrived",
|
||||||
|
"cancel": "Cancel",
|
||||||
|
"declineTitle": "Decline the booking",
|
||||||
|
"declineDefault": "No availability at that time",
|
||||||
|
"reason": "Reason",
|
||||||
|
"reasonHint": "The customer sees it.",
|
||||||
|
"newTitle": "New booking",
|
||||||
|
"editTitle": "Edit booking",
|
||||||
|
"name": "Name",
|
||||||
|
"nameNeeded": "Type the customer's name",
|
||||||
|
"people": "People",
|
||||||
|
"peopleNeeded": "At least 1",
|
||||||
|
"when": "Date & time",
|
||||||
|
"whenHint": "In the venue's time.",
|
||||||
|
"inMinutes_one": "+{{count}} min",
|
||||||
|
"inMinutes_other": "+{{count}} min",
|
||||||
|
"inHours_one": "+{{count}} h",
|
||||||
|
"inHours_other": "+{{count}} h",
|
||||||
|
"inDays_one": "+{{count}} day",
|
||||||
|
"inDays_other": "+{{count}} days",
|
||||||
|
"table": "Table (optional)",
|
||||||
|
"noTable": "No table",
|
||||||
|
"noZone": "No zone",
|
||||||
|
"phone": "Phone",
|
||||||
|
"email": "Email",
|
||||||
|
"note": "Note",
|
||||||
|
"noteHint": "For the staff only.",
|
||||||
|
"create": "Create",
|
||||||
|
"created": "Booking created",
|
||||||
|
"saved": "Saved"
|
||||||
|
},
|
||||||
|
"messages": {
|
||||||
|
"title": "Messages",
|
||||||
|
"new": "New",
|
||||||
|
"none": "No messages yet",
|
||||||
|
"to": "To: {{who}} · {{time}}",
|
||||||
|
"everyone": "Everyone",
|
||||||
|
"read": "{{read}}/{{of}} read",
|
||||||
|
"readBy": "How many have read it",
|
||||||
|
"newTitle": "New message",
|
||||||
|
"toOne": "Message to {{name}}",
|
||||||
|
"recipients": "Recipients",
|
||||||
|
"allOfThem": "(everyone)",
|
||||||
|
"tables": "About tables (optional)",
|
||||||
|
"quick": "Quick messages",
|
||||||
|
"text": "Message",
|
||||||
|
"send": "Send",
|
||||||
|
"sent": "Sent"
|
||||||
|
},
|
||||||
|
"day": {
|
||||||
|
"statsTitle": "Day stats",
|
||||||
|
"closeTitle": "Close the business day",
|
||||||
|
"open": "Day running",
|
||||||
|
"closedState": "Closed",
|
||||||
|
"openedAt": "Opened {{time}}",
|
||||||
|
"tab": {
|
||||||
|
"money": "Overview",
|
||||||
|
"staff": "Staff",
|
||||||
|
"zones": "Zones",
|
||||||
|
"printers": "Printers",
|
||||||
|
"cash": "Cash",
|
||||||
|
"checks": "Checks"
|
||||||
|
},
|
||||||
|
"toCash": "Count the drawer",
|
||||||
|
"toChecks": "On to the checks",
|
||||||
|
"revenue": "Revenue",
|
||||||
|
"orders": "Orders",
|
||||||
|
"items": "Items",
|
||||||
|
"waiters": "Waiters",
|
||||||
|
"opened": "Opened",
|
||||||
|
"closed": "Closed",
|
||||||
|
"stillOpen": "Day running",
|
||||||
|
"sales": "Revenue",
|
||||||
|
"salesTotal": "Total sales",
|
||||||
|
"onTabs": "On tabs (not taken yet)",
|
||||||
|
"onTabsTip": "Sales put on customers' tabs: they count as sales, the money comes when the tab is paid.",
|
||||||
|
"taken": "Net taken",
|
||||||
|
"cogs": "Cost of goods sold",
|
||||||
|
"cogsKnown": "Known cost",
|
||||||
|
"cogsTip": "What the sold items cost the venue, from the costs entered on the products (as they were at the sale).",
|
||||||
|
"uncosted_one": "{{count}} item without a cost ({{revenue}} revenue)",
|
||||||
|
"uncosted_other": "{{count}} items without a cost ({{revenue}} revenue)",
|
||||||
|
"gross": "Gross profit",
|
||||||
|
"partial": "Partial: some items have no cost",
|
||||||
|
"labour": "Wages",
|
||||||
|
"labourCost": "Labour cost (recorded)",
|
||||||
|
"noRate_one": "{{count}} shift without an hourly rate",
|
||||||
|
"noRate_other": "{{count}} shifts without an hourly rate",
|
||||||
|
"waste": "Thrown away",
|
||||||
|
"wasteEntries_one": "{{count}} entry",
|
||||||
|
"wasteEntries_other": "{{count}} entries",
|
||||||
|
"expenses": "Expenses (today)",
|
||||||
|
"expensesTotal": "Total expenses",
|
||||||
|
"expensesPaid": "Paid today",
|
||||||
|
"expensesDue": "Still owed",
|
||||||
|
"net": "Estimated net result",
|
||||||
|
"netHint": "Taken − costs − wages − waste − expenses",
|
||||||
|
"netTip": "An estimate: it only knows the costs and wages entered in the system.",
|
||||||
|
"netPartial": "Partial: some costs are unknown",
|
||||||
|
"payments": "Payments by method",
|
||||||
|
"drawer": "Drawer",
|
||||||
|
"drawerExpected": "Expected in the drawer",
|
||||||
|
"drawerExpectedTip": "The opening cash plus what the staff took in cash.",
|
||||||
|
"drawerCounted": "Counted",
|
||||||
|
"drawerDiff": "Difference",
|
||||||
|
"noStaff": "No staff found",
|
||||||
|
"role": {
|
||||||
|
"waiter": "Waiter",
|
||||||
|
"manager": "Manager"
|
||||||
|
},
|
||||||
|
"ordersOpened": "Orders",
|
||||||
|
"tablesServed": "Tables served",
|
||||||
|
"itemsPaid": "Items taken",
|
||||||
|
"collected": "Taken",
|
||||||
|
"shiftStart": "Shift start",
|
||||||
|
"shiftEnd": "Shift end",
|
||||||
|
"shiftRunning": "Shift running",
|
||||||
|
"rate": "Wage / hour",
|
||||||
|
"payNow": "Wage (so far)",
|
||||||
|
"notTracked": "Not tracked",
|
||||||
|
"startCash": "Starting cash",
|
||||||
|
"drawerNow": "Drawer now",
|
||||||
|
"noZones": "No zones found",
|
||||||
|
"perOrder": "Per order",
|
||||||
|
"noPrints": "No printing data",
|
||||||
|
"printedValue": "value printed",
|
||||||
|
"jobs": "Jobs",
|
||||||
|
"jobsOk": "Printed",
|
||||||
|
"jobsFailed": "Failed",
|
||||||
|
"takings": "What the shifts took",
|
||||||
|
"staffTook": "Taken by the staff",
|
||||||
|
"openingCash": "Opening cash",
|
||||||
|
"countDrawer": "Count the drawer: how much cash is in it?",
|
||||||
|
"countHint": "Optional. Without a count nothing is checked or recorded.",
|
||||||
|
"cash": {
|
||||||
|
"even": "The drawer matches what was taken.",
|
||||||
|
"short": "The drawer has {{amount}} less than expected. The gap isn't put on any one waiter.",
|
||||||
|
"over": "The drawer has {{amount}} more than expected."
|
||||||
|
},
|
||||||
|
"openTables": "Open tables",
|
||||||
|
"allClosed": "Every table is closed",
|
||||||
|
"stillOpenTables_one": "{{count}} table still open",
|
||||||
|
"stillOpenTables_other": "{{count}} tables still open",
|
||||||
|
"withUnpaid_one": "{{count}} with unpaid items",
|
||||||
|
"withUnpaid_other": "{{count}} with unpaid items",
|
||||||
|
"activeShifts": "Shifts running",
|
||||||
|
"noShifts": "No shift running",
|
||||||
|
"shiftsWillEnd_one": "{{count}} shift still running: it will end by itself",
|
||||||
|
"shiftsWillEnd_other": "{{count}} shifts still running: they will end by themselves",
|
||||||
|
"ready": "All checks passed: the day is ready to close.",
|
||||||
|
"unpaidWarning": "Some items are unpaid. If you force the close, the unpaid amounts won't be in the reports.",
|
||||||
|
"autoClose": "Some tables are open with nothing left to pay. They will be closed.",
|
||||||
|
"forceClose": "Force the close",
|
||||||
|
"closeNow": "Close the day"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ export function createFormatters({ language = 'en', timeZone = DEFAULT_TIMEZONE,
|
|||||||
if (!cache.has(k)) cache.set(k, make())
|
if (!cache.has(k)) cache.set(k, make())
|
||||||
return cache.get(k)
|
return cache.get(k)
|
||||||
}
|
}
|
||||||
const dtf = (style, zone) => intl('dt', `${style}|${zone}`, () => {
|
// style: a DATE_STYLES name or an Intl options object (cached by its JSON)
|
||||||
|
const dtf = (style, zone) => intl('dt', `${typeof style === 'string' ? style : JSON.stringify(style)}|${zone}`, () => {
|
||||||
const options = typeof style === 'string' ? DATE_STYLES[style] : style
|
const options = typeof style === 'string' ? DATE_STYLES[style] : style
|
||||||
if (!options) throw new Error(`unknown date style "${style}"`)
|
if (!options) throw new Error(`unknown date style "${style}"`)
|
||||||
return new Intl.DateTimeFormat(locale, { ...options, timeZone: zone })
|
return new Intl.DateTimeFormat(locale, { ...options, timeZone: zone })
|
||||||
@@ -61,7 +62,7 @@ export function createFormatters({ language = 'en', timeZone = DEFAULT_TIMEZONE,
|
|||||||
function formatDateTime(value, style = 'datetime') {
|
function formatDateTime(value, style = 'datetime') {
|
||||||
if (typeof value === 'string' && DATE_ONLY.test(value)) return formatDate(value, style)
|
if (typeof value === 'string' && DATE_ONLY.test(value)) return formatDate(value, style)
|
||||||
const d = toDate(value)
|
const d = toDate(value)
|
||||||
return d ? dtf(typeof style === 'string' ? style : JSON.stringify(style), timeZone).format(d) : ''
|
return d ? dtf(style, timeZone).format(d) : ''
|
||||||
}
|
}
|
||||||
const formatTime = (value, style = 'time') => formatDateTime(value, style)
|
const formatTime = (value, style = 'time') => formatDateTime(value, style)
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ test('date-time styles use a 24-hour clock in both languages', () => {
|
|||||||
assert.equal(en.formatTime('2026-07-01T16:05:09Z', 'timeSeconds'), '19:05:09')
|
assert.equal(en.formatTime('2026-07-01T16:05:09Z', 'timeSeconds'), '19:05:09')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('a style can also be Intl options (each cached on its own)', () => {
|
||||||
|
assert.equal(el.formatDateTime('2026-07-01T16:05:00Z', { hour: '2-digit', hourCycle: 'h23' }), '19')
|
||||||
|
assert.equal(en.formatDate('2026-07-01T16:05:00Z', { month: 'long' }), 'July')
|
||||||
|
assert.equal(en.formatDate('2026-07-01T16:05:00Z', { year: 'numeric' }), '2026')
|
||||||
|
})
|
||||||
|
|
||||||
test('money and numbers per language', () => {
|
test('money and numbers per language', () => {
|
||||||
assert.equal(nbsp(el.formatMoney(1234.5)), '1.234,50 €')
|
assert.equal(nbsp(el.formatMoney(1234.5)), '1.234,50 €')
|
||||||
assert.equal(en.formatMoney(1234.5), '€1,234.50')
|
assert.equal(en.formatMoney(1234.5), '€1,234.50')
|
||||||
|
|||||||
@@ -774,6 +774,98 @@ try {
|
|||||||
(await chefRow.textContent().catch(() => '')).includes('Kitchen pass · Kitchen display'))
|
(await chefRow.textContent().catch(() => '')).includes('Kitchen pass · Kitchen display'))
|
||||||
await o.screenshot({ path: path.join(OUT, 'manager-owner-flow.png'), fullPage: true })
|
await o.screenshot({ path: path.join(OUT, 'manager-owner-flow.png'), fullPage: true })
|
||||||
|
|
||||||
|
// ── 6.2: the overview (open the day, a shift, a table, close the day), online orders ──
|
||||||
|
const ov = 'overview:'
|
||||||
|
if (await api('GET', '/api/business-day/current', { token: boss })) { // earlier steps' orders may have opened one
|
||||||
|
await api('POST', '/api/business-day/close', { token: boss, body: { force: true } })
|
||||||
|
}
|
||||||
|
await page.goto(`${APP}/dashboard`)
|
||||||
|
await page.getByTestId('overview').waitFor({ timeout: 15_000 })
|
||||||
|
const dayState = () => page.getByTestId('day-state').getAttribute('data-open')
|
||||||
|
r.check(`${ov} the landing page shows the day closed, the figures, the tables and the cards`, await dayState() === 'false'
|
||||||
|
&& await page.getByTestId('kpis').count() === 1 && await page.getByTestId('table-chip').count() > 0 && await page.getByTestId('shifts-card').count() === 1)
|
||||||
|
await page.getByTestId('day-open').click()
|
||||||
|
await page.waitForFunction(() => document.querySelector('[data-testid="day-state"]')?.dataset.open === 'true', null, { timeout: 8000 }).catch(() => {})
|
||||||
|
r.check(`${ov} "Open the day" opens it`, await dayState() === 'true' && !!(await api('GET', '/api/business-day/current', { token: boss })))
|
||||||
|
const ovWaiter = (await api('GET', '/api/waiters/', { token: boss })).find(w => w.username === 'demo_maria')
|
||||||
|
await page.getByTestId('shift-start').click()
|
||||||
|
await page.getByTestId('shift-start-waiter').selectOption(String(ovWaiter.id))
|
||||||
|
await page.getByRole('dialog').getByLabel('Starting cash').fill('20,5')
|
||||||
|
await page.getByTestId('shift-start-confirm').click()
|
||||||
|
const ovRow = page.getByTestId('shift-row').filter({ hasText: ovWaiter.full_name })
|
||||||
|
r.check(`${ov} a shift started for a waiter with €20.50 (typed with a comma)`, await ovRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||||
|
&& (await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.some(s => s.waiter_id === ovWaiter.id && s.starting_cash === 20.5))
|
||||||
|
const freeTable = (await api('GET', '/api/tables/', { token: boss })).find(t => !t.open_order_id && !t.current_order_id)
|
||||||
|
const ovOrder = await api('POST', '/api/orders/', { token: await loginApi('demo_maria', { pin: '3302', client: 'waiter' }), body: { table_id: freeTable.id } })
|
||||||
|
const chip = page.locator(`[data-testid="table-chip"][data-state="open"]`).filter({ hasText: freeTable.label || `T${freeTable.number}` }).first()
|
||||||
|
r.check(`${ov} a table a waiter opens turns "open" by itself (live)`, await chip.waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||||
|
await chip.click()
|
||||||
|
r.check(`${ov} the table opens its order at a glance`, await page.getByTestId('order-dialog').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||||
|
&& (await page.getByRole('dialog').textContent()).includes(`#${ovOrder.id}`))
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-overview-order.png') })
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await ovRow.getByTestId('shift-stats').click()
|
||||||
|
await page.getByTestId('shift-dialog').waitFor({ timeout: 8000 }).catch(() => {})
|
||||||
|
r.check(`${ov} shift stats: €20.50 expected in the drawer`, (await page.getByTestId('shift-expected').textContent().catch(() => '')).includes('20.50'))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await ovRow.getByTestId('shift-end').click()
|
||||||
|
await page.getByTestId('shift-next').click()
|
||||||
|
await page.getByTestId('shift-counted').fill('18')
|
||||||
|
r.check(`${ov} ending it: €18 handed over shows "short"`, await page.getByTestId('shift-check').getAttribute('data-state').catch(() => '') === 'short')
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-overview-shift.png') })
|
||||||
|
await page.getByTestId('shift-end-confirm').click()
|
||||||
|
await ovRow.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {})
|
||||||
|
r.check(`${ov} …and the shift ends with the count kept`, await ovRow.count() === 0
|
||||||
|
&& !(await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.some(s => s.waiter_id === ovWaiter.id))
|
||||||
|
if (await page.getByTestId('booking-new').count()) {
|
||||||
|
await page.getByTestId('booking-new').click()
|
||||||
|
await page.getByTestId('booking-name').fill('Eleni E2E')
|
||||||
|
await page.getByRole('button', { name: '+1 h' }).click()
|
||||||
|
await page.getByTestId('booking-save').click()
|
||||||
|
const bookingRow = page.getByTestId('booking-row').filter({ hasText: 'Eleni E2E' })
|
||||||
|
const want = await page.evaluate(() => Date.now() + 3600_000)
|
||||||
|
const listed = await bookingRow.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||||
|
const saved = (await api('GET', '/api/reservations/?tab=upcoming', { token: boss })).find(b => b.guest_name === 'Eleni E2E')
|
||||||
|
r.check(`${ov} a booking "in 1 hour" is saved at that moment (venue time) and listed`, listed
|
||||||
|
&& !!saved && Math.abs(new Date(/[zZ]|[+-]\d\d:?\d\d$/.test(saved.reserved_for) ? saved.reserved_for : `${saved.reserved_for}Z`).getTime() - want) < 3 * 60_000, saved?.reserved_for)
|
||||||
|
}
|
||||||
|
await page.getByTestId('day-stats').click()
|
||||||
|
await page.getByTestId('day-money').waitFor({ timeout: 8000 }).catch(() => {})
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-overview-day.png') })
|
||||||
|
r.check(`${ov} day stats: the money tab, then staff`, await page.getByTestId('day-net').count() === 1
|
||||||
|
&& await page.getByTestId('day-tab-staff').click().then(() => page.getByTestId('day-staff').waitFor({ timeout: 5000 })).then(() => true).catch(() => false))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
// both languages
|
||||||
|
await page.getByTestId('user-menu').click()
|
||||||
|
await page.getByRole('menuitemradio', { name: 'Ελληνικά' }).click()
|
||||||
|
await page.waitForFunction(() => document.querySelector('[data-testid="tables-card"]')?.innerText.includes('Τραπέζια τώρα'), null, { timeout: 5000 }).catch(() => {})
|
||||||
|
r.check(`${ov} in Greek`, (await page.getByTestId('day-state').textContent()).includes('Ημέρα ανοιχτή') && (await page.getByTestId('tables-card').textContent()).includes('Τραπέζια τώρα'))
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-overview-el.png'), fullPage: true })
|
||||||
|
await page.getByTestId('user-menu').click()
|
||||||
|
await page.getByRole('menuitemradio', { name: 'English' }).click()
|
||||||
|
await page.waitForFunction(() => document.querySelector('[data-testid="tables-card"]')?.innerText.includes('Tables now'), null, { timeout: 5000 }).catch(() => {})
|
||||||
|
await page.screenshot({ path: path.join(OUT, 'manager-overview.png'), fullPage: true })
|
||||||
|
// close the day: the table is still open → the checks say so and the close is forced
|
||||||
|
await page.getByTestId('day-close').click()
|
||||||
|
await page.getByTestId('day-to-cash').click()
|
||||||
|
await page.getByTestId('day-counted').fill('0')
|
||||||
|
await page.getByTestId('day-to-checks').click()
|
||||||
|
r.check(`${ov} closing: the checks show the open table`, await page.getByTestId('check-tables').getAttribute('data-ok').catch(() => '') === 'false')
|
||||||
|
await page.getByTestId('day-close-confirm').click()
|
||||||
|
await page.waitForFunction(() => document.querySelector('[data-testid="day-state"]')?.dataset.open === 'false', null, { timeout: 8000 }).catch(() => {})
|
||||||
|
r.check(`${ov} …"Close the day" closes it and the open order with it`, await dayState() === 'false'
|
||||||
|
&& !(await api('GET', '/api/business-day/current', { token: boss }))
|
||||||
|
&& (await api('GET', `/api/orders/${ovOrder.id}`, { token: boss })).status === 'closed')
|
||||||
|
|
||||||
|
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
|
||||||
|
await page.goto(`${APP}/online-orders`)
|
||||||
|
await page.getByTestId('online-orders').waitFor({ timeout: 10_000 }).catch(() => {})
|
||||||
|
const noNew = await page.getByText('No new online orders.').waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||||
|
await page.getByTestId('online-tab-history').click()
|
||||||
|
const past = await page.getByTestId('online-order').first().waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||||
|
r.check(`${ov} online orders: nothing new; the history lists the earlier online orders`, noNew && past
|
||||||
|
&& await page.locator('[data-testid="online-order"]:not([data-status="delivered"]):not([data-status="rejected"])').count() === 0)
|
||||||
|
|
||||||
r.check('live: the manager connection carries no token in its address (4.0)', managerWs.some(u => u.includes('/api/ws/')) && managerWs.filter(u => u.includes('/api/')).every(u => !/token=/.test(u)), managerWs.filter(u => u.includes('/api/')).join(' ')) // (Vite's own dev socket has its token)
|
r.check('live: the manager connection carries no token in its address (4.0)', managerWs.some(u => u.includes('/api/ws/')) && managerWs.filter(u => u.includes('/api/')).every(u => !/token=/.test(u)), managerWs.filter(u => u.includes('/api/')).join(' ')) // (Vite's own dev socket has its token)
|
||||||
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
|
r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | '))
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user