Skip to content

Add per-user invoice numbers (schema, API, UI, PDF) and sequence trac…#59

Merged
grmbyrn merged 1 commit into
mainfrom
wl-43
Apr 2, 2026
Merged

Add per-user invoice numbers (schema, API, UI, PDF) and sequence trac…#59
grmbyrn merged 1 commit into
mainfrom
wl-43

Conversation

@grmbyrn
Copy link
Copy Markdown
Owner

@grmbyrn grmbyrn commented Apr 2, 2026

…king

Summary by CodeRabbit

  • New Features
    • Invoices now have unique, formatted invoice numbers (INV-001, INV-002, etc.)
    • Invoice numbers display prominently in the invoices table alongside client information
    • PDF exports now include the invoice number and use it in the downloaded filename

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
worklog Ready Ready Preview, Comment Apr 2, 2026 5:55pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16acc34b-9219-4bc6-917d-eab0171c432a

📥 Commits

Reviewing files that changed from the base of the PR and between 88329ef and 7ed8049.

📒 Files selected for processing (4)
  • app/api/invoices/route.ts
  • app/invoices/page.tsx
  • prisma/migrations/20260402160748_add_invoice_number_and_sequence/migration.sql
  • prisma/schema.prisma

📝 Walkthrough

Walkthrough

This pull request introduces per-user invoice numbering using Prisma transactions. The API handler now upserts a sequence record for each user to generate formatted invoice numbers (INV-XXXX), stores the number in the database, and displays it across the frontend UI and PDF exports.

Changes

Cohort / File(s) Summary
Database Schema
prisma/schema.prisma, prisma/migrations/20260402160748_add_invoice_number_and_sequence/migration.sql
Added new InvoiceSequence model to track per-user invoice numbering state with lastNumber counter. Extended Invoice model with optional invoiceNumber field and composite uniqueness constraint on (userId, invoiceNumber). Established foreign key relation with cascade delete.
Invoice API Handler
app/api/invoices/route.ts
Wrapped invoice creation in a Prisma transaction that upserts a per-user sequence record (incrementing lastNumber), generates formatted invoice number (INV- + zero-padded), and creates the invoice with the assigned number.
Frontend Display
app/invoices/page.tsx
Extended Invoice interface with optional invoiceNumber field. Updated table UI to display invoice number as primary identifier with client name as secondary line. Modified PDF generation to use invoice number in filename and display it in PDF layout, with fallback to invoice ID.

Sequence Diagram

sequenceDiagram
    actor Client
    participant API as API Handler
    participant DB as Prisma<br/>(Transaction)
    participant Seq as InvoiceSequence<br/>Table
    participant Inv as Invoice<br/>Table

    Client->>API: POST /invoices (invoiceData)
    API->>DB: prisma.$transaction()
    DB->>Seq: upsert InvoiceSequence<br/>(userId, lastNumber++)
    Seq-->>DB: sequence record<br/>(updated lastNumber)
    DB->>DB: format invoiceNumber<br/>(INV-XXXX)
    DB->>Inv: create Invoice<br/>(with invoiceNumber)
    Inv-->>DB: created invoice<br/>(+ relations)
    DB-->>API: transaction result
    API-->>Client: 200 OK<br/>(invoice with number)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Numbers flow with sequence grace,
Per user, numbered in their place,
INV- marks each invoice clean,
The finest numbering ever seen!
Transactions safe, transactions sound,
Invoice tracking, data-bound!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding per-user invoice numbers with sequence tracking across schema, API, UI, and PDF components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wl-43

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@grmbyrn grmbyrn merged commit 7f0cd9c into main Apr 2, 2026
4 checks passed
@grmbyrn grmbyrn deleted the wl-43 branch April 2, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant