Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR-1630 | Loans check and update page #1019

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -0,0 +1,117 @@
/*
* 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.nonsipp.loansmadeoroutstanding

import viewmodels.implicits._
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import com.google.inject.Inject
import controllers.nonsipp.loansmadeoroutstanding.LoansCheckAndUpdateController._
import cats.implicits.toShow
import controllers.actions.IdentifyAndRequireData
import pages.nonsipp.common.OtherRecipientDetailsPage
import pages.nonsipp.loansmadeoroutstanding._
import config.RefinedTypes.Max5000
import controllers.PSRController
import views.html.ContentTablePageView
import models.SchemeId.Srn
import utils.DateTimeUtils.localDateShow
import models.{IdentitySubject, Money, NormalMode}
import play.api.i18n.MessagesApi
import viewmodels.DisplayMessage
import viewmodels.DisplayMessage.{ListMessage, Message, ParagraphMessage}
import viewmodels.models.{ContentTablePageViewModel, FormPageViewModel}

import java.time.LocalDate

class LoansCheckAndUpdateController @Inject()(
override val messagesApi: MessagesApi,
identifyAndRequireData: IdentifyAndRequireData,
val controllerComponents: MessagesControllerComponents,
view: ContentTablePageView
) extends PSRController {

def onPageLoad(srn: Srn, index: Max5000): Action[AnyContent] = identifyAndRequireData(srn) { implicit request =>
(
for {
recipientName <- List(
request.userAnswers.get(IndividualRecipientNamePage(srn, index)),
request.userAnswers.get(CompanyRecipientNamePage(srn, index)),
request.userAnswers.get(PartnershipRecipientNamePage(srn, index)),
request.userAnswers.get(OtherRecipientDetailsPage(srn, index, IdentitySubject.LoanRecipient)).map(_.name)
).flatten.headOption.getOrRecoverJourney
datePeriodDetails <- request.userAnswers.get(DatePeriodLoanPage(srn, index)).getOrRecoverJourney
amountOfTheLoan <- request.userAnswers.get(AmountOfTheLoanPage(srn, index)).getOrRecoverJourney
} yield Ok(
view(
viewModel(
srn,
index,
recipientName,
datePeriodDetails._1,
amountOfTheLoan.loanAmount
)
)
)
).merge
}

def onSubmit(srn: Srn, index: Max5000): Action[AnyContent] = identifyAndRequireData(srn) { _ =>
Redirect(routes.AmountOfTheLoanController.onPageLoad(srn, index, NormalMode))
}
}

object LoansCheckAndUpdateController {

def viewModel(
srn: Srn,
index: Max5000,
recipientName: String,
dateOfTheLoan: LocalDate,
amountOfTheLoan: Money
): FormPageViewModel[ContentTablePageViewModel] = {

val rows: List[(DisplayMessage, DisplayMessage)] = List(
Message("loansCheckAndUpdate.table.one") -> Message(recipientName),
Message("loansCheckAndUpdate.table.two") -> Message(dateOfTheLoan.show),
Message("loansCheckAndUpdate.table.three") -> Message(amountOfTheLoan.displayAs)
)

FormPageViewModel(
mode = NormalMode,
title = "loansCheckAndUpdate.title",
heading = "loansCheckAndUpdate.heading",
description = None,
page = ContentTablePageViewModel(
inset = None,
beforeTable = Some(ParagraphMessage("loansCheckAndUpdate.paragraph")),
afterTable = Some(
ParagraphMessage("loansCheckAndUpdate.bullet.paragraph") ++ ListMessage
.Bullet(
"loansCheckAndUpdate.bullet.one",
"loansCheckAndUpdate.bullet.two"
)
),
rows = rows
),
refresh = None,
buttonText = "loansCheckAndUpdate.button",
details = None,
onSubmit = routes.LoansCheckAndUpdateController.onSubmit(srn, index),
optViewOnlyDetails = None
)
}
}
3 changes: 3 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ POST /:srn/remove-loan/:index
GET /:srn/change-remove-loan/:index controllers.nonsipp.loansmadeoroutstanding.RemoveLoanController.onPageLoad(srn: Srn, index: Max5000, mode: Mode = CheckMode)
POST /:srn/change-remove-loan/:index controllers.nonsipp.loansmadeoroutstanding.RemoveLoanController.onSubmit(srn: Srn, index: Max5000, mode: Mode = CheckMode)

GET /:srn/check-update-loans-information/:index controllers.nonsipp.loansmadeoroutstanding.LoansCheckAndUpdateController.onPageLoad(srn: Srn, index: Max5000)
GET /:srn/submit-check-update-loans-information/:index controllers.nonsipp.loansmadeoroutstanding.LoansCheckAndUpdateController.onSubmit(srn: Srn, index: Max5000)

GET /:srn/check-answers-financial-details controllers.nonsipp.schemedesignatory.FinancialDetailsCheckYourAnswersController.onPageLoad(srn: Srn, mode: Mode = NormalMode)
POST /:srn/submit-check-answers-financial-details controllers.nonsipp.schemedesignatory.FinancialDetailsCheckYourAnswersController.onSubmit(srn: Srn, mode: Mode = NormalMode)
GET /:srn/change-check-answers-financial-details controllers.nonsipp.schemedesignatory.FinancialDetailsCheckYourAnswersController.onPageLoad(srn: Srn, mode: Mode = CheckMode)
Expand Down
11 changes: 11 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,17 @@ removeLoan.title = Are you sure you want to remove this loan?
removeLoan.heading = Are you sure you want to remove the loan of £{0} to {1}?
removeLoan.error.required = Select yes if you are sure you want to remove this loan

loansCheckAndUpdate.title = Check and update the loans information
loansCheckAndUpdate.heading = Check and update the loans information
loansCheckAndUpdate.paragraph = You need to add data to this loan.
loansCheckAndUpdate.table.one = Recipient’s name
loansCheckAndUpdate.table.two = Date of the loan
loansCheckAndUpdate.table.three = Total loan amount
loansCheckAndUpdate.bullet.paragraph = Missing data could include:
loansCheckAndUpdate.bullet.one = Capital Repayment details
loansCheckAndUpdate.bullet.two = any outstanding arrears details
loansCheckAndUpdate.button = Add missing data

financialDetailsCheckYourAnswersController.title = Check your answers
financialDetailsCheckYourAnswersController.heading = Check your answers
financialDetailsCheckYourAnswersController.viewOnly.title = Financial details
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.nonsipp.loansmadeoroutstanding

import models.ConditionalYesNo._
import play.api.mvc.Call
import models.IdentityType.Individual
import controllers.ControllerBaseSpec
import views.html.ContentTablePageView
import models.{ConditionalYesNo, NormalMode, Security}
import pages.nonsipp.common.IdentityTypePage
import pages.nonsipp.loansmadeoroutstanding._
import models.IdentitySubject.LoanRecipient

class LoansCheckAndUpdateControllerSpec extends ControllerBaseSpec {

private val conditionalYesSecurity: ConditionalYes[Security] = ConditionalYesNo.yes(security)

private def onPageLoad: Call = routes.LoansCheckAndUpdateController.onPageLoad(srn, index1of5000)
private def onSubmit: Call = routes.LoansCheckAndUpdateController.onSubmit(srn, index1of5000)

private val prePopUserAnswers = defaultUserAnswers
.unsafeSet(IdentityTypePage(srn, index1of5000, LoanRecipient), Individual)
.unsafeSet(IndividualRecipientNamePage(srn, index1of5000), recipientName)
.unsafeSet(IndividualRecipientNinoPage(srn, index1of5000), conditionalYesNoNino)
.unsafeSet(IsIndividualRecipientConnectedPartyPage(srn, index1of5000), true)
.unsafeSet(DatePeriodLoanPage(srn, index1of5000), (localDate, money, loanPeriod))
.unsafeSet(AmountOfTheLoanPage(srn, index1of5000), partialAmountOfTheLoan)
.unsafeSet(AreRepaymentsInstalmentsPage(srn, index1of5000), true)
.unsafeSet(InterestOnLoanPage(srn, index1of5000), partialInterestOnLoan)
.unsafeSet(SecurityGivenForLoanPage(srn, index1of5000), conditionalYesSecurity)

"LoansCheckAndUpdateController" - {

act.like(
renderView(onPageLoad, prePopUserAnswers) { implicit app => implicit request =>
injected[ContentTablePageView].apply(
LoansCheckAndUpdateController.viewModel(
srn = srn,
index = index1of5000,
recipientName = recipientName,
dateOfTheLoan = localDate,
amountOfTheLoan = money
)
)
}.withName(s"render correct view")
)

act.like(
redirectToPage(onSubmit, routes.AmountOfTheLoanController.onPageLoad(srn, index1of5000, NormalMode))
)

act.like(
journeyRecoveryPage(onPageLoad)
.updateName("onPageLoad" + _)
)

act.like(
journeyRecoveryPage(onSubmit)
.updateName("onSubmit" + _)
)
}
}