Skip to content

Commit

Permalink
BST-110161 6048 /fixed-costs (#1070)
Browse files Browse the repository at this point in the history
* BST-110161 6048 `/fixed-costs`

* BST-110161 6048 `/fixed-costs`

* BST-110161 6048 `/fixed-costs`

* BST-110161 6048 `/fixed-costs`

* BST-110161 6048 `/fixed-costs`
  • Loading branch information
tumakha authored Nov 7, 2024
1 parent a73e045 commit 2d0fbf9
Show file tree
Hide file tree
Showing 24 changed files with 506 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/controllers/MaxOfLettingsReachedController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import models.submissions.MaxOfLettings
import models.submissions.aboutfranchisesorlettings.AboutFranchisesOrLettings.updateAboutFranchisesOrLettings
import models.submissions.connectiontoproperty.StillConnectedDetails.updateStillConnectedDetails
import navigation.{AboutFranchisesOrLettingsNavigator, ConnectionToPropertyNavigator}
import navigation.identifiers.{MaxOfLettingsReachedCateringId, MaxOfLettingsReachedCurrentId, MaxOfLettingsReachedId}
import navigation.identifiers.{MaxOfLettingsReachedCurrentId, MaxOfLettingsReachedId}
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import repositories.SessionRepo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ class CheckYourAnswersAboutTheTradingHistoryController @Inject() (
),
data => {
val updatedData = updateAboutTheTradingHistory(_.copy(checkYourAnswersAboutTheTradingHistory = Some(data)))
.copy(lastCYAPageUrl =
Some(controllers.aboutthetradinghistory.routes.CheckYourAnswersAboutTheTradingHistoryController.show().url)
)
.copy(lastCYAPageUrl = Some(routes.CheckYourAnswersAboutTheTradingHistoryController.show().url))
session.saveOrUpdate(updatedData).map { _ =>
Redirect(navigator.nextPage(CheckYourAnswersAboutTheTradingHistoryId, updatedData).apply(updatedData))
}
Expand All @@ -88,26 +86,21 @@ class CheckYourAnswersAboutTheTradingHistoryController @Inject() (

private def getBackLink(answers: Session): String =
answers.forType match {
case FOR6010 | FOR6011 | FOR6016 =>
controllers.aboutthetradinghistory.routes.TurnoverController.show().url
case FOR6015 | FOR6030 =>
controllers.aboutthetradinghistory.routes.UnusualCircumstancesController.show().url
case FOR6020 =>
controllers.aboutthetradinghistory.routes.ElectricVehicleChargingPointsController.show().url
case FOR6010 | FOR6011 | FOR6016 => routes.TurnoverController.show().url
case FOR6015 | FOR6030 => routes.UnusualCircumstancesController.show().url
case FOR6020 => routes.ElectricVehicleChargingPointsController.show().url
case FOR6045 | FOR6046 =>
if (
answers.aboutTheTradingHistoryPartOne
.flatMap(_.caravans)
.flatMap(_.anyStaticLeisureCaravansOnSite)
.contains(AnswerYes)
)
controllers.aboutthetradinghistory.routes.CaravansAnnualPitchFeeController.show().url
routes.CaravansAnnualPitchFeeController.show().url
else
controllers.aboutthetradinghistory.routes.StaticCaravansController.show().url
case FOR6076 =>
controllers.aboutthetradinghistory.routes.IncomeExpenditureSummary6076Controller.show().url
case _ =>
logger.warn(s"Back link for enforcement action page reached with unknown enforcement taken value")
controllers.routes.TaskListController.show().url
routes.StaticCaravansController.show().url
case FOR6048 => routes.FixedCosts6048Controller.show.url // TODO: OperationalCosts6048Controller
case FOR6076 => routes.IncomeExpenditureSummary6076Controller.show().url
}

}
108 changes: 108 additions & 0 deletions app/controllers/aboutthetradinghistory/FixedCosts6048Controller.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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.aboutthetradinghistory

import actions.{SessionRequest, WithSessionRefiner}
import controllers.{FORDataCaptureController, aboutthetradinghistory}
import form.aboutthetradinghistory.FixedCosts6048Form.fixedCosts6048Form
import models.submissions.aboutthetradinghistory.AboutTheTradingHistoryPartOne.updateAboutTheTradingHistoryPartOne
import models.submissions.aboutthetradinghistory.{FixedCosts6048, TurnoverSection6048}
import navigation.AboutTheTradingHistoryNavigator
import navigation.identifiers.FixedCosts6048Id
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result}
import repositories.SessionRepo
import views.html.aboutthetradinghistory.fixedCosts6048

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

/**
* @author Yuriy Tumakha
*/
@Singleton
class FixedCosts6048Controller @Inject() (
fixedCosts6048View: fixedCosts6048,
navigator: AboutTheTradingHistoryNavigator,
withSessionRefiner: WithSessionRefiner,
@Named("session") val session: SessionRepo,
mcc: MessagesControllerComponents
)(implicit ec: ExecutionContext)
extends FORDataCaptureController(mcc)
with I18nSupport {

def show: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request =>
runWithSessionCheck { turnoverSections6048 =>
val years = turnoverSections6048.map(_.financialYearEnd).map(_.getYear.toString)

Ok(
fixedCosts6048View(
fixedCosts6048Form(years).fill(
turnoverSections6048.map(_.fixedCosts getOrElse FixedCosts6048())
),
getBackLink
)
)
}
}

def submit: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request =>
runWithSessionCheck { turnoverSections6048 =>
val years = turnoverSections6048.map(_.financialYearEnd).map(_.getYear.toString)

continueOrSaveAsDraft[Seq[FixedCosts6048]](
fixedCosts6048Form(years),
formWithErrors => BadRequest(fixedCosts6048View(formWithErrors, getBackLink)),
success => {
val updatedSections =
(success zip turnoverSections6048).map { case (fixedCosts, previousSection) =>
previousSection.copy(
fixedCosts = Some(fixedCosts)
)
}

val updatedData = updateAboutTheTradingHistoryPartOne(
_.copy(
turnoverSections6048 = Some(updatedSections)
)
)

session
.saveOrUpdate(updatedData)
.map(_ => navigator.nextPage(FixedCosts6048Id, updatedData).apply(updatedData))
.map(Redirect)
}
)
}
}

private def runWithSessionCheck(
action: Seq[TurnoverSection6048] => Future[Result]
)(implicit request: SessionRequest[AnyContent]): Future[Result] =
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.filter(_.nonEmpty)
.fold(Future.successful(Redirect(routes.AboutYourTradingHistoryController.show())))(action)

private def getBackLink(implicit request: SessionRequest[AnyContent]): String =
navigator.from match {
case "CYA" =>
controllers.aboutthetradinghistory.routes.CheckYourAnswersAboutTheTradingHistoryController.show().url
case _ => aboutthetradinghistory.routes.Income6048Controller.show.url
}

}
47 changes: 47 additions & 0 deletions app/form/aboutthetradinghistory/FixedCosts6048Form.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 form.aboutthetradinghistory

import form.MappingSupport.*
import models.submissions.aboutthetradinghistory.FixedCosts6048
import play.api.data.Forms.mapping
import play.api.data.{Form, Mapping}
import play.api.i18n.Messages

/**
* @author Yuriy Tumakha
*/
object FixedCosts6048Form {

private def columnMapping(year: String)(implicit messages: Messages): Mapping[FixedCosts6048] =
mapping(
"insurance" -> turnoverSalesMappingWithYear("turnover.6048.fixedCosts.insurance", year),
"businessRatesOrCouncilTax" -> turnoverSalesMappingWithYear(
"turnover.6048.fixedCosts.businessRatesOrCouncilTax",
year
),
"rent" -> turnoverSalesMappingWithYear("turnover.6048.fixedCosts.rent", year)
)(FixedCosts6048.apply)(o => Some(Tuple.fromProductTyped(o)))

def fixedCosts6048Form(
years: Seq[String]
)(implicit messages: Messages): Form[Seq[FixedCosts6048]] =
Form {
mappingPerYear(years, (year, idx) => s"turnover[$idx]" -> columnMapping(year))
}

}
2 changes: 1 addition & 1 deletion app/form/lettingHistory/PermanentResidentsForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package form.lettingHistory
import form.MappingSupport.createYesNoType
import models.submissions.common.AnswersYesNo
import play.api.data.Form
import play.api.data.Forms.{mapping, single}
import play.api.data.Forms.single

object PermanentResidentsForm:
val theForm = Form[AnswersYesNo](
Expand Down
34 changes: 34 additions & 0 deletions app/models/submissions/aboutthetradinghistory/FixedCosts6048.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 models.submissions.aboutthetradinghistory

import play.api.libs.json.{Json, OFormat}

/**
* @author Yuriy Tumakha
*/
case class FixedCosts6048(
insurance: Option[BigDecimal] = None,
businessRatesOrCouncilTax: Option[BigDecimal] = None,
rent: Option[BigDecimal] = None
) {
def total: BigDecimal = Seq(insurance, businessRatesOrCouncilTax, rent).flatten.sum
}

object FixedCosts6048 {
implicit val format: OFormat[FixedCosts6048] = Json.format
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import java.time.LocalDate
case class TurnoverSection6048(
financialYearEnd: LocalDate,
tradingPeriod: Int = 52,
income: Option[Income6048] = None
income: Option[Income6048] = None,
fixedCosts: Option[FixedCosts6048] = None
)

object TurnoverSection6048 {
Expand Down
5 changes: 3 additions & 2 deletions app/navigation/AboutTheTradingHistoryNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import controllers.aboutthetradinghistory.routes
import models.submissions.common.{AnswerNo, AnswerYes}
import models.ForType.*
import models.Session
import navigation.identifiers._
import navigation.identifiers.*
import play.api.Logging
import play.api.mvc.{AnyContent, Call, Request}
import uk.gov.hmrc.http.HeaderCarrier
Expand Down Expand Up @@ -354,7 +354,8 @@ class AboutTheTradingHistoryNavigator @Inject() (audit: Audit) extends Navigator
),
ChangeOccupationAndAccountingId -> (_ => aboutthetradinghistory.routes.AboutYourTradingHistoryController.show()),
AreYouVATRegisteredId -> (_ => aboutthetradinghistory.routes.FinancialYearEndController.show()),
Income6048Id -> (_ =>
Income6048Id -> (_ => aboutthetradinghistory.routes.FixedCosts6048Controller.show),
FixedCosts6048Id -> (_ =>
aboutthetradinghistory.routes.CheckYourAnswersAboutTheTradingHistoryController.show()
) // TODO: FixedCosts6048Controller
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,7 @@ case object AreYouVATRegisteredId extends Identifier {
case object Income6048Id extends Identifier {
override def toString: String = "income6048Page"
}

case object FixedCosts6048Id extends Identifier {
override def toString: String = "fixedCostsPage"
}
Loading

0 comments on commit 2d0fbf9

Please sign in to comment.