feat(connect): the site side of online orders: fee line, customer's time, price check
Plan phase 3S, step S.5. - Pull: an online order keeps the customer's time (orders.requested_for, None = as soon as possible) and delivery area; quick options are stored in the site's entry shape; items get their cost snapshot. - The delivery fee is its own order line: a system product (products.system_key "delivery_fee", lifecycle "system", sold nowhere; services/system_products.py), created on first use in the venue's language with the VAT group most products use. Added printed and served, so kitchen tickets and the KDS never see it; paid at the counter with the items, counted in the shift, on the fiscal receipt with its VAT group. Never listed in the catalogue (products list, export, edit endpoints → 404) and never added by hand. - Price check (services/online_check.py): each line priced as the snapshot prices it, at the order's time, and the fee through the same engine with the site's rules and the cloud's area id; differences kept on orders.online_price_diff and shown. The customer pays what the cloud charged. - Counter: time chip (or as soon as possible), area, fee line, price warning; takeaway is its own kind (was shown as "at the venue") and finishes as "collected". KDS cards show the online reference and the time; kitchen tickets print the reference, the type and the time. - Manager: Online ordering → "The fee on the receipt" (name, VAT group; PUT /api/connect/fees/fee-product, fees.vat_group_unknown); the online orders page shows the time, area and price warning. - Migration 0019. Tests: tests/test_online_site_side.py (6), terminal unit test, e2e (terminal: fee, time, warning, paid in full; manager: fee line settings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// itself after 5 s without a touch); a long press on an unselected card shows quick actions.
|
||||
import { Fragment, useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { Bike, Info, ShoppingBag, User, Utensils } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { courseGroups, minutesSince } from '../logic/board'
|
||||
import { BLOCK_GAP, BODY_PAD_B, BODY_PAD_H, BODY_PAD_T, CARD_FOOT_H_BASE, CARD_HEAD_H_BASE, CARD_SUB_H_BASE } from '../logic/layout'
|
||||
import { KDS, alpha } from '../theme'
|
||||
@@ -16,8 +16,9 @@ const HOLD_MS = 500
|
||||
const IDLE_DESELECT_MS = 5000
|
||||
const CHANNEL_ICONS = { here: Utensils, takeaway: ShoppingBag, delivery: Bike }
|
||||
|
||||
function ChannelBadge({ orderType, tableName, fs }) {
|
||||
function ChannelBadge({ orderType, tableName, requestedFor, fs }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { formatTime } = useFormat()
|
||||
const type = CHANNEL_ICONS[orderType] ? orderType : 'here'
|
||||
const Icon = CHANNEL_ICONS[type]
|
||||
const iconSz = Math.round(17 * fs)
|
||||
@@ -25,6 +26,8 @@ function ChannelBadge({ orderType, tableName, fs }) {
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: Math.round(15 * fs), fontWeight: 700, whiteSpace: 'nowrap', color: alpha('on-status', 0.6), flexShrink: 0 }}>
|
||||
<Icon style={{ width: iconSz, height: iconSz, opacity: 0.65 }} />
|
||||
{type === 'here' && tableName ? tableName : t(`kds.channel.${type}`)}
|
||||
{/* an online order for a later time (phase 3S, S.5) */}
|
||||
{requestedFor && <span data-testid="card-for">{t('kds.card.for', { time: formatTime(requestedFor) })}</span>}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -159,14 +162,14 @@ export default function OrderCard({ order, age, ageText, layout, focused, dimmed
|
||||
{t('kds.card.items', { count: itemCount })}
|
||||
</span>
|
||||
</div>
|
||||
<div onClick={deselect}><ChannelBadge orderType={order.order_type} tableName={order.table_name} fs={fs} /></div>
|
||||
<div onClick={deselect}><ChannelBadge orderType={order.order_type} tableName={order.table_name} requestedFor={order.requested_for} fs={fs} /></div>
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'space-between', background: subBg, color: alpha('on-status', 0.88),
|
||||
padding: '0 11px', height: Math.round(CARD_SUB_H_BASE * fs), flexShrink: 0, fontSize: 12.5 * fs, fontWeight: 600,
|
||||
}}>
|
||||
<span style={{ fontFamily: 'ui-monospace, monospace', letterSpacing: '.02em', opacity: 0.85, lineHeight: 1 }}>#{order.id}</span>
|
||||
<span style={{ fontFamily: 'ui-monospace, monospace', letterSpacing: '.02em', opacity: 0.85, lineHeight: 1 }}>{order.online_ref || `#${order.id}`}</span>
|
||||
<span onClick={deselect} style={{ fontSize: 11 * fs, fontWeight: 700, letterSpacing: '.08em', textTransform: 'uppercase', lineHeight: 1 }}>
|
||||
{t(`kds.card.status.${order.kds_status === 'done' || order.kds_status === 'preparing' ? order.kds_status : 'pending'}`)}
|
||||
</span>
|
||||
|
||||
@@ -4,18 +4,22 @@
|
||||
// ready or out for delivery, then finish: take what's unpaid (the counter's ordinary payment,
|
||||
// cash/card/split with the drawer) and mark it delivered. Someone else's change meanwhile is
|
||||
// refused by the backend and the order shows where it is now.
|
||||
// Phase 3S (S.5): the customer's time (or "as soon as possible"), the delivery area, the
|
||||
// delivery fee as its own line (paid with the items), and a warning when the venue's own
|
||||
// prices differ from what the customer was charged online (the customer pays what they saw).
|
||||
import { useState } from 'react'
|
||||
import { Ban, Banknote, Bike, Check, ChefHat, MapPin, MessageSquare, PackageCheck, Phone, Utensils } from 'lucide-react'
|
||||
import { AlertTriangle, Ban, Banknote, Bike, Check, ChefHat, Clock, MapPin, MessageSquare, PackageCheck, Phone, ShoppingBag, Utensils } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, EmptyState, Input } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { nextStep } from './logic/online'
|
||||
import { diffRows, finishWord as finishOf, kindOf, nextStep } from './logic/online'
|
||||
import { itemPayments, orderLines, orderSums, qtyLabel } from './logic/tables'
|
||||
import PaymentDialog from './PaymentDialog'
|
||||
|
||||
const REASONS = ['busy', 'unavailable', 'closing', 'area']
|
||||
const STEP_ICON = { preparing: ChefHat, ready: PackageCheck, out_for_delivery: Bike }
|
||||
const KIND_ICON = { delivery: Bike, takeaway: ShoppingBag, dine_in: Utensils }
|
||||
|
||||
export default function OnlinePanel({ order, onChanged }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
@@ -36,8 +40,9 @@ export default function OnlinePanel({ order, onChanged }) {
|
||||
const lines = orderLines(order)
|
||||
const sums = orderSums(lines)
|
||||
const step = nextStep(order)
|
||||
const delivery = order.type === 'delivery'
|
||||
const finishWord = delivery ? 'delivered' : 'served'
|
||||
const kind = kindOf(order)
|
||||
const KindIcon = KIND_ICON[kind]
|
||||
const finishWord = finishOf(order)
|
||||
|
||||
const run = async (fn) => {
|
||||
setBusy(true)
|
||||
@@ -60,29 +65,32 @@ export default function OnlinePanel({ order, onChanged }) {
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="flex-1 text-title font-semibold">{order.ref}</span>
|
||||
<span className="text-label font-medium text-ink-2 flex items-center gap-1">
|
||||
{delivery ? <Bike size={16} aria-hidden="true" /> : <Utensils size={16} aria-hidden="true" />}
|
||||
{t(`pos.online.type.${delivery ? 'delivery' : 'dine_in'}`)}
|
||||
<KindIcon size={16} aria-hidden="true" />
|
||||
{t(`pos.online.type.${kind}`)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-caption text-ink-2">{t(`pos.online.status.${order.status}`)} · {formatTime(order.opened_at)}</div>
|
||||
{kind !== 'dine_in' && <WhenChip when={order.requested_for} />}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
<section className="p-3 border-b border-line grid gap-1.5 text-body" data-testid="online-customer">
|
||||
<div className="text-body-lg font-semibold">{order.customer.name}</div>
|
||||
{order.customer.phone && <Detail icon={Phone}>{order.customer.phone}</Detail>}
|
||||
{order.customer.address && <Detail icon={MapPin}>{order.customer.address}</Detail>}
|
||||
{order.customer.address && <Detail icon={MapPin}>{order.customer.address}{order.area ? ` · ${order.area}` : ''}</Detail>}
|
||||
{order.customer.notes && (
|
||||
<div className="p-2 rounded-control bg-warning-soft text-warning-ink flex gap-2">
|
||||
<MessageSquare size={16} className="mt-0.5 shrink-0" aria-hidden="true" /><span>{order.customer.notes}</span>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
<PriceCheck diff={order.price_diff} />
|
||||
<section data-testid="online-lines">
|
||||
{lines.map(l => (
|
||||
<div key={l.id} className={`px-3 py-2 border-b border-line flex items-start gap-2 ${l.paid ? 'text-ink-3' : 'text-ink'}`} data-testid="online-line">
|
||||
<div key={l.id} className={`px-3 py-2 border-b border-line flex items-start gap-2 ${l.paid ? 'text-ink-3' : 'text-ink'}`}
|
||||
data-testid={l.system ? 'online-fee' : 'online-line'}>
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className="text-body font-medium">{qtyLabel(l.quantity, l.unitType)} {l.name}</span>
|
||||
<span className={`text-body ${l.system ? 'text-ink-2' : 'font-medium'}`}>{l.system ? l.name : `${qtyLabel(l.quantity, l.unitType)} ${l.name}`}</span>
|
||||
{(l.options.length > 0 || l.notes) && (
|
||||
<span className="block text-caption text-ink-2">{[...l.options, l.notes && `“${l.notes}”`].filter(Boolean).join(' · ')}</span>
|
||||
)}
|
||||
@@ -138,6 +146,42 @@ export default function OnlinePanel({ order, onChanged }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** When the customer wants it: a time (with the day when it isn't today) or as soon as possible. */
|
||||
function WhenChip({ when }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { formatDate, formatDateTime, formatTime } = useFormat()
|
||||
const label = !when ? t('pos.online.asap')
|
||||
: t('pos.online.for', { when: formatDate(when) === formatDate(new Date()) ? formatTime(when) : formatDateTime(when, 'datetimeShort') })
|
||||
return (
|
||||
<div className={`justify-self-start mt-1 px-2 h-7 rounded-control flex items-center gap-1.5 text-label font-semibold
|
||||
${when ? 'bg-info-soft text-info-ink' : 'bg-surface-2 text-ink-2'}`} data-testid="online-when">
|
||||
<Clock size={14} aria-hidden="true" />{label}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** The venue's own prices differ from what the customer was charged (S.5): what differs, line by line. */
|
||||
function PriceCheck({ diff }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { formatMoney } = useFormat()
|
||||
const rows = diffRows(diff)
|
||||
if (!rows.length) return null
|
||||
const money = v => (v == null ? '—' : formatMoney(v))
|
||||
return (
|
||||
<section className="m-3 p-2.5 rounded-control bg-warning-soft text-warning-ink grid gap-1 text-label" role="note" data-testid="online-price-diff">
|
||||
<p className="font-semibold flex items-center gap-1.5"><AlertTriangle size={15} aria-hidden="true" />{t('pos.online.diff.title')}</p>
|
||||
<p>{t('pos.online.diff.body', { charged: formatMoney(diff.cloud_total), here: formatMoney(diff.site_total) })}</p>
|
||||
<ul className="grid gap-0.5">
|
||||
{rows.map(r => (
|
||||
<li key={r.key}>
|
||||
{r.name ?? t('pos.online.diff.fee')}: {t(`pos.online.diff.reason.${r.reason}`, { online: money(r.cloud), here: money(r.site) })}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function Detail({ icon: Icon, children }) {
|
||||
return <div className="flex items-start gap-2 text-ink-2"><Icon size={16} className="mt-0.5 shrink-0" aria-hidden="true" /><span className="text-ink">{children}</span></div>
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// finished; picked on the left), each order as a card with its reference, delivery or at the
|
||||
// venue, the customer, how long it has waited and what it costs. New orders stand out until
|
||||
// someone answers them. A tap shows the order on the right (OnlinePanel).
|
||||
import { Bike, Clock, Utensils } from 'lucide-react'
|
||||
import { AlertTriangle, Bike, Clock, ShoppingBag, Utensils } from 'lucide-react'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { EmptyState, Spinner } from '@xenia/ui'
|
||||
import { minutesSince } from './logic/online'
|
||||
import { kindOf, minutesSince } from './logic/online'
|
||||
|
||||
const LOOK = {
|
||||
pending_acceptance: 'bg-warning-soft border-warning text-warning-ink',
|
||||
@@ -38,18 +38,26 @@ export default function OnlineView({ data, list, picked, onPick, now }) {
|
||||
|
||||
function OrderCard({ order, picked, onPick, now }) {
|
||||
const { t } = useTranslation('terminal')
|
||||
const { formatMoney, formatTime } = useFormat()
|
||||
const Icon = order.type === 'delivery' ? Bike : Utensils
|
||||
const { formatDate, formatDateTime, formatMoney, formatTime } = useFormat()
|
||||
const kind = kindOf(order)
|
||||
const Icon = { delivery: Bike, takeaway: ShoppingBag, dine_in: Utensils }[kind]
|
||||
const waiting = order.status === 'pending_acceptance'
|
||||
const when = order.requested_for
|
||||
? (formatDate(order.requested_for) === formatDate(new Date(now)) ? formatTime(order.requested_for) : formatDateTime(order.requested_for, 'datetimeShort'))
|
||||
: null
|
||||
return (
|
||||
<button type="button" onClick={onPick} aria-pressed={picked} data-testid="online-order" data-order={order.id} data-status={order.status}
|
||||
className={`min-h-32 p-3 rounded-card border-2 shadow-raised text-left flex flex-col gap-1 active:scale-[0.98] transition-transform duration-fast
|
||||
${LOOK[order.status] ?? LOOK.delivered} ${picked ? 'ring-2 ring-accent ring-offset-2 ring-offset-canvas' : ''}`}>
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="flex-1 min-w-0 text-title font-semibold truncate">{order.ref}</span>
|
||||
<Icon size={18} aria-label={t(`pos.online.type.${order.type === 'delivery' ? 'delivery' : 'dine_in'}`)} />
|
||||
{order.price_diff && <AlertTriangle size={16} aria-label={t('pos.online.diff.title')} data-testid="card-diff" />}
|
||||
<Icon size={18} aria-label={t(`pos.online.type.${kind}`)} />
|
||||
</span>
|
||||
<span className="text-body font-medium truncate">{order.customer.name}</span>
|
||||
{kind !== 'dine_in' && (
|
||||
<span className="text-label font-semibold" data-testid="card-when">{when ? t('pos.online.for', { when }) : t('pos.online.asap')}</span>
|
||||
)}
|
||||
<span className="text-label font-medium">{t(`pos.online.status.${order.status}`)}</span>
|
||||
<span className="mt-auto flex items-baseline justify-between gap-2">
|
||||
<span className="text-heading font-semibold">{formatMoney(order.total)}</span>
|
||||
|
||||
@@ -11,7 +11,7 @@ export function nextStep(order) {
|
||||
switch (order.status) {
|
||||
case 'pending_acceptance': return { kind: 'answer' }
|
||||
case 'accepted': return { kind: 'status', to: 'preparing' }
|
||||
case 'preparing': return { kind: 'status', to: order.type === 'delivery' ? 'out_for_delivery' : 'ready' }
|
||||
case 'preparing': return { kind: 'status', to: kindOf(order) === 'delivery' ? 'out_for_delivery' : 'ready' }
|
||||
case 'ready':
|
||||
case 'out_for_delivery': return { kind: 'finish', pay: order.unpaid > 0.004 }
|
||||
default: return null
|
||||
@@ -32,3 +32,25 @@ export function findOnline(board, id) {
|
||||
export function minutesSince(iso, now = Date.now()) {
|
||||
return Math.max(0, Math.floor((now - Date.parse(iso)) / 60_000))
|
||||
}
|
||||
|
||||
/** What kind of online order: 'delivery' | 'takeaway' | 'dine_in' (a QR-menu table order). */
|
||||
export function kindOf(order) {
|
||||
return order?.type === 'delivery' || order?.type === 'takeaway' ? order.type : 'dine_in'
|
||||
}
|
||||
|
||||
/** The word the finish button uses: delivered (delivery), collected (takeaway), served. */
|
||||
export function finishWord(order) {
|
||||
return { delivery: 'delivered', takeaway: 'collected', dine_in: 'served' }[kindOf(order)]
|
||||
}
|
||||
|
||||
/** The site's price check of a pulled order (phase 3S, S.5; GET /board `price_diff`) as rows:
|
||||
* [{ key, name, cloud, site, reason }]; reason: price | not_sold | option (lines),
|
||||
* fee_price | fee_area | fee_minimum (the delivery fee). [] when the prices matched. */
|
||||
export function diffRows(diff) {
|
||||
if (!diff) return []
|
||||
const rows = (diff.lines ?? []).map((l, i) => ({
|
||||
key: `l${i}`, name: l.name, quantity: l.quantity, cloud: l.cloud, site: l.site, reason: l.reason,
|
||||
}))
|
||||
if (diff.fee) rows.push({ key: 'fee', name: null, quantity: 1, cloud: diff.fee.cloud, site: diff.fee.site, reason: `fee_${diff.fee.reason}` })
|
||||
return rows
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ export function orderLines(order) {
|
||||
options: optionNames(i.selected_options),
|
||||
notes: i.notes,
|
||||
kds: i.kds_status ?? 'pending',
|
||||
system: i.system_key ?? null, // a line the system added: 'delivery_fee' (phase 3S)
|
||||
}))
|
||||
return [...lines.filter(l => !l.paid), ...lines.filter(l => l.paid)]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user