Skip to content

fix(invoices): preserve leading zeros in invoice numbers - #76

Merged
brett-buskirk merged 1 commit into
mainfrom
fix/invoice-number-padding
Jul 28, 2026
Merged

fix(invoices): preserve leading zeros in invoice numbers#76
brett-buskirk merged 1 commit into
mainfrom
fix/invoice-number-padding

Conversation

@brett-buskirk

Copy link
Copy Markdown
Owner

What & why

Setting Next Invoice # to 0002 produced INV-2 — the leading zeros were stripped, because invoiceNextNumber is stored as a number and generateInvoiceNumber did ${prefix}${next}.

Fix — preserve the width you typed

  • Settings.invoiceNumberPadding (new, optional) — the zero-pad width.
  • Settings form — the "Next Invoice #" field is now a text input (so 0002 survives). On save, the raw digit width is captured as the padding; on load, the field shows the padded value (0002) so the width persists across re-saves.
  • generateInvoiceNumber — zero-pads to that width. padStart never truncates, so a number wider than the pad (e.g. 12345) is unaffected.

So 0002 → INV-0002, 0003 → INV-0003, and existing 4-digit numbers like 1001 are unchanged.

Verification

npm run build ✓ · npm run check:cycles ✓ · npm run test:run 239 pass (+3: padded, unpadded, and wider-than-pad). Worth a quick real check: set Next Invoice # to 0002, save, and confirm the next invoice is INV-0002.

🤖 Generated with Claude Code

Reported: setting Next Invoice # to "0002" produced INV-2 — the leading
zeros were stripped because invoiceNextNumber is stored as a number.

Preserve the width the user typed and zero-pad to it:
- Settings.invoiceNumberPadding (new, optional): the pad width.
- Settings form: the "Next Invoice #" input is now text (leading zeros
  survive); on save we capture the raw digit width as the padding, and on
  load we show the padded value so the width persists across re-saves.
- generateInvoiceNumber pads to that width (padStart never truncates, so
  larger numbers are unaffected).
- Tests for the padded / unpadded / wider-than-pad cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 28, 2026

Copy link
Copy Markdown

Deploying helm with  Cloudflare Pages  Cloudflare Pages

Latest commit: d70962e
Status: ✅  Deploy successful!
Preview URL: https://be0460ca.helm-d5s.pages.dev
Branch Preview URL: https://fix-invoice-number-padding.helm-d5s.pages.dev

View logs

@brett-buskirk brett-buskirk added the bug Something isn't working label Jul 28, 2026
@brett-buskirk brett-buskirk self-assigned this Jul 28, 2026
@brett-buskirk brett-buskirk added this to the v1.1.0 — Post-launch milestone Jul 28, 2026
@github-actions

Copy link
Copy Markdown

✅ AgentGate: Passed

4 files changed  ·  +63 -5 lines

No issues found.

Generated by AgentGate

@brett-buskirk
brett-buskirk merged commit b0e3ec0 into main Jul 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant