fix: calculate tax on discounted amount and add consistent rounding#59
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Math.round(...*100)/100to all client-side discount/tax calculations.useQuoteTotalshook and seed data generator.Files changed (9)
lib/invoices/actions.ts— proportional tax reduction in calculateTotals + per-item rounding in preliminarySubtotallib/quotes/actions.ts— proportional tax reduction in updateQuoteinvoices/new/new-invoice-form.tsx— tax on discounted subtotal + roundinginvoices/[id]/edit/edit-invoice-form.tsx— samequotes/new/new-quote-form.tsx— per-item rounding + tax on discounted subtotalquotes/[id]/edit/edit-quote-form.tsx— same + added missing tax calculationlib/stores/quote-builder-store.ts— proportional tax reductioncomponents/quotes/editor/hooks/useQuoteTotals.ts— per-item roundingpackages/database/prisma/seed.ts— 2-decimal rounding instead of integerTest plan
Fixes #56
🤖 Generated with Claude Code