diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoYouPayExtraForParkingSpacesController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoYouPayExtraForParkingSpacesController.scala new file mode 100644 index 00000000..fe62bac6 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoYouPayExtraForParkingSpacesController.scala @@ -0,0 +1,86 @@ +/* + * 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.i18n.I18nSupport +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.http.NotFoundException +import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction} +import uk.gov.hmrc.ngrraldfrontend.config.AppConfig +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios +import uk.gov.hmrc.ngrraldfrontend.models.forms.DoYouPayExtraForParkingSpacesForm +import uk.gov.hmrc.ngrraldfrontend.models.forms.DoYouPayExtraForParkingSpacesForm.form +import uk.gov.hmrc.ngrraldfrontend.models.{Landlord, Mode, NormalMode, UserAnswers} +import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator +import uk.gov.hmrc.ngrraldfrontend.pages.DoYouPayExtraForParkingSpacesPage +import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository +import uk.gov.hmrc.ngrraldfrontend.views.html.DoYouPayExtraForParkingSpacesView +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController + +import javax.inject.{Inject, Singleton} +import scala.concurrent.{ExecutionContext, Future} + +@Singleton +class DoYouPayExtraForParkingSpacesController @Inject()(doYouPayExtraForParkingSpacesView: DoYouPayExtraForParkingSpacesView, + authenticate : AuthRetrievals, + getData: DataRetrievalAction, + navigator: Navigator, + sessionRepository: SessionRepository, + mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext) + extends FrontendController(mcc) with I18nSupport { + + def show(mode: Mode): Action[AnyContent] = { + (authenticate andThen getData).async { implicit request => + val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(DoYouPayExtraForParkingSpacesPage) match { + case None => form + case Some(value) => form.fill(DoYouPayExtraForParkingSpacesForm(if (value) "Yes" else "No")) + } + Future.successful(Ok(doYouPayExtraForParkingSpacesView( + form = preparedForm, + radios = buildRadios(preparedForm, DoYouPayExtraForParkingSpacesForm.ngrRadio(preparedForm)), + propertyAddress = request.property.addressFull, + mode = mode + ))) + } + } + + def submit(mode: Mode): Action[AnyContent] = + (authenticate andThen getData).async { implicit request => + form.bindFromRequest().fold( + formWithErrors => { + Future.successful(BadRequest(doYouPayExtraForParkingSpacesView( + form = formWithErrors, + radios = buildRadios(formWithErrors, DoYouPayExtraForParkingSpacesForm.ngrRadio(formWithErrors)), + propertyAddress = request.property.addressFull, + mode = mode + ))) + }, + radioValue => + for { + updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)) + .set(DoYouPayExtraForParkingSpacesPage, + radioValue.radioValue match + case "Yes" => true + case _ => false + ) + ) + _ <- sessionRepository.set(updatedAnswers) + } yield Redirect(navigator.nextPage(DoYouPayExtraForParkingSpacesPage, mode, updatedAnswers)) + ) + } + +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala index cfabed28..b4529eb8 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala @@ -28,7 +28,7 @@ import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, NormalMode, ProvideDet import uk.gov.hmrc.ngrraldfrontend.models.components.* import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm -import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm.form +import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm._ import uk.gov.hmrc.ngrraldfrontend.utils.DateKeyFinder import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator import uk.gov.hmrc.ngrraldfrontend.pages.ProvideDetailsOfFirstSecondRentPeriodPage @@ -148,15 +148,7 @@ class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDet (authenticate andThen getData).async { implicit request => val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(ProvideDetailsOfFirstSecondRentPeriodPage) match { case None => form - case Some(value) => form.fill(ProvideDetailsOfFirstSecondRentPeriodForm(NGRDate.fromString(value.firstDateStart),NGRDate.fromString(value.firstDateEnd),value.firstRentPeriodRadio match { - case true => "yesPayedRent" - case false => "noRentPayed" - }, value.firstRentPeriodAmount match { - case Some(value) => Some(value) - case None => None - }, - NGRDate.fromString(value.secondDateStart),NGRDate.fromString(value.secondDateEnd),BigDecimal(value.secondHowMuchIsRent))) - + case Some(value) => answerToForm(value) } Future.successful(Ok(view( selectedPropertyAddress = request.property.addressFull, @@ -204,22 +196,8 @@ class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDet mode ))), provideDetailsOfFirstSecondRentPeriodForm => - val provideDetailsOfFirstSecondRentPeriod: ProvideDetailsOfFirstSecondRentPeriod = ProvideDetailsOfFirstSecondRentPeriod( - provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString, - provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString, - provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio match { - case "yesPayedRent" => true - case _ => false - }, - provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount match { - case Some(value) => Some(value) - case None => None - }, - provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString, - provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString, - provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent.toString()) for { - updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(ProvideDetailsOfFirstSecondRentPeriodPage, provideDetailsOfFirstSecondRentPeriod)) + updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(ProvideDetailsOfFirstSecondRentPeriodPage, formToAnswers(provideDetailsOfFirstSecondRentPeriodForm))) _ <- sessionRepository.set(updatedAnswers) } yield Redirect(navigator.nextPage(ProvideDetailsOfFirstSecondRentPeriodPage, NormalMode, updatedAnswers)) ) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala index 868a75ce..5583b231 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala @@ -24,7 +24,7 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.table.{Table, TableRow} import uk.gov.hmrc.http.NotFoundException import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction} import uk.gov.hmrc.ngrraldfrontend.config.AppConfig -import uk.gov.hmrc.ngrraldfrontend.models.{Mode, ProvideDetailsOfFirstSecondRentPeriod} +import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, ProvideDetailsOfFirstSecondRentPeriod} import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios import uk.gov.hmrc.ngrraldfrontend.models.forms.RentPeriodsForm @@ -58,7 +58,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView, content = Text(messages("rentPeriods.first.startDate")) ), TableRow( - content = Text(rentPeriods.firstDateStart), + content = Text(NGRDate.formatDate(rentPeriods.firstDateStart)), attributes = Map( "id" -> "first-period-start-date-id" ) @@ -69,7 +69,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView, content = Text(messages("rentPeriods.first.endDate")) ), TableRow( - content = Text(rentPeriods.firstDateEnd), + content = Text(NGRDate.formatDate(rentPeriods.firstDateEnd)), attributes = Map( "id" -> "first-period-end-date-id" ) @@ -119,7 +119,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView, content = Text(messages("rentPeriods.second.startDate")) ), TableRow( - content = Text(rentPeriods.secondDateStart), + content = Text(NGRDate.formatDate(rentPeriods.secondDateStart)), attributes = Map( "id" -> "second-period-start-date-id" ) @@ -130,7 +130,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView, content = Text(messages("rentPeriods.second.endDate")) ), TableRow( - content = Text(rentPeriods.secondDateEnd), + content = Text(NGRDate.formatDate(rentPeriods.secondDateEnd)), attributes = Map( "id" -> "second-period-end-date-id" ) @@ -141,7 +141,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView, content = Text(messages("rentPeriods.second.rentValue")) ), TableRow( - content = Text(rentPeriods.secondHowMuchIsRent), + content = Text(formatRentValue(rentPeriods.secondHowMuchIsRent.toDouble)), attributes = Map( "id" -> "second-period-rent-value-id" ) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala index 9c1b6e15..1d766eec 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala @@ -41,8 +41,8 @@ object NGRMonthYear { } def fromString(dateString: String): NGRMonthYear = { - val parts = dateString.split("-").map(_.toInt) - NGRMonthYear(parts(1).toString, parts(0).toString) + val parts = dateString.split("-") + NGRMonthYear(parts(1), parts(0)) } diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DoYouPayExtraForParkingSpacesForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DoYouPayExtraForParkingSpacesForm.scala new file mode 100644 index 00000000..b95f0e6b --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DoYouPayExtraForParkingSpacesForm.scala @@ -0,0 +1,48 @@ +/* + * 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.forms + +import play.api.data.Form +import play.api.data.Forms.mapping +import play.api.i18n.Messages +import play.api.libs.json.{Json, OFormat} +import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioName} +import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings + +case class DoYouPayExtraForParkingSpacesForm(radioValue: String) + +object DoYouPayExtraForParkingSpacesForm extends Mappings { + + implicit val format: OFormat[DoYouPayExtraForParkingSpacesForm] = Json.format[DoYouPayExtraForParkingSpacesForm] + + private lazy val radioUnselectedError = "doYouPayExtraForParkingSpaces.required.error" + val payExtraRadio = "payExtra" + + def unapply(doYouPayExtraForParkingSpacesForm: DoYouPayExtraForParkingSpacesForm): Option[String] = Some(doYouPayExtraForParkingSpacesForm.radioValue) + + def form: Form[DoYouPayExtraForParkingSpacesForm] = { + Form( + mapping( + payExtraRadio -> radioText(radioUnselectedError) + )(DoYouPayExtraForParkingSpacesForm.apply)(DoYouPayExtraForParkingSpacesForm.unapply) + ) + } + + def ngrRadio(form: Form[DoYouPayExtraForParkingSpacesForm])(implicit messages: Messages): NGRRadio = + NGRRadio(NGRRadioName(payExtraRadio), NGRRadioButtons = Seq(NGRRadio.yesButton, NGRRadio.noButton)) + +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala index 94cfb082..1b642f33 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala @@ -69,7 +69,39 @@ object ProvideDetailsOfFirstSecondRentPeriodForm extends CommonFormValidators wi provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput, provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent ) - + + def answerToForm(value: ProvideDetailsOfFirstSecondRentPeriod): Form[ProvideDetailsOfFirstSecondRentPeriodForm] = + form.fill( + ProvideDetailsOfFirstSecondRentPeriodForm( + NGRDate.fromString(value.firstDateStart), + NGRDate.fromString(value.firstDateEnd), + value.firstRentPeriodRadio match { + case true => "yesPayedRent" + case false => "noRentPayed" + }, + value.firstRentPeriodAmount, + NGRDate.fromString(value.secondDateStart), + NGRDate.fromString(value.secondDateEnd), + BigDecimal(value.secondHowMuchIsRent)) + ) + + def formToAnswers(provideDetailsOfFirstSecondRentPeriodForm: ProvideDetailsOfFirstSecondRentPeriodForm): ProvideDetailsOfFirstSecondRentPeriod = + ProvideDetailsOfFirstSecondRentPeriod( + provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio match { + case "yesPayedRent" => true + case _ => false + }, + provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount match { + case Some(value) if provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio.equals("yesPayedRent") => Some(value) + case _ => None + }, + provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent.toString() + ) + private def firstRentPeriodAmountValidation[A]: Constraint[A] = Constraint((input: A) => val provideDetailsOfFirstSecondRentPeriodForm = input.asInstanceOf[ProvideDetailsOfFirstSecondRentPeriodForm] diff --git a/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala b/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala index 1028e075..5c2c3fa5 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala @@ -131,17 +131,26 @@ class Navigator @Inject()() { answers.get(DoesYourRentIncludeParkingPage) match { case Some(value) => value match { case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowManyParkingSpacesOrGaragesIncludedInRentController.show(NormalMode) - case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode) + case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode) } case None => throw new NotFoundException("Failed to find answers") } - case HowManyParkingSpacesOrGaragesIncludedInRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode) + case HowManyParkingSpacesOrGaragesIncludedInRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode) case InterimSetByTheCourtPage => answers => answers.get(ProvideDetailsOfFirstSecondRentPeriodPage) match { case Some(_) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.show(NormalMode) - case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode) + case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode) } case RentFreePeriodPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.show(NormalMode) + //TODO need to connect to next pages when they are done + case DoYouPayExtraForParkingSpacesPage => answers => + answers.get(DoYouPayExtraForParkingSpacesPage) match { + case Some(value) => value match { + case true => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode) + case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.show(NormalMode) + } + case None => throw new NotFoundException("Failed to find answers") + } } //TODO change to check your answers page diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/DoYouPayExtraForParkingSpacesPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/DoYouPayExtraForParkingSpacesPage.scala new file mode 100644 index 00000000..613bdf69 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/DoYouPayExtraForParkingSpacesPage.scala @@ -0,0 +1,27 @@ +/* + * 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.pages + +import play.api.libs.json.JsPath + +case object DoYouPayExtraForParkingSpacesPage extends QuestionPage[Boolean]{ + + override def path: JsPath = JsPath \ toString + + override def toString: String = "doYouPayExtraForParkingSpacesNotIncludedInRent" + +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/DoYouPayExtraForParkingSpacesView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/DoYouPayExtraForParkingSpacesView.scala.html new file mode 100644 index 00000000..454dadc1 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/views/DoYouPayExtraForParkingSpacesView.scala.html @@ -0,0 +1,45 @@ +@* + * 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 uk.gov.hmrc.govukfrontend.views.html.components._ +@import uk.gov.hmrc.govukfrontend.views.Aliases._ +@import uk.gov.hmrc.ngrraldfrontend.views.html.components._ +@import uk.gov.hmrc.ngrraldfrontend.viewmodels.govuk.all._ +@import uk.gov.hmrc.ngrraldfrontend.config.AppConfig +@import uk.gov.hmrc.ngrraldfrontend.models.components.NavigationBarContent +@import uk.gov.hmrc.ngrraldfrontend.models.forms.DoYouPayExtraForParkingSpacesForm + + +@this( + layout: Layout, + govukRadios : GovukRadios, + formHelper: FormWithCSRF, + govukErrorSummary: GovukErrorSummary, + saveAndContinueButton: saveAndContinueButton) + +@(form:Form[DoYouPayExtraForParkingSpacesForm], radios: Radios, propertyAddress: String,mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig) + +@layout(pageTitle = Some(messages("doYouPayExtraForParkingSpaces.title")), showBackLink = true, fullWidth = false) { + @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoYouPayExtraForParkingSpacesController.submit(mode), Symbol("autoComplete") -> "off") { + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form)) + } + @propertyAddress +