feat(F-191): completed feature

This commit is contained in:
chattie
2026-08-23 07:51:56 +02:00
parent eb3322e309
commit e542b180ad
10 changed files with 306 additions and 39 deletions

View File

@@ -1,22 +1,26 @@
# F-190Reporting updates from POS sales and returns
# F-191POS terminal and daily cash close reconciliation
Fix reporting capture and refresh so POS sales payments returns pending and completed states update reports.
Design and implement terminal and daily cash close balancing: card/cash returns and pending payments.
## Scope
- POS sales (POST /pos/sales) already emit `reporting_payment_lines` rows on payment — these are verified to capture correctly.
- POS returns (POST /pos/sales/:id/returns) already emit `reporting_payment_lines` with status=`refund`/`partial_refund` — these are verified to capture correctly.
- PENDING-payment sales (F-188) when they transition to COMPLETED must emit a payment line to `reporting_payment_lines` so the report shows the sale.
- Orders in `PARTIALLY_REFUNDED` and `REFUNDED` must reflect the updated totals in `reporting_payment_lines`.
- A refresh mechanism for `reporting_payment_lines` for a given order_id exists (for correction scenarios) — or a clear note that manual correction is required.
- Any gaps in `expected_cash_cents` calculation for returns are verified and fixed.
- POS cashiers can **close their session** (cash close): finalize expected vs actual cash count, handle over/short.
- `POST /pos/sessions/:id/close` accepts `actualCashCents` and calculates `varianceCents = actualCashCents - expectedCashCents`. Stores `varianceCents` and `closedAt` on `pos_cash_sessions`.
- Closed sessions can no longer accept new sales or rest-payments.
- `GET /pos/sessions/:id` returns session summary including total sales, cash received, expected cash, variance.
- `GET /pos/sessions` lists all sessions (open and closed) for a terminal or store.
- Admin view: list all cash sessions across terminals with variance. Filter by date range, store, terminal.
- `expected_cash_cents` is already maintained atomically by sale/rest-payment/return operations.
- Pending (PENDING state) POS orders from a closed session are still payable via rest-payment from an OPEN session (separate session, same terminal).
## Out of scope
- Ecommerce or admin order refunds.
- Automatic reconciliation of discrepancies (manual correction only).
- Bank deposit slip generation.
- Multi-terminal reconciliation in a single close.
- Automatic variance alerts (out of scope, can be added later).
## Acceptance
1. A PENDING sale that transitions to COMPLETED emits exactly one `reporting_payment_lines` row with the correct amount and status.
2. A fully-returned sale shows a `refund` payment line in reporting with negative amount.
3. A partially-returned sale shows a `partial_refund` payment line in reporting with the partial amount.
4. Reporting summary totals match the sum of `reporting_payment_lines` for the date range.
5. `verify.sh` green, typecheck green, all tests pass.
1. Cashier can close an open session; session transitions to `CLOSED` and `expected_cash_cents` is frozen.
2. Closing with exact cash (variance=0) is accepted without warning.
3. Closing with over/short is accepted; variance is stored and visible in admin session list.
4. No new sales can be started on a closed session.
5. Pending orders from a closed session can still be completed via rest-payment from an open session.
6. `verify.sh` green, typecheck green, all tests pass.