Skip to content

Commit

Permalink
Merge pull request #14 from hmrc/ADR-796
Browse files Browse the repository at this point in the history
ADR-796: Changes for duty suspended deliveries outside of the UK
  • Loading branch information
sini-george authored Dec 11, 2023
2 parents 71f2296 + 50feb51 commit a5e9367
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.DeclareDutySuspendedDeliveriesOutsideUkFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.DeclareDutySuspendedDeliveriesOutsideUkPage
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.DeclareDutySuspendedDeliveriesOutsideUkView

import scala.concurrent.{ExecutionContext, Future}

class DeclareDutySuspendedDeliveriesOutsideUkController @Inject() (
override val messagesApi: MessagesApi,
cacheConnector: CacheConnector,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: DeclareDutySuspendedDeliveriesOutsideUkFormProvider,
val controllerComponents: MessagesControllerComponents,
view: DeclareDutySuspendedDeliveriesOutsideUkView
)(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(DeclareDutySuspendedDeliveriesOutsideUkPage) 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(DeclareDutySuspendedDeliveriesOutsideUkPage, value))
_ <- cacheConnector.set(updatedAnswers)
} yield Redirect(navigator.nextPage(DeclareDutySuspendedDeliveriesOutsideUkPage, mode, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 javax.inject.Inject
import play.api.data.Form

class DeclareDutySuspendedDeliveriesOutsideUkFormProvider @Inject() extends Mappings {

def apply(): Form[BigDecimal] =
Form(
"declare-duty-suspended-deliveries-outside-uk-input" -> bigDecimal(
"declareDutySuspendedDeliveriesOutsideUk.error.required",
"declareDutySuspendedDeliveriesOutsideUk.error.nonNumeric",
"declareDutySuspendedDeliveriesOutsideUk.error.twoDecimalPlaces"
)
.verifying(minimumValue(BigDecimal(0.01), "declareDutySuspendedDeliveriesOutsideUk.error.minimumRequired"))
.verifying(
maximumValue(BigDecimal(999999999.99), "declareDutySuspendedDeliveriesOutsideUk.error.maximumRequired")
)
)
}
26 changes: 26 additions & 0 deletions app/pages/DeclareDutySuspendedDeliveriesOutsideUkPage.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 DeclareDutySuspendedDeliveriesOutsideUkPage extends QuestionPage[BigDecimal] {

override def path: JsPath = JsPath \ toString

override def toString: String = "declareDutySuspendedDeliveriesOutsideUk"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.DeclareDutySuspendedDeliveriesOutsideUkPage
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object DeclareDutySuspendedDeliveriesOutsideUkSummary {

def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] =
answers.get(DeclareDutySuspendedDeliveriesOutsideUkPage).map { answer =>
SummaryListRowViewModel(
key = "declareDutySuspendedDeliveriesOutsideUk.checkYourAnswersLabel",
value = ValueViewModel(answer.toString),
actions = Seq(
ActionItemViewModel(
"site.change",
routes.DeclareDutySuspendedDeliveriesOutsideUkController.onPageLoad(CheckMode).url
)
.withVisuallyHiddenText(messages("declareDutySuspendedDeliveriesOutsideUk.change.hidden"))
)
)
}
}
68 changes: 68 additions & 0 deletions app/views/DeclareDutySuspendedDeliveriesOutsideUkView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@*
* 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("declareDutySuspendedDeliveriesOutsideUk.title"))) {

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

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

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

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

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

@govukInput(
InputViewModel(
field = form("declare-duty-suspended-deliveries-outside-uk-input"),
label = LabelViewModel(messages("declareDutySuspendedDeliveriesOutsideUk.heading")).asVisuallyHidden(),
)
.asNumeric()
.withWidth(Fixed10)
.withSuffix(PrefixOrSuffix(content = messages("declareDutySuspendedDeliveriesOutsideUk.inputSuffix")))
.withHint(Hint(content = messages("declareDutySuspendedDeliveriesOutsideUk.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 @@ -50,3 +50,8 @@ GET /declareDutySuspendedDeliveriesQuestion contro
POST /declareDutySuspendedDeliveriesQuestion controllers.DeclareDutySuspendedDeliveriesQuestionController.onSubmit(mode: Mode = NormalMode)
GET /changeDeclareDutySuspendedDeliveriesQuestion controllers.DeclareDutySuspendedDeliveriesQuestionController.onPageLoad(mode: Mode = CheckMode)
POST /changeDeclareDutySuspendedDeliveriesQuestion controllers.DeclareDutySuspendedDeliveriesQuestionController.onSubmit(mode: Mode = CheckMode)

GET /declareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onPageLoad(mode: Mode = NormalMode)
POST /declareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onSubmit(mode: Mode = NormalMode)
GET /changeDeclareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onPageLoad(mode: Mode = CheckMode)
POST /changeDeclareDutySuspendedDeliveriesOutsideUk controllers.DeclareDutySuspendedDeliveriesOutsideUkController.onSubmit(mode: Mode = CheckMode)
13 changes: 13 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ declareDutySuspendedDeliveriesQuestion.title = Do you need to declare alcohol yo
declareDutySuspendedDeliveriesQuestion.heading = Do you need to declare alcohol you delivered or received duty suspended?
declareDutySuspendedDeliveriesQuestion.error.required = Select yes if you need to declare any Duty Suspended Deliveries
declareDutySuspendedDeliveriesQuestion.p1 = For example, because you delivered it to a duty suspended warehouse.

declareDutySuspendedDeliveriesOutsideUk.title = How much have you delivered duty suspended outside of the UK?
declareDutySuspendedDeliveriesOutsideUk.heading = How much have you delivered duty suspended outside of the UK?
declareDutySuspendedDeliveriesOutsideUk.checkYourAnswersLabel = DeclareDutySuspendedDeliveriesOutsideUk
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.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.
Loading

0 comments on commit a5e9367

Please sign in to comment.