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:
@@ -150,6 +150,15 @@ def close_business_day(
|
||||
if body.notes:
|
||||
day.notes = body.notes
|
||||
|
||||
# Phase 2E: store-level cash reconciliation
|
||||
if body.store_closing_cash is not None:
|
||||
day.store_closing_cash = body.store_closing_cash
|
||||
# expected = store_opening_cash + sum of all waiter collected amounts this day
|
||||
all_shifts = db.query(WaiterShift).filter(WaiterShift.business_day_id == day.id).all()
|
||||
total_collected = sum(s.total_collected or 0.0 for s in all_shifts)
|
||||
expected_closing = (day.store_opening_cash or 0.0) + total_collected
|
||||
day.store_cash_discrepancy = round(body.store_closing_cash - expected_closing, 2)
|
||||
|
||||
db.commit()
|
||||
db.refresh(day)
|
||||
|
||||
@@ -409,6 +418,10 @@ def business_day_summary(
|
||||
for key in ("total_collected", "total_items_value", "cash", "card", "transfer", "treat", "other"):
|
||||
w[key] = round(w[key], 2)
|
||||
|
||||
# Phase 2E: store-level cash totals for summary view
|
||||
total_waiter_collected = sum(s.total_collected or 0.0 for s in shifts)
|
||||
store_expected_closing = (day.store_opening_cash or 0.0) + total_waiter_collected
|
||||
|
||||
return {
|
||||
"day_id": day.id,
|
||||
"status": day.status,
|
||||
@@ -425,6 +438,12 @@ def business_day_summary(
|
||||
"with_unpaid_items": with_unpaid_items,
|
||||
"active_shifts": active_shift_count,
|
||||
},
|
||||
# Phase 2E
|
||||
"store_opening_cash": day.store_opening_cash,
|
||||
"store_closing_cash": day.store_closing_cash,
|
||||
"store_cash_discrepancy": day.store_cash_discrepancy,
|
||||
"store_expected_closing": round(store_expected_closing, 2),
|
||||
"total_waiter_collected": round(total_waiter_collected, 2),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1495,6 +1495,8 @@ def shifts_export(
|
||||
"duration_hours": s.get("duration_hours", ""),
|
||||
"hourly_rate": s.get("hourly_rate_snapshot", ""),
|
||||
"shift_pay": s.get("shift_pay", ""),
|
||||
"counted_cash_end": s.get("counted_cash_end", ""),
|
||||
"cash_discrepancy": s.get("cash_discrepancy", ""),
|
||||
"starting_cash": s["starting_cash"],
|
||||
"total_collected": s["total_collected"],
|
||||
"net_to_deliver": s["net_to_deliver"],
|
||||
|
||||
@@ -90,6 +90,9 @@ def _enrich_shift(shift: WaiterShift, db: Session) -> dict:
|
||||
"hourly_rate_snapshot": shift.hourly_rate_snapshot,
|
||||
"duration_hours": pay_data["duration_hours"],
|
||||
"shift_pay": pay_data["shift_pay"],
|
||||
# Phase 2E
|
||||
"counted_cash_end": shift.counted_cash_end,
|
||||
"cash_discrepancy": shift.cash_discrepancy,
|
||||
"breaks": [
|
||||
{"id": b.id, "shift_id": b.shift_id, "started_at": _dt(b.started_at), "ended_at": _dt(b.ended_at)}
|
||||
for b in shift.breaks
|
||||
@@ -166,10 +169,16 @@ def end_shift(
|
||||
raise HTTPException(status_code=404, detail="No active shift found")
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
shift.total_collected = compute_shift_total(shift.id, db)
|
||||
total = compute_shift_total(shift.id, db)
|
||||
shift.total_collected = total
|
||||
shift.ended_at = now
|
||||
if body.notes:
|
||||
shift.notes = body.notes
|
||||
# Phase 2E: cash reconciliation
|
||||
if body.counted_cash_end is not None:
|
||||
shift.counted_cash_end = body.counted_cash_end
|
||||
expected = (shift.starting_cash or 0.0) + total
|
||||
shift.cash_discrepancy = round(body.counted_cash_end - expected, 2)
|
||||
|
||||
open_break = db.query(ShiftBreak).filter(
|
||||
ShiftBreak.shift_id == shift.id, ShiftBreak.ended_at == None
|
||||
@@ -233,10 +242,16 @@ def manager_end_shift(
|
||||
raise HTTPException(status_code=404, detail="Active shift not found")
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
shift.total_collected = compute_shift_total(shift.id, db)
|
||||
total = compute_shift_total(shift.id, db)
|
||||
shift.total_collected = total
|
||||
shift.ended_at = now
|
||||
if body.notes:
|
||||
shift.notes = body.notes
|
||||
# Phase 2E: cash reconciliation
|
||||
if body.counted_cash_end is not None:
|
||||
shift.counted_cash_end = body.counted_cash_end
|
||||
expected = (shift.starting_cash or 0.0) + total
|
||||
shift.cash_discrepancy = round(body.counted_cash_end - expected, 2)
|
||||
|
||||
open_break = db.query(ShiftBreak).filter(
|
||||
ShiftBreak.shift_id == shift.id, ShiftBreak.ended_at == None
|
||||
|
||||
Reference in New Issue
Block a user