Refactor savings tax calculation and breakdown#13
Merged
Conversation
Refactored CalculateSavingsTax to accept TaxCalculationResult and generate detailed breakdown lines for each savings tax band. Moved savings tax breakdown logic into the method, ensuring rUK/Welsh bands are always used and improving transparency in tax calculation results.
There was a problem hiding this comment.
Pull request overview
Refactors the savings tax calculation to generate a more detailed, per-band savings tax breakdown directly inside CalculateSavingsTax, and wires the breakdown into the overall TaxCalculationResult.
Changes:
- Updated
CalculateSavingsTaxto acceptTaxCalculationResultand append detailed savings breakdown lines. - Replaced the previous single “Tax on Savings” breakdown insertion at the call site with breakdown generation inside
CalculateSavingsTax. - Switched savings tax band selection to explicitly avoid Scottish bands.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+405
to
+408
| decimal incomeSoFar = taxableNonSavings; | ||
| int bandIdx = 0; | ||
| while (bandIdx < bands.Count && bands[bandIdx].UpperGrossThreshold > 0 && incomeSoFar >= bands[bandIdx].UpperGrossThreshold) | ||
| bandIdx++; |
Comment on lines
+412
to
+416
| var band = bands[bandIdx]; | ||
| decimal bandUpper = band.UpperGrossThreshold > 0 ? band.UpperGrossThreshold : decimal.MaxValue; | ||
| decimal bandWidth = bandUpper - incomeSoFar; | ||
| decimal inBand = Math.Min(savingsRemaining, bandWidth); | ||
| if (inBand > 0) |
Comment on lines
+404
to
+405
| // Find the taxable income position where savings start | ||
| decimal incomeSoFar = taxableNonSavings; |
|
|
||
| decimal startingRateAvailable = 0; | ||
| // 1. Starting rate for savings (if non-savings income after PA is below limit) | ||
| decimal nonSavingsAbovePA = Math.Max(0, nonSavingsIncome - rules.PersonalAllowance); |
Comment on lines
+374
to
+376
| // Collect breakdown lines for savings in a temporary list | ||
| var savingsBreakdown = new List<TaxBreakdownLine>(); | ||
|
|
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.
Refactored CalculateSavingsTax to accept TaxCalculationResult and generate detailed breakdown lines for each savings tax band. Moved savings tax breakdown logic into the method, ensuring rUK/Welsh bands are always used and improving transparency in tax calculation results.