Skip to content

Commit

Permalink
Merge pull request #437 from hmrc/DL-14132
Browse files Browse the repository at this point in the history
DL 14132: Fixing incomplete calculation error
  • Loading branch information
nadinJ authored Jul 25, 2024
2 parents e73e5e0 + cbf0d32 commit 448d7d7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import utils.AtedConstants._
import utils.AtedUtils
import uk.gov.hmrc.play.bootstrap.controller.WithUnsafeDefaultFormBinding
import scala.concurrent.{ExecutionContext, Future}
import utils.PeriodUtils

class PropertyDetailsSupportingInfoController @Inject()(mcc: MessagesControllerComponents,
authAction: AuthAction,
Expand All @@ -48,7 +49,6 @@ class PropertyDetailsSupportingInfoController @Inject()(mcc: MessagesControllerC
implicit val ec: ExecutionContext = mcc.executionContext
val controllerId: String = "PropertyDetailsSupportingInfoController"


def view(id: String) : Action[AnyContent] = Action.async { implicit request =>
authAction.authorisedAction { implicit authContext =>
ensureClientContext {
Expand Down Expand Up @@ -96,43 +96,52 @@ class PropertyDetailsSupportingInfoController @Inject()(mcc: MessagesControllerC
authAction.authorisedAction { implicit authContext =>
ensureClientContext {
serviceInfoService.getPartial.flatMap { serviceInfoContent =>
propertyDetailsSupportingInfoForm.bindFromRequest().fold(
formWithError => {
currentBackLink.map(backLink => BadRequest(template(id, periodKey, formWithError, mode, serviceInfoContent, backLink)))
},
propertyDetails => {
val backLink = Some(controllers.propertyDetails.routes.PropertyDetailsSupportingInfoController.view(id).url)
for {
cachedData <- dataCacheConnector.fetchAndGetFormData[Boolean](SelectedPreviousReturn)
_ <- propertyDetailsService.validateCalculateDraftPropertyDetails(id, AtedUtils.isEditSubmittedMode(mode) && cachedData.isEmpty)
_ <- propertyDetailsService.saveDraftPropertyDetailsSupportingInfo(id, propertyDetails)
result <-
if (AtedUtils.isEditSubmittedMode(mode) && cachedData.isEmpty) {
redirectWithBackLink(
editLiabilitySummaryController.controllerId,
controllers.editLiability.routes.EditLiabilitySummaryController.view(id),
backLink)
} else {
propertyDetailsService.calculateDraftPropertyDetails(id).flatMap { response =>
response.status match {
case OK =>
redirectWithBackLink(
propertyDetailsSummaryController.controllerId,
controllers.propertyDetails.routes.PropertyDetailsSummaryController.view(id),
backLink)
case BAD_REQUEST if response.body.contains("Agent not Valid") =>
Future.successful(BadRequest(templateError("ated.client-problem.title",
"ated.client-problem.header", "ated.client-problem.message", None, Some(appConfig.agentRedirectedToMandate), None, None, serviceInfoContent)))
case status =>
logger.error(s"[PropertyDetailsSupportingInfoController][save] UNKNOWN_SAVE_STATUS - $status - ${Option(response.body).getOrElse("No response body")}")
Future.successful(InternalServerError(templateError("ated.client-problem.title",
"ated.client-problem.header", "ated.client-problem.message", None, Some(appConfig.agentRedirectedToMandate), None, None, serviceInfoContent)))
propertyDetailsCacheResponse(id) {
case PropertyDetailsCacheSuccessResponse(propertyDetails) =>
val period: Option[PropertyDetailsPeriod] = propertyDetails.period
propertyDetailsSupportingInfoForm.bindFromRequest().fold(
formWithError => {
currentBackLink.map(backLink => BadRequest(template(id, periodKey, formWithError, mode, serviceInfoContent, backLink)))
},
propertyDetails => {
val backLink = Some(controllers.propertyDetails.routes.PropertyDetailsSupportingInfoController.view(id).url)
for {
cachedData <- dataCacheConnector.fetchAndGetFormData[Boolean](SelectedPreviousReturn)
_ <- propertyDetailsService.validateCalculateDraftPropertyDetails(id, AtedUtils.isEditSubmittedMode(mode) && cachedData.isEmpty)
_ <- propertyDetailsService.saveDraftPropertyDetailsSupportingInfo(id, propertyDetails)
result <-
if (AtedUtils.isEditSubmittedMode(mode) && cachedData.isEmpty) {
redirectWithBackLink(
editLiabilitySummaryController.controllerId,
controllers.editLiability.routes.EditLiabilitySummaryController.view(id),
backLink)
} else if (PeriodUtils.getDisplayPeriods(period, periodKey).nonEmpty) {
propertyDetailsService.calculateDraftPropertyDetails(id).flatMap { response =>
response.status match {
case OK =>
redirectWithBackLink(
propertyDetailsSummaryController.controllerId,
controllers.propertyDetails.routes.PropertyDetailsSummaryController.view(id),
backLink)
case BAD_REQUEST if response.body.contains("Agent not Valid") =>
Future.successful(BadRequest(templateError("ated.client-problem.title",
"ated.client-problem.header", "ated.client-problem.message", None, Some(appConfig.agentRedirectedToMandate), None, None, serviceInfoContent)))
case status =>
logger.error(s"[PropertyDetailsSupportingInfoController][save] UNKNOWN_SAVE_STATUS - $status - ${Option(response.body).getOrElse("No response body")}")
Future.successful(InternalServerError(templateError("ated.client-problem.title",
"ated.client-problem.header", "ated.client-problem.message", None, Some(appConfig.agentRedirectedToMandate), None, None, serviceInfoContent)))
}
}
} else {
redirectWithBackLink(
propertyDetailsSummaryController.controllerId,
controllers.propertyDetails.routes.PropertyDetailsSummaryController.view(id),
backLink)
}
}
}
} yield result
}
)
} yield result
}
)
}
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions app/views/propertyDetails/propertyDetailsSummary.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,19 @@ <h2 class="govuk-heading-m" id="return-status-header">@messages("ated.property-d
attributes = Map("id" -> "return-status")
))

<p class="govuk-body" id="ated-charge-text">@messages("ated.property-details-summary.table.ated-charge.text")</p>

@if(PeriodUtils.isListEmpty(periods)) {
<p class="govuk-body" id="ated-no-line-items">@messages("ated.property-details-summary.table.ated-no-line-items.text")</p>
} else {
<p class="govuk-body" id="ated-charge-text">@messages("ated.property-details-summary.table.ated-charge.text")</p>

<p id="ated-charge-value" class="govuk-heading-xl govuk-form-group">
@if(propertyDetails.calculated.isEmpty) {
@messages("ated.unknown-amount.text")
} else {
@propertyDetails.calculated.flatMap(x=>x.liabilityAmount.map(y=>formattedPounds(y)))
}
</p>
<p id="ated-charge-value" class="govuk-heading-xl govuk-form-group">
@if(propertyDetails.calculated.isEmpty) {
@messages("ated.unknown-amount.text")
} else {
@propertyDetails.calculated.flatMap(x=>x.liabilityAmount.map(y=>formattedPounds(y)))
}
</p>
}


@govukInsetText(InsetText(
Expand Down
1 change: 1 addition & 0 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ ated.property-details-summary.table.property-ated-details.promoter-reference.lab
ated.property-details-summary.table.property-ated-details.avoidance-details = Avoidance details
ated.property-details-summary.table.property-ated-details.return-status.header = Return status
ated.property-details-summary.table.property-ated-details.return-status.label = Status
ated.property-details-summary.table.ated-no-line-items.text = You need to complete the dates of liability to get your ATED charge.
ated.property-details-summary.table.ated-charge.text = Based on the information you have given us your ATED charge is
ated.property-details-summary.table.revised-ated-charge-further.text = Based on the information you have given us your revised ATED charge for this further return is
ated.property-details-summary.table.revised-ated-charge-amended.text = Based on the information you have given us your revised ATED charge for this amended return is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class PropertyDetailsSupportingInfoControllerSpec extends PlaySpec with GuiceOne
}
}
"for valid data, return Forward to the summary page" in new Setup {
val propertyDetails: PropertyDetails = PropertyDetailsBuilder.getPropertyDetails("1", Some("postCode"))
val propertyDetails: PropertyDetails = PropertyDetailsBuilder.getPropertyDetails(id = "1", Some("postCode"))
val inputJson: JsValue = Json.toJson(PropertyDetailsSupportingInfo(""))
when(mockBackLinkCacheConnector.saveBackLink(ArgumentMatchers.any(), ArgumentMatchers.any())(ArgumentMatchers.any())).thenReturn(Future.successful(None))
submitWithAuthorisedUser(inputJson, Some(propertyDetails)) {
Expand Down Expand Up @@ -355,6 +355,17 @@ class PropertyDetailsSupportingInfoControllerSpec extends PlaySpec with GuiceOne
status(result) must be(INTERNAL_SERVER_ERROR)
}
}

"for valid data with no line items, return forward to the summary page" in new Setup {
val propertyDetails: PropertyDetails = PropertyDetailsBuilder.getPropertyDetails(id = "1", Some("postCode")).copy(period = None)
val inputJson: JsValue = Json.toJson(PropertyDetailsSupportingInfo(""))
when(mockBackLinkCacheConnector.saveBackLink(ArgumentMatchers.any(), ArgumentMatchers.any())(ArgumentMatchers.any())).thenReturn(Future.successful(None))
submitWithAuthorisedUser(inputJson, Some(propertyDetails)) {
result =>
status(result) must be(SEE_OTHER)
redirectLocation(result).get must include("/liability/create/summary/")
}
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/views/propertyDetails/propertyDetailsSummarySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ class propertyDetailsSummarySpec extends AnyFeatureSpecLike with GuiceOneAppPerS
assert(document.select("#avoidance-scheme > div:nth-child(1) > dt").text() === "Avoidance scheme reference number")
assert(document.getElementById("return-status-header").text() === "Return status")
assert(document.select("#return-status > div > dt").text() contains "Status")
assert(document.getElementById("ated-charge-text").text() === "Based on the information you have given us your ATED charge is")
assert(document.getElementById("ated-charge-value").text() === "£1,000")
assert(document.getElementById("ated-no-line-items").text() === "You need to complete the dates of liability to get your ATED charge.")
assert(document.getElementById("submit-disabled-text").text() == "You cannot submit returns until 1 April.")
}

Expand Down

0 comments on commit 448d7d7

Please sign in to comment.