-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BST-110161 6048
/fixed-costs
(#1070)
* 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
Showing
24 changed files
with
506 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
app/controllers/aboutthetradinghistory/FixedCosts6048Controller.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/models/submissions/aboutthetradinghistory/FixedCosts6048.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.