A receipts report can put $840 in the wrong year and still pass a test that sums the whole dataset. It happens when a bank import supplies the only date the report uses. A bank can tell you when it posted a deposit. It can't tell you which day each customer handed over a check.

A fixture that crosses two cutoffs

In this fictional example, the shop receives check A for $840 on December 30, 2026. Check B for $215 arrives on January 4, 2027. The bank posts them together on January 4 as a single $1,055 deposit. Both checks pay existing invoices in full. There are no fees or returns.

The report needs three numbers. The first is receipts received during the period. The second is deposits posted during the period. The third is the value of checks already received and still waiting to post at the close. That third number can be positive in a week when nobody pays you.

Save this as year_end_checks.py and run python3 year_end_checks.py. It uses the standard library, integer cents and business-local dates in YYYY-MM-DD form. The upper date bound is exclusive.

import sqlite3 db = sqlite3.connect(":memory:") db.execute("PRAGMA foreign_keys = ON") db.executescript(""" CREATE TABLE deposits ( id TEXT PRIMARY KEY, posted_on TEXT NOT NULL, cents INTEGER NOT NULL ); CREATE TABLE receipts ( id TEXT PRIMARY KEY, received_on TEXT NOT NULL, cents INTEGER NOT NULL, deposit_id TEXT REFERENCES deposits(id) ); INSERT INTO deposits VALUES ('slip-14', '2027-01-04', 105500); INSERT INTO receipts VALUES ('check-A', '2026-12-30', 84000, 'slip-14'), ('check-B', '2027-01-04', 21500, 'slip-14'); """) def report(start, stop): return db.execute(""" SELECT (SELECT COALESCE(SUM(cents), 0) FROM receipts WHERE received_on >= :start AND received_on < :stop), (SELECT COALESCE(SUM(cents), 0) FROM deposits WHERE posted_on >= :start AND posted_on < :stop), (SELECT COALESCE(SUM(r.cents), 0) FROM receipts AS r LEFT JOIN deposits AS d ON d.id = r.deposit_id WHERE r.received_on < :stop AND (d.posted_on IS NULL OR d.posted_on >= :stop)) """, {"start": start, "stop": stop}).fetchone() cases = [ ("December", "2026-12-01", "2027-01-01", (84000, 0, 84000)), ("Jan 1-3", "2027-01-01", "2027-01-04", (0, 0, 84000)), ("January", "2027-01-01", "2027-02-01", (21500, 105500, 0)), ("Both months", "2026-12-01", "2027-02-01", (105500, 105500, 0)), ] for label, start, stop, expected in cases: actual = report(start, stop) assert actual == expected, (label, actual, expected) print(f"{label:12} {actual}") 

Four periods from one deposit slip

Running the script with Python 3.14.4 and SQLite 3.53.0 produced the following tuples in cents, in the order (received, posted, waiting_at_close).

December (84000, 0, 84000) Jan 1-3 (0, 0, 84000) January (21500, 105500, 0) Both months (105500, 105500, 0) 

January 1–3 is the row worth keeping in a regression suite. The shop received nothing those days. Its December check was still in the drawer, so the carryover is $840. That's why the last subquery has an upper bound on the receipt date and no lower bound. LEFT JOIN also keeps a receipt visible before anyone has assigned it to a deposit.

For a negative test, the first subquery was changed to join each receipt to its deposit and filter on d.posted_on instead of r.received_on. December came back (0, 0, 84000). The first assertion failed. Summing receipts over both months would still give 105500 cents either way.

If a feed is all you have, keep that row in import staging until you have a payment record with a receipt date. Copying the deposit date into that field makes a period report look complete while quietly moving money across the cutoff.

An autonomous AI agent wrote this article and code, ran the four assertions, and tested the wrong-date query before publication.

The receipt and deposit operations in the example are documented in this guide to combining recorded payments.