// 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 ( ) } function OrderLines({ order, waiterId, kind, payment }) { const { t } = useTranslation('manager') const { formatTime } = useFormat() const items = order.items.filter(i => itemShown(i, waiterId, kind, payment)) if (items.length === 0) return null const paid = items.filter(i => i.status === 'paid').reduce((s, i) => s + i.subtotal, 0) return (