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
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2026 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.amend

import controllers.actions._
import forms.amend.AreYouSureYouWantToAmendYesNoFormProvider
import javax.inject.Inject
import models.Mode
import navigation.Navigator
import pages.amend.AreYouSureYouWantToAmendYesNoPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.amend.AreYouSureYouWantToAmendYesNoView

import scala.concurrent.{ExecutionContext, Future}

class AreYouSureYouWantToAmendYesNoController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: AreYouSureYouWantToAmendYesNoFormProvider,
val controllerComponents: MessagesControllerComponents,
view: AreYouSureYouWantToAmendYesNoView
)(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(AreYouSureYouWantToAmendYesNoPage) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm))
}

def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(AreYouSureYouWantToAmendYesNoPage, value))
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(navigator.nextPage(AreYouSureYouWantToAmendYesNoPage, mode, updatedAnswers))
)
}
}
31 changes: 31 additions & 0 deletions app/forms/amend/AreYouSureYouWantToAmendYesNoFormProvider.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2026 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.amend

import javax.inject.Inject

import forms.mappings.Mappings
import play.api.data.Form
import models.amend.AreYouSureYouWantToAmendYesNo

class AreYouSureYouWantToAmendYesNoFormProvider @Inject() extends Mappings {

def apply(): Form[AreYouSureYouWantToAmendYesNo] =
Form(
"value" -> enumerable[AreYouSureYouWantToAmendYesNo]("amend.areYouSureYouWantToAmendYesNo.error.required")
)
}
46 changes: 46 additions & 0 deletions app/models/amend/AreYouSureYouWantToAmendYesNo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2026 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 models.amend

import models.{Enumerable, WithName}
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.Aliases.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.RadioItem

sealed trait AreYouSureYouWantToAmendYesNo

object AreYouSureYouWantToAmendYesNo extends Enumerable.Implicits {

case object Yes extends WithName("yes") with AreYouSureYouWantToAmendYesNo
case object No extends WithName("no") with AreYouSureYouWantToAmendYesNo

val values: Seq[AreYouSureYouWantToAmendYesNo] = Seq(
Yes,
No
)

def options(implicit messages: Messages): Seq[RadioItem] = values.zipWithIndex.map { case (value, index) =>
RadioItem(
content = Text(messages(s"amend.areYouSureYouWantToAmendYesNo.${value.toString}")),
value = Some(value.toString),
id = Some(s"value_$index")
)
}

implicit val enumerable: Enumerable[AreYouSureYouWantToAmendYesNo] =
Enumerable(values.map(v => v.toString -> v): _*)
}
28 changes: 28 additions & 0 deletions app/pages/amend/AreYouSureYouWantToAmendYesNoPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2026 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.amend

import models.amend.AreYouSureYouWantToAmendYesNo
import pages.QuestionPage
import play.api.libs.json.JsPath

case object AreYouSureYouWantToAmendYesNoPage extends QuestionPage[AreYouSureYouWantToAmendYesNo] {

override def path: JsPath = JsPath \ toString

override def toString: String = "areYouSureYouWantToAmendYesNo"
}
50 changes: 50 additions & 0 deletions app/views/amend/AreYouSureYouWantToAmendYesNoView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@*
* Copyright 2026 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 models.amend.AreYouSureYouWantToAmendYesNo
@import viewmodels.LegendSize

@this(
layout: templates.Layout,
formHelper: FormWithCSRF,
govukErrorSummary: GovukErrorSummary,
govukRadios: GovukRadios,
govukButton: GovukButton
)

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

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

@formHelper(action = controllers.amend.routes.AreYouSureYouWantToAmendYesNoController.onSubmit(), Symbol("autoComplete") -> "off") {

@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form, errorLinkOverrides = Map("value" -> "value_0")))
}

@govukRadios(
RadiosViewModel(
field = form("value"),
legend = LegendViewModel(messages("amend.areYouSureYouWantToAmendYesNo.heading")).asPageHeading(LegendSize.Large),
items = AreYouSureYouWantToAmendYesNo.options
)
)

@govukButton(
ButtonViewModel(messages("site.continue"))
)
}
}
3 changes: 3 additions & 0 deletions conf/app.routes
Comment thread
jassalrichy marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@ GET /amend-monthly-return/which-subcontractors-to-add controll
POST /amend-monthly-return/which-subcontractors-to-add controllers.amend.WhichSubcontractorsToAddController.onSubmit(mode: Mode = NormalMode)
GET /amend-monthly-return/change-which-subcontractors-to-add controllers.amend.WhichSubcontractorsToAddController.onPageLoad(mode: Mode = CheckMode)
POST /amend-monthly-return/change-which-subcontractors-to-add controllers.amend.WhichSubcontractorsToAddController.onSubmit(mode: Mode = CheckMode)

GET /amend-monthly-return/are-you-sure-you-want-to-amend controllers.amend.AreYouSureYouWantToAmendYesNoController.onPageLoad(mode: Mode = NormalMode)
POST /amend-monthly-return/are-you-sure-you-want-to-amend controllers.amend.AreYouSureYouWantToAmendYesNoController.onSubmit(mode: Mode = NormalMode)
6 changes: 6 additions & 0 deletions conf/messages.en
Comment thread
jassalrichy marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,9 @@ amend.whichSubcontractorsToAdd.heading = Which subcontractor do you want to add
amend.whichSubcontractorsToAdd.checkYourAnswersLabel = Which subcontractor do you want to add to this return?
amend.whichSubcontractorsToAdd.error.required = Select a subcontractor
amend.whichSubcontractorsToAdd.change.hidden = which subcontractor do you want to add to this return?

amend.areYouSureYouWantToAmendYesNo.title = Are you sure you want to amend this return to a nil return?
amend.areYouSureYouWantToAmendYesNo.heading = Are you sure you want to amend this return to a nil return?
amend.areYouSureYouWantToAmendYesNo.yes = Yes
amend.areYouSureYouWantToAmendYesNo.no = No, I want to make a different amendment
amend.areYouSureYouWantToAmendYesNo.error.required = You must select one option to amend
6 changes: 6 additions & 0 deletions test-utils/generators/ModelGenerators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package generators

import models.amend.AreYouSureYouWantToAmendYesNo
import models.monthlyreturns.{Declaration, InactivityRequest}
import org.scalacheck.{Arbitrary, Gen}

trait ModelGenerators {

implicit lazy val arbitraryAreYouSureYouWantToAmendYesNo: Arbitrary[AreYouSureYouWantToAmendYesNo] =
Arbitrary {
Gen.oneOf(AreYouSureYouWantToAmendYesNo.values.toSeq)
}

implicit lazy val arbitraryVerifySubcontractors: Arbitrary[Boolean] =
Arbitrary {
Gen.oneOf(true, false)
Expand Down
Loading