Skip to content

Commit

Permalink
Ensure breakdown works for SingleBand tax codes (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeherby authored Oct 24, 2019
1 parent cfb5eb7 commit 35740bd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,20 @@ class Calculator(
return when (taxCode) {
is StandardTaxCode, is AdjustedTaxFreeTCode, is EmergencyTaxCode, is MarriageTaxCodes ->
getTotalFromBands(adjustTaxBands(taxBands, taxCode), yearlyWages)
is NoTaxTaxCode -> yearlyWages * taxCode.taxFreeAmount
is SingleBandTax -> yearlyWages * taxBands[taxCode.taxAllAtBand].percentageAsDecimal
is NoTaxTaxCode -> getTotalFromSingleBand(yearlyWages, taxCode.taxFreeAmount)
is SingleBandTax -> getTotalFromSingleBand(yearlyWages, taxBands[taxCode.taxAllAtBand].percentageAsDecimal)
is KTaxCode ->
getTotalFromBands(adjustTaxBands(taxBands, taxCode), yearlyWages + taxCode.amountToAddToWages)
else -> throw InvalidTaxCodeException("$this is an invalid tax code")
}
}

private fun getTotalFromSingleBand(yearlyWage: Double, percentageForSingleBand: Double): Double {
val taxToPayForSingleBand: Double = yearlyWage * percentageForSingleBand
bandBreakdown.add(BandBreakdown(percentageForSingleBand, taxToPayForSingleBand))
return taxToPayForSingleBand
}

private fun adjustTaxBands(taxBands: List<Band>, taxCode: TaxCode): List<Band> {
// The full tax free amount e.g. 12509
val bandAdjuster = getDefaultTaxAllowance(taxYear, taxCode.country)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ class CalculatorResponseTests {
assertEquals(300.0, response.employersNI)
assertEquals(300.0, response.totalDeductions)
assertEquals(700.0, response.takeHome)
assertEquals(listOf(
BandBreakdown(0.0, 0.0),
BandBreakdown(0.2, 2000.0)
), response.taxBreakdown)
assertEquals(
listOf(
BandBreakdown(0.0, 0.0),
BandBreakdown(0.2, 2000.0)
), response.taxBreakdown
)
assertEquals(12509.0, response.taxFree)
}

Expand Down Expand Up @@ -324,4 +326,37 @@ class CalculatorResponseTests {
), response.weekly.taxBreakdown
)
}

@Test
fun `SD2`() {
val taxCode = "SD2"
val wages = 130000.00
val response = Calculator(taxCode, wages, payPeriod = YEARLY).run()

assertEquals(66364.16, response.yearly.totalDeductions)
assertEquals(
listOf(
BandBreakdown(
percentage = 0.46,
amount = 59800.00
)
), response.yearly.taxBreakdown
)
}
@Test
fun `NT`() {
val taxCode = "NT"
val wages = 130000.00
val response = Calculator(taxCode, wages, payPeriod = YEARLY).run()

assertEquals(6564.16, response.yearly.totalDeductions)
assertEquals(
listOf(
BandBreakdown(
percentage = 0.00,
amount = 0.00
)
), response.yearly.taxBreakdown
)
}
}

0 comments on commit 35740bd

Please sign in to comment.