From 89d6579525d7634c0bf94ac5ce7b25e197bcc25c Mon Sep 17 00:00:00 2001 From: cemyeniceri Date: Wed, 23 Oct 2024 12:41:02 +0100 Subject: [PATCH] PSR-1510 Alternative check-update page added & PREPOPULATION_FLAG is added to continue and start of outstanding journey --- app/config/Constants.scala | 1 + ...eckAndUpdateTheInformationController.scala | 83 +++++++++++++++++++ app/controllers/OverviewController.scala | 53 ++++++++---- conf/app.routes | 5 +- conf/messages.en | 7 ++ test/controllers/OverviewControllerSpec.scala | 2 +- 6 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 app/controllers/CheckAndUpdateTheInformationController.scala diff --git a/app/config/Constants.scala b/app/config/Constants.scala index 170f782b2..88dd88a2d 100755 --- a/app/config/Constants.scala +++ b/app/config/Constants.scala @@ -41,6 +41,7 @@ object Constants { val TAX_YEAR = "taxYear" val VERSION = "version" val FB_NUMBER = "fbNumber" + val PREPOPULATION_FLAG = "prePopulationFlag" val delimitedPSA = "DELIMITED_PSAID" val detailsNotFound = "no match found" diff --git a/app/controllers/CheckAndUpdateTheInformationController.scala b/app/controllers/CheckAndUpdateTheInformationController.scala new file mode 100644 index 000000000..414269e4e --- /dev/null +++ b/app/controllers/CheckAndUpdateTheInformationController.scala @@ -0,0 +1,83 @@ +/* + * 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 + +import pages.nonsipp.schemedesignatory.HowManyMembersPage +import viewmodels.implicits._ +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import pages.WhatYouWillNeedPage +import controllers.actions._ +import navigation.Navigator +import models.{CheckMode, NormalMode} +import views.html.ContentPageView +import models.SchemeId.Srn +import play.api.i18n.{I18nSupport, MessagesApi} +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController +import viewmodels.DisplayMessage._ +import viewmodels.models.{ContentPageViewModel, FormPageViewModel} + +import scala.concurrent.Future + +import javax.inject.{Inject, Named} + +class CheckAndUpdateTheInformationController @Inject()( + override val messagesApi: MessagesApi, + @Named("root") navigator: Navigator, + identify: IdentifierAction, + allowAccess: AllowAccessActionProvider, + getData: DataRetrievalAction, + requireData: DataRequiredAction, + val controllerComponents: MessagesControllerComponents, + view: ContentPageView +) extends FrontendBaseController + with I18nSupport { + + def onPageLoad(srn: Srn, taxYear: String, version: String): Action[AnyContent] = + identify.andThen(allowAccess(srn)).andThen(getData).andThen(requireData) { implicit request => + Ok(view(CheckAndUpdateTheInformationController.viewModel(srn, taxYear, version))) + } + + def onSubmit(srn: Srn, taxYear: String, version: String): Action[AnyContent] = + identify.andThen(allowAccess(srn)).andThen(getData).andThen(requireData).async { implicit request => + // as we cannot access pensionSchemeId in the navigator + val members = request.userAnswers.get(HowManyMembersPage(srn, request.pensionSchemeId)) + if (members.exists(_.totalActiveAndDeferred > 99)) { + Future.successful( + Redirect(controllers.nonsipp.routes.BasicDetailsCheckYourAnswersController.onPageLoad(srn, CheckMode)) + ) + } else { + Future.successful(Redirect(navigator.nextPage(WhatYouWillNeedPage(srn), NormalMode, request.userAnswers))) + } + } +} + +object CheckAndUpdateTheInformationController { + + def viewModel(srn: Srn, taxYear: String, version: String): FormPageViewModel[ContentPageViewModel] = + FormPageViewModel( + Message("checkAndUpdateTheInformation.title"), + Message("checkAndUpdateTheInformation.heading"), + ContentPageViewModel(isStartButton = true), + routes.CheckAndUpdateTheInformationController.onSubmit(srn, taxYear, version) + ).withButtonText(Message("site.continue")) + .withDescription( + ParagraphMessage("checkAndUpdateTheInformation.paragraph1") ++ + ParagraphMessage("checkAndUpdateTheInformation.paragraph2") ++ + Heading2.medium("checkAndUpdateTheInformation.legend") ++ + ParagraphMessage("checkAndUpdateTheInformation.paragraph3") + ) +} diff --git a/app/controllers/OverviewController.scala b/app/controllers/OverviewController.scala index bc04389cd..f12113187 100644 --- a/app/controllers/OverviewController.scala +++ b/app/controllers/OverviewController.scala @@ -93,6 +93,22 @@ class OverviewController @Inject()( val yearTo = overviewResponse.periodEndDate val compiled = overviewResponse.compiledVersionAvailable.getOrElse(YesNo.No) == YesNo.Yes + /** + * this logic assumes gap years are allowed in pre-population + * */ + val lastSubmittedPsrFbInPreviousYears = + versionsForYears + .filter(x => LocalDate.parse(x.startDate) < yearFrom) + .sortBy(x => LocalDate.parse(x.startDate))(Ordering[LocalDate].reverse) + .find(response => response.data.exists(isSubmitted)) + .flatMap { response => + response.data + .filter(isSubmitted) + .sortBy(_.reportVersion)(Ordering[Int].reverse) + .headOption + .map(_.reportFormBundleNumber) + } + val (status, url, label) = if (compiled) { val fbNumber = versionsForYears .find(x => LocalDate.parse(x.startDate) == yearFrom) @@ -106,24 +122,13 @@ class OverviewController @Inject()( formatDateForApi(yearFrom), "001", fbNumber, - overviewResponse.psrReportType.get.name + overviewResponse.psrReportType.get.name, + lastSubmittedPsrFbInPreviousYears ) .url, messages("site.continue") ) } else { - val lastSubmittedPsrFbInPreviousYears = - versionsForYears - .filter(x => LocalDate.parse(x.startDate) < yearFrom) - .sortBy(x => LocalDate.parse(x.startDate))(Ordering[LocalDate].reverse) - .find(response => response.data.exists(isSubmitted)) - .flatMap { response => - response.data - .filter(isSubmitted) - .sortBy(_.reportVersion)(Ordering[Int].reverse) - .headOption - .map(_.reportFormBundleNumber) - } ( ReportStatus.NotStarted, controllers.routes.OverviewController @@ -199,7 +204,8 @@ class OverviewController @Inject()( formatDateForApi(yearFrom), "%03d".format(last.reportVersion), Some(last.reportFormBundleNumber), - reportType + reportType, + None ) .url ) @@ -286,7 +292,14 @@ class OverviewController @Inject()( _ <- saveService.save(userAnswers.copy(id = UNCHANGED_SESSION_PREFIX + userAnswers.id)) _ <- saveService.save(userAnswers) } yield { - Redirect(controllers.routes.WhatYouWillNeedController.onPageLoad(srn, "", taxYear, version)) + if (lastSubmittedPsrFbInPreviousYears.isDefined) { + Redirect(controllers.routes.CheckAndUpdateTheInformationController.onPageLoad(srn, taxYear, version)) + .addingToSession(Constants.PREPOPULATION_FLAG -> String.valueOf(true)) + } else { + Redirect( + controllers.routes.WhatYouWillNeedController.onPageLoad(srn, "", taxYear, version) + ).addingToSession(Constants.PREPOPULATION_FLAG -> String.valueOf(false)) + } } } } @@ -296,7 +309,8 @@ class OverviewController @Inject()( taxYear: String, version: String, fbNumber: Option[String], - reportType: String + reportType: String, + lastSubmittedPsrFbInPreviousYears: Option[String] ): Action[AnyContent] = identifyAndRequireData(srn, taxYear, version).async { implicit request => reportType match { @@ -312,7 +326,12 @@ class OverviewController @Inject()( .getOrElse(result) } case _ => - Future.successful(Redirect(controllers.nonsipp.routes.TaskListController.onPageLoad(srn))) + Future.successful( + Redirect(controllers.nonsipp.routes.TaskListController.onPageLoad(srn)) + .addingToSession( + Constants.PREPOPULATION_FLAG -> String.valueOf(lastSubmittedPsrFbInPreviousYears.isDefined) + ) + ) } } diff --git a/conf/app.routes b/conf/app.routes index 46a53e51f..dcb631883 100755 --- a/conf/app.routes +++ b/conf/app.routes @@ -39,6 +39,9 @@ GET /:srn/what-you-will-need/:taxYear/:version GET /:srn/what-you-will-need controllers.WhatYouWillNeedController.onPageLoad(srn: Srn, fbNumber: String = "", taxYear: String = "2022-04-06", version: String = "001") GET /:srn/what-you-will-need-next-page controllers.WhatYouWillNeedController.onSubmit(srn: Srn, taxYear: String, fbNumber: String, version: String) +GET /:srn/check-update-information/:taxYear/:version controllers.CheckAndUpdateTheInformationController.onPageLoad(srn: Srn, taxYear: String, version: String) +GET /:srn/check-update-information-next-page controllers.CheckAndUpdateTheInformationController.onSubmit(srn: Srn, taxYear: String, version: String) + GET /:srn/which-tax-year controllers.nonsipp.WhichTaxYearController.onPageLoad(srn: Srn, mode: Mode = NormalMode) POST /:srn/which-tax-year controllers.nonsipp.WhichTaxYearController.onSubmit(srn: Srn, mode: Mode = NormalMode) @@ -454,7 +457,7 @@ POST /:srn/change-remove-unallocated-employer-contributions GET /:srn/overview controllers.OverviewController.onPageLoad(srn: Srn) GET /:srn/select-view-and-change controllers.OverviewController.onSelectViewAndChange(srn: Srn, fbNumber: String, taxYear: String, reportType: String) GET /:srn/select-start controllers.OverviewController.onSelectStart(srn: Srn, taxYear: String, version: String, reportType: String, lastSubmittedPsrFbInPreviousYears: Option[String]) -GET /:srn/select-continue controllers.OverviewController.onSelectContinue(srn: Srn, taxYear: String, version: String, fbNumber: Option[String], reportType: String) +GET /:srn/select-continue controllers.OverviewController.onSelectContinue(srn: Srn, taxYear: String, version: String, fbNumber: Option[String], reportType: String, lastSubmittedPsrFbInPreviousYears: Option[String]) GET /:srn/view-change/submitted-returns/:page controllers.ReturnsSubmittedController.onPageLoad(srn: Srn, page: Int) GET /:srn/view-change/select-submitted-returns controllers.ReturnsSubmittedController.onSelect(srn: Srn, fbNumber: String) GET /:srn/view-change/select-submitted-returns-to-view/:year/:current/:previous controllers.ReturnsSubmittedController.onSelectToView(srn: Srn, year: String, current: Int, previous: Int) diff --git a/conf/messages.en b/conf/messages.en index e85b4b9ee..cb3b0ce23 100755 --- a/conf/messages.en +++ b/conf/messages.en @@ -144,6 +144,13 @@ upload.acceptedFileType = Accepted file type: {0} upload.maxFileSize = Maximum file size: {0} upload.uploadAFile = Upload a file +checkAndUpdateTheInformation.title = Check and update the information you provided +checkAndUpdateTheInformation.heading = Check and update the information you provided +checkAndUpdateTheInformation.paragraph1 = Some of the information that you provided from the previous return period has been included for you to check or update. +checkAndUpdateTheInformation.paragraph2 = You must check that the information is correct, or make any required changes before submitting this period's return. +checkAndUpdateTheInformation.paragraph3 = You do not have to complete the whole return at once. You can save your answers and come back to them later. +checkAndUpdateTheInformation.legend = Saving your answers + whatYouWillNeed.title = What you will need whatYouWillNeed.heading = What you will need whatYouWillNeed.paragraph = To start a pension scheme return, you will need to tell us: diff --git a/test/controllers/OverviewControllerSpec.scala b/test/controllers/OverviewControllerSpec.scala index 1d9041cb1..e869a678a 100644 --- a/test/controllers/OverviewControllerSpec.scala +++ b/test/controllers/OverviewControllerSpec.scala @@ -43,7 +43,7 @@ class OverviewControllerSpec extends ControllerBaseSpec with CommonTestValues { .url lazy val onSelectContinue: String = routes.OverviewController - .onSelectContinue(srn, commonStartDate, commonVersion, Some(commonFbNumber), PsrReportType.Standard.name) + .onSelectContinue(srn, commonStartDate, commonVersion, Some(commonFbNumber), PsrReportType.Standard.name, None) .url lazy val onSelectViewAndChange: String = routes.OverviewController