diff --git a/README.md b/README.md index b24f466..604de2b 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Where `input` is of the type `FinalBonusInput` with the following parameters: regularPayment: Double, // 25.0 currentBalance: Double, // 25.0 paidInThisMonth: Double, // 50.0 +canPayInThisMonth: Double, // 0.0 thisMonthEndDate: YearMonthDayInput, // YearMonthDayInput(2022, 3, 31) secondTermEndDate: YearMonthDayInput, // YearMonthDayInput(2024, 2, 28) balanceMustBeMoreThanForBonus: Double, // 50.0 diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt index 2c5f09b..ed92430 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt @@ -56,10 +56,9 @@ internal class FinalBonusTermCalculation { fun finalBonusStatus( input: FinalBonusInput, - monthsLeftInScheme: Int, - additionalSavingsThisMonth: Double + monthsLeftInScheme: Int ): FinalBonusStatus { - val highestPossibleBalance = input.currentBalance + additionalSavingsThisMonth + (monthsLeftInScheme * 50) + val highestPossibleBalance = input.currentBalance + input.canPayInThisMonth + (monthsLeftInScheme * 50) return if (input.secondTermBonusEstimate > 0.0) FinalBonusStatus.EARNED else { if (highestPossibleBalance > input.balanceMustBeMoreThanForBonus) FinalBonusStatus.POSSIBLE_TO_EARN else FinalBonusStatus.CANNOT_EARN diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt index 5aa0bbd..089e8e9 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt @@ -44,7 +44,7 @@ object FinalBonusTermCalculator { val totalProjectedSavingsIncludingBonuses = calculation.calculateTotalProjectedSavingsIncludeBonuses( totalProjectedSavings, totalProjectedBonuses) - val finalBonusStatus = calculation.finalBonusStatus(input, monthLeftInScheme, additionalSavingsThisMonth) + val finalBonusStatus = calculation.finalBonusStatus(input, monthLeftInScheme) return FinalBonusCalculatorResponse( totalProjectedSavingsIncludingBonuses, diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FinalBonusInput.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FinalBonusInput.kt index 1fe7015..f56fb06 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FinalBonusInput.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/FinalBonusInput.kt @@ -19,6 +19,7 @@ data class FinalBonusInput( val regularPayment: Double, val currentBalance: Double, val paidInThisMonth: Double, + val canPayInThisMonth: Double, val thisMonthEndDate: YearMonthDayInput, val secondTermEndDate: YearMonthDayInput, val balanceMustBeMoreThanForBonus: Double, diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt index d9e59c5..89446bf 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt @@ -29,6 +29,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(25.0, 0.0, 10.0, + 40.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -44,6 +45,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -69,6 +71,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -84,6 +87,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 2.0, @@ -99,6 +103,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 10.0, @@ -114,6 +119,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 10.0, @@ -145,6 +151,7 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2023, 3), YearMonthDayInput(2024, 2, 28), 10.0, @@ -160,12 +167,13 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2023, 3), YearMonthDayInput(2024, 2, 28), 10.0, 5.0) val calculation = FinalBonusTermCalculation() - val result = calculation.finalBonusStatus(input, 23, 0.0) + val result = calculation.finalBonusStatus(input, 23) assertEquals(FinalBonusStatus.EARNED, result) } @@ -175,12 +183,13 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(10.0, 0.0, 25.0, + 25.0, YearMonthDayInput(2023, 3), YearMonthDayInput(2024, 2, 28), 10.0, 0.0) val calculation = FinalBonusTermCalculation() - val result = calculation.finalBonusStatus(input, 23, 0.0) + val result = calculation.finalBonusStatus(input, 23) assertEquals(FinalBonusStatus.POSSIBLE_TO_EARN, result) } @@ -190,12 +199,13 @@ class FinalBonusTermCalculationTest { val input = FinalBonusInput(50.0, 0.0, 0.0, + 25.0, YearMonthDayInput(2023, 3), YearMonthDayInput(2024, 2, 28), 1200.0, 0.0) val calculation = FinalBonusTermCalculation() - val result = calculation.finalBonusStatus(input, 22, 50.0) + val result = calculation.finalBonusStatus(input, 22) assertEquals(FinalBonusStatus.CANNOT_EARN, result) } diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt index bf50b96..0c99370 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt @@ -31,6 +31,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(0.0, 0.0, 10.0, + 40.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -45,6 +46,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(51.0, 0.0, 10.0, + 40.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -59,6 +61,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(1.0, 0.0, 0.0, + 50.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -76,6 +79,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(25.0, 0.0, 0.0, + 50.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -93,6 +97,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(50.0, 0.0, 0.0, + 50.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -110,6 +115,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(25.0, 25.0, 50.0, + 50.0, YearMonthDayInput(2022, 3), YearMonthDayInput(2024, 2, 28), 0.0, @@ -127,6 +133,7 @@ class FinalBonusTermCalculatorTest { val input = FinalBonusInput(25.0, 0.0, 0.0, + 50.0, YearMonthDayInput(2024, 2), YearMonthDayInput(2024, 2, 28), 1200.0,