Skip to content

Commit

Permalink
Merge pull request #527 from hmrc/SASS-9947
Browse files Browse the repository at this point in the history
SASS-9763: Adjustments section: Create 'Have you finished this section' page
  • Loading branch information
PraneethN-Kotaru authored Jan 8, 2025
2 parents 5c59919 + d08545b commit 0e79110
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2025 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.foreign.adjustments

import controllers.ControllerUtils.statusForPage
import controllers.actions._
import controllers.statusError
import forms.foreign.adjustments.ForeignAdjustmentsCompleteFormProvider
import models.JourneyPath.ForeignPropertyAdjustments
import models.{JourneyContext, NormalMode}
import navigation.ForeignPropertyNavigator
import pages.foreign.adjustments.ForeignAdjustmentsCompletePage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import service.JourneyAnswersService
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import views.html.foreign.adjustments.ForeignAdjustmentsCompleteView

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

class ForeignAdjustmentsCompleteController @Inject()(
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
foreignPropertyNavigator: ForeignPropertyNavigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
journeyAnswersService: JourneyAnswersService,
formProvider: ForeignAdjustmentsCompleteFormProvider,
val controllerComponents: MessagesControllerComponents,
view: ForeignAdjustmentsCompleteView
)(implicit ec: ExecutionContext)
extends FrontendBaseController with I18nSupport {

val form = formProvider()

def onPageLoad(taxYear: Int, countryCode: String): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
val preparedForm = request.userAnswers.get(ForeignAdjustmentsCompletePage(countryCode)) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, NormalMode, taxYear, countryCode))
}

def onSubmit(taxYear: Int, countryCode: String): Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors => Future.successful(BadRequest(view(formWithErrors, NormalMode, taxYear, countryCode))),
value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(ForeignAdjustmentsCompletePage(countryCode), value))
_ <- sessionRepository.set(updatedAnswers)
status <- journeyAnswersService.setStatus(
ctx = JourneyContext(
taxYear = taxYear,
mtditid = request.user.mtditid,
nino = request.user.nino,
journeyPath = ForeignPropertyAdjustments
),
status = statusForPage(value),
user = request.user
)
} yield status.fold(
_ =>
//TODO: When we implement navigation story, update the route to show message from backend or error
Redirect(controllers.routes.SummaryController.show(taxYear)
),
_ =>
Redirect(
foreignPropertyNavigator.nextPage(ForeignAdjustmentsCompletePage(countryCode), taxYear, NormalMode, request.userAnswers, updatedAnswers)
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2025 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.foreign.adjustments

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

import javax.inject.Inject

class ForeignAdjustmentsCompleteFormProvider @Inject() extends Mappings {

def apply(): Form[Boolean] =
Form(
"foreignAdjustmentsCompleteYesOrNo" -> boolean("haveYouFinishedThisSection.error.required")
)
}
2 changes: 2 additions & 0 deletions app/models/JourneyPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ object JourneyPath {

case object ForeignStructureBuildingAllowance extends WithName("foreign-property-sba") with JourneyPath

case object ForeignPropertyAdjustments extends WithName("foreign-property-adjustments") with JourneyPath

}
12 changes: 10 additions & 2 deletions app/pages/foreign/ForeignPropertySummaryPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pages.foreign

import models.{NormalMode, UserAnswers}
import pages.foreign.allowances.ForeignAllowancesCompletePage
import pages.foreign.adjustments.ForeignAdjustmentsCompletePage
import pages.foreign.expenses.ForeignExpensesSectionCompletePage
import pages.foreign.income.ForeignIncomeSectionCompletePage
import pages.foreign.structurebuildingallowance.{ForeignClaimStructureBuildingAllowancePage, ForeignSbaCompletePage, ForeignStructureBuildingAllowanceGroup}
Expand Down Expand Up @@ -100,7 +101,14 @@ object ForeignPropertySummaryPage {
}
}
.getOrElse(TaskListTag.NotStarted)

val taskListTagForAdjustments =
userAnswers
.flatMap { answers =>
answers.get(ForeignAdjustmentsCompletePage(countryCode)).map { finishedYesOrNo =>
if (finishedYesOrNo) TaskListTag.Completed else TaskListTag.InProgress
}
}
.getOrElse(TaskListTag.NotStarted)
val taskList = {
Seq(
TaskListItem(
Expand All @@ -124,7 +132,7 @@ object ForeignPropertySummaryPage {
TaskListItem(
"summary.adjustments",
controllers.foreign.adjustments.routes.ForeignAdjustmentsStartController.onPageLoad(taxYear, countryCode, isClaimingAllowances.getOrElse(true)),
taskListTagForAllowances,
taskListTagForAdjustments,
s"foreign_property_adjustments_$countryCode"
)
)
Expand Down
29 changes: 29 additions & 0 deletions app/pages/foreign/adjustments/ForeignAdjustmentsCompletePage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2025 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.foreign.adjustments

import models.ForeignProperty
import pages.PageConstants.adjustmentsPath
import pages.QuestionPage
import play.api.libs.json.JsPath

case class ForeignAdjustmentsCompletePage(countryCode: String) extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ adjustmentsPath(ForeignProperty) \ countryCode.toUpperCase \ toString

override def toString: String = "foreignAdjustmentsComplete"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@*
* Copyright 2025 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 controllers.foreign.adjustments.routes._
@import viewmodels.LegendSize

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


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

@layout(pageTitle = title(form, messages("haveYouFinishedThisSection.title"))) {
@formHelper(action = ForeignAdjustmentsCompleteController.onSubmit(taxYear, countryCode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}

@govukRadios(
RadiosViewModel.yesNo(
field = form("foreignAdjustmentsCompleteYesOrNo"),
legend = LegendViewModel(messages("haveYouFinishedThisSection.heading")).asPageHeading(LegendSize.Large)
).withHint(HintViewModel(messages("haveYouFinishedThisSection.hint")))
)

@govukButton(
ButtonViewModel(messages("site.continue")).withId("continue").preventingDoubleClick()
)
}
}

@{
// $COVERAGE-OFF$
}
7 changes: 6 additions & 1 deletion conf/foreign.routes
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ POST /:taxYear/foreign-property/adjustments/:countryCode/private-use-adjus
GET /:taxYear/foreign-property/adjustments/:countryCode/change-private-use-adjustment controllers.foreign.adjustments.ForeignPrivateUseAdjustmentController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = CheckMode)
POST /:taxYear/foreign-property/adjustments/:countryCode/change-private-use-adjustment controllers.foreign.adjustments.ForeignPrivateUseAdjustmentController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = CheckMode)


GET /:taxYear/foreign-property/adjustments/:countryCode/complete-yes-no controllers.foreign.adjustments.ForeignAdjustmentsCompleteController.onPageLoad(taxYear: Int, countryCode: String)
POST /:taxYear/foreign-property/adjustments/:countryCode/complete-yes-no controllers.foreign.adjustments.ForeignAdjustmentsCompleteController.onSubmit(taxYear: Int, countryCode: String)

GET /:taxYear/foreign-property/adjustments/:countryCode/unused-residential-finance-cost controllers.foreign.adjustments.ForeignUnusedResidentialFinanceCostController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = NormalMode)
POST /:taxYear/foreign-property/adjustments/:countryCode/unused-residential-finance-cost controllers.foreign.adjustments.ForeignUnusedResidentialFinanceCostController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = NormalMode)
GET /:taxYear/foreign-property/adjustments/:countryCode/change-unused-residential-finance-cost controllers.foreign.adjustments.ForeignUnusedResidentialFinanceCostController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = CheckMode)
Expand All @@ -238,4 +242,5 @@ POST /:taxYear/foreign-property/adjustments/:countryCode/change-unused-res
GET /:taxYear/foreign-property/adjustments/:countryCode/residential-finance-costs controllers.foreign.adjustments.ForeignResidentialFinanceCostsController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = NormalMode)
POST /:taxYear/foreign-property/adjustments/:countryCode/residential-finance-costs controllers.foreign.adjustments.ForeignResidentialFinanceCostsController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = NormalMode)
GET /:taxYear/foreign-property/adjustments/:countryCode/change-residential-finance-costs controllers.foreign.adjustments.ForeignResidentialFinanceCostsController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = CheckMode)
POST /:taxYear/foreign-property/adjustments/:countryCode/change-residential-finance-costs controllers.foreign.adjustments.ForeignResidentialFinanceCostsController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = CheckMode)
POST /:taxYear/foreign-property/adjustments/:countryCode/change-residential-finance-costs controllers.foreign.adjustments.ForeignResidentialFinanceCostsController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = CheckMode)

Loading

0 comments on commit 0e79110

Please sign in to comment.