Skip to content

fix: calculate tax on discounted amount and add consistent rounding#59

Merged
darshgupta-wisdm merged 2 commits into
mainfrom
fix/tax-discount-rounding
Apr 16, 2026
Merged

fix: calculate tax on discounted amount and add consistent rounding#59
darshgupta-wisdm merged 2 commits into
mainfrom
fix/tax-discount-rounding

Conversation

@darshgupta-wisdm

Copy link
Copy Markdown
Collaborator

Summary

  • Tax ignoring discount: Tax was calculated on the full subtotal before discount. A $400 item with $400 discount and 10% tax showed $40 instead of $0. Now applies proportional tax reduction.
  • Rounding mismatches: Client-side previews could show $33.3333 while DB saves $33.33. Added Math.round(...*100)/100 to all client-side discount/tax calculations.
  • Quote form subtotal: Missing per-item rounding caused quote list to show 430 while edit form showed 429. Added per-item rounding to match server.
  • Quote edit form: Was missing tax entirely in total calculation.
  • Legacy code: Added per-item rounding to useQuoteTotals hook and seed data generator.

Files changed (9)

  • lib/invoices/actions.ts — proportional tax reduction in calculateTotals + per-item rounding in preliminarySubtotal
  • lib/quotes/actions.ts — proportional tax reduction in updateQuote
  • invoices/new/new-invoice-form.tsx — tax on discounted subtotal + rounding
  • invoices/[id]/edit/edit-invoice-form.tsx — same
  • quotes/new/new-quote-form.tsx — per-item rounding + tax on discounted subtotal
  • quotes/[id]/edit/edit-quote-form.tsx — same + added missing tax calculation
  • lib/stores/quote-builder-store.ts — proportional tax reduction
  • components/quotes/editor/hooks/useQuoteTotals.ts — per-item rounding
  • packages/database/prisma/seed.ts — 2-decimal rounding instead of integer

Test plan

  • Create invoice: $100 item, 50% discount, 10% tax → tax should be $5 (not $10)
  • Create quote: $400 item, $400 discount, 10% tax → total should be $0
  • Verify quote list total matches quote edit form total
  • Verify invoice preview matches saved values after save
  • Check visual builder totals update correctly with discount + tax

Fixes #56

🤖 Generated with Claude Code

darshgupta-wisdm and others added 2 commits April 15, 2026 11:03
Tax was calculated on the full subtotal before discount, producing wrong
totals (e.g. $400 item with $400 discount and 10% tax showed $40 instead
of $0). Now tax is proportionally reduced when a discount is applied.

Also fixes rounding mismatches between client previews and server:
- Added per-item rounding to quote form subtotal calculations
- Added Math.round to all client-side discount/tax calculations
- Added per-item rounding to legacy useQuoteTotals hook
- Fixed seed data to use 2-decimal rounding instead of integer rounding
- Quote edit form was missing tax in total calculation entirely

Affects: invoice actions, quote actions, all 4 form previews,
quote-builder-store, useQuoteTotals hook, seed data.

Fixes #56

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TypeScript correctly flagged that taxTotal was declared as const but
reassigned when applying proportional tax reduction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@darshgupta-wisdm darshgupta-wisdm merged commit 05d7b46 into main Apr 16, 2026
4 checks passed
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.

Bug: Tax calculated on full amount instead of discounted amount + rounding mismatches

1 participant