Skip to content

Commit

Permalink
Merge pull request #458 from hmrc/SASS-9705
Browse files Browse the repository at this point in the history
SASS-9705 - Foreign Property - Expenses section: Create 'Have you finished this section' page
  • Loading branch information
tapiwa-tiyemba authored Nov 28, 2024
2 parents d559690 + 1963c49 commit 6e3c0fa
Show file tree
Hide file tree
Showing 10 changed files with 459 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2024 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.expenses

import controllers.ControllerUtils.statusForPage
import controllers.actions._
import forms.foreign.expenses.ForeignExpensesSectionCompleteFormProvider
import models.JourneyPath.ForeignPropertyExpenses
import models.{JourneyContext, NormalMode}
import navigation.ForeignPropertyNavigator
import pages.foreign.expenses.ForeignExpensesSectionCompletePage
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.expenses.ForeignExpensesSectionCompleteView

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

class ForeignExpensesSectionCompleteController @Inject()(
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: ForeignPropertyNavigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
formProvider: ForeignExpensesSectionCompleteFormProvider,
val controllerComponents: MessagesControllerComponents,
view: ForeignExpensesSectionCompleteView,
journeyAnswersService: JourneyAnswersService
)(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(ForeignExpensesSectionCompletePage(countryCode)) match {
case None => form
case Some(value) => form.fill(value)
}

Ok(view(preparedForm, 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, taxYear, countryCode))),

value =>
for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(ForeignExpensesSectionCompletePage(countryCode), value))
_ <- sessionRepository.set(updatedAnswers)
status <- journeyAnswersService.setStatus(
JourneyContext(
taxYear = taxYear,
mtditid = request.user.mtditid,
nino = request.user.nino,
journeyPath = ForeignPropertyExpenses
),
status = statusForPage(value),
request.user
)
} yield Redirect(navigator.nextPage(ForeignExpensesSectionCompletePage(countryCode), taxYear, NormalMode, request.userAnswers, updatedAnswers))
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 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.expenses

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

import javax.inject.Inject

class ForeignExpensesSectionCompleteFormProvider @Inject() extends Mappings {

def apply(): Form[Boolean] =
Form(
"foreignExpensesSectionComplete" -> 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 @@ -92,4 +92,6 @@ object JourneyPath {

case object ForeignPropertyTax extends WithName("foreign-property-tax") with JourneyPath

case object ForeignPropertyExpenses extends WithName("foreign-property-expenses") with JourneyPath

}
6 changes: 6 additions & 0 deletions app/navigation/ForeignPropertyNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import models.ForeignTotalIncome.{LessThanOneThousand, OneThousandAndMore}
import models._
import pages.Page
import pages.foreign._
import pages.foreign.expenses.ForeignExpensesSectionCompletePage
import pages.foreign.income._
import play.api.mvc.Call

Expand Down Expand Up @@ -71,6 +72,11 @@ class ForeignPropertyNavigator {
ForeignReceivedGrantLeaseAmountController
.onPageLoad(taxYear, countryCode, NormalMode)
}
case ForeignExpensesSectionCompletePage(countryCode) =>
taxYear =>
_ =>
_ =>
SummaryController.show(taxYear)
case _ => _ => _ => _ => controllers.routes.IndexController.onPageLoad
}

Expand Down
16 changes: 11 additions & 5 deletions app/pages/foreign/ForeignPropertySummaryPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
package pages.foreign

import models.{NormalMode, UserAnswers}
import pages.foreign.expenses.ForeignExpensesSectionCompletePage
import pages.foreign.income.ForeignIncomeSectionCompletePage
import controllers.propertyrentals.expenses.routes.ExpensesCheckYourAnswersController
import models.{NormalMode, Rentals, UserAnswers}
import pages.enhancedstructuresbuildingallowance.EsbaSectionFinishedPage
import play.api.mvc.Call
import viewmodels.summary.{TaskListItem, TaskListTag}

case class ForeignPropertySummaryPage(
Expand Down Expand Up @@ -73,6 +70,15 @@ object ForeignPropertySummaryPage {
}
.getOrElse(TaskListTag.NotStarted)

val taskListTagForExpenses =
userAnswers
.flatMap { answers =>
answers.get(ForeignExpensesSectionCompletePage(countryCode)).map { finishedYesOrNo =>
if (finishedYesOrNo) TaskListTag.Completed else TaskListTag.InProgress
}
}
.getOrElse(TaskListTag.NotStarted)

Seq(
TaskListItem(
"foreign.tax",
Expand All @@ -89,7 +95,7 @@ object ForeignPropertySummaryPage {
TaskListItem(
"foreign.expenses",
controllers.foreign.expenses.routes.ForeignPropertyExpensesStartController.onPageLoad(taxYear, countryCode),
TaskListTag.NotStarted,
taskListTagForExpenses,
s"foreign_property_expenses_$countryCode"
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 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.expenses

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

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

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

override def toString: String = "foreignExpensesSectionComplete"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@*
* Copyright 2024 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.expenses.routes
@import viewmodels.LegendSize

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

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

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

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

@formHelper(action = routes.ForeignExpensesSectionCompleteController.onSubmit(taxYear, countryCode), Symbol("autoComplete") -> "off") {

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

@govukButton(
ButtonViewModel(messages("site.continue")).withId("continue")
)
}
}
5 changes: 4 additions & 1 deletion conf/foreign.routes
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ POST /:taxYear/foreign-property/expenses/:countryCode/change-foreign-non-r
GET /:taxYear/foreign-property/expenses/:countryCode/foreign-professional-fees controllers.foreign.expenses.ForeignProfessionalFeesController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = NormalMode)
POST /:taxYear/foreign-property/expenses/:countryCode/foreign-professional-fees controllers.foreign.expenses.ForeignProfessionalFeesController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = NormalMode)
GET /:taxYear/foreign-property/expenses/:countryCode/change-foreign-professional-fees controllers.foreign.expenses.ForeignProfessionalFeesController.onPageLoad(taxYear: Int, countryCode: String, mode: Mode = CheckMode)
POST /:taxYear/foreign-property/expenses/:countryCode/change-foreign-professional-fees controllers.foreign.expenses.ForeignProfessionalFeesController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = CheckMode)
POST /:taxYear/foreign-property/expenses/:countryCode/change-foreign-professional-fees controllers.foreign.expenses.ForeignProfessionalFeesController.onSubmit(taxYear: Int, countryCode: String, mode: Mode = CheckMode)

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

0 comments on commit 6e3c0fa

Please sign in to comment.