Skip to content

Commit

Permalink
BST-111580 parts unavailable screen supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
michjanowicz committed Nov 15, 2024
1 parent d718699 commit a184de9
Show file tree
Hide file tree
Showing 15 changed files with 583 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.aboutyouandtheproperty

import actions.{SessionRequest, WithSessionRefiner}
import controllers.FORDataCaptureController
import form.aboutyouandtheproperty.PartsUnavailableForm.partsUnavailableForm
import models.submissions.aboutyouandtheproperty.AboutYouAndThePropertyPartTwo.updateAboutYouAndThePropertyPartTwo
import models.submissions.common.AnswersYesNo
import navigation.AboutYouAndThePropertyNavigator
import navigation.identifiers.PartsUnavailableId
import play.api.Logging
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepo
import views.html.aboutyouandtheproperty.partsUnavailable

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

@Singleton
class PartsUnavailableController @Inject() (
mcc: MessagesControllerComponents,
navigator: AboutYouAndThePropertyNavigator,
view: partsUnavailable,
withSessionRefiner: WithSessionRefiner,
@Named("session") val session: SessionRepo
)(implicit val ec: ExecutionContext)
extends FORDataCaptureController(mcc)
with I18nSupport
with Logging {

def show: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request =>
Future.successful(
Ok(
view(
request.sessionData.aboutYouAndThePropertyPartTwo.flatMap(_.partsUnavailable) match {
case Some(tiedForGoods) => partsUnavailableForm.fill(tiedForGoods)
case _ => partsUnavailableForm
},
calculateBackLink,
request.sessionData.toSummary
)
)
)
}

def submit: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request =>
continueOrSaveAsDraft[AnswersYesNo](
partsUnavailableForm,
formWithErrors =>
BadRequest(
view(
formWithErrors,
calculateBackLink,
request.sessionData.toSummary
)
),
data => {
val updatedData = updateAboutYouAndThePropertyPartTwo(_.copy(partsUnavailable = Some(data)))
session
.saveOrUpdate(updatedData)
.map(_ => Redirect(navigator.nextPage(PartsUnavailableId, updatedData).apply(updatedData)))
}
)
}

private def calculateBackLink(implicit request: SessionRequest[AnyContent]): String =
navigator.from match {
case "CYA" => controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show().url
case "TL" => s"${controllers.routes.TaskListController.show().url}#family-usage"
case _ =>
if (request.sessionData.isWelsh) {
controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsWelshController.show().url
} else {
controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsController.show().url
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepo
import views.html.aboutyouandtheproperty.threeYearsConstructed

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

@Singleton
class ThreeYearsConstructedController @Inject() (
mcc: MessagesControllerComponents,
navigator: AboutYouAndThePropertyNavigator,
view: threeYearsConstructed,
withSessionRefiner: WithSessionRefiner,
@Named("session") val session: SessionRepo
) extends FORDataCaptureController(mcc)
)(implicit val ec: ExecutionContext)
extends FORDataCaptureController(mcc)
with I18nSupport
with Logging {

Expand Down Expand Up @@ -70,8 +72,9 @@ class ThreeYearsConstructedController @Inject() (
),
data => {
val updatedData = updateAboutYouAndTheProperty(_.copy(threeYearsConstructed = Some(data)))
session.saveOrUpdate(updatedData)
Redirect(navigator.nextPage(ThreeYearsConstructedPageId, updatedData).apply(updatedData))
session
.saveOrUpdate(updatedData)
.map(_ => Redirect(navigator.nextPage(ThreeYearsConstructedPageId, updatedData).apply(updatedData)))
}
)
}
Expand Down
32 changes: 32 additions & 0 deletions app/form/aboutyouandtheproperty/PartsUnavailableForm.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 form.aboutyouandtheproperty

import form.MappingSupport.createYesNoType
import models.submissions.common.AnswersYesNo
import play.api.data.Form
import play.api.data.Forms.single

object PartsUnavailableForm {

val partsUnavailableForm: Form[AnswersYesNo] =
Form(
single(
"partsUnavailable" -> createYesNoType("error.partsUnavailable.required")
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package models.submissions.aboutyouandtheproperty
import actions.SessionRequest
import models.Session
import models.submissions.Form6010.MonthsYearDuration
import models.submissions.common.AnswersYesNo
import play.api.libs.json.{Json, OFormat}

import java.time.LocalDate
Expand All @@ -33,7 +34,8 @@ case class AboutYouAndThePropertyPartTwo(
commercialLetAvailabilityWelsh: Option[Seq[LettingAvailability]] = None,
financialEndYearDates: Option[Seq[LocalDate]] = None,
completedCommercialLettings: Option[Int] = None,
completedCommercialLettingsWelsh: Option[Seq[CompletedLettings]] = None
completedCommercialLettingsWelsh: Option[Seq[CompletedLettings]] = None,
partsUnavailable: Option[AnswersYesNo] = None
)

object AboutYouAndThePropertyPartTwo {
Expand Down
42 changes: 40 additions & 2 deletions app/navigation/AboutYouAndThePropertyNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,43 @@ class AboutYouAndThePropertyNavigator @Inject() (audit: Audit) extends Navigator
throw new RuntimeException("Invalid option exception for alternative details question routing")
}

private def completedCommercialLettingsRouting: Session => Call = answers => {
val canProceed: Boolean =
answers.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetAvailability).getOrElse(0) >= 140 &&
answers.aboutYouAndThePropertyPartTwo.flatMap(_.completedCommercialLettings).getOrElse(0) >= 70
if canProceed then controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show()
else controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show()
}

private def completedCommercialLettingsWelshRouting: Session => Call = answers => {
val canProceed: Boolean = {
val commercialLetNightsSum = answers.aboutYouAndThePropertyPartTwo
.flatMap(_.commercialLetAvailabilityWelsh)
.getOrElse(Seq.empty)
.map(_.numberOfNights)
.sum

val completedLettingsNightsSum = answers.aboutYouAndThePropertyPartTwo
.flatMap(_.completedCommercialLettingsWelsh)
.getOrElse(Seq.empty)
.map(_.numberOfNights)
.sum

commercialLetNightsSum >= 252 && completedLettingsNightsSum >= 182
}

if (canProceed)
controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show()
else
controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show()
}

private def partsUnavailableRouting: Session => Call = answers =>
answers.aboutYouAndThePropertyPartTwo.flatMap(_.partsUnavailable) match {
case Some(AnswerYes) => controllers.routes.TaskListController.show() // TODO !!!
case _ => controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show()
}

private def threeYearsConstructedRouting: Session => Call = answers =>
answers.aboutYouAndTheProperty.flatMap(_.threeYearsConstructed) match {
case Some(AnswerYes) => controllers.aboutyouandtheproperty.routes.CostsBreakdownController.show()
Expand All @@ -194,8 +231,9 @@ class AboutYouAndThePropertyNavigator @Inject() (audit: Audit) extends Navigator
CommercialLettingAvailabilityWelshId -> (_ =>
controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsWelshController.show()
),
CompletedCommercialLettingsId -> (_ => controllers.routes.TaskListController.show()), // TODO!!!
CompletedCommercialLettingsWelshId -> (_ => controllers.routes.TaskListController.show()), // TODO!!!
CompletedCommercialLettingsId -> completedCommercialLettingsRouting,
CompletedCommercialLettingsWelshId -> completedCommercialLettingsWelshRouting,
PartsUnavailableId -> partsUnavailableRouting,
AboutThePropertyPageId -> aboutThePropertyDescriptionRouting,
PropertyCurrentlyUsedPageId -> (_ => controllers.aboutyouandtheproperty.routes.WebsiteForPropertyController.show()),
WebsiteForPropertyPageId -> websiteForPropertyRouting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ case object CompletedCommercialLettingsWelshId extends Identifier {
override def toString: String = "completedCommercialLettingsWelshPage"
}

case object PartsUnavailableId extends Identifier {
override def toString: String = "partsUnavailablePage"
}

case object PlantAndTechnologyId extends Identifier {
override def toString: String = "plantAndTechnologyPage"
}
Expand Down
52 changes: 52 additions & 0 deletions app/views/aboutyouandtheproperty/partsUnavailable.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@*
* 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 models.submissions.common.AnswersYesNo
@import uk.gov.hmrc.govukfrontend.views.html.components._
@import models.pages.Summary

@this(layout: Layout,
govukButton: GovukButton,
govukRadios: GovukRadios,
formWithCSRF: FormWithCSRF
)

@(theForm: Form[AnswersYesNo],backLink: String, summary: Summary)(implicit request: Request[?], messages: Messages)

@layout(
pageHeading = messages("partsUnavailable.heading"),
showSection = true,
summary = Option(summary),
sectionName = messages("label.section.aboutTheProperty"),
backLinkUrl = backLink,
theForm = theForm
) {

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

@formWithCSRF(action = controllers.aboutyouandtheproperty.routes.PartsUnavailableController.submit()) {

@includes.radioButtonsYesNo(
govukRadios,
theForm,
"partsUnavailable",
"partsUnavailable.label",
classes = "govuk-fieldset__legend--m",
)

@includes.continueSaveAsDraftButtons(govukButton)
}
}
6 changes: 3 additions & 3 deletions app/views/taskList.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ <h2 id="aboutTheProperty" class="app-task-list__section">
session.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetDate),
session.aboutYouAndTheProperty.flatMap(_.customerDetails).isEmpty
)
@includes.taskListItem("site-construction-details", "taskList.familyUse",
controllers.routes.TaskListController.show(), // TODO,
@includes.taskListItem("family-use", "taskList.familyUse",
controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show(),
section2Completed,
session.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetDate), // TODO
session.aboutYouAndThePropertyPartTwo.flatMap(_.partsUnavailable),
session.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetDate).isEmpty
)
}
Expand Down
5 changes: 5 additions & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -2973,7 +2973,12 @@ error.commercialLettingAvailability.range = The number of nights must be a figur
error.commercialLettingAvailability.welsh.required = State how many nights was the property available in the year ending {0}
error.commercialLettingAvailability.welsh.range = Number of nights in the year ending {0} must be a number between 1 and 365

#PARTS OF THE PROPERTY UNAVAILABLE TO RENT

partsUnavailable.heading = Parts of the property unavailable for rent
partsUnavailable.p = You must declare if parts of the property are unavailable for rent as they are occupied by you or your family. This includes any accommodation used as main residence or as a second home.
partsUnavailable.label = Do you or your family occupy any part of the property as a main residence or a second home?
error.partsUnavailable.required = Select yes if you or your family occupy any part of the property

#TYPE OF RENEWABLE PLANT
renewablesPlant.heading = What type of renewables plant do you operate?
Expand Down
3 changes: 3 additions & 0 deletions conf/youAndProperty.routes
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ POST /completed-commercial-lettings controllers.aboutyouan
GET /completed-commercial-lettings-welsh controllers.aboutyouandtheproperty.CompletedCommercialLettingsWelshController.show()
POST /completed-commercial-lettings-welsh controllers.aboutyouandtheproperty.CompletedCommercialLettingsWelshController.submit()

GET /parts-unavailable controllers.aboutyouandtheproperty.PartsUnavailableController.show()
POST /parts-unavailable controllers.aboutyouandtheproperty.PartsUnavailableController.submit()

# About you and the property 6076

GET /renewables-plants controllers.aboutyouandtheproperty.RenewablesPlantController.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ class CompletedCommercialLettingsWelshControllerSpec extends TestBaseSpec {

"save the form data and redirect to the next page" in {
val res = controller().submit(
fakePostRequest.withFormUrlEncodedBody(formData(12)*)
fakePostRequest.withFormUrlEncodedBody(formData(2)*)
)
status(res) shouldBe SEE_OTHER
redirectLocation(res) shouldBe Option(controllers.routes.TaskListController.show().url) // TOD0
status(res) shouldBe SEE_OTHER
}

"return 400 and error message for invalid character" in {
Expand Down
Loading

0 comments on commit a184de9

Please sign in to comment.