Skip to content

Commit

Permalink
[PH][MIBM-126] /check-your-answers has single tax due; correct messag…
Browse files Browse the repository at this point in the history
…es (#43)
  • Loading branch information
PaulHodgson authored Oct 12, 2020
1 parent b4bae9d commit ffa9819
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import javax.inject.{Inject, Singleton}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.merchandiseinbaggagefrontend.config.AppConfig
import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.InvoiceNumberForm.form
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.AmountInPence
import uk.gov.hmrc.merchandiseinbaggagefrontend.repositories.DeclarationJourneyRepository
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.InvoiceNumberView

Expand Down Expand Up @@ -56,7 +57,7 @@ class InvoiceNumberController @Inject()(
idx,
request.goodsEntry.copy(
maybeInvoiceNumber = Some(invoiceNumber),
maybeTaxDue = Some(BigDecimal(-999.99))
maybeTaxDue = Some(AmountInPence(-9999))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import uk.gov.hmrc.merchandiseinbaggagefrontend.config.{AppConfig, ErrorHandler}
import uk.gov.hmrc.merchandiseinbaggagefrontend.connectors.PaymentConnector
import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.CheckYourAnswersFormProvider
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.api._
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.AmountInPence
import uk.gov.hmrc.merchandiseinbaggagefrontend.views.html.PaymentPage
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object TestOnlyController {
Some("France"),
Some(PurchaseDetails("99.99", Currency("Eurozone", "Euro", "EUR"))),
Some("1234560"),
Some(BigDecimal(10.11)))
Some(AmountInPence(1011)))

def sampleDeclarationJourney(sessionId: SessionId): DeclarationJourney =
DeclarationJourney(
Expand All @@ -91,7 +91,7 @@ object TestOnlyController {
Some("France"),
Some(PurchaseDetails("199.99", Currency("Eurozone", "Euro", "EUR"))),
Some("1234560"),
Some(BigDecimal(20.00))))),
Some(AmountInPence(2000))))),
maybeNameOfPersonCarryingTheGoods = Some(Name("Terry", "Test")),
maybeIsACustomsAgent = Some(true),
maybeCustomsAgentName = Some("Andy Agent"),
Expand Down
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/merchandiseinbaggagefrontend/model/Enum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ trait Enum[A <: EnumEntry] extends PlayEnum[A] {
value = Some(value.toString),
content = Text(messages(s"$baseMessageKey.${value.toString}")),
checked = form("value").value.contains(value.toString),
hint = hint(value)
hint = hint(value, messages)
)
}

protected def hint(value: A)(implicit messages: Messages): Option[Hint] = None
protected def hint(value: A, messages: Messages): Option[Hint] = None
}

object EnumFormat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package uk.gov.hmrc.merchandiseinbaggagefrontend.model.api

import play.api.libs.json.{Format, Json}
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.AmountInPence
import uk.gov.hmrc.merchandiseinbaggagefrontend.utils.ValueClassFormat


Expand All @@ -25,11 +26,6 @@ object MibReference {
implicit val format: Format[MibReference] = ValueClassFormat.format(value => MibReference.apply(value))(_.value)
}

case class AmountInPence(value: Long)
object AmountInPence {
implicit val format: Format[AmountInPence] = ValueClassFormat.formatDouble(value => AmountInPence.apply(value))(_.value)
}

case class TraderDetails(value: String)
object TraderDetails {
implicit val format: Format[TraderDetails] = ValueClassFormat.format(value => TraderDetails.apply(value))(_.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@

package uk.gov.hmrc.merchandiseinbaggagefrontend.model.core

import java.text.NumberFormat.getCurrencyInstance
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Locale.UK
import java.util.UUID.randomUUID

import play.api.i18n.Messages
import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.routes._
import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, Json, OFormat}
import uk.gov.hmrc.govukfrontend.views.Aliases.{HtmlContent, Key, SummaryList, Text, Value}
import uk.gov.hmrc.govukfrontend.views.Aliases._
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.routes._
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.currencyconversion.Currency
import uk.gov.hmrc.merchandiseinbaggagefrontend.utils.ValueClassFormat

case class SessionId(value: String)

Expand Down Expand Up @@ -54,12 +57,21 @@ object CategoryQuantityOfGoods {
implicit val format: OFormat[CategoryQuantityOfGoods] = Json.format[CategoryQuantityOfGoods]
}

case class AmountInPence(value: Long) {
val inPounds: BigDecimal = (BigDecimal(value) / 100).setScale(2)
val formattedInPounds: String = getCurrencyInstance(UK).format(inPounds)
}

object AmountInPence {
implicit val format: Format[AmountInPence] = ValueClassFormat.formatDouble(value => AmountInPence.apply(value))(_.value)
}

case class GoodsEntry(maybeCategoryQuantityOfGoods: Option[CategoryQuantityOfGoods] = None,
maybeGoodsVatRate: Option[GoodsVatRate] = None,
maybeCountryOfPurchase: Option[String] = None,
maybePurchaseDetails: Option[PurchaseDetails] = None,
maybeInvoiceNumber: Option[String] = None,
maybeTaxDue: Option[BigDecimal] = None) {
maybeTaxDue: Option[AmountInPence] = None) {

val goodsIfComplete: Option[Goods] =
for {
Expand Down Expand Up @@ -89,10 +101,10 @@ case class GoodsEntries(entries: Seq[GoodsEntry] = Seq(GoodsEntry.empty)) {
}

def patch(idx: Int, goodsEntry: GoodsEntry): GoodsEntries =
GoodsEntries(entries.updated(idx -1, goodsEntry))
GoodsEntries(entries.updated(idx - 1, goodsEntry))

def remove(idx: Int): GoodsEntries = {
if(entries.size == 1) GoodsEntries.empty
if (entries.size == 1) GoodsEntries.empty
else GoodsEntries(entries.zipWithIndex.filter(_._2 != idx - 1).map(_._1))
}
}
Expand Down Expand Up @@ -202,7 +214,7 @@ case class DeclarationJourney(sessionId: SessionId,
maybeCustomsAgent,
eori,
journeyDetails,
maybeTravellingByVehicle.getOrElse(false),
YesNo(maybeTravellingByVehicle.getOrElse(false)),
maybeRegistrationNumber
)
}
Expand All @@ -220,7 +232,7 @@ case class Goods(categoryQuantityOfGoods: CategoryQuantityOfGoods,
countryOfPurchase: String,
purchaseDetails: PurchaseDetails,
invoiceNumber: String,
taxDue: BigDecimal) {
taxDue: AmountInPence) {
def toSummaryList(idx: Int)(implicit messages: Messages): SummaryList = {
val price =
s"${purchaseDetails.amount}, ${purchaseDetails.currency.displayName}"
Expand Down Expand Up @@ -260,7 +272,9 @@ object Goods {
implicit val format: OFormat[Goods] = Json.format[Goods]
}

case class DeclarationGoods(goods: Seq[Goods])
case class DeclarationGoods(goods: Seq[Goods]) {
val totalTaxDue: AmountInPence = AmountInPence(goods.map(g => g.taxDue.value).sum.max(0))
}

object DeclarationGoods {
implicit val format: OFormat[DeclarationGoods] = Json.format[DeclarationGoods]
Expand All @@ -274,13 +288,21 @@ object CustomsAgent {
implicit val format: OFormat[CustomsAgent] = Json.format[CustomsAgent]
}

case class YesNo(yes: Boolean) {
override val toString: String = if (yes) "Yes" else "No"
}

object YesNo {
implicit val format: OFormat[YesNo] = Json.format[YesNo]
}

case class Declaration(sessionId: SessionId,
declarationGoods: DeclarationGoods,
nameOfPersonCarryingTheGoods: Name,
maybeCustomsAgent: Option[CustomsAgent],
eori: Eori,
journeyDetails: JourneyDetails,
travellingByVehicle: Boolean,
travellingByVehicle: YesNo,
maybeRegistrationNumber: Option[String] = None)

object Declaration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ object GoodsDestinations extends Enum[GoodsDestination] {

case object GreatBritain extends GoodsDestination

override def hint(value: GoodsDestination)(implicit messages: Messages): Option[Hint] =
override def hint(value: GoodsDestination, messages: Messages): Option[Hint] =
if (value == GreatBritain) Some(Hint(content = Text(messages("goodsDestination.GreatBritain.hint")))) else None
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ <h2 class="govuk-heading-m" id="main-message">@messages("checkYourAnswers.detail
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.detailsOfTheGoods.invoiceNumber")</dt>
<dd class="govuk-summary-list__value" style="text-transform: capitalize">@goods.invoiceNumber</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.detailsOfTheGoods.taxDue")</dt>
<dd class="govuk-summary-list__value" style="text-transform: capitalize">£@goods.taxDue</dd>
</div>
</dl>
<input id="@taxDue" type="hidden" name="@taxDue" value="@declaration.declarationGoods.goods.map(_.taxDue).sum">
}

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.detailsOfTheGoods.taxDue")</dt>
<dd class="govuk-summary-list__value" style="text-transform: capitalize">@declaration.declarationGoods.totalTaxDue.formattedInPounds</dd>
</div>
</dl>

<h2 class="govuk-heading-m" id="main-message">@messages("checkYourAnswers.personalDetails")</h2>

<dl class="govuk-summary-list govuk-!-margin-bottom-9">
Expand Down Expand Up @@ -108,12 +110,12 @@ <h2 class="govuk-heading-m" id="main-message">@messages("checkYourAnswers.journe
<dd class="govuk-summary-list__value" style="text-transform: capitalize">@declaration.journeyDetails.formattedDateOfArrival</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.travellingByVehicle")</dt>
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.journeyDetails.travellingByVehicle")</dt>
<dd class="govuk-summary-list__value" style="text-transform: capitalize">@declaration.travellingByVehicle</dd>
</div>
@declaration.maybeRegistrationNumber.fold(Html("")) { registrationNumber =>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.vehicleRegistrationNumber")</dt>
<dt class="govuk-summary-list__key">@messages("checkYourAnswers.journeyDetails.vehicleRegistrationNumber")</dt>
<dd class="govuk-summary-list__value" style="text-transform: capitalize">@registrationNumber</dd>
</div>
}
Expand Down
2 changes: 1 addition & 1 deletion conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ cannotUseService.href = https://www.gov.uk/guidance/making-a-full-import-declara

checkYourAnswers.title = Check your answers before making your declaration
checkYourAnswers.detailsOfTheGoods = Details of the goods
checkYourAnswers.detailsOfTheGoods.category = Item
checkYourAnswers.detailsOfTheGoods.category = Type of goods
checkYourAnswers.detailsOfTheGoods.quantity = Number of items
checkYourAnswers.detailsOfTheGoods.country = Country
checkYourAnswers.detailsOfTheGoods.price = Price paid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend

import uk.gov.hmrc.merchandiseinbaggagefrontend.controllers.testonly.TestOnlyController
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.api._
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{CategoryQuantityOfGoods, Declaration, DeclarationJourney, GoodsEntries, GoodsEntry, SessionId}
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core._

trait CoreTestData {
val payApiRequest: PayApiRequest = PayApiRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CheckYourAnswersControllerSpec extends DeclarationJourneyControllerSpec {
content must include("Check your answers before making your declaration")

content must include("Details of the goods")
content must include("Item")
content must include("Type of goods")
content must include("wine")
content must include("cheese")
content must include("Country")
Expand All @@ -48,7 +48,7 @@ class CheckYourAnswersControllerSpec extends DeclarationJourneyControllerSpec {
content must include("99.99, Eurozone Euro (EUR)")
content must include("199.99, Eurozone Euro (EUR)")
content must include("Tax due")
content must include("£10.11")
content must include("£30.11")

content must include("Personal details")
content must include("Name")
Expand All @@ -61,6 +61,10 @@ class CheckYourAnswersControllerSpec extends DeclarationJourneyControllerSpec {
content must include("Dover")
content must include("Date of arrival")
content must include(completedDeclarationJourney.maybeJourneyDetails.get.formattedDateOfArrival)
content must include("Travelling by vehicle")
content must include("Yes")
content must include("Vehicle registration number")
content must include("T5 RRY")

content must include("Now send your declaration")
content must include("I understand that:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ReviewGoodsControllerSpec extends DeclarationJourneyControllerSpec {
Some("Austria"),
Some(PurchaseDetails("10.00", Currency("test country", "test currency", "TST"))),
Some("test invoice number"),
Some(0.00)
Some(AmountInPence(0))
)

private val goodsEntries = GoodsEntries(goods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.model.api

import play.api.libs.json.Json
import uk.gov.hmrc.merchandiseinbaggagefrontend.BaseSpec
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.AmountInPence

class PayApiRequestSpec extends BaseSpec {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class DeclarationSpec extends BaseSpec with CoreTestData {
}
}

"AmountInPence" should {
"format correctly" in {
AmountInPence(0).formattedInPounds mustBe "£0.00"
AmountInPence(101).formattedInPounds mustBe "£1.01"
AmountInPence(100101).formattedInPounds mustBe "£1,001.01"
}
}

"GoodsEntry" should {
"convert to a Goods" when {
"the GoodsEntry is complete" in {
Expand Down Expand Up @@ -208,7 +216,7 @@ class DeclarationSpec extends BaseSpec with CoreTestData {
completedDeclarationJourney.maybeCustomsAgent,
completedDeclarationJourney.maybeEori.get,
completedDeclarationJourney.maybeJourneyDetails.get,
completedDeclarationJourney.maybeTravellingByVehicle.get,
YesNo(completedDeclarationJourney.maybeTravellingByVehicle.get),
completedDeclarationJourney.maybeRegistrationNumber))
}
}
Expand Down Expand Up @@ -265,6 +273,13 @@ class DeclarationSpec extends BaseSpec with CoreTestData {
}
}

"declaration goods" should {
"sum the total tax due" in {
declaration.declarationGoods.totalTaxDue mustBe AmountInPence(3011)
declaration.declarationGoods.copy(goods = Seq.empty).totalTaxDue mustBe AmountInPence(0)
}
}

"declaration" should {
"serialise and de-serialise" in {
parse(toJson(declaration).toString()).validate[Declaration].asOpt mustBe Some(declaration)
Expand Down

0 comments on commit ffa9819

Please sign in to comment.