-
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.
SASS-9703: Expenses section: Create 'Other allowable property expense…
…s' page
- Loading branch information
Showing
11 changed files
with
524 additions
and
1 deletion.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
app/controllers/foreign/expenses/ForeignOtherAllowablePropertyExpensesController.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,72 @@ | ||
/* | ||
* 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.foreign.expenses | ||
|
||
import controllers.actions._ | ||
import forms.foreign.expenses.ForeignOtherAllowablePropertyExpensesFormProvider | ||
import models.Mode | ||
import navigation.ForeignPropertyNavigator | ||
import pages.foreign.expenses.ForeignOtherAllowablePropertyExpensesPage | ||
import play.api.i18n.{I18nSupport, MessagesApi} | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import repositories.SessionRepository | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
import views.html.foreign.expenses.ForeignOtherAllowablePropertyExpensesView | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ForeignOtherAllowablePropertyExpensesController @Inject()( | ||
override val messagesApi: MessagesApi, | ||
sessionRepository: SessionRepository, | ||
foreignNavigator: ForeignPropertyNavigator, | ||
identify: IdentifierAction, | ||
getData: DataRetrievalAction, | ||
requireData: DataRequiredAction, | ||
formProvider: ForeignOtherAllowablePropertyExpensesFormProvider, | ||
val controllerComponents: MessagesControllerComponents, | ||
view: ForeignOtherAllowablePropertyExpensesView | ||
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { | ||
|
||
|
||
|
||
def onPageLoad(taxYear: Int, countryCode: String,mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { | ||
implicit request => | ||
val form = formProvider(request.user.isAgentMessageKey) | ||
val preparedForm = request.userAnswers.get(ForeignOtherAllowablePropertyExpensesPage(countryCode)) match { | ||
case None => form | ||
case Some(value) => form.fill(value) | ||
} | ||
|
||
Ok(view(preparedForm, taxYear, countryCode, request.user.isAgentMessageKey, mode)) | ||
} | ||
|
||
def onSubmit(taxYear: Int, countryCode: String, mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { | ||
implicit request => | ||
val form = formProvider(request.user.isAgentMessageKey) | ||
form.bindFromRequest().fold( | ||
formWithErrors => | ||
Future.successful(BadRequest(view(formWithErrors, taxYear, countryCode, request.user.isAgentMessageKey, mode))), | ||
|
||
value => | ||
for { | ||
updatedAnswers <- Future.fromTry(request.userAnswers.set(ForeignOtherAllowablePropertyExpensesPage(countryCode), value)) | ||
_ <- sessionRepository.set(updatedAnswers) | ||
} yield Redirect(foreignNavigator.nextPage(ForeignOtherAllowablePropertyExpensesPage(countryCode), taxYear, mode, request.userAnswers, updatedAnswers)) | ||
) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/forms/foreign/expenses/ForeignOtherAllowablePropertyExpensesFormProvider.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,36 @@ | ||
/* | ||
* 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 forms.foreign.expenses | ||
|
||
import forms.mappings.Mappings | ||
import play.api.data.Form | ||
|
||
import javax.inject.Inject | ||
|
||
class ForeignOtherAllowablePropertyExpensesFormProvider @Inject() extends Mappings { | ||
|
||
val minimum = 0 | ||
val maximum = 100000000 | ||
def apply(individualOrAgent: String): Form[BigDecimal] = | ||
Form( | ||
"otherAllowablePropertyExpensesAmount" -> currency( | ||
s"foreignOtherAllowablePropertyExpenses.error.required.$individualOrAgent", | ||
s"foreignOtherAllowablePropertyExpenses.error.nonNumeric.$individualOrAgent", | ||
s"foreignOtherAllowablePropertyExpenses.error.nonNumeric.$individualOrAgent") | ||
.verifying(inRange(BigDecimal(minimum), BigDecimal(maximum), "foreignOtherAllowablePropertyExpenses.error.outOfRange")) | ||
) | ||
} |
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
29 changes: 29 additions & 0 deletions
29
app/pages/foreign/expenses/ForeignOtherAllowablePropertyExpensesPage.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,29 @@ | ||
/* | ||
* 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.foreign.expenses | ||
|
||
import models.ForeignProperty | ||
import pages.PageConstants.foreignPropertyExpensesPath | ||
import pages.QuestionPage | ||
import play.api.libs.json.JsPath | ||
|
||
case class ForeignOtherAllowablePropertyExpensesPage(countryCode: String) extends QuestionPage[BigDecimal] { | ||
|
||
override def path: JsPath = JsPath \ foreignPropertyExpensesPath(ForeignProperty) \ countryCode.toUpperCase \ toString | ||
|
||
override def toString: String = "foreignOtherAllowablePropertyExpenses" | ||
} |
42 changes: 42 additions & 0 deletions
42
...ewmodels/checkAnswers/foreign/expenses/ForeignOtherAllowablePropertyExpensesSummary.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,42 @@ | ||
/* | ||
* 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.foreign.expenses | ||
|
||
import controllers.routes | ||
import models.{CheckMode, UserAnswers} | ||
import pages.foreign.expenses.ForeignOtherAllowablePropertyExpensesPage | ||
import play.api.i18n.Messages | ||
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow | ||
import viewmodels.govuk.summarylist._ | ||
import viewmodels.implicits._ | ||
|
||
object ForeignOtherAllowablePropertyExpensesSummary { | ||
|
||
def row(taxYear: Int, countryCode: String, answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = | ||
answers.get(ForeignOtherAllowablePropertyExpensesPage(countryCode)).map { | ||
answer => | ||
|
||
SummaryListRowViewModel( | ||
key = "foreignOtherAllowablePropertyExpenses.checkYourAnswersLabel", | ||
value = ValueViewModel(answer.toString), | ||
actions = Seq( | ||
ActionItemViewModel("site.change", controllers.foreign.expenses.routes.ForeignOtherAllowablePropertyExpensesController.onPageLoad(taxYear, countryCode, CheckMode).url) | ||
.withVisuallyHiddenText(messages("foreignOtherAllowablePropertyExpenses.change.hidden")) | ||
) | ||
) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/views/foreign/expenses/ForeignOtherAllowablePropertyExpensesView.scala.html
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,61 @@ | ||
@* | ||
* 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. | ||
*@ | ||
|
||
@import viewmodels.InputWidth._ | ||
@import viewmodels.LabelSize | ||
|
||
@this( | ||
layout: templates.Layout, | ||
formHelper: FormWithCSRF, | ||
govukErrorSummary: GovukErrorSummary, | ||
govukInput: GovukInput, | ||
govukButton: GovukButton | ||
) | ||
|
||
@(form: Form[_], taxYear: Int, countryCode: String, individualOrAgent: String, mode: Mode)(implicit request: Request[_], messages: Messages) | ||
|
||
@layout(pageTitle = title(form, messages("foreignOtherAllowablePropertyExpenses.title"))) { | ||
|
||
@formHelper(action = controllers.foreign.expenses.routes.ForeignOtherAllowablePropertyExpensesController.onSubmit(taxYear, countryCode, mode), Symbol("autoComplete") -> "off") { | ||
|
||
@if(form.errors.nonEmpty) { | ||
@govukErrorSummary(ErrorSummaryViewModel(form)) | ||
} | ||
<h1 class="govuk-heading-l">@messages("foreignOtherAllowablePropertyExpenses.heading")</h1> | ||
<ul class="govuk-list govuk-list--bullet"> | ||
<li>@messages("foreignOtherAllowablePropertyExpenses.bullet1")</li> | ||
<li>@messages("foreignOtherAllowablePropertyExpenses.bullet2")</li> | ||
<li>@messages("foreignOtherAllowablePropertyExpenses.bullet3")</li> | ||
<li>@messages("foreignOtherAllowablePropertyExpenses.bullet4")</li> | ||
<li>@messages(s"foreignOtherAllowablePropertyExpenses.bullet5.$individualOrAgent")</li> | ||
<li>@messages("foreignOtherAllowablePropertyExpenses.bullet6")</li> | ||
<li>@messages(s"foreignOtherAllowablePropertyExpenses.bullet7.$individualOrAgent")</li> | ||
</ul> | ||
<p class="govuk-body">@messages("foreignOtherAllowablePropertyExpenses.hyperlink.text.1") <a href="https://www.gov.uk/expenses-if-youre-self-employed">@messages("foreignOtherAllowablePropertyExpenses.hyperlink.text.2")</a></p> | ||
@govukInput( | ||
InputViewModel( | ||
field = form("otherAllowablePropertyExpensesAmount"), | ||
label = LabelViewModel(messages(s"foreignOtherAllowablePropertyExpenses.label.$individualOrAgent")).withCssClass("govuk-label govuk-label--m") | ||
).withHint(HintViewModel(messages("foreignOtherAllowablePropertyExpenses.hint"))) | ||
.asNumeric() | ||
.withWidth(Fixed10).withPrefix(PrefixOrSuffix(content = Text("£"))) | ||
) | ||
|
||
@govukButton( | ||
ButtonViewModel(messages("site.continue")).withId("continue") | ||
) | ||
} | ||
} |
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.