Skip to content

Commit

Permalink
BST-109988 6048 - Added page "Occupation and accounting CYA". Used ne…
Browse files Browse the repository at this point in the history
…w model `TurnoverSection6048` in accounting info controllers (#1056)

* BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers.

* BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers.

* BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers.

* BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers.

* BST-109988 6048 - Add page "Occupation and accounting CYA". Used new model `TurnoverSection6048` in accounting info controllers.
  • Loading branch information
tumakha authored Oct 23, 2024
1 parent 8dc9cf4 commit 42847da
Show file tree
Hide file tree
Showing 20 changed files with 434 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class AboutYourTradingHistoryController @Inject() (
&& (
newFinancialYears(occupationAndAccounting) == previousFinancialYears ||
newFinancialYears(occupationAndAccounting) == previousFinancialYears6076 ||
newFinancialYears(occupationAndAccounting) == previousFinancialYears6045
newFinancialYears(occupationAndAccounting) == previousFinancialYears6045 ||
newFinancialYears(occupationAndAccounting) == previousFinancialYears6048
)
)
.getOrElse(navigator.nextPage(AboutYourTradingHistoryPageId, updatedData).apply(updatedData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class EditFinancialYearEndDateController @Inject() (
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6045)
.fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case FOR6048 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case FOR6076 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6076)
Expand All @@ -82,6 +86,8 @@ class EditFinancialYearEndDateController @Inject() (
case FOR6030 => aboutTheTradingHistory.turnoverSections6030.nonEmpty
case FOR6045 | FOR6046 =>
request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6045).exists(_.nonEmpty)
case FOR6048 =>
request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).exists(_.nonEmpty)
case FOR6076 =>
request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6076).exists(_.nonEmpty)
case _ => aboutTheTradingHistory.turnoverSections.nonEmpty
Expand All @@ -99,6 +105,10 @@ class EditFinancialYearEndDateController @Inject() (
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6045)
.fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case FOR6048 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case FOR6076 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6076)
Expand Down Expand Up @@ -136,6 +146,7 @@ class EditFinancialYearEndDateController @Inject() (
case FOR6030 =>
buildUpdateData6030(aboutTheTradingHistory, index, data, newOccupationAndAccounting)
case FOR6045 | FOR6046 => buildUpdatedData6045(index, data, newOccupationAndAccounting)
case FOR6048 => buildUpdatedData6048(index, data, newOccupationAndAccounting)
case FOR6076 => buildUpdatedData6076(index, data, newOccupationAndAccounting)
case _ => buildUpdateData(aboutTheTradingHistory, index, data, newOccupationAndAccounting)
}
Expand Down Expand Up @@ -166,6 +177,11 @@ class EditFinancialYearEndDateController @Inject() (
.flatMap(_.turnoverSections6045)
.flatMap(_.headOption)
.exists(_.grossReceiptsCaravanFleetHire.isDefined)
case FOR6048 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.flatMap(_.headOption)
.exists(_.income.isDefined)
case FOR6076 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6076)
Expand Down Expand Up @@ -267,6 +283,32 @@ class EditFinancialYearEndDateController @Inject() (
)
}

private def buildUpdatedData6048(
index: Int,
data: LocalDate,
newOccupationAndAccounting: OccupationalAndAccountingInformation
)(implicit request: SessionRequest[AnyContent]): Session = {
val turnoverSections6048 =
request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).getOrElse(Seq.empty)
val updatedTurnoverSections = turnoverSections6048.updated(
index,
turnoverSections6048(index).copy(financialYearEnd = data)
)

val updatedData = updateAboutTheTradingHistory(
_.copy(
occupationAndAccountingInformation = Some(newOccupationAndAccounting)
)
)
updatedData.copy(
aboutTheTradingHistoryPartOne = Some(
updatedData.aboutTheTradingHistoryPartOne
.getOrElse(AboutTheTradingHistoryPartOne())
.copy(turnoverSections6048 = Some(updatedTurnoverSections))
)
)
}

private def buildUpdatedData6076(
index: Int,
data: LocalDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ class FinancialYearEndController @Inject() (
newOccupationAndAccounting,
isFinancialYearEndDayUnchanged
)
case FOR6048 =>
buildUpdatedData6048(
aboutTheTradingHistory,
newOccupationAndAccounting,
isFinancialYearEndDayUnchanged
)
case FOR6076 =>
buildUpdatedData6076(
aboutTheTradingHistory,
Expand Down Expand Up @@ -140,6 +146,12 @@ class FinancialYearEndController @Inject() (
.flatMap(_.turnoverSections6045)
.flatMap(_.headOption)
.exists(_.grossReceiptsCaravanFleetHire.isDefined)
) || (
request.sessionData.forType == FOR6048 &&
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.flatMap(_.headOption)
.exists(_.income.isDefined)
))
)
.getOrElse(navigator.nextPage(FinancialYearEndPageId, updatedData).apply(updatedData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class FinancialYearEndDatesSummaryController @Inject() (
.flatMap(_.turnoverSections6045)
.flatMap(_.headOption)
.exists(_.grossReceiptsCaravanFleetHire.isDefined)
case FOR6048 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.flatMap(_.headOption)
.exists(_.income.isDefined)
case FOR6076 =>
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6076)
Expand Down
5 changes: 5 additions & 0 deletions app/models/Session.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ case class Session(
.flatMap(_.turnoverSections6045)
.fold(Seq.empty[(LocalDate, Int)])(_.map(_.financialYearEnd).zipWithIndex)

def financialYearEndDates6048: Seq[(LocalDate, Int)] =
aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.fold(Seq.empty[(LocalDate, Int)])(_.map(_.financialYearEnd).zipWithIndex)

def financialYearEndDates6076: Seq[(LocalDate, Int)] =
aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6076)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ case class AboutTheTradingHistoryPartOne(
additionalMiscDetails: Option[AdditionalMiscDetails] = None,
fromCYA: Option[Boolean] = None,
// 6048
turnoverSections6048: Option[Seq[TurnoverSection6048]] = None,
areYouVATRegistered: Option[AnswersYesNo] = None
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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}

import java.time.LocalDate

/**
* 6048 Trading history.
*
* @author Yuriy Tumakha
*/
case class TurnoverSection6048(
financialYearEnd: LocalDate,
income: Option[BigDecimal] = None // TODO: replace with income: Option[Income6048] = None
)

object TurnoverSection6048 {
implicit val format: OFormat[TurnoverSection6048] = Json.format
}
25 changes: 13 additions & 12 deletions app/navigation/AboutTheTradingHistoryNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ class AboutTheTradingHistoryNavigator @Inject() (audit: Audit) extends Navigator
s.aboutTheTradingHistory.flatMap(_.occupationAndAccountingInformation.flatMap(_.yearEndChanged)) match {
case Some(true) =>
s.forType match {
case FOR6020 | FOR6045 | FOR6046 | FOR6076 =>
case FOR6020 | FOR6045 | FOR6046 | FOR6048 | FOR6076 =>
aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show()
case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show()
case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show()
}

case _ =>
s.forType match {
case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show()
case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show()
case FOR6045 | FOR6046 => aboutthetradinghistory.routes.FinancialYearsController.show
case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show()
case _ => aboutthetradinghistory.routes.TurnoverController.show()
case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show()
case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show()
case FOR6045 | FOR6046 | FOR6048 => aboutthetradinghistory.routes.FinancialYearsController.show
case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show()
case _ => aboutthetradinghistory.routes.TurnoverController.show()
}
}
}
Expand All @@ -117,18 +117,19 @@ class AboutTheTradingHistoryNavigator @Inject() (audit: Audit) extends Navigator

private def financialYearEndDatesRouting: Session => Call =
_.forType match {
case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show()
case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show()
case FOR6045 | FOR6046 => aboutthetradinghistory.routes.FinancialYearsController.show
case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show()
case _ => aboutthetradinghistory.routes.TurnoverController.show()
case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show()
case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show()
case FOR6045 | FOR6046 | FOR6048 => aboutthetradinghistory.routes.FinancialYearsController.show
case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show()
case _ => aboutthetradinghistory.routes.TurnoverController.show()
}

private def financialYearsRouting: Session => Call =
_.forType match {
case FOR6020 => aboutthetradinghistory.routes.TotalFuelSoldController.show()
case FOR6030 => aboutthetradinghistory.routes.Turnover6030Controller.show()
case FOR6045 | FOR6046 => aboutthetradinghistory.routes.StaticCaravansController.show()
case FOR6048 => aboutthetradinghistory.routes.StaticCaravansController.show() // TODO: Income6048Controller
case FOR6076 => aboutthetradinghistory.routes.ElectricityGeneratedController.show()
case _ => aboutthetradinghistory.routes.TurnoverController.show()
}
Expand Down
45 changes: 45 additions & 0 deletions app/util/AccountingInformationUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ object AccountingInformationUtil {
.flatMap(_.turnoverSections6045)
.fold(Seq.empty[Int])(_.map(_.financialYearEnd.getYear))

def previousFinancialYears6048(implicit request: SessionRequest[AnyContent]): Seq[Int] =
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6048)
.fold(Seq.empty[Int])(_.map(_.financialYearEnd.getYear))

def previousFinancialYears6076(implicit request: SessionRequest[AnyContent]): Seq[Int] =
request.sessionData.aboutTheTradingHistoryPartOne
.flatMap(_.turnoverSections6076)
Expand Down Expand Up @@ -113,6 +118,46 @@ object AccountingInformationUtil {
)
}

def buildUpdatedData6048(
aboutTheTradingHistory: AboutTheTradingHistory,
newOccupationAndAccounting: OccupationalAndAccountingInformation,
isFinancialYearEndDayUnchanged: Boolean
)(implicit request: SessionRequest[AnyContent]): Session = {

val firstOccupy = newOccupationAndAccounting.firstOccupy
val financialYear = newOccupationAndAccounting.financialYear.get
val originalTurnoverSections6048 =
request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).getOrElse(Seq.empty)
val isFinancialYearsListUnchanged = newFinancialYears(newOccupationAndAccounting) == previousFinancialYears6048

val turnoverSections6048 =
if isFinancialYearEndDayUnchanged && isFinancialYearsListUnchanged then originalTurnoverSections6048
else if isFinancialYearsListUnchanged then
(originalTurnoverSections6048 zip financialYearsRequired(firstOccupy, financialYear)).map {
case (turnoverSection, finYearEnd) => turnoverSection.copy(financialYearEnd = finYearEnd)
}
else
financialYearsRequired(firstOccupy, financialYear).map { finYearEnd =>
TurnoverSection6048(financialYearEnd = finYearEnd)
}

val updatedData = updateAboutTheTradingHistory(
_.copy(
occupationAndAccountingInformation = Some(newOccupationAndAccounting),
checkYourAnswersAboutTheTradingHistory = sectionCompleted(isFinancialYearsListUnchanged, aboutTheTradingHistory)
)
)
updatedData.copy(
aboutTheTradingHistoryPartOne = Some(
updatedData.aboutTheTradingHistoryPartOne
.getOrElse(AboutTheTradingHistoryPartOne())
.copy(
turnoverSections6048 = Some(turnoverSections6048)
)
)
)
}

def buildUpdatedData6076(
aboutTheTradingHistory: AboutTheTradingHistory,
newOccupationAndAccounting: OccupationalAndAccountingInformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
case FOR6020 => aboutTheTradingHistory.turnoverSections6020.getOrElse(Seq.empty).map(_.financialYearEnd)
case FOR6030 => aboutTheTradingHistory.turnoverSections6030.map(_.financialYearEnd)
case FOR6045 | FOR6046 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6045).fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case FOR6048 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6048).fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case FOR6076 => request.sessionData.aboutTheTradingHistoryPartOne.flatMap(_.turnoverSections6076).fold(Seq.empty[LocalDate])(_.map(_.financialYearEnd))
case _ => aboutTheTradingHistory.turnoverSections.map(_.financialYearEnd)
}
Expand Down
3 changes: 2 additions & 1 deletion app/views/aboutthetradinghistory/financialYears.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
case FOR6020 => aboutTheTradingHistory.turnoverSections6020.getOrElse(Seq.empty).map(_.financialYearEnd)
case FOR6030 => aboutTheTradingHistory.turnoverSections6030.map(_.financialYearEnd)
case FOR6045 | FOR6046 => request.sessionData.financialYearEndDates6045.map(_._1)
case FOR6048 => request.sessionData.financialYearEndDates6048.map(_._1)
case FOR6076 => request.sessionData.financialYearEndDates6076.map(_._1)
case _ => aboutTheTradingHistory.turnoverSections.map(_.financialYearEnd)
}
Expand Down Expand Up @@ -144,7 +145,7 @@
Seq(
ActionItem(
href = forType match {
case FOR6020 | FOR6045 | FOR6046 | FOR6076 =>
case FOR6020 | FOR6045 | FOR6046 | FOR6048 | FOR6076 =>
aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show().url
case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show().url
},
Expand Down
14 changes: 11 additions & 3 deletions app/views/answers/answersAboutYourTradingHistory.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@import models.submissions.aboutthetradinghistory.TurnoverSection6020
@import models.submissions.aboutthetradinghistory.TurnoverSection6030
@import models.submissions.aboutthetradinghistory.TurnoverSection6045
@import models.submissions.aboutthetradinghistory.TurnoverSection6048
@import models.submissions.aboutthetradinghistory.TurnoverSection6076
@import models.submissions.aboutthetradinghistory.VariableOperatingExpensesSections
@import util.DateUtilLocalised
Expand Down Expand Up @@ -112,6 +113,7 @@
case FOR6020 => aboutTheTradingHistory.turnoverSections6020.getOrElse(Seq.empty).map(_.financialYearEnd)
case FOR6030 => aboutTheTradingHistory.turnoverSections6030.map(_.financialYearEnd)
case FOR6045 | FOR6046 => request.sessionData.financialYearEndDates6045.map(_._1)
case FOR6048 => request.sessionData.financialYearEndDates6048.map(_._1)
case FOR6076 => request.sessionData.financialYearEndDates6076.map(_._1)
case _ => aboutTheTradingHistory.turnoverSections.map(_.financialYearEnd)
}
Expand Down Expand Up @@ -487,6 +489,12 @@ <h2 class="govuk-heading-m">@messages(pageHeadingKey)</h2>
additionalParagraph)
}

@answer6048(valueLabelKey: String, getAnswer: TurnoverSection6048 => String, additionalParagraph: Option[String] = None) = @{
answer(valueLabelKey,
sectionAnswers1.answers.flatMap(_.turnoverSections6048).getOrElse(Seq.empty).map(getAnswer),
additionalParagraph)
}

@answer6076(valueLabelKey: String, getAnswer: TurnoverSection6076 => String, additionalParagraph: Option[String] = None) = @{
answer(valueLabelKey,
sectionAnswers1.answers.flatMap(_.turnoverSections6076).getOrElse(Seq.empty).map(getAnswer),
Expand All @@ -496,7 +504,7 @@ <h2 class="govuk-heading-m">@messages(pageHeadingKey)</h2>

<h2 class="govuk-heading-m">@messages("aboutYourTradingHistory.heading")</h2>

@if(Seq(FOR6045, FOR6046) contains forType) {
@if(Seq(FOR6045, FOR6046, FOR6048) contains forType) {
@govukSummaryList(SummaryList(rows =
sectionAnswers.row("checkYourAnswersAboutTheTradingHistory.occupationDate",
_.occupationAndAccountingInformation.map(_.firstOccupy.toYearMonth).map(dateUtil.formatYearMonth),
Expand All @@ -522,7 +530,7 @@ <h2 class="govuk-heading-m">@messages("aboutYourTradingHistory.heading")</h2>
sectionAnswers.row("checkYourAnswersAboutTheTradingHistory.financialYearEndUpdates",
_.fold("")(t => financialYearEndDatesTable(financialYearEndDates(t))),
forType match {
case FOR6020 | FOR6045 | FOR6046 | FOR6076 =>
case FOR6020 | FOR6045 | FOR6046 | FOR6048 | FOR6076 =>
aboutthetradinghistory.routes.FinancialYearEndDatesSummaryController.show()
case _ => aboutthetradinghistory.routes.FinancialYearEndDatesController.show()
},
Expand All @@ -531,7 +539,7 @@ <h2 class="govuk-heading-m">@messages("aboutYourTradingHistory.heading")</h2>
}


@if(!(Seq(FOR6020, FOR6045, FOR6046, FOR6076) contains forType)) {
@if(!(Seq(FOR6020, FOR6045, FOR6046, FOR6048, FOR6076) contains forType)) {
<h2 class="govuk-heading-m">@messages("turnover.heading")</h2>

@govukSummaryList(SummaryList(rows =
Expand Down
Loading

0 comments on commit 42847da

Please sign in to comment.