-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SASS-9703: Expenses section: add 'Other allowable property expenses' page #456
Open
RGlossop
wants to merge
1
commit into
main
Choose a base branch
from
SASS-9703
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bigDecimal |
||
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" class="govuk-link" target="_blank">@messages("foreignOtherAllowablePropertyExpenses.hyperlink.text.2")</a></p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save the url in messages |
||
@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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.withCssClass(keyCssClass)