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

SASS-10526: Implement navigation functionality for 'Struct… #513

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
Expand Up @@ -20,7 +20,7 @@ import controllers.actions._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import pages.foreign.structurebuildingallowance.ForeignStructureBuildingAllowancePage
import pages.foreign.structurebuildingallowance.{ForeignStructureBuildingAllowanceGroup, ForeignStructureBuildingAllowancePage}
import views.html.foreign.structurebuildingallowance.ForeignStructureBuildingAllowanceView

import javax.inject.Inject
Expand All @@ -38,6 +38,7 @@ class ForeignAddClaimStructureBuildingAllowanceController @Inject()(

def onPageLoad(taxYear: Int, countryCode: String): Action[AnyContent] =
(identify andThen getData andThen requireData) { implicit request =>
Ok(view(ForeignStructureBuildingAllowancePage(taxYear, countryCode, request.user.isAgentMessageKey)))
val nextIndex = request.userAnswers.get(ForeignStructureBuildingAllowanceGroup(countryCode)).map(_.length).getOrElse(0)
Ok(view(ForeignStructureBuildingAllowancePage(taxYear, countryCode, nextIndex, request.user.isAgentMessageKey)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package controllers.foreign.structuresbuildingallowance

import controllers.ControllerUtils.statusForPage
import controllers.actions.{DataRequiredAction, DataRetrievalAction, IdentifierAction}
import controllers.exceptions.InternalErrorFailure
import forms.foreign.structurebuildingallowance.ForeignSbaCompleteFormProvider
import models.JourneyPath.ForeignStructureBuildingAllowance
import navigation.ForeignPropertyNavigator
import models.JourneyPath.ForeignPropertyAllowances
import models.{JourneyContext, NormalMode}
import navigation.ForeignPropertyNavigator
import pages.foreign.structurebuildingallowance.ForeignSbaCompletePage
import play.api.data.Form
import play.api.i18n.{I18nSupport, MessagesApi}
Expand Down Expand Up @@ -76,28 +77,29 @@ class ForeignSbaCompleteController @Inject()(
taxYear = taxYear,
mtditid = request.user.mtditid,
nino = request.user.nino,
journeyPath = ForeignStructureBuildingAllowance
journeyPath = ForeignPropertyAllowances
),
status = statusForPage(value),
request.user
)
} yield status.fold(
_ =>
//TODO: When we implement navigation story, update the route to show message from backend or error
Redirect(controllers.routes.SummaryController.show(taxYear)
),
_ =>
Redirect(
foreignPropertyNavigator
.nextPage(
ForeignSbaCompletePage(countryCode),
taxYear,
NormalMode,
request.userAnswers,
updatedAnswers
).flatMap {
case Right(_) =>
Future.successful(Redirect(
foreignPropertyNavigator
.nextPage(
ForeignSbaCompletePage(countryCode),
taxYear,
NormalMode,
request.userAnswers,
updatedAnswers
)
))
case Left(_) =>
Future.failed(
InternalErrorFailure(s"Failed to save the status for SBA section in tax year: $taxYear")
)
)
)
}
} yield status
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import controllers.actions._
import forms.foreign.structurebuildingallowance.ForeignSbaRemoveConfirmationFormProvider
import models.{Mode, UserAnswers}
import navigation.ForeignPropertyNavigator
import pages.foreign.structurebuildingallowance.{ForeignSbaRemoveConfirmationPage, ForeignStructureBuildingAllowanceClaimPage}
import pages.foreign.structurebuildingallowance.{ForeignSbaRemoveConfirmationPage, ForeignStructureBuildingAllowanceClaimPage, ForeignStructureBuildingAllowanceWithIndex}
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
Expand Down Expand Up @@ -73,7 +73,7 @@ class ForeignSbaRemoveConfirmationController @Inject() (
updatedAnswers <-
Future.fromTry {
if (value) {
updatedAnswers.remove(ForeignStructureBuildingAllowanceClaimPage(countryCode, index))
updatedAnswers.remove(ForeignStructureBuildingAllowanceWithIndex(index, countryCode))
} else {
Success(updatedAnswers)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import forms.ForeignStructureBuildingAllowanceClaimsFormProvider
import models.backend.PropertyDetails
import models.requests.DataRequest
import models.{AccountingMethod, AuditPropertyType, JourneyContext, JourneyName, JourneyPath, NormalMode, SectionName, UserAnswers}
import org.apache.pekko.actor.FSM.Normal
import pages.foreign.structurebuildingallowance.{ForeignSbaInfo, ForeignStructureBuildingAllowanceClaimsPage, ForeignStructureBuildingAllowanceGroup, SaveForeignSba}
import pages.foreign.structurebuildingallowance.{ForeignSbaInfo, ForeignStructureBuildingAllowanceClaimsPage, ForeignStructureBuildingAllowanceGroup}
import play.api.data.Form
import play.api.i18n.Lang.logger
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
Expand Down Expand Up @@ -178,6 +177,7 @@ class ForeignStructureBuildingAllowanceClaimsController @Inject() (
Future.failed(InternalErrorFailure("Foreign Structure and Building Allowance not found in userAnswers"))
}

// TODO - revise audit model/method for Foreign Property
private def auditSBAClaims(
taxYear: Int,
request: DataRequest[AnyContent],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ForeignStructureBuildingQualifyingDateController @Inject()(
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(
foreignNavigator.nextPage(
ForeignStructureBuildingAllowanceClaimPage(countryCode, index),
ForeignStructureBuildingQualifyingDatePage(countryCode, index),
taxYear,
mode,
request.userAnswers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package controllers.foreign.structuresbuildingallowance
import controllers.actions._
import forms.foreign.structurebuildingallowance.ForeignStructuresBuildingAllowanceAddressFormProvider
import models.Mode
import navigation.Navigator
import navigation.ForeignPropertyNavigator
import pages.foreign.structurebuildingallowance.ForeignStructuresBuildingAllowanceAddressPage
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
Expand All @@ -33,7 +33,7 @@ import scala.concurrent.{ExecutionContext, Future}
class ForeignStructuresBuildingAllowanceAddressController @Inject() (
override val messagesApi: MessagesApi,
sessionRepository: SessionRepository,
navigator: Navigator,
foreignNavigator: ForeignPropertyNavigator,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
Expand Down Expand Up @@ -70,11 +70,10 @@ class ForeignStructuresBuildingAllowanceAddressController @Inject() (
)
_ <- sessionRepository.set(updatedAnswers)
} yield Redirect(
navigator.sbaNextPage(
foreignNavigator.nextPage(
ForeignStructuresBuildingAllowanceAddressPage(index, countryCode),
taxYear,
mode,
index,
request.userAnswers,
updatedAnswers
)
Expand Down
57 changes: 57 additions & 0 deletions app/navigation/ForeignPropertyNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import controllers.foreign.allowances.routes._
import controllers.foreign.expenses.routes._
import controllers.foreign.income.routes._
import controllers.foreign.routes._
import controllers.foreign.structuresbuildingallowance.routes._
import controllers.routes.{IndexController, SummaryController}
import models.ForeignTotalIncome.{LessThanOneThousand, OneThousandAndMore}
import models._
import pages.Page
import pages.foreign._
import pages.foreign.allowances._
import pages.foreign.structurebuildingallowance._
import pages.foreign.expenses._
import pages.foreign.income._
import play.api.mvc.Call
Expand Down Expand Up @@ -94,6 +96,7 @@ class ForeignPropertyNavigator {
taxYear => _ => userAnswers => consolidatedExpensesNavigation(taxYear, userAnswers, countryCode)
case ForeignExpensesSectionCompletePage(_) =>
taxYear => _ => _ => SummaryController.show(taxYear)

//Allowances
case ForeignZeroEmissionCarAllowancePage(countryCode) =>
taxYear => _ => _ => ForeignZeroEmissionGoodsVehiclesController.onPageLoad(taxYear, countryCode, NormalMode)
Expand All @@ -103,9 +106,40 @@ class ForeignPropertyNavigator {
taxYear => _ => _ => ForeignOtherCapitalAllowancesController.onPageLoad(taxYear, countryCode, NormalMode)
case ForeignOtherCapitalAllowancesPage(countryCode) => // TODO route to CYA page once created
taxYear => _ => _ => ForeignAllowancesCheckYourAnswersController.onPageLoad(taxYear, countryCode)
// Allowances // Structure Building Allowance
case ForeignClaimStructureBuildingAllowancePage(countryCode) =>
taxYear => _ => userAnswers => foreignSbaNavigation(taxYear, userAnswers, countryCode)
case ForeignStructureBuildingQualifyingDatePage(countryCode, index) =>
taxYear => _ => _ => ForeignStructureBuildingQualifyingAmountController.onPageLoad(taxYear, countryCode, index, NormalMode)
case ForeignStructureBuildingQualifyingAmountPage(countryCode, index) =>
taxYear => _ => _ => ForeignStructureBuildingAllowanceClaimController.onPageLoad(taxYear, countryCode, index, NormalMode)
case ForeignStructureBuildingAllowanceClaimPage(countryCode, index) =>
taxYear => _ => _ => ForeignStructuresBuildingAllowanceAddressController.onPageLoad(taxYear, index, countryCode, NormalMode)
case ForeignStructuresBuildingAllowanceAddressPage(index, countryCode) =>
taxYear => _ => _ => ForeignSbaCheckYourAnswersController.onPageLoad(taxYear,countryCode, index)
case ForeignSbaRemoveConfirmationPage(countryCode) =>
taxYear => _ => userAnswers => foreignSbaRemoveConfirmationNavigationNormalMode(taxYear, userAnswers, countryCode)
case ForeignSbaCompletePage(_) =>
taxYear => _ => _ => SummaryController.show(taxYear)


case _ => _ => _ => _ => controllers.routes.IndexController.onPageLoad
}

private def foreignSbaRemoveConfirmationNavigationNormalMode(
taxYear: Int,
userAnswers: UserAnswers,
countryCode: String
): Call = (
userAnswers.get(ForeignSbaRemoveConfirmationPage(countryCode)),
userAnswers.get(ForeignStructureBuildingAllowanceGroup(countryCode))
) match {
case (Some(true), Some(sbaForm)) if sbaForm.isEmpty =>
ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode)
case (_, Some(sbaForm)) if sbaForm.nonEmpty => ForeignStructureBuildingAllowanceClaimsController.onPageLoad(taxYear, countryCode)
case (_, _) => SummaryController.show(taxYear)
}

private def consolidatedExpensesNavigation(taxYear: Int, userAnswers: UserAnswers, countryCode: String): Call =
userAnswers.get(ConsolidatedOrIndividualExpensesPage(countryCode)) match {
case Some(ConsolidatedOrIndividualExpenses(true, _)) =>
Expand Down Expand Up @@ -184,6 +218,17 @@ class ForeignPropertyNavigator {
taxYear => _ => _ => ForeignAllowancesCheckYourAnswersController.onPageLoad(taxYear, countryCode)
case ForeignOtherCapitalAllowancesPage(countryCode) =>
taxYear => _ => _ => ForeignAllowancesCheckYourAnswersController.onPageLoad(taxYear, countryCode)
// Allowances // Structure Building Allowance
case ForeignStructureBuildingQualifyingDatePage(countryCode, index) =>
taxYear => _ => _ => ForeignSbaCheckYourAnswersController.onPageLoad(taxYear,countryCode, index)
case ForeignStructureBuildingQualifyingAmountPage(countryCode, index) =>
taxYear => _ => _ => ForeignSbaCheckYourAnswersController.onPageLoad(taxYear,countryCode, index)
case ForeignStructureBuildingAllowanceClaimPage(countryCode, index) =>
taxYear => _ => _ => ForeignSbaCheckYourAnswersController.onPageLoad(taxYear,countryCode, index)
case ForeignStructuresBuildingAllowanceAddressPage(index, countryCode) =>
taxYear => _ => _ => ForeignSbaCheckYourAnswersController.onPageLoad(taxYear,countryCode, index)


case _ => _ => _ => _ => controllers.routes.IndexController.onPageLoad
}

Expand Down Expand Up @@ -309,4 +354,16 @@ class ForeignPropertyNavigator {
case _ =>
ForeignTaxCheckYourAnswersController.onSubmit(taxYear, countryCode)
}

private def foreignSbaNavigation(
taxYear: Int,
userAnswers: UserAnswers,
countryCode: String
): Call =
userAnswers.get(ForeignClaimStructureBuildingAllowancePage(countryCode)) match {
case Some(true) => ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode)
// TODO - redirect to CYA
// case Some(false) => ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode)
case _ => SummaryController.show(taxYear)
}
}
2 changes: 1 addition & 1 deletion app/pages/foreign/ForeignPropertySummaryPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ object ForeignPropertySummaryPage {
),
TaskListItem(
"summary.structuresAndBuildingAllowance",
controllers.foreign.structuresbuildingallowance.routes.ForeignClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode, CheckMode),
controllers.foreign.structuresbuildingallowance.routes.ForeignClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode, NormalMode),
taskListTagForSba,
s"foreign_structure_and_building_allowance_$countryCode"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ package pages.foreign.structurebuildingallowance
case class ForeignStructureBuildingAllowancePage(
taxYear: Int,
countryCode: String,
nextIndex: Int,
individualOrAgent: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package viewmodels.checkAnswers.foreign.structurebuildingallowance

import controllers.foreign.structuresbuildingallowance.routes
import models.{CheckMode, ForeignSbaOnIndex, UserAnswers}
import models.{ForeignSbaOnIndex, UserAnswers}
import play.api.i18n.Messages
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.Aliases.HtmlContent
Expand All @@ -44,9 +44,8 @@ object ForeignStructureBuildingAllowanceClaimsSummary {
actions = Seq(
ActionItemViewModel(
"site.change",
// TODO - change to CYA page load
routes.ForeignStructureBuildingAllowanceClaimController
.onPageLoad(taxYear, countryCode, index, CheckMode)
routes.ForeignSbaCheckYourAnswersController
.onPageLoad(taxYear, countryCode, index)
.url
).withVisuallyHiddenText(messages("foreignStructureBuildingAllowanceClaims.change.hidden")),

Expand All @@ -57,6 +56,5 @@ object ForeignStructureBuildingAllowanceClaimsSummary {
),
actionsCss = "w-25"
)

}.orElse(Option.empty[SummaryListRow])
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package viewmodels.checkAnswers.foreign.structurebuildingallowance

import controllers.foreign.structuresbuildingallowance.routes
import models.{CheckMode, UserAnswers}
import pages.foreign.structurebuildingallowance.ForeignStructureBuildingQualifyingDatePage
import play.api.i18n.Messages
Expand All @@ -40,7 +41,9 @@ object ForeignStructureBuildingQualifyingDateSummary {
actions = Seq(
ActionItemViewModel(
"site.change",
controllers.foreign.structuresbuildingallowance.routes.ForeignStructureBuildingQualifyingDateController.onPageLoad(taxYear, countryCode, index, CheckMode).url
routes.ForeignStructureBuildingQualifyingDateController
.onPageLoad(taxYear, countryCode, index, CheckMode)
.url
)
.withVisuallyHiddenText(messages("foreignStructureBuildingQualifyingDate.change.hidden"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="govuk-heading-l">@messages("checkYourAnswers.heading")</h1>
<p class="govuk-body">
@govukButton(
ButtonViewModel(messages("site.saveAndContinue"))
.asLink(routes.ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(taxYear, countryCode).url)
.asLink(routes.ForeignStructureBuildingAllowanceClaimsController.onPageLoad(taxYear, countryCode).url)
.withId("continue")
)
</p>
Expand All @@ -44,7 +44,5 @@ <h1 class="govuk-heading-l">@messages("checkYourAnswers.heading")</h1>
// $COVERAGE-OFF$
}

<!--TODO - redirect to routes.ForeignStructureBuildingAllowanceClaimsController.onPageLoad(taxYear, countryCode).url -->



Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="govuk-heading-l">@messages("foreignStructureBuildingAllowance.heading
<p class="govuk-body">
@govukButton(
ButtonViewModel(messages("foreignStructureBuildingAllowance.button"))
.asLink(routes.ForeignAddClaimStructureBuildingAllowanceController.onPageLoad(page.taxYear, page.countryCode).url)
.asLink(routes.ForeignStructureBuildingQualifyingDateController.onPageLoad(page.taxYear, page.countryCode, page.nextIndex, NormalMode).url)
.withId("continue")
)
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,18 @@

<h1 class="govuk-heading-l">@messages("foreignStructureBuildingQualifyingDate.heading")</h1>

<details class="govuk-details" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
@messages("foreignStructureBuildingQualifyingDate.details.heading")
</span>
</summary>
<div class="govuk-details__text">
<p class="govuk-body">@messages(s"foreignStructureBuildingQualifyingDate.details.content1.$individualOrAgent") </p>
<ul class="govuk-list govuk-list--bullet">
<li>@messages(s"foreignStructureBuildingQualifyingDate.details.l1.$individualOrAgent")</li>
<li>@messages(s"foreignStructureBuildingQualifyingDate.details.l2.$individualOrAgent")</li>
</ul>
<p class="govuk-body">@messages("foreignStructureBuildingQualifyingDate.details.content2.link.intro")
<a href="@messages("foreignStructureBuildingQualifyingDate.details.content2.link.href")" class="govuk-link" target="_blank" rel="noreferrer noopener">
@messages("foreignStructureBuildingQualifyingDate.details.content2.link.text")
</a>
</p>
</div>
</details>

<p class="govuk-body">@messages(s"foreignStructureBuildingQualifyingDate.details.content1.$individualOrAgent") </p>
<ul class="govuk-list govuk-list--bullet">
<li>@messages(s"foreignStructureBuildingQualifyingDate.details.l1.$individualOrAgent")</li>
<li>@messages(s"foreignStructureBuildingQualifyingDate.details.l2.$individualOrAgent")</li>
</ul>
<p class="govuk-body">@messages("foreignStructureBuildingQualifyingDate.details.content2.link.intro")
<a href="@messages("foreignStructureBuildingQualifyingDate.details.content2.link.href")" class="govuk-link" target="_blank" rel="noreferrer noopener">
@messages("foreignStructureBuildingQualifyingDate.details.content2.link.text")
</a>
</p>


@govukDateInput(
DateViewModel(
Expand Down
Loading