// 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, InfoTip, 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', 'tabs.changed'], }) 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 ? (<> {t('overview.shift.live')} ) : step === 1 ? (<> {t('overview.shift.checkFirst')} ) : (<> ) return ( {shift.waiter_name} {closing ? t('overview.shift.closing') : t('overview.shift.running')} {t('overview.shift.number', { id: shift.id })} }>
{formatTime(shift.started_at)}
{since(shift.started_at)}
{['overview', 'lines'].map(s => ( ))}
{screen === 'overview' && (<>
{t('overview.shift.expected')}
{t('overview.shift.startCash')}
+ {t('overview.shift.cashSales')} {money.tabCash > 0 && <>
+ {t('overview.shift.tabCash')} } {money.refunded > 0 && <>
− {t('overview.shift.refunded')} }
{money.total > 0 && p.value > 0)} />} {data.activity && } {summary && shiftPairs(summary).length > 0 && (
{t('overview.shift.perHour')}
)}
{counts.items}
{counts.tables}
{counts.orders}
{data.shift_pay != null ? : '—'}
{closing && step === 1 && (