diff --git a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt index ba049b6..b13c1c2 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt @@ -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, taxCode: TaxCode): List { // The full tax free amount e.g. 12509 val bandAdjuster = getDefaultTaxAllowance(taxYear, taxCode.country) diff --git a/src/commonTest/kotlin/uk/gov/hmrc/calculator/model/CalculatorResponseTests.kt b/src/commonTest/kotlin/uk/gov/hmrc/calculator/model/CalculatorResponseTests.kt index a16641d..450d64b 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/calculator/model/CalculatorResponseTests.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/calculator/model/CalculatorResponseTests.kt @@ -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) } @@ -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 + ) + } }