Stage 2 · First Version · Chapter 17

How to Design Cash Boxes and Bank Accounts That Never Lose Money

Money lives in three records: balance, movements and ledger. Learn to cancel instead of delete, number vouchers safely, and record who did what.

Dr. Yahia Elkhouli · November 11, 2026 · 7 min read

In August 2026 the AI was repairing a customer's books. Many journal entries had been posted to the wrong cash box account, and the fix was to move them to the right ones. The work was correct, and I had approved it. Then the AI wrote me a status line saying it was "returning the 358 entries to their cash boxes".

I panicked. I wrote back, with far too many question marks, asking whether I had ever told it to change what the customer sees in his cash box. To me "cash box" means one thing: the screen where a business owner sees his money. The AI had meant the cash box's account in the ledger. The balance the customer saw never moved.

That moment taught me the central idea of this article: in a business system, money lives in more than one record, and you have to be precise about which one you mean.

The short answer

Design every cash box and bank account around three records that must always agree: the stored balance, the list of movements, and the ledger account in the books. Write a movement in the same database transaction as every balance change, cancel mistakes instead of deleting them, use one central counter for voucher numbers, and store the user from the login session on every money record. Put these protections in the database, not only in the app.

Three records of the same money

A cash box is any place cash is kept: a cashier's drawer, a sales rep's pouch, the main safe. A bank account holds money at a bank, and a mobile wallet behaves like one. Money moves through movements: a receipt voucher for money in, a payment voucher for money out, and a transfer, which is two movements, out of one box and into another.

For each box, three records should tell the same story:

  1. The stored balance, kept on the box for speed.
  2. The movements, whose sum must equal the stored balance.
  3. The ledger account, the box's account in the chart of accounts, built from journal entries.

If the balance and the movements disagree, the history has a hole. If the movements and the ledger disagree, the books are wrong even when the drawer is right.

Step 1: A balance change always writes a movement

In May 2026 we found that moving money between two employees' boxes changed both balances correctly but wrote the movement only into a separate transfers table. Neither box's movement list showed it. A check that adds up each box's movements found a small amount missing from one history. The money was fine; the story was broken.

We wrote it down as an invariant: every change to a cash box balance must insert a matching movement in the same database transaction, with no exceptions for internal transfers, opening balances or end-of-day resets. Then we built one function for all receipts and payments, and one for transfers in all four directions between boxes and banks.

THE PROMPT
Find every place in my project that changes a cash box or bank balance.
For each one, check that it also writes a movement row in the same transaction.
List the ones that don't, and the ones that do it in two separate calls.
Then create one database function for receipts and payments that does both
together and returns the new balance or a clear error.
Finally, write a read-only check comparing each box's balance with the sum
of its movements, and run it on [COMPANY NAME].

Cancel, never delete

A voucher that was a mistake is not deleted. It is canceled: it stays in place with its number, visibly struck through, and its effect on the balance is reversed. Deleting money records destroys the history you need when something goes wrong, and it breaks numbering.

In August 2026 I gave a firm instruction that no voucher may be deleted. We found seven places that could delete movements, three in the database and four in the app. Now there are none: a database trigger raises an error on any attempt. Canceled movements count as zero in every balance, and web and mobile show them with the same strike-through.

THE MISTAKE WE MADE

Canceling a transfer between two cash boxes looked up the transfer's two legs by number, but did not check whether they were already canceled. Canceling the same transfer a second time returned the money a second time: one box gained money that did not exist, and the other lost money it still had. At one company our integrity log showed it had really happened, with the same transfer canceled twice about thirty-five minutes apart. Nobody noticed, because the company's total cash did not change. No report turned red. The cancel function now skips legs that are already canceled and answers "already canceled" as a normal result.

The lesson for checks is to compare cash box by box. A total that stays right can hide money moving to the wrong place.

The same thinking applies to deleting containers. When an employee was deleted, his personal box and all its movements went too. A guard refused deletion if the balance was not zero, but a cashier hands his cash to the main box every shift, so his balance returns to zero while the box is full of real history. A zero balance is not zero history. We now archive the box instead, and for cash boxes themselves the safe path is to deactivate, never delete. A protection that lives only in the app protects only that screen.

Numbers that never collide

Every voucher and invoice has a number like REC-00042 or PAY-00117. Numbers must be unique inside a company, come from one central counter per type, and never be reused. Gaps are acceptable; duplicates are not.

Two bugs taught us to use the central helper and nothing else. Some older functions calculated the next number themselves by taking the highest existing number and stripping out everything that was not a digit. Two old receipts contained a date and time in their numbers, which became 14-digit values too big for the integer type, and saving any expense from the cashier failed with a cryptic error. In another case, several document types fell into a default branch and got the same generic prefix from their own counters, so sooner or later two vouchers collided and the uniqueness guard refused one with "this voucher number is already used". One employee pressed save three times and succeeded only three hours later.

THE PROMPT
Find every place in my database that generates a document number.
Tell me which ones use the central numbering function and which calculate
the number themselves. Also list every document type and its prefix,
and flag any two types that share the same prefix with separate counters.
Do not change any existing numbers. Propose a fix that keeps every number
already issued exactly as it is, and show me a test on a rolled-back copy.

Who did it

In August 2026 we were tracing a transfer for a customer and needed to know who made it. The record could not tell us, because the transfer function stored no user at all. Every transfer had an empty "created by".

You can sometimes reconstruct the answer from the employee's role, the devices logged in at the time and the nearby movements, but a proper audit trail works every time. My rule for every new money function is that it must record who did it, and the safest source is the login session, not a value the app sends along.

Key takeaways

Chapter 17 of the book also covers how we diagnosed cash boxes whose balance did not match their own movements.

Frequently asked questions

Why should I cancel a voucher instead of deleting it?

Deleting erases the evidence you need in a dispute and leaves a gap or a duplicate in your numbering. A canceled voucher keeps its number and shows struck through, while its effect on the balance is reversed, so the history stays complete.

How do I check that a cash box balance is correct?

Add up all its non-canceled movements and compare the result with the stored balance, then compare both with the box's ledger account. Do this for each box separately, because a correct company total can hide money sitting in the wrong box.

What is an audit trail in accounting software?

It is the record of who did each action, when, from which account and why. For every money movement, store the user from the login session, so you can answer who made it even months later.