Invoice number gaps: why they happen and how to stop them (GST)

Why invoice numbers skip when a save fails, what GST expects, three fixes without new software, and the pattern Brimpa Care uses so a series never skips.

The short answer: invoice numbers skip because most software takes the next number from a database counter before the invoice is saved, so a failed or cancelled save burns a number. Under GST the invoice series must be consecutive, so every gap becomes a question at audit. The fix is to allocate the number inside the same transaction that saves the invoice, backed by a unique index, and to record a cancelled invoice instead of deleting it. If you cannot change the software, keep a cancellation register and never delete.

Disclosure: Brimpa builds Brimpa Care and Brimpa Gas, both of which use the pattern described here. This note is written by their builder.

The problem, in the owner’s words

“Bill 1047 is missing. 1046 is there, 1048 is there. Where did it go?” Nobody remembers. The software says it never existed. The accountant wants a reason, and if a GST officer asks the same question, “the computer skipped it” is not an answer anyone accepts.

Every number a person reads off a document is a promise: patient codes, bill numbers, invoice numbers, delivery challans. The series runs 1, 2, 3 with nothing missing, and anyone who checks the books expects it to.

Why it happens

The obvious way to number invoices is a database sequence: ask the database for the next number, use it. Every database offers one, and it is fast and safe against two users asking at the same moment. The problem is that the sequence hands out the number outside the transaction that saves the invoice. If the save then fails, because a validation rejects it, the network drops, the printer jams and the user cancels, the number is gone. The sequence has moved on and the next invoice gets the one after. Within a month the series has holes, each one an invoice that never existed.

This is not a bug in the database. Sequences are designed never to block, and for internal identifiers nobody reads that is exactly right. It is wrong for a number a person reads.

A second cause is simpler: someone deleted an invoice. Software that allows a hard delete turns every mistake into a gap.

What GST expects

Under India’s GST rules a tax invoice carries a consecutive serial number, unique for a financial year, and a cancelled invoice is cancelled on record, not removed (the rule is in the CGST Rules on tax invoices; check the current text with your accountant, as this note is not tax advice). Gaps are not illegal in themselves, but each one has to be explained, and a series full of them invites a closer look at everything else.

Three fixes that need no new software

  1. Never delete an invoice. Cancel it, with the date and the reason, and keep it in the series. A cancelled 1047 is an answer; a missing 1047 is a question.
  2. Keep a cancellation register for the gaps that already exist: the number, the date, why it was lost. An auditor accepts a register; they do not accept a shrug.
  3. Start a new series each financial year with a clear prefix, so a gap in one year does not confuse the next, and switch off any “auto-delete on cancel” setting in the software you have.

These three fix the audit problem for most small businesses today, with the software they already own.

The pattern that stops gaps at the source

When you build or buy software, the number should be allocated inside the same transaction that inserts the invoice. The insert reads the highest existing number for that business and that period, adds one, and writes the invoice with it. If the transaction fails, nothing was written and nothing was consumed; the next invoice takes the number the failed one would have taken.

Two things make this safe. First, the read goes through the same row-level security as everything else, so one business can never see or take another business’s numbers in a shared installation. Second, and this is the real guarantee, a unique index on the business, the period and the number. If two counters race and both compute the same next number, the second insert fails on the index and is retried, reading the new highest number. The index is the rule; the read-and-add-one is the usual case.

The retry is cheap because races are rare: two invoices at the same counter in the same millisecond. The index is what lets you sleep.

The one exception

In Brimpa Care, the IPD series, the numbers given to admitted patients, takes the lowest free number of the month rather than the highest plus one. An admission can be registered for a bed before an earlier one is closed, so an IPD number may be chosen higher than the next in line, and a month that ends first leaves the lower ones unused. Filling the lowest free slot keeps that series gap-free too. It is slower than highest plus one, it is written down as an exception with the reason, and it applies to nothing else.

What the lesson cost

It arrived as a failed restore. An earlier design kept a “counters” table, one row per series, and a backup taken mid-way left it disagreeing with the invoices it was supposed to count. Restoring the backup produced duplicate numbers on the first day. The table was removed, the pattern above replaced it, and the decision was written into the project’s rules ledger with the reason, so that nobody rebuilds a counters table in year three because it looks simpler.

Who this is not for

Internal identifiers, log entries, anything a person never reads: use the database’s sequence or a random identifier and move on. The gap-free pattern costs a read and an occasional retry per insert, and it is worth paying only for numbers that carry a promise.

A checklist for anyone building or buying billing software in India

  1. List every number a person reads: patient codes, bill numbers, receipts, invoices, challans.
  2. For each, decide the scope of the series: per business, per branch, per financial year.
  3. Allocate inside the insert’s transaction, never from a sequence.
  4. Put a unique index on the scope plus the number, and retry on a collision.
  5. No hard deletes: cancel with a reason and keep the record.
  6. Write the exceptions down with the reason.
  7. Restore a backup once and check the series before going live.

Questions people ask

Is an invoice number gap illegal under GST? The rules ask for consecutive numbering; a gap is a discrepancy to explain, not an offence by itself. Keep the cancellation register and ask your accountant about your case.

Can I reuse a cancelled invoice number? No. The cancelled invoice stays in the series with its status. Reusing a number creates two documents with one identity, which is worse than a gap.

My software says it is “GST compliant” and still skips numbers. Why? Because “compliant” usually means the invoice format, not the numbering method. Ask the vendor the one question that matters: “if a bill fails to save, is its number lost?”

Does this apply to patient numbers and challans too? Yes, to any series a person reads and an auditor may check.

Brimpa Care and Brimpa Gas both number their bills this way. If you are buying hospital or billing software, the checklist for choosing hospital management software has the rest of the questions.

All posts