Skip to content
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 @@ -17,24 +17,63 @@
package controllers.taxCalculation

import controllers.actions.*
import controllers.routes.*
import models.NormalMode
import models.prelimQuestions.TransactionType
import models.prelimQuestions.TransactionType.GrantOfLease
import models.taxCalculation.{MissingFullReturnError, TaxCalculationResult}
import navigation.Navigator
import pages.preliminary.TransactionTypePage
import pages.taxCalculation.{IsLeaseholdAndSelfAssessedPage, TaxCalculationBeforeYouStartPage}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepository
import services.taxCalculation.SdltCalculationService
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import uk.gov.hmrc.play.http.HeaderCarrierConverter
import utils.TaxCalculationHelper.*
import views.html.taxCalculation.TaxCalculationBeforeYouStartView

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class TaxCalculationBeforeYouStartController @Inject()(
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
val controllerComponents: MessagesControllerComponents,
view: TaxCalculationBeforeYouStartView
) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData) {
override val messagesApi: MessagesApi,
identify: IdentifierAction,
getData: DataRetrievalAction,
requireData: DataRequiredAction,
sdltCalculationService: SdltCalculationService,
sessionRepository: SessionRepository,
navigator: Navigator,
val controllerComponents: MessagesControllerComponents,
view: TaxCalculationBeforeYouStartView
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport {

def onPageLoad: Action[AnyContent] = (identify andThen getData andThen requireData).async {
implicit request =>

implicit val hc: HeaderCarrier = HeaderCarrierConverter.fromRequestAndSession(request, request.session)

sdltCalculationService.calculateStampDutyLandTax(request.userAnswers).flatMap {
case Right(result) =>

val isLeasehold: Boolean = request.userAnswers.get(TransactionTypePage).contains(GrantOfLease)

val leaseholdSelfAssessedFlag = isLeasehold && isSelfAssessedResponse(result)

for {
updatedAnswers <- Future.fromTry(request.userAnswers.set(IsLeaseholdAndSelfAssessedPage, leaseholdSelfAssessedFlag))
_ <- sessionRepository.set(updatedAnswers)
} yield Ok(view(leaseholdSelfAssessedFlag))

case Left(MissingFullReturnError) => Future.successful(Redirect(NoReturnReferenceController.onPageLoad()))
case Left(_) => Future.successful(Redirect(ReturnTaskListController.onPageLoad()))
}
}

def onSubmit: Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
Ok(view())
Redirect(navigator.nextPage(TaxCalculationBeforeYouStartPage, NormalMode, request.userAnswers))
}
}
33 changes: 33 additions & 0 deletions app/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import pages.vendor.*
import pages.vendorAgent.*
import pages.land.*
import pages.transaction.*
import pages.taxCalculation.*
import pages.ukResidency.*
import play.api.mvc.Call

Expand Down Expand Up @@ -65,6 +66,7 @@ class Navigator @Inject()() {
case landPage if isLandSection(landPage) => landRoutes(landPage)
case residencyPage if isResidencySection(residencyPage) => residencyRoutes(residencyPage)
case transactionPage if isTransactionSection(transactionPage) => transactionRoutes(transactionPage)
case taxCalcPage if isTaxCalculationSection(taxCalcPage) => taxCalculationRoutes(taxCalcPage)
case _ => _ => routes.IndexController.onPageLoad()
}

Expand Down Expand Up @@ -254,6 +256,30 @@ class Navigator @Inject()() {
case _ => _ => routes.IndexController.onPageLoad()
}

private def isTaxCalculationSection(page: Page): Boolean = page match {
case TaxCalculationBeforeYouStartPage | CalculatedSdltPage | CalculatedSdltBreakdownPage
| SelfAssessmentAmountPage | PremiumPayableTaxPage | NpvTaxPage
| TotalAmountDuePage | PenaltiesAndInterestPage | TaxCalculationCheckYourAnswersPage => true
case _ => false
}

private def taxCalculationRoutes(page: Page): UserAnswers => Call = page match {

case TaxCalculationBeforeYouStartPage => answers =>
if (answers.get(IsLeaseholdAndSelfAssessedPage).contains(true)) routes.IndexController.onPageLoad() // TODO: replace -> PremiumPayableTaxController
else routes.IndexController.onPageLoad() // TODO: replace -> CalculatedSdltController
case CalculatedSdltPage => _ => routes.IndexController.onPageLoad() // TODO: replace -> SelfAssessmentAmountController
case CalculatedSdltBreakdownPage => _ => routes.IndexController.onPageLoad() // TODO: replace -> CalculatedSdltController
case SelfAssessmentAmountPage => _ => routes.IndexController.onPageLoad() // TODO: replace -> TotalAmountDueController
case PremiumPayableTaxPage => _ => routes.IndexController.onPageLoad() // TODO: replace -> NpvTaxController
case NpvTaxPage => _ => routes.IndexController.onPageLoad() // TODO: replace -> TotalAmountDueController
case TotalAmountDuePage => _ => routes.IndexController.onPageLoad() // TODO: replace -> PenaltiesAndInterestController
case PenaltiesAndInterestPage => _ => routes.IndexController.onPageLoad() // TODO: replace -> TaxCalculationCheckYourAnswersController
case TaxCalculationCheckYourAnswersPage => _ => routes.ReturnTaskListController.onPageLoad()

case _ => _ => routes.IndexController.onPageLoad()
}

private val checkRouteMap: Page => UserAnswers => Call = {
case WhoIsMakingThePurchasePage => _ => controllers.purchaser.routes.PurchaserCheckYourAnswersController.onPageLoad()
case NameOfPurchaserPage => _ => controllers.purchaser.routes.PurchaserCheckYourAnswersController.onPageLoad()
Expand Down Expand Up @@ -315,6 +341,13 @@ class Navigator @Inject()() {
case LandMineralsOrMineralRightsPage => _ => controllers.land.routes.LandCheckYourAnswersController.onPageLoad()
case LandSelectMeasurementUnitPage => _ => controllers.land.routes.AreaOfLandController.onPageLoad(CheckMode)

// TODO: replace -> TaxCalculationCheckYourAnswersController
case SelfAssessmentAmountPage => _ => routes.IndexController.onPageLoad()
case PremiumPayableTaxPage => _ => routes.IndexController.onPageLoad()
case NpvTaxPage => _ => routes.IndexController.onPageLoad()
case TotalAmountDuePage => _ => routes.IndexController.onPageLoad()
case PenaltiesAndInterestPage => _ => routes.IndexController.onPageLoad()

case _ => _ => controllers.routes.ReturnTaskListController.onPageLoad()
}

Expand Down
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/CalculatedSdltBreakdownPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object CalculatedSdltBreakdownPage extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "calculatedSdltBreakdown"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/CalculatedSdltPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object CalculatedSdltPage extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "calculatedSdlt"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/IsLeaseholdAndSelfAssessedPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object IsLeaseholdAndSelfAssessedPage extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "isLeaseholdAndSelfAssessed"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/NpvTaxPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object NpvTaxPage extends QuestionPage[BigDecimal] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "npvTax"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/PenaltiesAndInterestPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object PenaltiesAndInterestPage extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "penaltiesAndInterest"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/PremiumPayableTaxPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object PremiumPayableTaxPage extends QuestionPage[BigDecimal] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "premiumPayableTax"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/SelfAssessmentAmountPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object SelfAssessmentAmountPage extends QuestionPage[BigDecimal] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "selfAssessmentAmount"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/TaxCalculationBeforeYouStartPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object TaxCalculationBeforeYouStartPage extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "taxCalculationBeforeYouStart"
}
27 changes: 27 additions & 0 deletions app/pages/taxCalculation/TaxCalculationCheckYourAnswersPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 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 pages.taxCalculation

import pages.QuestionPage
import play.api.libs.json.JsPath

case object TaxCalculationCheckYourAnswersPage extends QuestionPage[Boolean] {

override def path: JsPath = JsPath \ "taxCalculationCurrent" \ toString

override def toString: String = "taxCalculationCheckYourAnswers"
}
Loading