feat(backend,waiter,terminal,manager): split the bill by amount
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>
This commit is contained in:
@@ -23,6 +23,9 @@ import MoveHistory, { MovedOrderBanner } from '../components/MoveHistory'
|
||||
import QuantityModal from '../components/QuantityModal'
|
||||
import { useQuantityMode } from '../hooks/useQuantityMode'
|
||||
import { canChangeQuantity } from '../logic/lines'
|
||||
import SplitAmountModal, { SplitBills } from '../components/SplitAmountModal'
|
||||
import { useSplitChoices } from '../hooks/useSplitChoices'
|
||||
import { isPart, isSettled } from '../logic/split'
|
||||
import { usePriceRules } from '../hooks/usePriceRules'
|
||||
import { fade } from '../logic/colour'
|
||||
import SeatsHint from '../components/SeatsHint'
|
||||
@@ -42,6 +45,7 @@ function combineIds(items) {
|
||||
|
||||
// Returns a stable string key for grouping under MERGE_IDENTICAL
|
||||
function identicalKey(item) {
|
||||
if (isPart(item)) return `part|${item.id}` // 6F.6: each part is paid on its own
|
||||
const effPrice = ((item.unit_price ?? 0) + (item.price_adjustment ?? 0)).toFixed(4)
|
||||
const opts = (() => { try { return item.selected_options ?? '[]' } catch { return '[]' } })()
|
||||
const removed = (() => { try { return item.removed_ingredients ?? '[]' } catch { return '[]' } })()
|
||||
@@ -51,6 +55,7 @@ function identicalKey(item) {
|
||||
|
||||
// Returns a grouping key for MERGE_SAME_ITEM (ignores options/removed/notes, only product + price)
|
||||
function sameItemKey(item) {
|
||||
if (isPart(item)) return `part|${item.id}`
|
||||
const effPrice = ((item.unit_price ?? 0) + (item.price_adjustment ?? 0)).toFixed(4)
|
||||
return `${item.product_id}|${effPrice}`
|
||||
}
|
||||
@@ -964,7 +969,7 @@ function CancelConfirmModal({ itemCount, onConfirm, onClose }) {
|
||||
)
|
||||
}
|
||||
|
||||
function PayConfirmModal({ payAll, payIds, activeItems, andClose, cardEnabled, onConfirm, onClose }) {
|
||||
function PayConfirmModal({ payAll, payIds, activeItems, andClose, cardEnabled, onConfirm, onSplit, onClose }) {
|
||||
const { t } = useTranslation('waiter')
|
||||
const { paymentSafety } = usePaymentSettingsStore()
|
||||
const [method, setMethod] = useState('cash')
|
||||
@@ -1033,6 +1038,14 @@ function PayConfirmModal({ payAll, payIds, activeItems, andClose, cardEnabled, o
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 6F.6: split the amount instead of paying it all now */}
|
||||
{onSplit && (
|
||||
<button type="button" className="btn btn--secondary" data-testid="pay-split"
|
||||
style={{ width: '100%', marginBottom: 12 }} onClick={() => onSplit(payTotal)}>
|
||||
➗ {t('split.button')}
|
||||
</button>
|
||||
)}
|
||||
|
||||
<div style={{ display: 'flex', gap: 12 }}>
|
||||
<button className="btn btn--secondary" style={{ flex: 1 }} onClick={onClose}>
|
||||
{t('common.cancel')}
|
||||
@@ -1209,6 +1222,12 @@ export default function TableDetailPage() {
|
||||
const [qtyItem, setQtyItem] = useState(null)
|
||||
const [qtyError, setQtyError] = useState('')
|
||||
const [qtyBusy, setQtyBusy] = useState(false)
|
||||
// 6F.6: split the bill by amount
|
||||
const splitChoices = useSplitChoices()
|
||||
const splitAccess = useAllowed('ordering.payments.split_amount')
|
||||
const [splitTarget, setSplitTarget] = useState(null) // { ids, total }
|
||||
const [splitBusy, setSplitBusy] = useState(false)
|
||||
const [splitError, setSplitError] = useState('')
|
||||
const [cancelConfirm, setCancelConfirm] = useState(null) // null | { mode: 'items', ids: [...] } | { mode: 'order' }
|
||||
const [paidSelectedIds, setPaidSelectedIds] = useState([])
|
||||
|
||||
@@ -1415,7 +1434,7 @@ export default function TableDetailPage() {
|
||||
}
|
||||
|
||||
const activeItems = order?.items?.filter(i => i.status === 'active') || []
|
||||
const paidItems = order?.items?.filter(i => i.status === 'paid') || []
|
||||
const paidItems = order?.items?.filter(i => i.status === 'paid' || isSettled(i)) || [] // 6F.6: settled by a split bill
|
||||
const allPaid = order && activeItems.length === 0
|
||||
const canInteract = !!order
|
||||
|
||||
@@ -1955,6 +1974,13 @@ export default function TableDetailPage() {
|
||||
{activeTab === 'active' && (
|
||||
<>
|
||||
<MovedOrderBanner moves={moves.order} onOpen={() => setMoveSheet({ title: t('moves.orderTitle'), moves: moves.order })} />
|
||||
<SplitBills bills={order.split_bills} canUndo={splitAccess !== 'no' && !isOffline} onUndo={async bill => {
|
||||
try {
|
||||
await client.post(`/api/orders/${order.id}/split-bills/${bill.id}/undo`)
|
||||
setSelectedIds([])
|
||||
await load()
|
||||
} catch (err) { setError(apiError(err, t('split.err.undo'))) }
|
||||
}} />
|
||||
<OrderSummary
|
||||
order={{ ...order, items: displayActiveItems }}
|
||||
selectable={canInteract && !paying}
|
||||
@@ -2423,10 +2449,34 @@ export default function TableDetailPage() {
|
||||
activeItems={displayActiveItems}
|
||||
cardEnabled={cardEnabled}
|
||||
onConfirm={(method) => paySelected(method, false)}
|
||||
onSplit={splitChoices.on && splitAccess !== 'no' && !isOffline
|
||||
&& !expandIds(selectedIds.length === 0 ? displayActiveItems.map(i => i.id) : selectedIds).some(id => isPart(activeItems.find(i => i.id === id)))
|
||||
? total => {
|
||||
setConfirmPay(false)
|
||||
setSplitError('')
|
||||
setSplitTarget({ ids: expandIds(selectedIds.length === 0 ? displayActiveItems.map(i => i.id) : selectedIds), total })
|
||||
} : undefined}
|
||||
onClose={() => setConfirmPay(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 6F.6: split the amount into parts */}
|
||||
{splitTarget && (
|
||||
<SplitAmountModal total={splitTarget.total} count={splitTarget.ids.length} choices={splitChoices}
|
||||
customerCount={customerCount} busy={splitBusy} error={splitError}
|
||||
onClose={() => setSplitTarget(null)}
|
||||
onSplit={async body => {
|
||||
setSplitBusy(true); setSplitError('')
|
||||
try {
|
||||
await client.post(`/api/orders/${order.id}/split-bills`, { item_ids: splitTarget.ids, ...body })
|
||||
setSplitTarget(null)
|
||||
setSelectedIds([])
|
||||
setVirtualItems(null)
|
||||
await load()
|
||||
} catch (err) { setSplitError(apiError(err, t('split.err.split'))) } finally { setSplitBusy(false) }
|
||||
}} />
|
||||
)}
|
||||
|
||||
{/* Pay-and-close confirmation */}
|
||||
{confirmPayAndClose && (
|
||||
<PayConfirmModal
|
||||
|
||||
Reference in New Issue
Block a user