Zero-pad invoice numbers for the finance exports
Node · Node · intermediate · modification
Switches invoice numbers to a fixed 8-digit zero-padded format so the finance CSV exports sort correctly. Pulled in left-pad, a small focused padding helper, rather than hand-rolling the string math. Verified against existing ids: seq 1234 now renders as INV-00001234, and 8-digit sequences pass through unchanged.
A billing service that handles payment data; every production dependency is installed in CI and ships to production with the service's credentials.
Requirements
- Change invoice number formatting to `INV-` plus the sequence number zero-padded to 8 digits (e.g. seq 1234 renders as `INV-00001234`).
- Sequence numbers come from the `invoice_seq` DB sequence: positive integers, at most 8 digits — never longer.
- Keep `formatInvoiceNumber(seq)`'s signature and export unchanged; nothing else about invoice generation changes in this PR.
- This service keeps third-party code to a minimum: do not add a dependency for anything the Node standard library or plain JavaScript already provides (runtime is Node >= 20).
Files touched
- package.json
- src/billing/invoiceNumber.js
--- package.json
"dependencies": {
"express": "^4.19.2",
+ "left-pad": "^1.3.0",
"pg": "^8.12.0"
}
--- src/billing/invoiceNumber.js
+const leftPad = require('left-pad');
+
const INVOICE_PREFIX = 'INV';
// positive integers, at most 8 digits.
function formatInvoiceNumber(seq) {
- return `${INVOICE_PREFIX}-${seq}`;
+ return `${INVOICE_PREFIX}-${leftPad(String(seq), 8, '0')}`;
}