Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMA-9175 Fixed negative taxable income to default 0 when yearly income is less than tax free amount. #131

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- Fixed negative taxable income to default 0 when income is less than tax free amount.
- Fixed default tax code comparison when Tapering not applied and yearly income above 100k.

## [2.14.1] - 2024-10-15Z
Expand Down
12 changes: 9 additions & 3 deletions src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ class Calculator @JvmOverloads constructor(
val studentLoan = StudentLoanCalculation(taxYear, yearlyWages, studentLoanPlans)
studentLoan.studentLoanClarification?.let { listOfClarification.add(it) }

val taxableIncome = amountToAddToWages?.let { kCodeAdjustedAmount ->
(yearlyWageAfterPension - taxFreeAmount) + kCodeAdjustedAmount
} ?: (yearlyWageAfterPension - taxFreeAmount)
val taxableIncome = (
amountToAddToWages?.let { kCodeAdjustedAmount ->
(yearlyWageAfterPension - taxFreeAmount) + kCodeAdjustedAmount
} ?: (yearlyWageAfterPension - taxFreeAmount)
).coerceAtLeast(ZERO)

return createResponse(
taxCodeType,
Expand Down Expand Up @@ -414,4 +416,8 @@ class Calculator @JvmOverloads constructor(
val method: PensionMethod,
val contributionAmount: Double,
)

private companion object {
const val ZERO = 0.0
}
}
36 changes: 36 additions & 0 deletions src/commonTest/kotlin/uk/gov/hmrc/calculator/CalculatorTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ import kotlin.test.assertTrue

internal class CalculatorTests {

@Test
fun `GIVEN TWENTY_TWENTY_FOUR WHEN wage is less than personal allowance THEN calculates response`() {
val result = Calculator(
taxCode = "1257L",
userSuppliedTaxCode = false,
wages = 7000.0,
payPeriod = PayPeriod.YEARLY,
taxYear = TaxYear.TWENTY_TWENTY_FOUR
).run()
Logger.i(result.prettyPrintDataClass())

assertEquals(Country.ENGLAND, result.country)
assertFalse(result.isKCode)

val yearly = result.yearly
assertEquals(PayPeriod.YEARLY, yearly.payPeriod)
assertEquals(ZERO, yearly.employeesNI)
assertEquals(ZERO, yearly.employersNI)
assertEquals(7000.00, yearly.wages)
assertEquals(12570.0, yearly.taxFree)
assertEquals(ZERO, yearly.taxToPay)
assertEquals(7000.0, yearly.takeHome)
assertEquals(ZERO, yearly.pensionContribution)
assertEquals(7000.0, yearly.wageAfterPensionDeduction)
assertEquals(ZERO, yearly.taperingAmountDeduction)
assertNull(yearly.studentLoanBreakdown)
assertEquals(ZERO, yearly.finalStudentLoanAmount)
assertEquals(ZERO, yearly.finalPostgraduateLoanAmount)
assertEquals(ZERO, yearly.otherAmount)
assertEquals(ZERO, yearly.taxableIncome)
}

@Test
fun `GIVEN TWENTY_TWENTY_ONE WHEN 40000 wage THEN calculates response`() {
val result = Calculator(
Expand Down Expand Up @@ -1957,4 +1989,8 @@ internal class CalculatorTests {

assertEquals(listOfExpectedResult, result.listOfClarification)
}

private companion object {
const val ZERO = 0.0
}
}