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:
2026-11-15 15:38:25 +02:00
co-authored by Claude Opus 5.5
parent 8ea44d71aa
commit 0ca700279a
38 changed files with 899 additions and 69 deletions
+53 -9
View File
@@ -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>
}