What two ERPs taught me about double-entry accounting
Lessons from building the accounting side of two Laravel ERPs: balanced vouchers, reversal-only corrections, sign conventions and snapshotting what you charged.
3 min read
On this page
I'm a developer, not an accountant. But over the past year I've built the accounting side of two ERPs: one for walk-in government-service centres, one for a business-setup consultancy. Both had to turn every payment into correct double-entry bookkeeping, in a system used by cashiers all day.
Here is what I'd want to know if I were starting again.
One place writes to the ledger
Both systems are Laravel applications with a service layer: workflow, pricing, cashier shifts, commissions and accounting are separate services. The most important rule is that only the accounting service writes ledger lines. The cashier desk doesn't know which accounts a payment touches; it asks the accounting service to post it.
That service resolves the right general-ledger accounts for the service being paid for, builds the voucher and checks that it balances before anything is saved:
public function post(Voucher $voucher, array $lines): Voucher
{
return DB::transaction(function () use ($voucher, $lines) {
$debits = $credits = 0;
foreach ($lines as $line) {
$debits += $line['debit'];
$credits += $line['credit'];
}
// Compare whole minor units (fils), never floats, so the check is exact.
if ($debits !== $credits) {
throw new UnbalancedVoucher($voucher, $debits, $credits);
}
$voucher->save();
$voucher->lines()->createMany($lines);
return $voucher;
});
}If a voucher can't balance, nothing is written. A half-posted payment is far worse than a failed one.
Never edit, always reverse
This felt heavy at first. Why not just fix the amount? Because the moment you edit history, the reports you printed last week no longer match the ledger, and nobody can tell why. With reversals, every number on every old report can still be explained, and the audit trail is the ledger itself.
Before
After
Signs are a convention, so pick one
Debits and credits are not positive and negative numbers; whether a balance is "positive" depends on the account. Assets and expenses grow with debits. Liabilities, equity and income grow with credits.
We store debit and credit amounts in separate columns and only apply a sign when presenting a balance, based on the account's normal side:
public function balance(int $debits, int $credits): int
{
return $this->isCreditNormal()
? $credits - $debits // liabilities, equity, income
: $debits - $credits; // assets, expenses
}Getting this wrong doesn't break the books, which still balance, but it makes statements show negative revenue and confuses everyone who reads them. It's worth a test per account type.
Snapshot what you charged
Prices and commission rates change. A ticket from March must still show March's price and March's commission, even after the rate card is updated in June.
In the government-services ERP, a service's price is made of separate components (government fee, bank fee, typing, staff commission and service fee), with VAT switched on per component. When a ticket line is created, the resolved amounts are stamped on the line. Commission rates resolve through four tiers, from a specific agent and service down to a common rate for the service, and the result is stored on the line too. Reports read the stamped values; nothing recalculates history from today's settings.
Expect to repair data
Real systems collect strange data: double-clicked payments, interrupted requests, migrated records from an older system that never balanced in the first place. Instead of fixing these by hand in the database, both projects grew small, repeatable repair commands. One finds duplicate vouchers and reverses the extra copy. Another backfilled years of legacy wallet journals during migration. Each one logs what it changed.
The short version
Funnel every posting through one service
It owns account resolution and the balance check.
Make posted vouchers immutable
Correct with reversals, never edits.
Store debits and credits separately
Apply signs only when presenting, from each account's normal side.
Stamp prices and rates onto the transaction
History must never depend on today's configuration.
Write repair tools, not one-off fixes
Repeatable, logged and reviewed like any other code.
None of this is new to accountants. But as a developer, learning to think in vouchers and reversals made both systems simpler, because the books explain themselves.