Skip to content

Commit

Permalink
MCSC-950 Calculate Net Change Figure (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
bharti5verma authored Nov 11, 2024
1 parent 8e57ed1 commit c877f8a
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 44 deletions.
12 changes: 8 additions & 4 deletions app/models/CalculationResults/InDatesTaxYearsCalculation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ case class InDatesTaxYearsCalculation(
revisedChargableAmountBeforeTaxRate: Int,
revisedChargableAmountAfterTaxRate: Int,
unusedAnnualAllowance: Int,
taxYearSchemes: List[InDatesTaxYearSchemeCalculation]
taxYearSchemes: List[InDatesTaxYearSchemeCalculation],
totalCompensation: Option[Int]
)

object InDatesTaxYearsCalculation {
Expand All @@ -48,7 +49,8 @@ object InDatesTaxYearsCalculation {
(__ \ "revisedChargableAmountBeforeTaxRate").read[Int] and
(__ \ "revisedChargableAmountAfterTaxRate").read[Int] and
(__ \ "unusedAnnualAllowance").read[Int] and
(__ \ "taxYearSchemes").read[List[InDatesTaxYearSchemeCalculation]]
(__ \ "taxYearSchemes").read[List[InDatesTaxYearSchemeCalculation]] and
(__ \ "totalCompensation").readNullable[Int]
)(InDatesTaxYearsCalculation.apply _)
}

Expand All @@ -66,7 +68,8 @@ object InDatesTaxYearsCalculation {
(__ \ "revisedChargableAmountBeforeTaxRate").write[Int] and
(__ \ "revisedChargableAmountAfterTaxRate").write[Int] and
(__ \ "unusedAnnualAllowance").write[Int] and
(__ \ "taxYearSchemes").write[List[InDatesTaxYearSchemeCalculation]]
(__ \ "taxYearSchemes").write[List[InDatesTaxYearSchemeCalculation]] and
(__ \ "totalCompensation").writeNullable[Int]
)(a =>
(
a.period,
Expand All @@ -78,7 +81,8 @@ object InDatesTaxYearsCalculation {
a.revisedChargableAmountBeforeTaxRate,
a.revisedChargableAmountAfterTaxRate,
a.unusedAnnualAllowance,
a.taxYearSchemes
a.taxYearSchemes,
a.totalCompensation
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ case class OutOfDatesTaxYearsCalculation(
revisedChargableAmountBeforeTaxRate: Int,
revisedChargableAmountAfterTaxRate: Int,
unusedAnnualAllowance: Int,
taxYearSchemes: List[OutOfDatesTaxYearSchemeCalculation]
taxYearSchemes: List[OutOfDatesTaxYearSchemeCalculation],
adjustedCompensation: Option[Int]
)

object OutOfDatesTaxYearsCalculation {
Expand All @@ -46,7 +47,8 @@ object OutOfDatesTaxYearsCalculation {
(__ \ "revisedChargableAmountBeforeTaxRate").read[Int] and
(__ \ "revisedChargableAmountAfterTaxRate").read[Int] and
(__ \ "unusedAnnualAllowance").read[Int] and
(__ \ "taxYearSchemes").read[List[OutOfDatesTaxYearSchemeCalculation]]
(__ \ "taxYearSchemes").read[List[OutOfDatesTaxYearSchemeCalculation]] and
(__ \ "adjustedCompensation").readNullable[Int]
)(OutOfDatesTaxYearsCalculation.apply _)

}
Expand All @@ -64,7 +66,8 @@ object OutOfDatesTaxYearsCalculation {
(__ \ "revisedChargableAmountBeforeTaxRate").write[Int] and
(__ \ "revisedChargableAmountAfterTaxRate").write[Int] and
(__ \ "unusedAnnualAllowance").write[Int] and
(__ \ "taxYearSchemes").write[List[OutOfDatesTaxYearSchemeCalculation]]
(__ \ "taxYearSchemes").write[List[OutOfDatesTaxYearSchemeCalculation]] and
(__ \ "adjustedCompensation").writeNullable[Int]
)(a =>
(
a.period,
Expand All @@ -75,7 +78,8 @@ object OutOfDatesTaxYearsCalculation {
a.revisedChargableAmountBeforeTaxRate,
a.revisedChargableAmountAfterTaxRate,
a.unusedAnnualAllowance,
a.taxYearSchemes
a.taxYearSchemes,
a.adjustedCompensation
)
)
}
Expand Down
24 changes: 9 additions & 15 deletions app/services/CalculationResultService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -718,49 +718,43 @@ class CalculationResultService @Inject() (
"calculationReview.period." + outDate.period.toString,
Some(changeInAAOutDateTaxCharge(outDate)),
controllers.routes.CalculationReviewIndividualAAController.onPageLoad(outDate.period).url,
Some(outDateTotalTaxCharge(outDate))
outDate.adjustedCompensation.map(Math.abs).orElse(Some(0))
)
)
}

private def changeInAAOutDateTaxCharge(outDate: OutOfDatesTaxYearsCalculation): String = {
val totalCharge = outDateTotalTaxCharge(outDate)
if (totalCharge == 0) {
val totalCharge = outDate.adjustedCompensation
if (totalCharge.contains(0)) {
"calculationReview.taxChargeNotChanged"
} else {
"calculationReview.taxChargeDecreasedBy"
}
}

private def outDateTotalTaxCharge(outDate: OutOfDatesTaxYearsCalculation): Int =
outDate.directCompensation + outDate.indirectCompensation

private def inDatesReview(calculationResponse: CalculationResponse): Seq[Seq[ReviewRowViewModel]] =
calculationResponse.inDates.map { inDate =>
Seq(
ReviewRowViewModel(
"calculationReview.period." + inDate.period.toString,
Some(changeInAAInDateTaxCharge(inDate)),
controllers.routes.CalculationReviewIndividualAAController.onPageLoad(inDate.period).url,
Some(abs(inDateTotalTaxCharge(inDate)))
inDate.totalCompensation.map(Math.abs).orElse(Some(0))
)
)
}

private def changeInAAInDateTaxCharge(inDate: InDatesTaxYearsCalculation): String = {
val totalCharge = inDateTotalTaxCharge(inDate)
if (totalCharge == 0) {
val totalCharge = inDate.totalCompensation
if (totalCharge.contains(0)) {
"calculationReview.taxChargeNotChanged"
} else if (totalCharge > 0) {
} else if (totalCharge.exists(_ > 0)) {
"calculationReview.taxChargeDecreasedBy"
} else {
"calculationReview.taxChargeIncreasedBy"
}
}

private def inDateTotalTaxCharge(inDate: InDatesTaxYearsCalculation): Int =
inDate.memberCredit + inDate.schemeCredit - inDate.debit

private def lifetimeAllowanceReview: Seq[ReviewRowViewModel] =
Seq(
ReviewRowViewModel(
Expand All @@ -777,7 +771,7 @@ class CalculationResultService @Inject() (
def outDatesSummary(calculationResponse: CalculationResponse): Seq[IndividualAASummaryModel] =
calculationResponse.outDates.map { outDate =>
val changeInTaxChargeAmount =
outDateTotalTaxCharge(outDate) /// outdate.totalcompensation when bhartis branch comes in
outDate.adjustedCompensation.getOrElse(0)

val messageKey = if (changeInTaxChargeAmount > 0) {
"calculationReviewIndividualAA.changeInTaxChargeString.decrease."
Expand All @@ -799,7 +793,7 @@ class CalculationResultService @Inject() (

def inDatesSummary(calculationResponse: CalculationResponse): Seq[IndividualAASummaryModel] =
calculationResponse.inDates.map { inDate =>
val changeInTaxChargeAmount = inDateTotalTaxCharge(inDate)
val changeInTaxChargeAmount = inDate.totalCompensation.getOrElse(0)

val messageKey = if (changeInTaxChargeAmount > 0) {
"calculationReviewIndividualAA.changeInTaxChargeString.decrease."
Expand Down
8 changes: 5 additions & 3 deletions app/views/CalculationReviewView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ <h2 class="govuk-heading-m">@messages("calculationReview.outDatesAA.heading")</h

<p class="govuk-body">@messages("calculationReview.outDatesAA.message2")</p>

<p class="govuk-body">@messages("calculationReview.outDatesAA.message3a") <a class="govuk-link" id="pension-scheme-pays" href="https://www.gov.uk/guidance/who-must-pay-the-pensions-annual-allowance-tax-charge">@messages("calculationReview.nextSteps.schemePays")</a>
<p class="govuk-body">@messages("calculationReview.outDatesAA.message3a")
<a class="govuk-link" id="pension-scheme-pays" href="https://www.gov.uk/guidance/who-must-pay-the-pensions-annual-allowance-tax-charge" rel="noreferrer noopener" target="_blank">@messages("calculationReview.nextSteps.schemePays")</a>
@messages("calculationReview.outDatesAA.message3b")</p>

<p class="govuk-body">@messages("calculationReview.outDatesAA.message4")</p>
Expand Down Expand Up @@ -192,7 +193,7 @@ <h2 class="govuk-heading-m">@messages("calculationReview.nextSteps.heading1")</h

<!-- no AA charge with LTA-->
@if(!isInDebit && !isInCredit && !includeCompensation2015 && isLTACompleteWithoutKickout) {
<p class="govuk-body">@messages("calculationReview.nextSteps.message.noAAChargeHasLTA ")</p>
<p class="govuk-body">@messages("calculationReview.nextSteps.message.noAAChargeHasLTA")</p>
}

@if(isUserAuthenticated) {
Expand Down Expand Up @@ -241,7 +242,8 @@ <h2 class="govuk-heading-m">@messages("calculationReview.nextSteps.heading1")</h
@if(isInDebit) {
<p class="govuk-body">@messages("calculationReview.nextSteps.message8")</p>
<div class="govuk-inset-text">
<p class="govuk-body">@messages("calculationReview.nextSteps.message9a") <a class="govuk-link" id="scheme-pays" href="https://www.gov.uk/guidance/who-must-pay-the-pensions-annual-allowance-tax-charge">@messages("calculationReview.nextSteps.schemePays")</a>
<p class="govuk-body">@messages("calculationReview.nextSteps.message9a")
<a class="govuk-link" id="scheme-pays" href="https://www.gov.uk/guidance/who-must-pay-the-pensions-annual-allowance-tax-charge" rel="noreferrer noopener" target="_blank">@messages("calculationReview.nextSteps.schemePays")</a>
@messages("calculationReview.nextSteps.message9b")</p>
<p class="govuk-body">@messages("calculationReview.nextSteps.message10")</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/PrintReviewView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h2 class="govuk-heading-m">@messages("printReview.heading.changeOutDates")</h2>
@data.map { section =>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@messages(section.title)</th>
@if(section.totalCharge.get == 0) {
@if(section.totalCharge.getOrElse(0) == 0) {
<td class="govuk-table__cell">@messages(section.changeString.get)</td>
} else {
<td class="govuk-table__cell">@messages(section.changeString.get)@section.totalCharge</td>
Expand Down Expand Up @@ -195,7 +195,7 @@ <h2 class="govuk-heading-m">@messages("printReview.heading.changeInDates")</h2>
@data.map { section =>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">@messages(section.title)</th>
@if(section.totalCharge.get == 0) {
@if(section.totalCharge.getOrElse(0) == 0) {
<td class="govuk-table__cell">@messages(section.changeString.get)</td>
} else {
<td class="govuk-table__cell">@messages(section.changeString.get)@section.totalCharge</td>
Expand Down
2 changes: 1 addition & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ features {
}

feature-flags {
calculation-review = false
calculation-review = true
}

auditing {
Expand Down
12 changes: 8 additions & 4 deletions test/resources/CalculationResultsOutDatesTestData.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
},
{
"period": "2017",
Expand All @@ -41,7 +42,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
},
{
"period": "2018",
Expand All @@ -58,7 +60,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
},
{
"period": "2019",
Expand All @@ -75,7 +78,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
}
],
"inDates": []
Expand Down
24 changes: 16 additions & 8 deletions test/resources/CalculationResultsTestData.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
},
{
"period": "2017",
Expand All @@ -41,7 +42,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 1200
},
{
"period": "2018",
Expand All @@ -58,7 +60,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
},
{
"period": "2019",
Expand All @@ -75,7 +78,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"compensation": 0
}
]
],
"adjustedCompensation": 0
}
],
"inDates": [
Expand All @@ -95,7 +99,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"chargePaidByScheme": 0
}
]
],
"totalCompensation" : 0
},
{
"period": "2021",
Expand All @@ -113,7 +118,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"chargePaidByScheme": 0
}
]
],
"totalCompensation" : 0
},
{
"period": "2022",
Expand All @@ -131,7 +137,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"chargePaidByScheme": 0
}
]
],
"totalCompensation" : 0
},
{
"period": "2023",
Expand All @@ -149,7 +156,8 @@
"pensionSchemeTaxReference": "pstrTest1",
"chargePaidByScheme": 0
}
]
],
"totalCompensation" : 0
}
]
}
9 changes: 6 additions & 3 deletions test/services/AuditServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ class AuditServiceSpec extends SpecBase with MockitoSugar {
List(
OutOfDatesTaxYearSchemeCalculation("Scheme 1", "00348916RT", 0),
OutOfDatesTaxYearSchemeCalculation("Scheme 2", "00348916RG", 0)
)
),
Some(0)
),
OutOfDatesTaxYearsCalculation(
Period._2017,
Expand All @@ -371,7 +372,8 @@ class AuditServiceSpec extends SpecBase with MockitoSugar {
List(
OutOfDatesTaxYearSchemeCalculation("Scheme 1", "00348916RT", 0),
OutOfDatesTaxYearSchemeCalculation("Scheme 2", "00348916RG", 0)
)
),
Some(1200)
),
OutOfDatesTaxYearsCalculation(
Period._2018,
Expand All @@ -385,7 +387,8 @@ class AuditServiceSpec extends SpecBase with MockitoSugar {
List(
OutOfDatesTaxYearSchemeCalculation("Scheme 1", "00348916RT", 0),
OutOfDatesTaxYearSchemeCalculation("Scheme 2", "00348916RG", 0)
)
),
Some(0)
)
),
List()
Expand Down

0 comments on commit c877f8a

Please sign in to comment.