Skip to content
Open
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
2 changes: 1 addition & 1 deletion app/config/CurrencyFormatter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait CurrencyFormatter {
}

implicit class StringToCurrency(amt: String) {
def toCurrency: Option[String] = Try(BigDecimal(amt)).toOption.map(currencyFormat)
def toCurrency: String = Try(BigDecimal(amt)).toOption.map(currencyFormat).getOrElse(amt)
}

implicit class IntToPercentage(amt: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LeaseholdSelfAssessedPremiumPayableTaxController @Inject()(

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { implicit request =>
sdltCalculationService.whenInFlow(LeaseholdSelfAssessed) {
val premiumPayable = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.totalPremiumPayable.flatMap(_.toCurrency)))
val premiumPayable = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.totalPremiumPayable.map(_.toCurrency)))

premiumPayable match {
case Some(premiumPayable) =>
Expand All @@ -69,7 +69,7 @@ class LeaseholdSelfAssessedPremiumPayableTaxController @Inject()(

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { implicit request =>
sdltCalculationService.whenInFlowAsync(LeaseholdSelfAssessed) {
val premiumPayable = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.totalPremiumPayable.flatMap(_.toCurrency)))
val premiumPayable = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.totalPremiumPayable.map(_.toCurrency)))

premiumPayable match {
case Some(premiumPayable) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LeaseholdSelfAssessedTaxDueOnNpvController @Inject()(
def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
sdltCalculationService.whenInFlow(LeaseholdSelfAssessed) {
val npv = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.netPresentValue.flatMap(_.toCurrency)))
val npv = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.netPresentValue.map(_.toCurrency)))

npv match {
case Some(npv) =>
Expand All @@ -73,7 +73,7 @@ class LeaseholdSelfAssessedTaxDueOnNpvController @Inject()(
def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
sdltCalculationService.whenInFlowAsync(LeaseholdSelfAssessed) {
val npv = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.netPresentValue.flatMap(_.toCurrency)))
val npv = request.userAnswers.fullReturn.flatMap(_.lease.flatMap(_.netPresentValue.map(_.toCurrency)))

npv match {
case Some(npv) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

package viewmodels.checkAnswers.taxCalculation

import config.CurrencyFormatter
import play.api.i18n.Messages
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent
import viewmodels.checkAnswers.summary.SummaryRowResult
import viewmodels.checkAnswers.summary.SummaryRowResult.Row
import viewmodels.govuk.summarylist.*
import viewmodels.implicits.*

object CalculatedSdltDueSummary {
object CalculatedSdltDueSummary extends CurrencyFormatter {

def row(sdltDue: String)(implicit messages: Messages): SummaryRowResult = {
val label = messages("taxCalculation.calculatedSdltDue.checkYourAnswersLabel")

Row(
SummaryListRowViewModel(
key = label,
value = ValueViewModel(HtmlFormat.escape(s"£$sdltDue").toString)
value = ValueViewModel(HtmlContent(sdltDue.toCurrency))
)
)
}
Expand Down
14 changes: 7 additions & 7 deletions test/config/CurrencyFormatterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ class CurrencyFormatterSpec extends AnyFreeSpec with Matchers {
}

"strips the .00 suffix from a decimal string" in {
"500000.00".toCurrency mustEqual Some("£500,000")
"500000.00".toCurrency mustEqual "£500,000"
}

"formats a whole-number string" in {
"500000".toCurrency mustEqual Some("£500,000")
"500000".toCurrency mustEqual "£500,000"
}

"groups thousands with commas" in {
"1234567.00".toCurrency mustEqual Some("£1,234,567")
"1234567.00".toCurrency mustEqual "£1,234,567"
}

"returns None for a non-numeric string" in {
"my-name-is-jeff".toCurrency mustEqual None
"returns the original string for a non-numeric string" in {
"my-name-is-jeff".toCurrency mustEqual "my-name-is-jeff"
}

"returns None for an empty string" in {
"".toCurrency mustEqual None
"returns the original string for an empty string" in {
"".toCurrency mustEqual ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LeaseholdSelfAssessedPremiumPayableTaxControllerSpec extends AnyFreeSpec w
private val fullReturnWithLeaseData = emptyFullReturn.copy(lease = Some(completeLease))
val form = new LeaseholdSelfAssessedPremiumPayableTaxFormProvider()()
val premiumPayable = "50000.00"
val formattedPremiumPayable = premiumPayable.toCurrency.getOrElse("")
val formattedPremiumPayable = premiumPayable.toCurrency

lazy val premiumPayableRoute = controllers.taxCalculation.leaseholdSelfAssessed.routes.LeaseholdSelfAssessedPremiumPayableTaxController.onPageLoad(NormalMode).url

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LeaseholdSelfAssessedTaxDueOnNpvControllerSpec extends SpecBase with Mocki
val form: Form[String] = formProvider()

val npv = "95000.00"
val formattedNPV = npv.toCurrency.getOrElse("")
val formattedNPV = npv.toCurrency

private val fullReturnWithLeaseData =
emptyFullReturn.copy(lease = Some(completeLease))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CalculatedSdltDueSummarySpec extends SpecBase {

"CalculatedSdltDueSummary" - {

val sdltDue = "27,500.00"
val sdltDue = "27500"

"when the tax due on NPV is present" - {

Expand All @@ -46,7 +46,7 @@ class CalculatedSdltDueSummarySpec extends SpecBase {
result.key.content.asHtml.toString() mustEqual msgs("taxCalculation.calculatedSdltDue.checkYourAnswersLabel")

val valueHtml = result.value.content.asHtml.toString()
valueHtml mustEqual "£27,500.00"
valueHtml mustEqual "£27,500"
result.actions mustBe None
}
}
Expand Down