Skip to content
Merged
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
Expand Up @@ -23,6 +23,7 @@ import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingActio
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar
import uk.gov.hmrc.ngrraldfrontend.models.components.Yes
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreedRentChangeForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreedRentChangeForm.form
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
Expand Down Expand Up @@ -71,7 +72,11 @@ class AgreedRentChangeController @Inject()(agreedRentChangeView: AgreedRentChang
credId = CredId(request.credId.getOrElse("")),
agreedRentChange = radioValue.radioValue
)
Future.successful(Redirect(routes.WhatTypeOfLeaseRenewalController.show.url))
if(radioValue.radioValue == "Yes"){
Future.successful(Redirect(routes.ProvideDetailsOfFirstSecondRentPeriodController.show.url))
}else {
Future.successful(Redirect(routes.WhatTypeOfLeaseRenewalController.show.url))
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ class AgreementController @Inject()(view: AgreementView,
formWithErrors =>
val correctedFormErrors = formWithErrors.errors.map { formError =>
(formError.key, formError.messages) match
case ("", messages) if messages.contains("agreement.radio.breakClause.required.error") =>
case ("", messages) if messages.contains("agreement.radio.conditional.breakClause.required.error") =>
formError.copy(key = "about-break-clause")
case ("", messages) if messages.contains("agreement.radio.breakClause.tooLong.error") =>
case ("", messages) if messages.contains("agreement.radio.conditional.breakClause.tooLong.error") =>
formError.copy(key = "about-break-clause")
case ("", messages) =>
formError.copy(key = "agreementEndDate")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* 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 uk.gov.hmrc.ngrraldfrontend.controllers

import play.api.data.Form
import play.api.i18n.{I18nSupport, Messages}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import play.twirl.api.Html
import uk.gov.hmrc.govukfrontend.views.Aliases.*
import uk.gov.hmrc.govukfrontend.views.viewmodels.dateinput.DateInput
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar
import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm.form
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
import uk.gov.hmrc.ngrraldfrontend.views.html.ProvideDetailsOfFirstSecondRentPeriodView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

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

class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDetailsOfFirstSecondRentPeriodView,
authenticate: AuthRetrievals,
inputText: InputText,
hasLinkedProperties: PropertyLinkingAction,
raldRepo: RaldRepo,
mcc: MessagesControllerComponents
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {

def firstDateStartInput()(implicit messages: Messages) : DateInput = DateInput(
id = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date",
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date"),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.label")),
classes = "govuk-fieldset__legend--s",
isPageHeading = true
))
)),
hint = Some(Hint(
id = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint"),
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint"))
))
)

def firstDateEndInput()(implicit messages: Messages): DateInput = DateInput(
id = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date",
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date"),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.label")),
classes = "govuk-fieldset__legend--s",
isPageHeading = true
))
)),
hint = Some(Hint(
id = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint"),
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint"))
))
)

private def firstRentPeriodYesButton(form: Form[ProvideDetailsOfFirstSecondRentPeriodForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons(
radioContent = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.yes",
radioValue = yesPayedRent,
conditionalHtml = Some(inputText(
form = form,
id = "RentPeriodAmount",
name = "RentPeriodAmount",
label = messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint.bold"),
isVisible = true,
hint = Some(Hint(
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint"))
)),
classes = Some("govuk-input--width-10"),
prefix = Some(PrefixOrSuffix(content = Text("£")))
))
)

private def firstRentPeriodRadio(form: Form[ProvideDetailsOfFirstSecondRentPeriodForm])(implicit messages: Messages): NGRRadio = {
val ngrRadioButtons: Seq[NGRRadioButtons] = Seq(
firstRentPeriodYesButton(form),
NGRRadioButtons(radioContent = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.no", radioValue = noRentPayed),
)
NGRRadio(
NGRRadioName("provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio"),
ngrTitle = Some(Legend(content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.label")), classes = "govuk-fieldset__legend--m", isPageHeading = true)),
NGRRadioButtons = ngrRadioButtons
)
}

def secondDateStartInput()(implicit messages: Messages): DateInput = DateInput(
id = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date",
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date"),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.label")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add this to the messages file please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also need to provide a message for this error as well provideDetailsOfFirstSecondRentPeriod.second.startDate.required.error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I click Yes in the first rent period to the Do you pay rent in this period, an error doesn't show . It shows all the other errors but nothing for the currency input

classes = "govuk-fieldset__legend--s",
isPageHeading = true
))
)),
hint = Some(Hint(
id = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint"),
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint"))
))
)

def secondDateEndInput()(implicit messages: Messages): DateInput = DateInput(
id = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date",
namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date"),
fieldset = Some(Fieldset(
legend = Some(Legend(
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.label")),
classes = "govuk-fieldset__legend--s",
isPageHeading = true
))
)),
hint = Some(Hint(
id = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint"),
content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint"))
))
)

def show: Action[AnyContent] = {
(authenticate andThen hasLinkedProperties).async { implicit request =>
request.propertyLinking.map(property =>
Future.successful(Ok(view(
navigationBarContent = createDefaultNavBar,
selectedPropertyAddress = property.addressFull,
form,
firstDateStartInput(),
firstDateEndInput(),
buildRadios(form, firstRentPeriodRadio(form)),
secondDateStartInput(),
secondDateEndInput()
)))
).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
}
}

def submit: Action[AnyContent] = {
(authenticate andThen hasLinkedProperties).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors =>
val correctedFormErrors = formWithErrors.errors.map { formError =>
(formError.key, formError.messages) match
case ("", messages) =>
formError.copy(key = "RentPeriodAmount")
case _ =>
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)

request.propertyLinking.map(property =>
Future.successful(BadRequest(view(
createDefaultNavBar,
selectedPropertyAddress = property.addressFull,
formWithCorrectedErrors,
firstDateStartInput(),
firstDateEndInput(),
buildRadios(formWithErrors, firstRentPeriodRadio(formWithCorrectedErrors)),
secondDateStartInput(),
secondDateEndInput()
)))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
provideDetailsOfFirstSecondRentPeriodForm =>
raldRepo.insertProvideDetailsOfFirstSecondRentPeriod(
CredId(request.credId.getOrElse("")),
provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio,
provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount,
provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent,
)
Future.successful(Redirect(routes.WhatIsYourRentBasedOnController.show.url))
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 uk.gov.hmrc.ngrraldfrontend.models

import play.api.libs.json.{Json, OFormat}

case class ProvideDetailsOfFirstSecondRentPeriod(
firstDateStart: String,
firstDateEnd: String,
firstRentPeriodRadio: Boolean,
firstRentPeriodAmount: Option[String],
secondDateStart: String,
secondDateEnd: String,
secondHowMuchIsRent: String
)

object ProvideDetailsOfFirstSecondRentPeriod {
implicit val format: OFormat[ProvideDetailsOfFirstSecondRentPeriod] = Json.format[ProvideDetailsOfFirstSecondRentPeriod]
}
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ final case class RaldUserAnswers(
agreedRentChange: Option[String] = None,
agreementVerbal: Option[AgreementVerbal] = None,
hasRentFreePeriod: Option[Boolean] = None,
agreement: Option[Agreement] = None
agreement: Option[Agreement] = None,
provideDetailsOfFirstSecondRentPeriod: Option[ProvideDetailsOfFirstSecondRentPeriod] = None
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ case object NoOpenEnded extends Agreement
case object YesBreakClause extends Agreement
case object NoBreakClause extends Agreement

sealed trait firstRentPeriod extends RadioEntry
case object yesPayedRent extends RadioEntry
case object noRentPayed extends RadioEntry

case class NGRRadioName(key: String)

case class NGRRadioButtons(radioContent: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import uk.gov.hmrc.ngrraldfrontend.models.*
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementVerbalForm.{dateValidation, firstError, isDateEmpty, isDateValid}
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm.firstError
import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings
import scala.util.Try

final case class AgreementForm(
agreementStart: NGRDate,
Expand Down Expand Up @@ -147,7 +148,6 @@ object AgreementForm extends CommonFormValidators with Mappings with DateMapping
isEndDateValid("agreement.endDate.format.error")
)
)

)
}
}
Loading