Skip to content

Commit

Permalink
Merge pull request #13 from hmrc/ADR-797
Browse files Browse the repository at this point in the history
ADR-797 Duty Suspended Deliveries Inside UK input page
  • Loading branch information
Ewan-James-Donovan authored Dec 12, 2023
2 parents a5e9367 + bfb262c commit e9c358d
Show file tree
Hide file tree
Showing 13 changed files with 508 additions and 7 deletions.
71 changes: 71 additions & 0 deletions app/controllers/DutySuspendedDeliveriesController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package controllers

import connectors.CacheConnector
import controllers.actions._
import forms.DutySuspendedDeliveriesFormProvider
import models.Mode
import navigation.Navigator
import pages.DutySuspendedDeliveriesPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.DutySuspendedDeliveriesView

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class DutySuspendedDeliveriesController @Inject() (
override val messagesApi: MessagesApi,
cacheConnector: CacheConnector,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: DutySuspendedDeliveriesFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DutySuspendedDeliveriesView
)(implicit ec: ExecutionContext)
extends FrontendBaseController
with I18nSupport {

val form = formProvider()

def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { implicit request =>
val preparedForm = request.userAnswers.get(DutySuspendedDeliveriesPage) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, mode))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(DutySuspendedDeliveriesPage, value))
_ <- cacheConnector.set(updatedAnswers)
} yield Redirect(navigator.nextPage(DutySuspendedDeliveriesPage, mode, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeclareDutySuspendedDeliveriesOutsideUkFormProvider @Inject() extends Mapp
"declareDutySuspendedDeliveriesOutsideUk.error.nonNumeric",
"declareDutySuspendedDeliveriesOutsideUk.error.twoDecimalPlaces"
)
.verifying(minimumValue(BigDecimal(0.01), "declareDutySuspendedDeliveriesOutsideUk.error.minimumRequired"))
.verifying(minimumValue(BigDecimal(0.00), "declareDutySuspendedDeliveriesOutsideUk.error.minimumRequired"))
.verifying(
maximumValue(BigDecimal(999999999.99), "declareDutySuspendedDeliveriesOutsideUk.error.maximumRequired")
)
Expand Down
36 changes: 36 additions & 0 deletions app/forms/DutySuspendedDeliveriesFormProvider.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package forms

import forms.mappings.Mappings
import play.api.data.Form

import javax.inject.Inject

class DutySuspendedDeliveriesFormProvider @Inject() extends Mappings {

def apply(): Form[BigDecimal] =
Form(
"duty-suspended-deliveries-input" -> bigDecimal(
"dutySuspendedDeliveries.error.required",
"dutySuspendedDeliveries.error.nonNumeric",
"dutySuspendedDeliveries.error.twoDecimalPlaces"
)
.verifying(minimumValue(BigDecimal(0.00), "dutySuspendedDeliveries.error.minimumRequired"))
.verifying(maximumValue(BigDecimal(999999999.99), "dutySuspendedDeliveries.error.maximumRequired"))
)
}
10 changes: 6 additions & 4 deletions app/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ import models._
class Navigator @Inject() () {

private val normalRoutes: Page => UserAnswers => Call = {
case ProductNamePage => _ => routes.AlcoholByVolumeQuestionController.onPageLoad(NormalMode)
case AlcoholByVolumeQuestionPage => _ => routes.DraughtReliefQuestionController.onPageLoad(NormalMode)
case DraughtReliefQuestionPage => _ => routes.SmallProducerReliefQuestionController.onPageLoad(NormalMode)
case _ =>
case ProductNamePage => _ => routes.AlcoholByVolumeQuestionController.onPageLoad(NormalMode)
case AlcoholByVolumeQuestionPage => _ => routes.DraughtReliefQuestionController.onPageLoad(NormalMode)
case DraughtReliefQuestionPage => _ => routes.SmallProducerReliefQuestionController.onPageLoad(NormalMode)
case DeclareDutySuspendedDeliveriesOutsideUkPage =>
_ => routes.DutySuspendedDeliveriesController.onPageLoad(NormalMode)
case _ =>
_ => routes.IndexController.onPageLoad

}
Expand Down
26 changes: 26 additions & 0 deletions app/pages/DutySuspendedDeliveriesPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pages

import play.api.libs.json.JsPath

case object DutySuspendedDeliveriesPage extends QuestionPage[BigDecimal] {

override def path: JsPath = JsPath \ toString

override def toString: String = "dutySuspendedDeliveries"
}
40 changes: 40 additions & 0 deletions app/viewmodels/checkAnswers/DutySuspendedDeliveriesSummary.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package viewmodels.checkAnswers

import controllers.routes
import models.{CheckMode, UserAnswers}
import pages.DutySuspendedDeliveriesPage
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object DutySuspendedDeliveriesSummary {

def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] =
answers.get(DutySuspendedDeliveriesPage).map { answer =>
SummaryListRowViewModel(
key = "dutySuspendedDeliveries.checkYourAnswersLabel",
value = ValueViewModel(answer.toString),
actions = Seq(
ActionItemViewModel("site.change", routes.DutySuspendedDeliveriesController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("dutySuspendedDeliveries.change.hidden"))
)
)
}
}
65 changes: 65 additions & 0 deletions app/views/DutySuspendedDeliveriesView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@*
* Copyright 2023 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*@

@import viewmodels.InputWidth._
@import components.{Link, SectionHeading, PageHeading}
@import uk.gov.hmrc.govukfrontend.views.viewmodels.content.Empty

@this(
layout: templates.Layout,
formHelper: FormWithCSRF,
govukErrorSummary: GovukErrorSummary,
govukInput: GovukInput,
govukButton: GovukButton,
sectionHeading: SectionHeading,
pageHeading: PageHeading
)

@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages)

@layout(pageTitle = title(form, messages("dutySuspendedDeliveries.title"))) {

@formHelper(action = routes.DutySuspendedDeliveriesController.onSubmit(mode), Symbol("autoComplete") -> "off") {

@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}

@sectionHeading(
id = "duty-suspended-deliveries-section",
text = messages("section.alcoholDutyReturn"),
)

@pageHeading(messages("dutySuspendedDeliveries.heading"))

<p class="govuk-body">@messages("dutySuspendedDeliveries.p1")</p>

@govukInput(
InputViewModel(
field = form("duty-suspended-deliveries-input"),
label = LabelViewModel(messages("dutySuspendedDeliveries.heading")).asVisuallyHidden(),
)
.asNumeric()
.withWidth(Fixed10)
.withSuffix(PrefixOrSuffix(content = messages("dutySuspendedDeliveries.inputSuffix")))
.withHint(Hint(content = HtmlContent(messages("dutySuspendedDeliveries.hint"))))
)

@govukButton(
ButtonViewModel("saveAndContinueButton", messages("site.saveAndContinue"))
)
}
}
5 changes: 5 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ GET /declareDutySuspendedDeliveriesOutsideUk controllers
POST /declareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onSubmit(mode: Mode = NormalMode)
GET /changeDeclareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onPageLoad(mode: Mode = CheckMode)
POST /changeDeclareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onSubmit(mode: Mode = CheckMode)

GET /dutySuspendedDeliveries controllers.DutySuspendedDeliveriesController.onPageLoad(mode: Mode = NormalMode)
POST /dutySuspendedDeliveries controllers.DutySuspendedDeliveriesController.onSubmit(mode: Mode = NormalMode)
GET /dutySuspendedDeliveries controllers.DutySuspendedDeliveriesController.onPageLoad(mode: Mode = CheckMode)
POST /dutySuspendedDeliveries controllers.DutySuspendedDeliveriesController.onSubmit(mode: Mode = CheckMode)
15 changes: 14 additions & 1 deletion conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,22 @@ declareDutySuspendedDeliveriesOutsideUk.checkYourAnswersLabel = DeclareDutySuspe
declareDutySuspendedDeliveriesOutsideUk.error.required = Enter how much you have delivered duty suspended
declareDutySuspendedDeliveriesOutsideUk.error.nonNumeric = How much you have delivered duty suspended must be a number
declareDutySuspendedDeliveriesOutsideUk.change.hidden = DeclareDutySuspendedDeliveriesOutsideUk
declareDutySuspendedDeliveriesOutsideUk.error.minimumRequired = How much you have delivered duty suspended must be 0.01 or more
declareDutySuspendedDeliveriesOutsideUk.error.minimumRequired = How much you have delivered duty suspended must be 0.00 or more
declareDutySuspendedDeliveriesOutsideUk.error.maximumRequired = How much you have delivered duty suspended must be 999999999.99 or less
declareDutySuspendedDeliveriesOutsideUk.error.twoDecimalPlaces = How much you have delivered duty suspended must be a number to 2 decimal places
declareDutySuspendedDeliveriesOutsideUk.inputSuffix = litres
declareDutySuspendedDeliveriesOutsideUk.p1 = This includes to sites in EU countries, sites in countries outside of the EU and ship stores. This will not change your duty calculation.
declareDutySuspendedDeliveriesOutsideUk.hint = Give your answers in litres, to 2 decimal places.

dutySuspendedDeliveries.title = How much have you delivered duty suspended within the UK?
dutySuspendedDeliveries.heading = How much have you delivered duty suspended within the UK?
dutySuspendedDeliveries.p1 = For example, to UK sites that are registered to hold it duty suspended. This will not change your duty calculation.
dutySuspendedDeliveries.hint = Give your answers in litres, to 2 decimal places.
dutySuspendedDeliveries.inputSuffix = litres
dutySuspendedDeliveries.checkYourAnswersLabel = DutySuspendedDeliveries
dutySuspendedDeliveries.error.nonNumeric = How much you have delivered duty suspended must be a number
dutySuspendedDeliveries.error.required = Enter how much you have delivered duty suspended
dutySuspendedDeliveries.error.minimumRequired = How much you have delivered duty suspended must be 0.00 or more
dutySuspendedDeliveries.error.maximumRequired = How much you have delivered duty suspended must be 999999999.99 or less
dutySuspendedDeliveries.error.twoDecimalPlaces = How much you have delivered duty suspended must be a number to 2 decimal places
dutySuspendedDeliveries.change.hidden = Duty Suspended Deliveries
Loading

0 comments on commit e9c358d

Please sign in to comment.