-
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.
MMCA-4898 | Display MRN details on click of MRN hyperlink from the Ca…
…sh Account Transactions List (#134) * MMCA-4898 | Added declaration details, route, unit tests * MMCA-4898 | Cleanup * MMCA-4898 | Added H2Inner component, more unit tests * MMCA-4898 | Fix unit tests * MMCA-4898 | Added TaxType to fix backend, fixed amount issue * MMCA-4898 | Removed 'Action' from SummaryLists * MMCA-4898 | Removed extra spacing
- Loading branch information
Showing
28 changed files
with
1,166 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2023 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 | ||
|
||
import config.{AppConfig, ErrorHandler} | ||
import connectors.CustomsFinancialsApiConnector | ||
import controllers.actions.{EmailAction, IdentifierAction} | ||
import helpers.CashAccountUtils | ||
import models.CashAccount | ||
import models.request.IdentifierRequest | ||
import play.api.i18n.I18nSupport | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Result} | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController | ||
import views.html.{cash_account_declaration_details, cash_transactions_no_result} | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
import play.api.Logging | ||
import viewmodels.{DeclarationDetailViewModel, ResultsPageSummary} | ||
|
||
import java.time.LocalDate | ||
|
||
class DeclarationDetailController @Inject()(authenticate: IdentifierAction, | ||
verifyEmail: EmailAction, | ||
apiConnector: CustomsFinancialsApiConnector, | ||
errorHandler: ErrorHandler, | ||
mcc: MessagesControllerComponents, | ||
view: cash_account_declaration_details, | ||
cashAccountUtils: CashAccountUtils, | ||
noTransactions: cash_transactions_no_result | ||
)(implicit executionContext: ExecutionContext, | ||
val appConfig: AppConfig | ||
) extends FrontendController(mcc) with I18nSupport with Logging { | ||
|
||
def displayDetails(ref: String, page: Option[Int]): Action[AnyContent] = | ||
(authenticate andThen verifyEmail).async { implicit request => | ||
|
||
apiConnector.getCashAccount(request.eori).flatMap { | ||
|
||
case Some(account) => | ||
val (from, to) = cashAccountUtils.transactionDateRange() | ||
retrieveCashAccountTransactionAndDisplay(account, from, to, ref, page) | ||
|
||
case None => Future.successful(NotFound(errorHandler.notFoundTemplate)) | ||
} | ||
} | ||
|
||
private def retrieveCashAccountTransactionAndDisplay(account: CashAccount, | ||
from: LocalDate, | ||
to: LocalDate, | ||
ref: String, | ||
page: Option[Int]) | ||
(implicit request: IdentifierRequest[_]): Future[Result] = { | ||
|
||
apiConnector.retrieveCashTransactions(account.number, from, to).map { | ||
|
||
case Right(transactions) => | ||
transactions.cashDailyStatements | ||
.flatMap(_.declarations) | ||
.find(_.secureMovementReferenceNumber.contains(ref)) | ||
.map(declaration => Ok(view(DeclarationDetailViewModel(request.eori, account), declaration, page))) | ||
.getOrElse(NotFound(errorHandler.notFoundTemplate)) | ||
|
||
case Left(_) => Ok(noTransactions(new ResultsPageSummary(from, to))) | ||
} | ||
} | ||
} |
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
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
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,96 @@ | ||
/* | ||
* Copyright 2023 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 | ||
|
||
import helpers.Formatters | ||
import models.{CashAccount, CustomsDuty, Declaration, ExciseDuty, ImportVat} | ||
import models.domain.EORI | ||
import play.api.i18n.Messages | ||
import uk.gov.hmrc.govukfrontend.views.Aliases.{HtmlContent, SummaryList, SummaryListRow, Text} | ||
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.{Key, Value} | ||
import utils.Utils.emptyString | ||
|
||
case class DeclarationDetailViewModel(eori: EORI, account: CashAccount) | ||
|
||
object DeclarationDetailViewModel { | ||
|
||
def declarationSummaryList(declaration: Declaration)(implicit messages: Messages): SummaryList = { | ||
SummaryList( | ||
attributes = Map("id" -> "mrn"), | ||
rows = Seq( | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.date"))), | ||
value = Value(content = HtmlContent(Formatters.dateAsDayMonthAndYear(declaration.date))) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.movementReferenceNumber"))), | ||
value = Value(content = HtmlContent(declaration.movementReferenceNumber)) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.uniqueConsignmentReference"))), | ||
value = Value(content = HtmlContent(declaration.declarantReference.getOrElse(emptyString))) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.declarantEori"))), | ||
value = Value(content = HtmlContent(declaration.declarantEori)) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.importerEori"))), | ||
value = Value(content = HtmlContent(declaration.importerEori.getOrElse(emptyString))) | ||
) | ||
) | ||
) | ||
} | ||
|
||
def taxSummaryList(declaration: Declaration)(implicit messages: Messages): SummaryList = { | ||
SummaryList( | ||
attributes = Map("id" -> "tax-details"), | ||
rows = Seq( | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.duty"))), | ||
value = Value(content = HtmlContent( | ||
Formatters.formatCurrencyAmount(declaration.taxGroups.find(_.taxGroupDescription == CustomsDuty) | ||
.map(_.amount) | ||
.getOrElse(BigDecimal(0))) | ||
)) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.vat"))), | ||
value = Value(content = HtmlContent( | ||
Formatters.formatCurrencyAmount(declaration.taxGroups.find(_.taxGroupDescription == ImportVat) | ||
.map(_.amount) | ||
.getOrElse(BigDecimal(0))) | ||
)) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.csv.excise"))), | ||
value = Value(content = HtmlContent( | ||
declaration.taxGroups.find(_.taxGroupDescription == ExciseDuty) | ||
.map(_.amount) | ||
.fold(emptyString)(amount => Formatters.formatCurrencyAmount(amount)) | ||
)) | ||
), | ||
SummaryListRow( | ||
key = Key(content = Text(messages("cf.cash-account.detail.total.paid"))), | ||
value = Value(content = HtmlContent( | ||
Formatters.formatCurrencyAmount(declaration.amount) | ||
)) | ||
) | ||
) | ||
) | ||
} | ||
} |
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,45 @@ | ||
@* | ||
* Copyright 2023 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. | ||
*@ | ||
|
||
@import helpers.Formatters | ||
@import viewmodels.DeclarationDetailViewModel | ||
|
||
@this(main_template: Layout, govukSummaryList: GovukSummaryList, h1: components.h1, h2: components.h2Inner) | ||
|
||
@(viewModel: DeclarationDetailViewModel, | ||
declarationDetails: Declaration, | ||
pageNumber: Option[Int] | ||
)(implicit request: Request[_], messages: Messages) | ||
|
||
@main_template( | ||
pageTitle = Some(messages("cf.cash-account.detail.title")), | ||
backLink = Some(routes.CashAccountController.showAccountDetails(page = pageNumber).url), | ||
fullWidth = false | ||
) { | ||
|
||
@h2(msg = "cf.cash-account.detail.account", | ||
innerMsg = viewModel.account.number, | ||
id = Some("account-number"), | ||
classes = "govuk-caption-xl" | ||
) | ||
|
||
@h1(msg="cf.cash-account.detail.declaration.title") | ||
|
||
@govukSummaryList(DeclarationDetailViewModel.declarationSummaryList(declarationDetails)) | ||
|
||
@govukSummaryList(DeclarationDetailViewModel.taxSummaryList(declarationDetails)) | ||
|
||
} |
Oops, something went wrong.