Skip to content

fix(cash): file shift close under opening date - #1375

Merged
khaira777 merged 3 commits into
mainfrom
fm/flocafe-1360-shift-close-business-date
Oct 26, 2026
Merged

khaira777 merged 3 commits into
mainfrom
fm/flocafe-1360-shift-close-business-date

Conversation

@khaira777

@khaira777 khaira777 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix FloCafe issue #1360 (#1360): cross-midnight shift closures receive the closing business date instead of the opening business date. Verified against 46b6a7c (3.13.13): a shift opened October 25 and closed October 26 at 00:30 saved and printed October 26, while its opening float remained October 25, reproduced in UTC, Montevideo, and Sydney, with expected cash reconciling at $231.64 and zero variance. File future shift closures under the shift's opening business date calculated using the store timezone and business-day cutoff via sessionBusinessDate(db, session), while keeping actual opening/closing timestamps, daily sales attribution, and historical closures unchanged.

Fixes #1360

What Changed

  • Updated closeSessionTxn in main/routes/cash-sessions.ts to derive cash_closures.business_date from the shift's opening timestamp via sessionBusinessDate(db, session) rather than the closing wall-clock date, preserving actual opened_at/closed_at and [period_start, period_end] timestamps, daily sales boundaries, and historical closures.
  • Updated docs/architecture/business-time.md to document that shift session closures (scope = 'session') record their actual UTC [period_start, period_end] window while filing business_date under the shift's opening business date.
  • Added regression tests in tests/cash-sessions.test.ts covering cross-midnight shift closures and Z-report print/reprint output across UTC, America/Montevideo, and Australia/Sydney, custom business_day_start_time cutoffs, daylight-saving transitions, same-day closures, stale session auto-closures, and historical closures.

Risk Assessment

✅ Low: The change replaces the closing-time date calculation in closeSessionTxn with the existing sessionBusinessDate(db, session) helper, affecting only newly closed shift sessions while leaving opening/closing timestamps, daily sales boundaries, and historical closures untouched.

Testing

Ran the focused cash-sessions, cash-closures, business-date, and timezone-report-boundaries test suites, built the backend, and stood up the compiled FloCafe server against an isolated SQLite database to drive cross-midnight shift closures, 04:00 cutoff and Sydney DST transitions, stale-shift auto-close, Z-report ESC/POS printing/reprinting, daily X-report attribution, and historical closure preservation live over HTTP. This backend-only change has no UI, HTML, or CSS surface modifications, and all scenarios passed with API, database, and decoded thermal receipt evidence captured in the evidence directory.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Cross-midnight shift opened Oct 25 at 22:00 local ($200 float, $9.32 pre-midnight card sale, $31.64 post-midnight cash sale) and closed Oct 26 at 00:30 local in UTC, America/Montevideo, and Australia/… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json and ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/utc-cross-midn…
Shift closures across a non-midnight business_day_start_time cutoff (04:00, opened 2026-10-26 02:00 and closed 05:00), across an Australia/Sydney DST spring-forward transition (opened 2026-10-03 22:00… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json
Adversarial stale shift opened on effective business date 2026-10-14 (2026-10-15 02:30 America/Montevideo before 04:00 cutoff) and auto-closed 10 days later when opening a new shift on 2026-10-25 file… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json
Daily sales attribution (GET /api/reports/x-report for 2026-10-25 and 2026-10-26) continues to bound sales by each business day's window ($9.32 on Oct 25 and $31.64 on Oct 26), and pre-existing histor… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json
Evidence: Live cross-midnight shift closure HTTP, SQLite, and X-report verification JSON
{
  "serverUrl": "http://127.0.0.1:13101",
  "scenarios": {
    "crossMidnightByZone": [
      {
        "zone": "UTC",
        "timezone": "UTC",
        "openStatus": 200,
        "currentExpectedCashBeforeClose": 23164,
        "closeStatus": 200,
        "closeResponse": {
          "closure_id": 1,
          "variance_cents": 0,
          "expected_cash_cents": 23164,
          "counted_cash_cents": 23164
        },
        "floatMovement": {
          "business_date": "2026-10-25",
          "movement_type": "opening_float",
          "amount_cents": 20000,
          "created_at": "2026-10-25 22:00:00"
        },
        "sessionRow": {
          "id": 1,
          "opened_at": "2026-10-25 22:00:00",
          "closed_at": "2026-10-26 00:30:00",
          "opening_float_cents": 20000,
          "status": "closed",
          "closure_id": 1
        },
        "closureRow": {
          "id": 1,
          "scope": "session",
          "business_date": "2026-10-25",
          "period_start": "2026-10-25 22:00:00",
          "period_end": "2026-10-26 00:30:00",
          "opening_float_cents": 20000,
          "expected_cash_cents": 23164,
          "counted_cash_cents": 23164,
          "variance_cents": 0,
          "gross_collected_cents": 4096,
          "net_collected_cents": 4096,
          "bill_count": 2,
          "z_number": 1
        },
        "xReportOct25": {
          "businessDate": "2026-10-25",
          "periodStart": "2026-10-25 00:00:00",
          "periodEnd": "2026-10-26 00:00:00",
          "grossCollected": 9.32,
          "billCount": 1,
          "paymentMethods": [
            {
              "method": "card",
              "count": 1,
              "total": 9.32
            }
          ]
        },
        "xReportOct26": {
          "businessDate": "2026-10-26",
          "periodStart": "2026-10-26 00:00:00",
          "periodEnd": "2026-10-27 00:00:00",
          "grossCollected": 31.64,
          "billCount": 1,
          "paymentMethods": [
            {
              "method": "cash",
              "count": 1,
              "total": 31.64
            }
          ]
        }
      },
      {
        "zone": "Montevideo",
        "timezone": "America/Montevideo",
        "openStatus": 200,
        "currentExpectedCashBeforeClose": 23164,
        "closeStatus": 200,
        "closeResponse": {
          "closure_id": 2,
          "variance_cents": 0,
          "expected_cash_cents": 23164,
          "counted_cash_cents": 23164
        },
        "floatMovement": {
          "business_date": "2026-10-25",
          "movement_type": "opening_float",
          "amount_cents": 20000,
          "created_at": "2026-10-26 01:00:00"
        },
        "sessionRow": {
          "id": 2,
          "opened_at": "2026-10-26 01:00:00",
          "closed_at": "2026-10-26 03:30:00",
          "opening_float_cents": 20000,
          "status": "closed",
          "closure_id": 2
        },
        "closureRow": {
          "id": 2,
          "scope": "session",
          "business_date": "2026-10-25",
          "period_start": "2026-10-26 01:00:00",
          "period_end": "2026-10-26 03:30:00",
          "opening_float_cents": 20000,
          "expected_cash_cents": 23164,
          "counted_cash_cents": 23164,
          "variance_cents": 0,
          "gross_collected_cents": 4096,
          "net_collected_cents": 4096,
          "bill_count": 2,
          "z_number": 2
        }
      },
      {
        "zone": "Sydney",
        "timezone": "Australia/Sydney",
        "openStatus": 200,
        "currentExpectedCashBeforeClose": 23164,
        "closeStatus": 200,
        "closeResponse": {
          "closure_id": 3,
          "variance_cents": 0,
          "expected_cash_cents": 23164,
          "counted_cash_cents": 23164
        },
        "floatMovement": {
          "business_date": "2026-10-25",
          "movement_type": "opening_float",
          "amount_cents": 20000,
          "created_at": "2026-10-25 11:00:00"
        },
        "sessionRow": {
          "id": 3,
          "opened_at": "2026-10-25 11:00:00",
          "closed_at": "2026-10-25 13:30:00",
          "opening_float_cents": 20000,
          "status": "closed",
          "closure_id": 3
        },
        "closureRow": {
          "id": 3,
          "scope": "session",
          "business_date": "2026-10-25",
          "period_start": "2026-10-25 11:00:00",
          "period_end": "2026-10-25 13:30:00",
          "opening_float_cents": 20000,
          "expected_cash_cents": 23164,
          "counted_cash_cents": 23164,
          "variance_cents": 0,
          "gross_collected_cents": 4096,
          "net_collected_cents": 4096,
          "bill_count": 2,
          "z_number": 3
        }
      }
    ],
    "cutoffDstAndSameDay": {
      "cutoff0400": {
        "id": 4,
        "scope": "session",
        "business_date": "2026-10-25",
        "period_start": "2026-10-26 02:00:00",
        "period_end": "2026-10-26 05:00:00"
      },
      "sydneyDstSpringForward": {
        "id": 5,
        "scope": "session",
        "business_date": "2026-10-03",
        "period_start": "2026-10-03 12:00:00",
        "period_end": "2026-10-03 16:30:00"
      },
      "sameBusinessDay": {
        "id": 6,
        "scope": "session",
        "business_date": "2026-10-25",
        "period_start": "2026-10-25 10:00:00",
        "period_end": "2026-10-25 18:00:00"
      }
    },
    "staleAutoClose": {
      "staleSession": {
        "id": 7,
        "status": "closed",
        "opened_at": "2026-10-15 05:30:00",
        "closed_at": "2026-10-25 15:00:00",
        "closure_id": 7
      },
      "staleClosure": {
        "id": 7,
        "scope": "session",
        "business_date": "2026-10-14",
        "period_start": "2026-10-15 05:30:00",
        "period_end": "2026-10-25 15:00:00",
        "notes": "System auto-close: stale session, flagged for manager review"
      },
      "freshOpenStatus": 200,
      "freshCloseStatus": 200
    },
    "historicalClosurePreserved": {
      "rowAfterReprint": {
        "id": 9,
        "scope": "session",
        "business_date": "2026-10-20",
        "period_start": "2026-10-19 22:00:00",
        "period_end": "2026-10-20 00:30:00",
        "z_number": 991360
      },
      "reprintContainsHeader": true
    }
  }
}
Evidence: Decoded ESC/POS thermal Z-report receipt at close and later reprint (UTC cross-midnight shift)
=== INITIAL PRINT AT CLOSE (2026-10-26 00:30:00 UTC) ===

Z REPORT #1

==========================================
Date:                           2026-10-25
Period start:      10/25/2026, 10:00:00 PM
Period end:        10/26/2026, 12:30:00 AM
==========================================

Opening float
                                   $200.00

Cash movements
Pay in                               $0.00
Pay out                              $0.00
Safe drop                            $0.00

Sales by payment method
  Card x1                            $9.32
  Cash x1                           $31.64

Refunds
Count:                                   0
Total:                               $0.00

Tax breakdown
  (none)

Staff sales
  Live Cashier x2                   $40.96

==========================================
Expected cash
                                   $231.64
Counted cash
                                   $231.64
==========================================
Variance $0.00
------------------------------------------

Closed by: Live Cashier
Operator signature: ______________________

Generated by FloCafe
Z#1 - 2026-10-25

=== REPRINT DAYS LATER (2026-10-28 14:00:00 UTC) ===

Z REPORT #1 (REPRINT)

==========================================
Date:                           2026-10-25
Period start:      10/25/2026, 10:00:00 PM
Period end:        10/26/2026, 12:30:00 AM
==========================================

Opening float
                                   $200.00

Cash movements
Pay in                               $0.00
Pay out                              $0.00
Safe drop                            $0.00

Sales by payment method
  Card x1                            $9.32
  Cash x1                           $31.64

Refunds
Count:                                   0
Total:                               $0.00

Tax breakdown
  (none)

Staff sales
  Live Cashier x2                   $40.96

==========================================
Expected cash
                                   $231.64
Counted cash
                                   $231.64
==========================================
Variance $0.00
------------------------------------------

Closed by: Live Cashier
Operator signature: ______________________

Generated by FloCafe
Z#1 - 2026-10-25

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Cross-midnight shift opened Oct 25 at 22:00 local ($200 float, $9.32 pre-midnight card sale, $31.64 post-midnight cash sale) and closed Oct 26 at 00:30 local in UTC, America/Montevideo, and Australia/… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json and ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/utc-cross-midn…
Shift closures across a non-midnight business_day_start_time cutoff (04:00, opened 2026-10-26 02:00 and closed 05:00), across an Australia/Sydney DST spring-forward transition (opened 2026-10-03 22:00… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json
Adversarial stale shift opened on effective business date 2026-10-14 (2026-10-15 02:30 America/Montevideo before 04:00 cutoff) and auto-closed 10 days later when opening a new shift on 2026-10-25 file… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json
Daily sales attribution (GET /api/reports/x-report for 2026-10-25 and 2026-10-26) continues to bound sales by each business day's window ($9.32 on Oct 25 and $31.64 on Oct 26), and pre-existing histor… ✅ pass live ~/.no-mistakes/evidence/01M5WGX244R098951FZEP1H5NM/live-shift-close-1360-verification.json
  • npm run test:cash-sessions
  • npm run test:cash-closures
  • npm run test:business-date
  • npm run test:timezone-report-boundaries
  • npm run build
  • Live HTTP server execution against compiled dist/main/server.js (POST /api/auth/login, POST /api/cash-sessions/open, POST /api/bills/:id/payment, GET /api/cash-sessions/current, POST /api/cash-sessions/:id/close, POST /api/cash-closures/:id/print, GET /api/reports/x-report) across UTC, America/Montevideo, and Australia/Sydney
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by CodeRabbit

  • Bug Fixes

    • Cash-session closures are now assigned to the business date when the shift opened, including shifts that cross midnight or a business-day cutoff. Daily reports and day-close totals continue to use the business day’s UTC boundaries.
  • Documentation

    • Clarified how session closure dates differ from daily closure dates and specified that daily closure totals refer to the day-close Z-report.
  • Tests

    • Added coverage for time zones, business-day cutoffs, daylight-saving transitions, automatic closure, and report dates.

Use sessionBusinessDate(db, session) in closeSessionTxn() so manual and stale automatic shift closures record the opening business date in the store timezone and cutoff while preserving actual period_start, period_end, closed_at timestamps, daily reporting windows, and historical closures (fixes #1360).
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8282f3a and 6d11665.

Files selected for processing: 3
  • docs/architecture/business-time.md
  • main/routes/cash-sessions.ts
  • tests/cash-sessions.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

Cash-session closures now use the business date on which the shift opened, calculated with the store timezone and business-day cutoff. Daily reports and day-close aggregates continue to use each business day’s UTC boundaries.

Changes

Cash-session closure date

Layer / File(s) Summary
Assign the session business date
main/routes/cash-sessions.ts, docs/architecture/business-time.md
The route uses sessionBusinessDate to set a session closure’s business date. The documentation distinguishes the shift’s actual UTC closure period from the business date used to file the closure.
Check closure dates across time boundaries
tests/cash-sessions.test.ts
Tests cover cross-midnight shifts in three timezones, a 04:00 cutoff, a same-day shift, a daylight-saving transition, stale-session auto-close, and historical reprints.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • FreeOpenSourcePOS/FloCafe#1360 — The issue concerns cash-session closure dates after midnight; this change sets the closure date from the session’s opening business date.
  • FreeOpenSourcePOS/FloCafe#830 — The epic covers cash shifts and business-day cutoffs; this change addresses a business-date error in the cash-session lifecycle.
Merge Risk: Low · up to 6d116

Changing the business-day cutoff during an open shift can file its closure under the wrong date. The PR is mergeable with awareness of that limitation.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description is detailed and covers the issue, change summary, scope, risk, verification commands, test coverage, compatibility impact, and live results. It does not use all template h…
Title check Passed The title "fix(cash): file shift close under opening date" is specific and matches the main change in the changeset. The PR switches shift-session closures to use sessionBusinessDate so that a cross-m…
Full details: Description check

Explanation

The pull request description is detailed and covers the issue, change summary, scope, risk, verification commands, test coverage, compatibility impact, and live results. It does not use all template headings and does not explicitly complete the cross-cutting surfaces, developer documentation, or contributor checklist sections, but the required information is mostly present.

Full details: Title check

Explanation

The title "fix(cash): file shift close under opening date" is specific and matches the main change in the changeset. The PR switches shift-session closures to use sessionBusinessDate so that a cross-midnight shift is filed under the business date it opened on, not the date it closed. The title is short, names the area (cash), and describes the fix. The raw summary and objectives both confirm this change in cash-sessions.ts, the business-time docs, and the regression tests.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777 khaira777 changed the title fix(main): file shift closures under the shift's opening business date fix(cash): file shift close under opening date Oct 26, 2026
@khaira777
khaira777 enabled auto-merge (squash) October 26, 2026 17:58
@khaira777
khaira777 merged commit 868b546 into main Oct 26, 2026
38 of 41 checks passed
@khaira777
khaira777 deleted the fm/flocafe-1360-shift-close-business-date branch October 26, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-midnight shift close files the Z report under the next business day

1 participant