feat: Phase 2E — cash drawer reconciliation

Backend:
- WaiterShift: add counted_cash_end (physical cash handed over) + cash_discrepancy (computed)
- BusinessDay: add store_opening_cash, store_closing_cash, store_cash_discrepancy
- EndShiftRequest: accept counted_cash_end (optional)
- CloseBusinessDayRequest: accept store_closing_cash (optional)
- Shift end (both /end and /manager/end/{id}): compute cash_discrepancy =
  counted_cash_end - (starting_cash + total_collected); negative = short, positive = over
- Business day close: compute store_cash_discrepancy = store_closing_cash - expected;
  expected = store_opening_cash + sum(shift.total_collected for day)
- _enrich_shift: expose counted_cash_end + cash_discrepancy in all shift responses
- Business day summary: expose store cash fields + store_expected_closing + total_waiter_collected
- BusinessDayOut schema: expose new store cash fields
- Shifts CSV export: add counted_cash_end + cash_discrepancy columns

Frontend:
- EndShiftConfirmModal: 2-step flow — step 1 notes, step 2 cash handover with live discrepancy
  (shows ✓ clean / ⚠ short / ⚠ over in real time before confirming)
- WorkdaySummaryModal close flow: new Ταμείο tab with store cash count + live discrepancy;
  footer navigates overview → Ταμείο → Έλεγχοι; store_closing_cash included in close payload
- ShiftsOverview report: Ταμείο column showing counted_cash_end + discrepancy badge
- ShiftDetailModal row 2: replaces Εξ.Τραπεζιών with Παραδόθηκαν + Ταμείο discrepancy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 02:47:03 +03:00
co-authored by Claude Sonnet 4.6
parent a675c2e091
commit 9da396b82a
12 changed files with 301 additions and 44 deletions
@@ -418,6 +418,84 @@ function PrintersTab({ data }) {
)
}
function CashReconciliationTab({ data, storeCash, onStoreCashChange }) {
const expected = data.store_expected_closing ?? 0
const counted = storeCash !== '' ? parseFloat(storeCash) : null
const discrepancy = counted != null ? counted - expected : null
const isShort = discrepancy != null && discrepancy < -0.005
const isOver = discrepancy != null && discrepancy > 0.005
const isClean = discrepancy != null && !isShort && !isOver
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
<div style={{ border: '1px solid #e5e7eb', borderRadius: 12, padding: '16px 18px', background: '#f9fafb' }}>
<div style={{ fontSize: 11, fontWeight: 700, color: '#9ca3af', textTransform: 'uppercase', letterSpacing: '0.05em', marginBottom: 10 }}>Σύνοψη Εισπράξεων Βάρδιας</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, fontSize: 13.5 }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span style={{ color: '#6b7280' }}>Σύνολο εισπράξεων σερβιτόρων</span>
<span style={{ fontWeight: 700, color: '#111315' }}>{fmt(data.total_waiter_collected)}</span>
</div>
{data.store_opening_cash != null && (
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span style={{ color: '#6b7280' }}>Αρχικό ταμείο</span>
<span style={{ fontWeight: 600, color: '#111315' }}>{fmt(data.store_opening_cash)}</span>
</div>
)}
<div style={{ display: 'flex', justifyContent: 'space-between', borderTop: '1px solid #e5e7eb', paddingTop: 6, marginTop: 2 }}>
<span style={{ color: '#374151', fontWeight: 600 }}>Αναμενόμενο ταμείο τώρα</span>
<span style={{ fontWeight: 800, color: '#111315', fontSize: 15 }}>{fmt(expected)}</span>
</div>
</div>
</div>
<div>
<label style={{ fontSize: 13, fontWeight: 600, color: '#374151', display: 'block', marginBottom: 6 }}>
Μετρήστε το ταμείο — πόσα μετρητά υπάρχουν;
<span style={{ fontWeight: 400, color: '#9ca3af' }}> (προαιρετικό)</span>
</label>
<input
type="number"
step="0.01"
min="0"
value={storeCash}
onChange={e => onStoreCashChange(e.target.value)}
placeholder="0.00"
style={{
width: '100%', padding: '10px 14px', border: '1.5px solid #e5e7eb',
borderRadius: 10, fontSize: 18, fontWeight: 700, color: '#111315',
outline: 'none', boxSizing: 'border-box', background: 'white',
}}
/>
</div>
{discrepancy != null && (
<div style={{
padding: '14px 16px', borderRadius: 10,
background: isClean ? '#f0fdf4' : '#fef2f2',
border: `1.5px solid ${isClean ? '#86efac' : '#fca5a5'}`,
}}>
<div style={{ fontSize: 14, fontWeight: 700, color: isClean ? '#16a34a' : '#dc2626', marginBottom: 4 }}>
{isClean && '✓ Ταμείο εντάξει'}
{isShort && `⚠ Έλλειμμα ${fmt(Math.abs(discrepancy))}`}
{isOver && `⚠ Πλεόνασμα ${fmt(Math.abs(discrepancy))}`}
</div>
<div style={{ fontSize: 12.5, color: isClean ? '#166534' : '#7f1d1d', lineHeight: 1.5 }}>
{isClean && 'Το φυσικό ταμείο συμφωνεί με τις καταγεγραμμένες εισπράξεις.'}
{isShort && `Το ταμείο έχει ${fmt(Math.abs(discrepancy))} λιγότερα από το αναμενόμενο. Το κενό δεν αποδίδεται σε κάποιον σερβιτόρο συγκεκριμένα.`}
{isOver && `Το ταμείο έχει ${fmt(Math.abs(discrepancy))} περισσότερα από το αναμενόμενο.`}
</div>
</div>
)}
{storeCash === '' && (
<p style={{ fontSize: 12, color: '#9ca3af', margin: 0 }}>
Αν παραλείψετε τη μέτρηση, η επαλήθευση δεν θα καταγραφεί.
</p>
)}
</div>
)
}
function ChecksTab({ data, onForceClose, closing, isOpen }) {
const { checks } = data
const allGood = checks.open_orders === 0
@@ -524,6 +602,7 @@ function ChecksTab({ data, onForceClose, closing, isOpen }) {
export default function WorkdaySummaryModal({ dayId, onClose, showCloseAction = false, onDayClosed }) {
const [tab, setTab] = useState('overview')
const [closing, setClosing] = useState(false)
const [storeCash, setStoreCash] = useState('') // Phase 2E: store cash count
const { data, isLoading, error } = useQuery({
queryKey: ['workday-summary', dayId ?? 'current'],
@@ -534,7 +613,9 @@ export default function WorkdaySummaryModal({ dayId, onClose, showCloseAction =
async function handleClose(force = false) {
setClosing(true)
try {
await client.post('/api/business-day/close', { force })
const payload = { force }
if (storeCash !== '') payload.store_closing_cash = parseFloat(storeCash)
await client.post('/api/business-day/close', payload)
onDayClosed?.()
} catch (e) {
const detail = e.response?.data?.detail
@@ -553,11 +634,14 @@ export default function WorkdaySummaryModal({ dayId, onClose, showCloseAction =
{ id: 'waiters', label: 'Προσωπικό', badge: data?.waiters?.length },
{ id: 'zones', label: 'Ζώνες', badge: data?.zones?.length },
{ id: 'printers', label: 'Εκτυπωτές', badge: data?.printers?.length },
...(showCloseAction ? [{
id: 'checks', label: 'Έλεγχοι',
badge: data?.checks ? (data.checks.open_orders + data.checks.active_shifts) : null,
warn: data?.checks?.with_unpaid_items > 0,
}] : []),
...(showCloseAction ? [
{ id: 'cash', label: 'Ταμείο' },
{
id: 'checks', label: 'Έλεγχοι',
badge: data?.checks ? (data.checks.open_orders + data.checks.active_shifts) : null,
warn: data?.checks?.with_unpaid_items > 0,
},
] : []),
]
const isOpen = data?.status === 'open'
@@ -643,6 +727,13 @@ export default function WorkdaySummaryModal({ dayId, onClose, showCloseAction =
{tab === 'waiters' && <WaitersTab data={data} />}
{tab === 'zones' && <ZonesTab data={data} />}
{tab === 'printers' && <PrintersTab data={data} />}
{tab === 'cash' && (
<CashReconciliationTab
data={data}
storeCash={storeCash}
onStoreCashChange={setStoreCash}
/>
)}
{tab === 'checks' && (
<ChecksTab
data={data}
@@ -666,11 +757,19 @@ export default function WorkdaySummaryModal({ dayId, onClose, showCloseAction =
border: '1px solid #e5e7eb', background: 'white',
fontSize: 13, fontWeight: 600, cursor: 'pointer', color: '#374151',
}}>Ακύρωση</button>
<button onClick={() => setTab('checks')} style={{
height: 40, padding: '0 20px', borderRadius: 9,
background: '#111315', border: 'none', color: 'white',
fontSize: 13, fontWeight: 700, cursor: 'pointer',
}}>Προχωρήστε στους Ελέγχους →</button>
{tab !== 'cash' ? (
<button onClick={() => setTab('cash')} style={{
height: 40, padding: '0 20px', borderRadius: 9,
background: '#111315', border: 'none', color: 'white',
fontSize: 13, fontWeight: 700, cursor: 'pointer',
}}>Μέτρηση Ταμείου →</button>
) : (
<button onClick={() => setTab('checks')} style={{
height: 40, padding: '0 20px', borderRadius: 9,
background: '#111315', border: 'none', color: 'white',
fontSize: 13, fontWeight: 700, cursor: 'pointer',
}}>Προχωρήστε στους Ελέγχους →</button>
)}
</div>
)}
</div>