Skip to content

Commit

Permalink
PSR-1510 Alternative check-update page added & PREPOPULATION_FLAG is …
Browse files Browse the repository at this point in the history
…added to continue and start of outstanding journey
  • Loading branch information
cyeniceri committed Oct 23, 2024
1 parent 1d0db24 commit 2f51eab
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/config/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
83 changes: 83 additions & 0 deletions app/controllers/CheckAndUpdateTheInformationController.scala
Original file line number Diff line number Diff line change
@@ -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")
)
}
53 changes: 36 additions & 17 deletions app/controllers/OverviewController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -199,7 +204,8 @@ class OverviewController @Inject()(
formatDateForApi(yearFrom),
"%03d".format(last.reportVersion),
Some(last.reportFormBundleNumber),
reportType
reportType,
None
)
.url
)
Expand Down Expand Up @@ -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))
}
}
}
}
Expand All @@ -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 {
Expand All @@ -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)
)
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
7 changes: 7 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2f51eab

Please sign in to comment.