Skip to content

Commit

Permalink
Merge pull request #112 from hmrc/VEIOSS-569
Browse files Browse the repository at this point in the history
VEIOSS-569 | Correction Check Your Answers needs adding to Returns
  • Loading branch information
Lee-Powell authored Apr 11, 2024
2 parents be03b56 + 0b6fb48 commit 883ccea
Show file tree
Hide file tree
Showing 13 changed files with 469 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/config/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ object Constants {
val maxCurrencyAmount: BigDecimal = 1000000000
val minCurrencyAmount: BigDecimal = -1000000000
val correctionsPeriodsLimit: Int = 3
val periodYear: Int = 2023

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

import controllers.actions._
import models.Index
import models.corrections.CorrectionToCountry
import pages.Waypoints
import pages.corrections.{CorrectionCountryPage, CorrectionReturnPeriodPage}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import utils.CompletionChecks
import utils.FutureSyntax.FutureOps
import viewmodels.checkAnswers.corrections.{CountryVatCorrectionSummary, NewVatTotalSummary, PreviousVatTotalSummary}
import viewmodels.govuk.summarylist._
import views.html.corrections.CheckVatPayableAmountView

import javax.inject.Inject
import scala.concurrent.ExecutionContext

class CheckVatPayableAmountController @Inject()(
override val messagesApi: MessagesApi,
cc: AuthenticatedControllerComponents,
view: CheckVatPayableAmountView
)(implicit ec: ExecutionContext) extends FrontendBaseController with CompletionChecks with I18nSupport with CorrectionBaseController {

protected val controllerComponents: MessagesControllerComponents = cc

def onPageLoad(waypoints: Waypoints, periodIndex: Index, countryIndex: Index): Action[AnyContent] = cc.authAndGetDataAndCorrectionEligible().async {
implicit request =>

val period = request.userAnswers.period
val correctionPeriod = request.userAnswers.get(CorrectionReturnPeriodPage(periodIndex))
val selectedCountry = request.userAnswers.get(CorrectionCountryPage(periodIndex, countryIndex))

(correctionPeriod, selectedCountry) match {
case (Some(correctionPeriod), Some(country)) =>
getPreviouslyDeclaredCorrectionAnswers(waypoints, periodIndex, countryIndex) { originalAmount =>

val summaryList = SummaryListViewModel(
rows = Seq(
Some(PreviousVatTotalSummary.row(originalAmount.amount)),
CountryVatCorrectionSummary.row(request.userAnswers, waypoints, periodIndex, countryIndex),
NewVatTotalSummary.row(request.userAnswers, periodIndex, countryIndex, originalAmount.amount)
).flatten
)

withCompleteDataAsync[CorrectionToCountry](
periodIndex,
data = getIncompleteCorrections _,
onFailure = (_: Seq[CorrectionToCountry]) => {
Ok(view(
waypoints,
period,
summaryList,
country,
correctionPeriod,
periodIndex,
countryIndex,
countryCorrectionComplete = false
)).toFuture
}) {
Ok(view(waypoints, period, summaryList, country, correctionPeriod, periodIndex, countryIndex, countryCorrectionComplete = true)).toFuture
}
}
case _ =>
Redirect(controllers.routes.JourneyRecoveryController.onPageLoad()).toFuture
}
}

def onSubmit(waypoints: Waypoints, periodIndex: Index, countryIndex: Index, incompletePromptShown: Boolean): Action[AnyContent] =
cc.authAndGetDataAndCorrectionEligible() {
implicit request =>
val incomplete = getIncompleteCorrectionsToCountry(periodIndex, countryIndex)
if(incomplete.isEmpty) {
Redirect(controllers.corrections.routes.CorrectionListCountriesController.onPageLoad(waypoints, periodIndex))
} else {
if(incompletePromptShown) {
Redirect(routes.CorrectionCountryController.onPageLoad(waypoints, periodIndex, countryIndex))
} else {
Redirect(routes.CheckVatPayableAmountController.onPageLoad(waypoints, periodIndex, countryIndex))
}
}
}
}
28 changes: 28 additions & 0 deletions app/pages/corrections/CheckVatPayableAmountPage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 pages.corrections

import models.Index
import pages.{Page, Waypoints}
import play.api.mvc.Call

case class CheckVatPayableAmountPage(periodIndex: Index, countryIndex: Index) extends Page {

override def route(waypoints: Waypoints): Call =
controllers.corrections.routes.CheckVatPayableAmountController.onPageLoad(waypoints, periodIndex, countryIndex)

}
2 changes: 1 addition & 1 deletion app/pages/corrections/VatPayableForCountryPage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ case class VatPayableForCountryPage(periodIndex: Index, countryIndex: Index) ext
nextPageNormalMode(waypoints, answers)
override protected def nextPageNormalMode(waypoints: Waypoints, answers: UserAnswers): Page =
answers.get(VatPayableForCountryPage(periodIndex, countryIndex)) match {
case Some(true) => CorrectionListCountriesPage(periodIndex)
case Some(true) => CheckVatPayableAmountPage(periodIndex, countryIndex)
case Some(false) => VatAmountCorrectionCountryPage(periodIndex, countryIndex)

case _ => JourneyRecoveryPage
Expand Down
1 change: 0 additions & 1 deletion app/services/VatReturnService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class VatReturnService @Inject() {
)
}


private def getSales(answers: UserAnswers): ValidationResult[List[SalesToCountry]] =
answers.get(SoldGoodsPage) match {
case Some(true) =>
Expand Down
6 changes: 6 additions & 0 deletions app/utils/CompletionChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ trait CompletionChecks {
}
}

def getIncompleteCorrectionsToCountry(periodIndex: Index, countryIndex: Index)(implicit request: DataRequest[AnyContent]): Option[CorrectionToCountry] = {
request.userAnswers
.get(CorrectionToCountryQuery(periodIndex, countryIndex))
.find(_.countryVatCorrection.isEmpty)
}

def getIncompleteCorrections(periodIndex: Index)(implicit request: DataRequest[AnyContent]): List[CorrectionToCountry] = {
request.userAnswers
.get(AllCorrectionCountriesQuery(periodIndex))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 viewmodels.checkAnswers.corrections

import models.{Index, UserAnswers}
import pages.Waypoints
import pages.corrections.VatAmountCorrectionCountryPage
import play.api.i18n.Messages
import play.twirl.api.Html
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.govuk.all.currencyFormat
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object CountryVatCorrectionSummary {

def row(answers: UserAnswers, waypoints: Waypoints, periodIndex: Index, countryIndex: Index)(implicit messages: Messages): Option[SummaryListRow] = {
answers.get(VatAmountCorrectionCountryPage(periodIndex, countryIndex)).map {
answer =>

SummaryListRowViewModel(
key = "vatAmountCorrectionCountry.checkYourAnswersLabel",
value = ValueViewModel(HtmlContent(Html(currencyFormat(answer)))),
actions = Seq(
ActionItemViewModel(
"site.change",
controllers.corrections.routes.VatAmountCorrectionCountryController.onPageLoad(
waypoints, periodIndex, countryIndex
).url
).withVisuallyHiddenText(messages("vatAmountCorrectionCountry.change.hidden"))
.withAttribute(("id", "change-correction-amount"))
)
)
}

}
}
43 changes: 43 additions & 0 deletions app/viewmodels/checkAnswers/corrections/NewVatTotalSummary.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 viewmodels.checkAnswers.corrections

import models.{Index, UserAnswers}
import pages.corrections.VatAmountCorrectionCountryPage
import play.api.i18n.Messages
import play.twirl.api.Html
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.govuk.all.currencyFormat
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object NewVatTotalSummary {

def row(answers: UserAnswers, periodIndex: Index, countryIndex: Index, originalAmount: BigDecimal)(implicit messages: Messages): Option[SummaryListRow] = {
answers.get(VatAmountCorrectionCountryPage(periodIndex, countryIndex)).map {
answer =>

SummaryListRowViewModel(
key = "checkVatPayableAmount.newVatTotal.checkYourAnswersLabel",
value = ValueViewModel(HtmlContent(Html(currencyFormat(answer + originalAmount)))),
actions = Seq.empty
)
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 viewmodels.checkAnswers.corrections


import play.api.i18n.Messages
import play.twirl.api.Html
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.govuk.all.currencyFormat
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object PreviousVatTotalSummary {

def row(originalAmount: BigDecimal)(implicit messages: Messages): SummaryListRow =

SummaryListRowViewModel(
key = "checkVatPayableAmount.previousVatTotal.checkYourAnswersLabel",
value = ValueViewModel(HtmlContent(Html(currencyFormat(originalAmount)))),
actions = Seq.empty
)
}
73 changes: 73 additions & 0 deletions app/views/corrections/CheckVatPayableAmountView.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@*
* 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.
*@

@this(
layout: templates.Layout,
govukSummaryList: GovukSummaryList,
govukButton: GovukButton,
formHelper: FormWithCSRF,
govukWarningText: GovukWarningText,
button: ButtonGroup
)

@(
waypoints: Waypoints,
period: Period,
summaryList: SummaryList,
country: Country,
correctionPeriod: Period,
periodIndex: Index,
countryIndex: Index,
countryCorrectionComplete: Boolean
)(implicit request: Request[_], messages: Messages)

@layout(pageTitle = titleNoForm(messages("checkVatPayableAmount.title"))) {

<header class="hmrc-page-heading">
<p class="govuk-caption-l hmrc-caption-l">@messages("checkVatPayableAmount.caption", correctionPeriod.displayText, country.name)</p>
<h1 class="govuk-heading-l">@messages("checkVatPayableAmount.heading")</h1>
</header>

@if(!countryCorrectionComplete) {
@govukWarningText(WarningText(
iconFallbackText = Option(messages("site.warning")),
content = Text(messages("error.missing_answers"))
))
}

@govukSummaryList(summaryList)

@if(countryCorrectionComplete) {
@formHelper(action = controllers.corrections.routes.CheckVatPayableAmountController.onSubmit(waypoints, periodIndex, countryIndex, false)) {

<p class="govuk-!-margin-bottom-9" style="margin-top:50px;">
<div class="govuk-button-group">
@button("site.continue", controllers.corrections.routes.CheckVatPayableAmountController.onPageLoad(waypoints, periodIndex, countryIndex).url, period, waypoints
)
</div>
</p>
}
} else {
<h2 class="govuk-heading-m push--top">@messages("error.missing_answers_header")</h2>
<p class="govuk-body">@messages("error.missing_answers_prompt", country.name)</p>

@formHelper(action = controllers.corrections.routes.CheckVatPayableAmountController.onSubmit(waypoints, periodIndex, countryIndex, true)) {
@govukButton(
ButtonViewModel(messages("error.resolve_missing_answers"))
)
}
}
}
3 changes: 3 additions & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,6 @@ POST /which-previous-registration-to-pay

GET /which-previous-registration-vat-period-to-pay controllers.payments.WhichPreviousRegistrationVatPeriodToPayController.onPageLoad(waypoints: Waypoints ?= EmptyWaypoints)
POST /which-previous-registration-vat-period-to-pay controllers.payments.WhichPreviousRegistrationVatPeriodToPayController.onSubmit(waypoints: Waypoints ?= EmptyWaypoints)

GET /vat-payable-check/:periodIndex/:countryIndex controllers.corrections.CheckVatPayableAmountController.onPageLoad(waypoints: Waypoints ?= EmptyWaypoints, periodIndex: Index, countryIndex: Index)
POST /vat-payable-check/:periodIndex/:countryIndex controllers.corrections.CheckVatPayableAmountController.onSubmit(waypoints: Waypoints ?= EmptyWaypoints, periodIndex: Index, countryIndex: Index, incompletePromptShown: Boolean)
6 changes: 6 additions & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,9 @@ whichPreviousRegistrationToPay.error.required = Select which previous registrati
whichPreviousRegistrationToPay.change.hidden = which previous registration you want to pay

whichPreviousRegistrationVatPeriodToPay.error.required = Select which month you would like to make a payment for

checkVatPayableAmount.title = Check your answers
checkVatPayableAmount.heading = Check your answers
checkVatPayableAmount.caption = Correction month: {0}
checkVatPayableAmount.previousVatTotal.checkYourAnswersLabel = Previous VAT total declared
checkVatPayableAmount.newVatTotal.checkYourAnswersLabel = New VAT total
Loading

0 comments on commit 883ccea

Please sign in to comment.