Owner 2026-11-23 (plan 6F.6). Venue setting payments.split_amount (off | two_equal | two_custom |
multiple_equal, each level with the ones before; default off) and payments.split_max_parts (10);
key ordering.payments.split_amount (everyone who takes payments; Alembic 0050 grants it).
POST /api/orders/{id}/split-bills settles the chosen unpaid lines (status 'split': sold, no shift,
no payment method) and adds part lines (system product split_part, "Split bill 1/3", printed and
served; equal parts with the remainder on the last, or two parts with part 1 typed). Parts are paid
like any line (cash, card, tab). POST .../split-bills/{bill}/undo while no part is paid or tabbed.
Counting (services/sales.py): settled lines are the sales, parts never (a refunded part comes off
the settled lines by share); drawers and payment methods count the parts. Older reports use
split_bills.sold_filter / counts_as_sale. Locks: parts can't be cancelled, moved, combined or
re-priced; settled lines are no longer active; closing or cancelling an order with unpaid parts is
refused. Fiscal: one receipt with the settled lines when the last part is paid, with each method's
amount (txt driver: CD per card amount, then CR for cash).
Waiter: Pay -> "Split the amount" (pre-filled from the customers), the split bill above the lines
with Undo. Counter: "By amount" in the payment (quick sale split and paid at once, Q-4; a table's
lines split then paid). Manager: the pay dialog splits, the order shows its split bills, Settings ->
Operation card. Shared rules in @xenia/ordering/split.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
757 lines
34 KiB
React
757 lines
34 KiB
React
import { useRef, useState } from 'react'
|
||
import useTableViewStore from '../store/tableViewStore'
|
||
import { money } from '../i18n'
|
||
import { useTranslation } from '@xenia/i18n'
|
||
import { fade } from '../logic/colour'
|
||
import OneMore from './OneMore'
|
||
import { canOneMore } from '../logic/lines'
|
||
import { countsInTotal, isPart, isSettled } from '../logic/split'
|
||
|
||
const fmtPrice = money
|
||
|
||
const UNIT_LABELS = { kg: 'kg', liter: 'L', gram: 'g', ml: 'mL' }
|
||
function fmtQty(qty, unitType) {
|
||
const label = UNIT_LABELS[unitType]
|
||
if (!label) return `×${qty}`
|
||
if (unitType === 'kg' || unitType === 'liter') return `${Number(qty).toFixed(1)}${label}`
|
||
return `${qty}${label}`
|
||
}
|
||
|
||
function fmtDateTime(iso) {
|
||
if (!iso) return null
|
||
try {
|
||
const d = new Date(iso)
|
||
return d.toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' })
|
||
} catch { return null }
|
||
}
|
||
|
||
// ── Icons ─────────────────────────────────────────────────────────────────────
|
||
|
||
function SectionIcon({ type }) {
|
||
const icons = {
|
||
prefs: <svg width="13" height="13" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="4" fill="var(--x-warning)"/><circle cx="12" cy="12" r="9" stroke="var(--x-warning)" strokeWidth="2"/></svg>,
|
||
quick: <svg width="13" height="13" viewBox="0 0 24 24" fill="none"><path d="M5 12h14M13 6l6 6-6 6" stroke="var(--x-success)" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"/></svg>,
|
||
extras: <svg width="13" height="13" viewBox="0 0 24 24" fill="none"><path d="M12 5v14M5 12h14" stroke="var(--x-info)" strokeWidth="2.5" strokeLinecap="round"/></svg>,
|
||
removed: <svg width="13" height="13" viewBox="0 0 24 24" fill="none"><path d="M5 12h14" stroke="var(--x-danger)" strokeWidth="2.5" strokeLinecap="round"/></svg>,
|
||
note: <svg width="13" height="13" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="12" r="1.5" fill="var(--x-ink-2)"/><path d="M12 7v1M12 16v1" stroke="var(--x-ink-2)" strokeWidth="2" strokeLinecap="round"/><circle cx="12" cy="12" r="9" stroke="var(--x-ink-2)" strokeWidth="1.5"/></svg>,
|
||
}
|
||
return <span style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0 }}>{icons[type] ?? null}</span>
|
||
}
|
||
|
||
function ExpandArrow({ expanded, onClick }) {
|
||
return (
|
||
<button
|
||
onClick={e => { e.stopPropagation(); onClick() }}
|
||
style={{
|
||
background: 'none', border: 'none', padding: 4, cursor: 'pointer',
|
||
color: 'var(--muted)', display: 'flex', alignItems: 'center', flexShrink: 0,
|
||
}}
|
||
>
|
||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none"
|
||
style={{ transform: `rotate(${expanded ? 180 : 0}deg)`, transition: 'transform 180ms' }}>
|
||
<path d="M6 9L12 15L18 9" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round"/>
|
||
</svg>
|
||
</button>
|
||
)
|
||
}
|
||
|
||
// ── Parse selected_options into grouped sections ──────────────────────────────
|
||
|
||
function buildSections(item) {
|
||
const sections = []
|
||
const opts = (() => {
|
||
try { return item.selected_options ? JSON.parse(item.selected_options) : [] } catch { return [] }
|
||
})()
|
||
const removed = (() => {
|
||
try { return item.removed_ingredients ? JSON.parse(item.removed_ingredients) : [] } catch { return [] }
|
||
})()
|
||
|
||
const prefGroups = []
|
||
const extraGroups = []
|
||
const quickLines = []
|
||
|
||
const idCount = {}
|
||
opts.forEach(o => { if (o.id != null) idCount[o.id] = (idCount[o.id] || 0) + 1 })
|
||
|
||
const consumedAsSubAtIndex = new Set()
|
||
let i = 0
|
||
while (i < opts.length) {
|
||
const o = opts[i]
|
||
if (consumedAsSubAtIndex.has(i)) { i++; continue }
|
||
|
||
if (o.id == null) {
|
||
const existing = quickLines.find(x => x.name === o.name)
|
||
if (existing) existing._qty = (existing._qty || 1) + 1
|
||
else quickLines.push({ name: o.name, _qty: 1 })
|
||
i++
|
||
continue
|
||
}
|
||
|
||
let subName = null
|
||
if (i + 1 < opts.length && opts[i + 1].id == null) {
|
||
subName = opts[i + 1].name
|
||
consumedAsSubAtIndex.add(i + 1)
|
||
}
|
||
|
||
if (idCount[o.id] > 1) {
|
||
const existing = extraGroups.find(g => g.id === o.id && g.subName === subName)
|
||
if (existing) existing.qty++
|
||
else extraGroups.push({ id: o.id, name: o.name, subName, qty: 1 })
|
||
} else {
|
||
const value = subName ? `${o.name} · ${subName}` : o.name
|
||
prefGroups.push({ setName: null, values: [value] })
|
||
}
|
||
i++
|
||
}
|
||
|
||
if (prefGroups.length > 0) sections.push({ type: 'prefs', lines: prefGroups })
|
||
if (quickLines.length > 0) sections.push({ type: 'quick', lines: quickLines })
|
||
if (extraGroups.length > 0) sections.push({ type: 'extras', lines: extraGroups })
|
||
if (removed.length > 0) sections.push({ type: 'removed', lines: removed.map(n => ({ name: n })) })
|
||
if (item.notes) sections.push({ type: 'note', lines: [{ name: item.notes }] })
|
||
|
||
return sections
|
||
}
|
||
|
||
// ── KDS colour strip ──────────────────────────────────────────────────────────
|
||
|
||
const KDS_COLORS = {
|
||
pending: { textColor: 'var(--x-warning)', label: 'kds.pending', icon: '⏳', dot: 'var(--x-warning)' },
|
||
preparing: { textColor: 'var(--x-info)', label: 'kds.preparing', icon: '🔥', dot: 'var(--x-info)' },
|
||
done: { textColor: 'var(--x-success)', label: 'kds.ready', icon: '✓', dot: 'var(--x-success)' },
|
||
served: { textColor: null, label: null, icon: null, dot: null },
|
||
}
|
||
|
||
// ── Shared expanded details panel ─────────────────────────────────────────────
|
||
|
||
function OptionsPanel({ sections }) {
|
||
const { t } = useTranslation('waiter')
|
||
return (
|
||
<div style={{ paddingBottom: 8 }}>
|
||
{sections.map((sec, si) => (
|
||
<div key={si}>
|
||
<div style={{ margin: '0 12px', height: 1, background: 'var(--border)' }} />
|
||
<div style={{ padding: '5px 12px 2px', display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||
{sec.type === 'prefs' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||
<SectionIcon type="prefs" />
|
||
<span style={{ fontSize: 12, lineHeight: 1.4, flex: 1 }}>
|
||
{line.setName && (
|
||
<span style={{ color: 'var(--muted)', display: 'block', fontSize: 11 }}>{line.setName}</span>
|
||
)}
|
||
<span style={{ color: 'var(--text)' }}>{line.values.join(' · ')}</span>
|
||
</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'quick' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||
<SectionIcon type="quick" />
|
||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>
|
||
{line.name}
|
||
{line._qty > 1 && <span style={{ color: 'var(--x-warning)', marginLeft: 4, fontWeight: 700 }}>×{line._qty}</span>}
|
||
</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'extras' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||
<SectionIcon type="extras" />
|
||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>
|
||
{line.name}
|
||
{line.subName && <span> · {line.subName}</span>}
|
||
{line.qty > 1 && <span style={{ color: 'var(--x-warning)', marginLeft: 4, fontWeight: 700 }}>×{line.qty}</span>}
|
||
</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'removed' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||
<SectionIcon type="removed" />
|
||
<span style={{ fontSize: 12, color: 'var(--text)', flex: 1 }}>{t('drawer.without', { name: line.name })}</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'note' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
|
||
<SectionIcon type="note" />
|
||
<span style={{ fontSize: 12, color: 'var(--text)', lineHeight: 1.4, flex: 1, whiteSpace: 'pre-wrap' }}>{line.name}</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// ── KDS badge/icon renderer ───────────────────────────────────────────────────
|
||
|
||
function KdsBadge({ kdsColor, kdsDisplayStyle }) {
|
||
const { t } = useTranslation('waiter')
|
||
if (!kdsColor?.label) return null
|
||
if (kdsDisplayStyle === 'icon' && kdsColor.dot) {
|
||
return (
|
||
<span style={{
|
||
width: 8, height: 8, borderRadius: '50%',
|
||
background: kdsColor.dot, flexShrink: 0, display: 'inline-block',
|
||
}} title={t(kdsColor.label)} />
|
||
)
|
||
}
|
||
return (
|
||
<span style={{
|
||
fontSize: 9, fontWeight: 800, letterSpacing: 0.4,
|
||
color: kdsColor.textColor,
|
||
borderRadius: 3, padding: '1px 5px',
|
||
border: `1px solid ${fade(kdsColor.textColor, 0.38)}`,
|
||
flexShrink: 0,
|
||
}}>{t(kdsColor.label)}</span>
|
||
)
|
||
}
|
||
|
||
// ── Price event label helpers ─────────────────────────────────────────────────
|
||
|
||
const PRICING_EVENT_STYLE = {
|
||
modifier_applied: { color: 'var(--x-info)', label: null }, // label comes from modifier_name
|
||
waiter_discount: { color: 'var(--x-special-ink)', label: 'summary.discount' },
|
||
free_item_added: { color: 'var(--x-success)', label: 'summary.free' },
|
||
deal_offer_accepted: { color: 'var(--x-success)', label: null }, // label from deal_name
|
||
}
|
||
|
||
function PricingRows({ events, _layout, nameIndent = 12 }) {
|
||
const { t } = useTranslation('waiter')
|
||
const rows = events.filter(ev =>
|
||
ev.event_type === 'modifier_applied' ||
|
||
ev.event_type === 'waiter_discount' ||
|
||
ev.event_type === 'free_item_added'
|
||
)
|
||
if (rows.length === 0) return null
|
||
|
||
// Match OptionsPanel container padding: section divider + inner padding
|
||
return (
|
||
<div>
|
||
<div style={{ margin: `0 12px`, height: 1, background: 'var(--border)' }} />
|
||
<div style={{ padding: `4px 12px 4px ${nameIndent}px`, display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||
{rows.map((ev, i) => {
|
||
const evStyle = PRICING_EVENT_STYLE[ev.event_type] || { color: 'var(--x-ink-2)', label: ev.event_type }
|
||
const label = ev.modifier_name || ev.deal_name || (evStyle.label && t(evStyle.label)) || ev.event_type
|
||
const delta = ev.delta_amount
|
||
|
||
return (
|
||
<div key={i} style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" style={{ flexShrink: 0 }}>
|
||
<circle cx="9" cy="9" r="2" stroke={evStyle.color} strokeWidth="2"/>
|
||
<circle cx="15" cy="15" r="2" stroke={evStyle.color} strokeWidth="2"/>
|
||
<path d="M5 19L19 5" stroke={evStyle.color} strokeWidth="2" strokeLinecap="round"/>
|
||
</svg>
|
||
<span style={{ fontSize: 12, color: evStyle.color, flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', lineHeight: 1.4 }}>
|
||
{label}
|
||
</span>
|
||
{delta != null && (
|
||
<span style={{ fontSize: 12, color: evStyle.color, fontWeight: 700, flexShrink: 0, marginLeft: 8 }}>
|
||
{delta > 0 ? '+' : ''}{money(delta)}
|
||
</span>
|
||
)}
|
||
</div>
|
||
)
|
||
})}
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// Small badge shown on the main item row to hint that pricing changes exist
|
||
function PricingBadge({ events }) {
|
||
const { t } = useTranslation('waiter')
|
||
if (!events || events.length === 0) return null
|
||
const hasDiscount = events.some(ev => ev.event_type === 'waiter_discount')
|
||
const hasModifier = events.some(ev => ev.event_type === 'modifier_applied')
|
||
const hasFree = events.some(ev => ev.event_type === 'free_item_added')
|
||
|
||
const icons = []
|
||
if (hasModifier) icons.push(
|
||
<svg key="mod" width="10" height="10" viewBox="0 0 24 24" fill="none" title={t('summary.modifier')}>
|
||
<path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5" stroke="var(--x-info)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
||
</svg>
|
||
)
|
||
if (hasDiscount) icons.push(
|
||
<svg key="disc" width="10" height="10" viewBox="0 0 24 24" fill="none" title={t('summary.discount')}>
|
||
<circle cx="9" cy="9" r="2" stroke="var(--x-special-ink)" strokeWidth="2"/>
|
||
<circle cx="15" cy="15" r="2" stroke="var(--x-special-ink)" strokeWidth="2"/>
|
||
<path d="M5 19L19 5" stroke="var(--x-special-ink)" strokeWidth="2" strokeLinecap="round"/>
|
||
</svg>
|
||
)
|
||
if (hasFree) icons.push(
|
||
<svg key="free" width="10" height="10" viewBox="0 0 24 24" fill="none" title={t('summary.free')}>
|
||
<path d="M20 12v10H4V12M22 7H2v5h20V7z" stroke="var(--x-success)" strokeWidth="2" strokeLinecap="round"/>
|
||
</svg>
|
||
)
|
||
|
||
if (icons.length === 0) return null
|
||
return (
|
||
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 2, marginLeft: 3 }}>
|
||
{icons}
|
||
</span>
|
||
)
|
||
}
|
||
|
||
// Deal badge on items that triggered or were added by a deal
|
||
function DealBadge({ item }) {
|
||
const { t } = useTranslation('waiter')
|
||
if (item.deal_id) {
|
||
return (
|
||
<span style={{
|
||
fontSize: 9, fontWeight: 700, padding: '1px 5px', borderRadius: 4,
|
||
background: 'rgb(var(--x-special-rgb) / 0.15)', color: 'var(--x-special-ink)',
|
||
border: '1px solid rgb(var(--x-special-rgb) / 0.4)', flexShrink: 0, letterSpacing: 0.3,
|
||
}}>
|
||
{t('summary.freeCaps')}
|
||
</span>
|
||
)
|
||
}
|
||
return null
|
||
}
|
||
|
||
function MergedBadge({ item }) {
|
||
if (!item._isMerged) return null
|
||
return (
|
||
<span style={{
|
||
fontSize: 9, fontWeight: 700, padding: '1px 5px', borderRadius: 4,
|
||
background: 'rgb(var(--x-info-rgb) / 0.15)', color: 'var(--x-info-ink)',
|
||
border: '1px solid rgb(var(--x-info-rgb) / 0.35)', flexShrink: 0, letterSpacing: 0.3,
|
||
}}>
|
||
∑{item._sourceIds?.length}
|
||
</span>
|
||
)
|
||
}
|
||
|
||
// ── ItemRow ───────────────────────────────────────────────────────────────────
|
||
|
||
function ItemRow({ item, selectable, selected, onToggle, onLongPress, isLast, kdsDisplayStyle, orderItemLayout, waiterMap, courses, priceEvents, moved = false }) {
|
||
const { t } = useTranslation('waiter')
|
||
const isPaid = item.status === 'paid'
|
||
const isCancelled = item.status === 'cancelled'
|
||
const effectiveKds = item.kds_status || 'pending'
|
||
const isServed = effectiveKds === 'served'
|
||
const kdsColor = !isCancelled && !isServed ? KDS_COLORS[effectiveKds] : null
|
||
|
||
const sections = buildSections(item)
|
||
const hasDetails = sections.length > 0
|
||
const [expanded, setExpanded] = useState(false)
|
||
|
||
const pressTimer = useRef(null)
|
||
const didLongPress = useRef(false)
|
||
const touchStartPos = useRef({ x: 0, y: 0 })
|
||
|
||
const canSelect = selectable && !isCancelled
|
||
|
||
function handleTouchStart(e) {
|
||
if (!canSelect || !onLongPress) return
|
||
didLongPress.current = false
|
||
touchStartPos.current = { x: e.touches[0].clientX, y: e.touches[0].clientY }
|
||
pressTimer.current = setTimeout(() => {
|
||
didLongPress.current = true
|
||
onLongPress(item)
|
||
}, 500)
|
||
}
|
||
|
||
function handleTouchMove(e) {
|
||
const dx = Math.abs(e.touches[0].clientX - touchStartPos.current.x)
|
||
const dy = Math.abs(e.touches[0].clientY - touchStartPos.current.y)
|
||
if (dx > 8 || dy > 8) clearTimeout(pressTimer.current)
|
||
}
|
||
|
||
function handleTouchEnd() { clearTimeout(pressTimer.current) }
|
||
|
||
function handleBodyClick() {
|
||
if (didLongPress.current) { didLongPress.current = false; return }
|
||
if (canSelect) onToggle(item.id)
|
||
}
|
||
|
||
const nameColor = !isCancelled && !isServed ? kdsColor?.textColor : null
|
||
const totalPrice = fmtPrice(((item.unit_price ?? 0) + (item.price_adjustment ?? 0)) * item.quantity)
|
||
const unitPriceAdjusted = (item.unit_price ?? 0) + (item.price_adjustment ?? 0)
|
||
// Cast to boolean so JSX never renders the raw number 0
|
||
const hasPriceAdj = !!(item.price_adjustment && item.price_adjustment !== 0)
|
||
|
||
const courseBadge = item.course_id != null && courses?.length > 0 ? (() => {
|
||
const course = courses.find(c => c.id === item.course_id)
|
||
if (!course) return null
|
||
return (
|
||
<span style={{
|
||
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
||
width: 16, height: 16, borderRadius: '50%',
|
||
background: course.color, color: 'var(--x-on-colour)',
|
||
fontSize: 9, fontWeight: 700, flexShrink: 0, marginLeft: 4,
|
||
}}>
|
||
{courses.indexOf(course) + 1}
|
||
</span>
|
||
)
|
||
})() : null
|
||
|
||
// Lines the guests sent themselves (QR menu at the table) or an online order (plan step 4.8)
|
||
const sourceBadge = item.source === 'qr' || item.source === 'online' ? (
|
||
<span data-testid="item-source" data-source={item.source} title={t(`summary.source.${item.source}`)}
|
||
style={{ marginLeft: 6, fontSize: 10, fontWeight: 800, padding: '1px 5px', borderRadius: 4, verticalAlign: 'middle',
|
||
background: 'rgb(var(--x-info-rgb) / 0.15)', color: 'var(--x-info)', border: '1px solid rgb(var(--x-info-rgb) / 0.35)' }}>
|
||
{item.source === 'qr' ? '📱 QR' : `🌐 ${t('summary.source.onlineShort')}`}
|
||
</span>
|
||
) : null
|
||
|
||
const nameEl = (
|
||
<span
|
||
className={[
|
||
'order-item__name',
|
||
isCancelled ? 'order-item__name--cancelled' : '',
|
||
isServed ? 'order-item__name--served' : '',
|
||
effectiveKds === 'done' && !isCancelled && !isServed ? 'kds-ready-flash-text' : '',
|
||
].filter(Boolean).join(' ')}
|
||
style={nameColor ? { color: nameColor } : undefined}
|
||
>
|
||
{(isPart(item) ? item.product_name : item.product?.name) || `#${item.product_id}`}
|
||
{isSettled(item) && (
|
||
<span data-testid="item-settled" title={t('split.settledHint')}
|
||
style={{ marginLeft: 6, fontSize: 10, fontWeight: 800, padding: '1px 5px', borderRadius: 4, verticalAlign: 'middle',
|
||
background: 'rgb(var(--x-info-rgb) / 0.15)', color: 'var(--x-info)', border: '1px solid rgb(var(--x-info-rgb) / 0.35)' }}>
|
||
➗ {t('split.settled')}
|
||
</span>
|
||
)}
|
||
{courseBadge}
|
||
{sourceBadge}
|
||
{moved && (
|
||
<span data-testid="item-moved" title={t('moves.lineMoved')}
|
||
style={{ marginLeft: 6, fontSize: 10, fontWeight: 800, padding: '1px 5px', borderRadius: 4, verticalAlign: 'middle',
|
||
background: 'rgb(var(--x-info-rgb) / 0.15)', color: 'var(--x-info)', border: '1px solid rgb(var(--x-info-rgb) / 0.35)' }}>
|
||
↪ {t('moves.movedShort')}
|
||
</span>
|
||
)}
|
||
</span>
|
||
)
|
||
|
||
const paidBadge = isPaid && !isServed ? <span className="badge badge--paid">{t('summary.paidBadge')}</span> : null
|
||
const cancelledBadge = isCancelled ? <span className="badge badge--cancelled">{t('summary.cancelledBadge')}</span> : null
|
||
const draftBadge = !isPaid && !isCancelled && !item.printed
|
||
? <span className="badge badge--draft" title={t('summary.notPrinted')}>⏳</span>
|
||
: null
|
||
|
||
// Whole-card click+touch handlers on the outer wrapper
|
||
const cardHandlers = {
|
||
onClick: handleBodyClick,
|
||
onTouchStart: handleTouchStart,
|
||
onTouchMove: handleTouchMove,
|
||
onTouchEnd: handleTouchEnd,
|
||
onTouchCancel: handleTouchEnd,
|
||
}
|
||
|
||
const cardClass = [
|
||
'order-item',
|
||
isPaid && isServed ? 'order-item--paid' : '',
|
||
isCancelled ? 'order-item--cancelled' : '',
|
||
selectable && selected ? 'order-item--selected' : '',
|
||
isLast ? 'order-item--last' : '',
|
||
].filter(Boolean).join(' ')
|
||
|
||
// Indent of secondary rows — lines up with the start of the item name
|
||
const nameIndent = selectable && !isCancelled ? 44 : 12
|
||
|
||
// ── COMPACT ──────────────────────────────────────────────────────────────────
|
||
const hasPricingRows = priceEvents && priceEvents.some(ev => ['modifier_applied','waiter_discount','free_item_added'].includes(ev.event_type))
|
||
const [pricingExpanded, setPricingExpanded] = useState(false)
|
||
|
||
if (orderItemLayout === 'compact') {
|
||
return (
|
||
<div
|
||
className={cardClass}
|
||
style={{ userSelect: 'none', position: 'relative', cursor: canSelect ? 'pointer' : 'default' }}
|
||
{...cardHandlers}
|
||
>
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '7px 12px' }}>
|
||
{selectable && !isCancelled && (
|
||
<span style={{ color: selected ? 'var(--x-warning)' : 'var(--x-ink-3)', flexShrink: 0, fontSize: 16 }}>
|
||
{selected ? '☑' : '☐'}
|
||
</span>
|
||
)}
|
||
|
||
<div style={{ flex: 1, minWidth: 0 }}>
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||
{nameEl}
|
||
<MergedBadge item={item} />
|
||
<DealBadge item={item} />
|
||
<PricingBadge events={priceEvents} />
|
||
{(hasDetails || hasPricingRows) && (
|
||
<ExpandArrow
|
||
expanded={expanded || pricingExpanded}
|
||
onClick={() => {
|
||
const next = !(expanded || pricingExpanded)
|
||
if (hasDetails) setExpanded(next)
|
||
if (hasPricingRows) setPricingExpanded(next)
|
||
}}
|
||
/>
|
||
)}
|
||
{paidBadge}
|
||
{cancelledBadge}
|
||
{draftBadge}
|
||
</div>
|
||
</div>
|
||
|
||
<KdsBadge kdsColor={kdsColor} kdsDisplayStyle={kdsDisplayStyle} />
|
||
<span className="order-item__qty">{fmtQty(item.quantity, item.unit_type)}</span>
|
||
<span className="order-item__price" style={hasPriceAdj ? { color: 'var(--x-info)' } : undefined}>
|
||
{totalPrice}
|
||
</span>
|
||
</div>
|
||
|
||
{(expanded || pricingExpanded) && hasPricingRows && (
|
||
<PricingRows events={priceEvents} layout="compact" nameIndent={nameIndent} />
|
||
)}
|
||
{expanded && hasDetails && <OptionsPanel sections={sections} />}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// ── EXPANDED ─────────────────────────────────────────────────────────────────
|
||
if (orderItemLayout === 'expanded') {
|
||
return (
|
||
<div
|
||
className={cardClass}
|
||
style={{ userSelect: 'none', position: 'relative', cursor: canSelect ? 'pointer' : 'default' }}
|
||
{...cardHandlers}
|
||
>
|
||
{/* Row 1: checkbox · name · badges · expand arrow · KDS badge */}
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px 2px' }}>
|
||
{selectable && !isCancelled && (
|
||
<span style={{ color: selected ? 'var(--x-warning)' : 'var(--x-ink-3)', flexShrink: 0, fontSize: 16 }}>
|
||
{selected ? '☑' : '☐'}
|
||
</span>
|
||
)}
|
||
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||
{nameEl}
|
||
<DealBadge item={item} />
|
||
<PricingBadge events={priceEvents} />
|
||
{(hasDetails || hasPricingRows) && (
|
||
<ExpandArrow
|
||
expanded={expanded || pricingExpanded}
|
||
onClick={() => {
|
||
const next = !(expanded || pricingExpanded)
|
||
if (hasDetails) setExpanded(next)
|
||
if (hasPricingRows) setPricingExpanded(next)
|
||
}}
|
||
/>
|
||
)}
|
||
{paidBadge}
|
||
{cancelledBadge}
|
||
{draftBadge}
|
||
</div>
|
||
<KdsBadge kdsColor={kdsColor} kdsDisplayStyle={kdsDisplayStyle} />
|
||
</div>
|
||
|
||
{/* Row 2: unit price · qty · total */}
|
||
<div style={{
|
||
display: 'flex', alignItems: 'center',
|
||
padding: `2px 12px ${hasPricingRows && !pricingExpanded ? 2 : 8}px ${nameIndent}px`,
|
||
}}>
|
||
<span style={{ fontSize: 12, color: 'var(--muted)', flex: 1 }}>
|
||
{hasPriceAdj
|
||
? <><span style={{ textDecoration: 'line-through', marginRight: 4, opacity: 0.6 }}>{fmtPrice(item.unit_price)}</span><span style={{ color: 'var(--x-info)' }}>{fmtPrice(unitPriceAdjusted)}</span></>
|
||
: fmtPrice(unitPriceAdjusted)
|
||
}
|
||
</span>
|
||
<span className="order-item__qty" style={{ textAlign: 'center', minWidth: 48 }}>
|
||
{fmtQty(item.quantity, item.unit_type)}
|
||
</span>
|
||
<span className="order-item__price" style={{ minWidth: 64, textAlign: 'right', ...(hasPriceAdj ? { color: 'var(--x-info)' } : {}) }}>
|
||
{totalPrice}
|
||
</span>
|
||
</div>
|
||
|
||
{(pricingExpanded || expanded) && hasPricingRows && <PricingRows events={priceEvents} layout="expanded" nameIndent={nameIndent} />}
|
||
{expanded && hasDetails && <OptionsPanel sections={sections} />}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
// ── FULLY DETAILED ────────────────────────────────────────────────────────────
|
||
const addedByName = waiterMap?.[item.added_by] ?? null
|
||
const paidByName = waiterMap?.[item.paid_by] ?? null
|
||
const addedAtFmt = fmtDateTime(item.added_at)
|
||
const paidAtFmt = fmtDateTime(item.paid_at)
|
||
|
||
return (
|
||
<div
|
||
className={cardClass}
|
||
style={{ userSelect: 'none', position: 'relative', cursor: canSelect ? 'pointer' : 'default' }}
|
||
{...cardHandlers}
|
||
>
|
||
{/* Row 1 */}
|
||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 12px 2px' }}>
|
||
{selectable && !isCancelled && (
|
||
<span style={{ color: selected ? 'var(--x-warning)' : 'var(--x-ink-3)', flexShrink: 0, fontSize: 16 }}>
|
||
{selected ? '☑' : '☐'}
|
||
</span>
|
||
)}
|
||
<div style={{ flex: 1, minWidth: 0, display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||
{nameEl}
|
||
<DealBadge item={item} />
|
||
<PricingBadge events={priceEvents} />
|
||
{paidBadge}
|
||
{cancelledBadge}
|
||
{draftBadge}
|
||
</div>
|
||
<KdsBadge kdsColor={kdsColor} kdsDisplayStyle={kdsDisplayStyle} />
|
||
</div>
|
||
|
||
{/* Row 2 — pricing */}
|
||
<div style={{
|
||
display: 'flex', alignItems: 'center',
|
||
padding: `2px 12px 6px ${nameIndent}px`,
|
||
}}>
|
||
<span style={{ fontSize: 12, color: 'var(--muted)', flex: 1 }}>
|
||
{hasPriceAdj
|
||
? <><span style={{ textDecoration: 'line-through', marginRight: 4, opacity: 0.6 }}>{fmtPrice(item.unit_price)}</span><span style={{ color: 'var(--x-info)' }}>{fmtPrice(unitPriceAdjusted)}</span></>
|
||
: fmtPrice(unitPriceAdjusted)
|
||
}
|
||
</span>
|
||
<span className="order-item__qty" style={{ textAlign: 'center', minWidth: 48 }}>
|
||
{fmtQty(item.quantity, item.unit_type)}
|
||
</span>
|
||
<span className="order-item__price" style={{ minWidth: 64, textAlign: 'right', ...(hasPriceAdj ? { color: 'var(--x-info)' } : {}) }}>
|
||
{totalPrice}
|
||
</span>
|
||
</div>
|
||
|
||
{hasPricingRows && <PricingRows events={priceEvents} layout="full" nameIndent={nameIndent} />}
|
||
|
||
{/* Detail rows */}
|
||
<div style={{
|
||
padding: `0 12px 8px ${nameIndent}px`,
|
||
display: 'flex', flexDirection: 'column', gap: 3,
|
||
}}>
|
||
<div style={{ height: 1, background: 'var(--border)', marginBottom: 4 }} />
|
||
|
||
{/* Ordered by */}
|
||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||
<span style={{ fontSize: 11, color: 'var(--muted)', minWidth: 90 }}>{t('summary.ordered')}</span>
|
||
<span style={{ flex: 1 }} />
|
||
<span style={{ fontSize: 11, color: 'var(--muted)', textAlign: 'right' }}>
|
||
{addedByName && addedAtFmt ? `${addedByName} · ${addedAtFmt}` : addedByName || addedAtFmt || '—'}
|
||
</span>
|
||
</div>
|
||
|
||
{/* Paid by — only if paid */}
|
||
{isPaid && (
|
||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||
<span style={{ fontSize: 11, color: 'var(--muted)', minWidth: 90 }}>{t('summary.paidAt')}</span>
|
||
<span style={{ flex: 1 }} />
|
||
<span style={{ fontSize: 11, color: 'var(--muted)', textAlign: 'right' }}>
|
||
{paidByName && paidAtFmt ? `${paidByName} · ${paidAtFmt}` : paidByName || paidAtFmt || '—'}
|
||
</span>
|
||
</div>
|
||
)}
|
||
|
||
{/* Options — inline, no expand needed */}
|
||
{hasDetails && (
|
||
<div style={{ marginTop: 2 }}>
|
||
{sections.map((sec, si) => (
|
||
<div key={si} style={{ display: 'flex', flexDirection: 'column', gap: 2, marginTop: 2 }}>
|
||
{sec.type === 'prefs' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 6 }}>
|
||
<SectionIcon type="prefs" />
|
||
<span style={{ fontSize: 11, lineHeight: 1.4, flex: 1, color: 'var(--text)' }}>
|
||
{line.setName && <span style={{ color: 'var(--muted)' }}>{line.setName}: </span>}
|
||
{line.values.join(' · ')}
|
||
</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'quick' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||
<SectionIcon type="quick" />
|
||
<span style={{ fontSize: 11, color: 'var(--text)', flex: 1 }}>
|
||
{line.name}
|
||
{line._qty > 1 && <span style={{ color: 'var(--x-warning)', marginLeft: 4, fontWeight: 700 }}>×{line._qty}</span>}
|
||
</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'extras' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||
<SectionIcon type="extras" />
|
||
<span style={{ fontSize: 11, color: 'var(--text)', flex: 1 }}>
|
||
{line.name}
|
||
{line.subName && <span> · {line.subName}</span>}
|
||
{line.qty > 1 && <span style={{ color: 'var(--x-warning)', marginLeft: 4, fontWeight: 700 }}>×{line.qty}</span>}
|
||
</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'removed' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||
<SectionIcon type="removed" />
|
||
<span style={{ fontSize: 11, color: 'var(--text)', flex: 1 }}>{t('drawer.without', { name: line.name })}</span>
|
||
</div>
|
||
))}
|
||
{sec.type === 'note' && sec.lines.map((line, li) => (
|
||
<div key={li} style={{ display: 'flex', alignItems: 'flex-start', gap: 6 }}>
|
||
<SectionIcon type="note" />
|
||
<span style={{ fontSize: 11, color: 'var(--text)', lineHeight: 1.4, flex: 1, whiteSpace: 'pre-wrap' }}>{line.name}</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
))}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
export default function OrderSummary({ order, selectable = false, selectedIds = [], onToggle, onLongPressItem, waiterMap, courses = [], priceEventsMap = {}, movedItems = {}, onOneMore }) {
|
||
const { t } = useTranslation('waiter')
|
||
const kdsDisplayStyle = useTableViewStore(s => s.kdsDisplayStyle || 'badge')
|
||
const orderItemLayout = useTableViewStore(s => s.orderItemLayout || 'compact')
|
||
const activeItems = order.items?.filter(i => i.status !== 'cancelled') || []
|
||
const total = activeItems
|
||
.filter(countsInTotal) // 6F.6: a split bill's settled lines are counted through its parts
|
||
.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||
const paidTotal = activeItems
|
||
.filter(i => i.status === 'paid')
|
||
.reduce((s, i) => s + ((i.unit_price ?? 0) + (i.price_adjustment ?? 0)) * i.quantity, 0)
|
||
|
||
return (
|
||
<div className="order-summary">
|
||
{activeItems.length === 0 && <p style={{ color: 'var(--x-ink-3)', textAlign: 'center' }}>{t('summary.noItems')}</p>}
|
||
{activeItems.map((item, idx) => (
|
||
// 6F.5: "+1" beside a line whose product allows it, outside the line's own tap area
|
||
<div key={item.id} style={{ display: 'flex', alignItems: 'center' }}>
|
||
<div style={{ flex: 1, minWidth: 0 }}>
|
||
<ItemRow
|
||
item={item}
|
||
selectable={selectable}
|
||
selected={selectedIds.includes(item.id)}
|
||
onToggle={onToggle}
|
||
onLongPress={onLongPressItem}
|
||
isLast={idx === activeItems.length - 1}
|
||
kdsDisplayStyle={kdsDisplayStyle}
|
||
orderItemLayout={orderItemLayout}
|
||
waiterMap={waiterMap}
|
||
courses={courses}
|
||
priceEvents={priceEventsMap[item.id] ?? []}
|
||
moved={!!movedItems[item.id]}
|
||
/>
|
||
</div>
|
||
{onOneMore && canOneMore(item) && <OneMore onSend={qty => onOneMore(item, qty)} />}
|
||
</div>
|
||
))}
|
||
<div className="order-summary__total">
|
||
<span>{t('common.total')}</span>
|
||
<span>{fmtPrice(total)}</span>
|
||
</div>
|
||
{paidTotal > 0 && paidTotal < total && (
|
||
<div style={{ display: 'flex', justifyContent: 'space-between', padding: '0 12px 8px', fontSize: 13, color: 'var(--x-ink-3)' }}>
|
||
<span>{t('tables.quick.paid')}</span>
|
||
<span style={{ color: 'var(--x-success)' }}>{fmtPrice(paidTotal)}</span>
|
||
</div>
|
||
)}
|
||
{paidTotal > 0 && paidTotal < total && (
|
||
<div style={{ display: 'flex', justifyContent: 'space-between', padding: '0 12px 8px', fontSize: 13, color: 'var(--x-ink-2)' }}>
|
||
<span>{t('summary.due')}</span>
|
||
<span style={{ color: 'var(--x-warning)', fontWeight: 700 }}>{fmtPrice(total - paidTotal)}</span>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)
|
||
}
|