-
Notifications
You must be signed in to change notification settings - Fork 1
Initial changes for VAT Registration Number capture #60
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
Open
dillimateti501
wants to merge
1
commit into
main
Choose a base branch
from
DTR-1606
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
98 changes: 98 additions & 0 deletions
98
app/controllers/purchaser/RegistrationNumberController.scala
This file contains hidden or 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,98 @@ | ||
| /* | ||
| * Copyright 2025 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.purchaser | ||
|
|
||
| import controllers.actions.* | ||
| import forms.purchaser.RegistrationNumberFormProvider | ||
| import models.{Mode, NormalMode} | ||
| import models.purchaser.{NameOfPurchaser, WhoIsMakingThePurchase, PurchaserConfirmIdentity} | ||
| import navigation.Navigator | ||
| import pages.purchaser.{NameOfPurchaserPage, PurchaserConfirmIdentityPage, RegistrationNumberPage, WhoIsMakingThePurchasePage} | ||
| import play.api.i18n.{I18nSupport, MessagesApi} | ||
| import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
| import repositories.SessionRepository | ||
| import services.purchaser.PurchaserService | ||
| import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
| import views.html.purchaser.RegistrationNumberView | ||
|
|
||
| import javax.inject.Inject | ||
| import scala.concurrent.{ExecutionContext, Future} | ||
|
|
||
| class RegistrationNumberController @Inject()( | ||
| override val messagesApi: MessagesApi, | ||
| sessionRepository: SessionRepository, | ||
| navigator: Navigator, | ||
| identify: IdentifierAction, | ||
| getData: DataRetrievalAction, | ||
| requireData: DataRequiredAction, | ||
| formProvider: RegistrationNumberFormProvider, | ||
| val controllerComponents: MessagesControllerComponents, | ||
| view: RegistrationNumberView, | ||
| purchaserService: PurchaserService | ||
| )(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { | ||
|
|
||
| val form = formProvider() | ||
|
|
||
| def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { | ||
| implicit request => | ||
| val purchaserFullName: Option[String] = request.userAnswers.get(NameOfPurchaserPage).map(_.fullName) | ||
| // val isPurchaserVATRegistered: Option[String] = Some("VATRegistrationNumber") | ||
| val isPurchaserVATRegistered: Option[PurchaserConfirmIdentity] = request.userAnswers.get(PurchaserConfirmIdentityPage) | ||
|
|
||
| purchaserService.checkPurchaserTypeAndCompanyDetails( | ||
| purchaserType = WhoIsMakingThePurchase.Company, | ||
| userAnswers = request.userAnswers, | ||
| continueRoute = { | ||
| (purchaserFullName) match { | ||
| case Some(purchaserFullName) if isPurchaserVATRegistered.contains(PurchaserConfirmIdentity.VatRegistrationNumber) => | ||
| val preparedForm = request.userAnswers.get(RegistrationNumberPage) match { | ||
| case None => form | ||
| case Some(value) => form.fill(value) | ||
| } | ||
| Ok(view(preparedForm, mode, purchaserFullName)) | ||
| case None => Redirect(controllers.purchaser.routes.NameOfPurchaserController.onPageLoad(NormalMode)) | ||
| case _ => | ||
| //TODO update to more relevant path i.e. back to pr-5b | ||
| Redirect(controllers.routes.GenericErrorController.onPageLoad()) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { | ||
| implicit request => | ||
|
|
||
| val purchaserFullName: Option[String] = request.userAnswers.get(NameOfPurchaserPage).map(_.fullName) | ||
|
|
||
| purchaserFullName match { | ||
| case Some(purchaserFullName) => | ||
| form.bindFromRequest().fold( | ||
| formWithErrors => | ||
| Future.successful(BadRequest(view(formWithErrors, mode, purchaserFullName))), | ||
|
|
||
| value => | ||
| for { | ||
| updatedAnswers <- Future.fromTry(request.userAnswers.set(RegistrationNumberPage, value)) | ||
| _ <- sessionRepository.set(updatedAnswers) | ||
| } yield Redirect(navigator.nextPage(RegistrationNumberPage, mode, updatedAnswers)) | ||
| ) | ||
| case _ => | ||
| Future.successful(Redirect(controllers.purchaser.routes.NameOfPurchaserController.onPageLoad(mode))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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,35 @@ | ||
| /* | ||
| * Copyright 2025 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.purchaser | ||
|
|
||
| import forms.mappings.Mappings | ||
| import play.api.data.Form | ||
| import play.api.data.validation.Constraints.minLength | ||
| import forms.mappings.Constraints | ||
| import javax.inject.Inject | ||
|
|
||
| class RegistrationNumberFormProvider @Inject() extends Mappings with Constraints{ | ||
|
|
||
| private val RegistrationNumberPattern = "^[0-9]*$" | ||
|
|
||
| def apply(): Form[String] = | ||
| Form( | ||
| "registrationNumber" -> text("purchaser.registrationNumber.error.required") | ||
| .verifying(vatCheckF16Validation("purchaser.registrationNumber.error")) | ||
|
|
||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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,27 @@ | ||
| /* | ||
| * Copyright 2025 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.purchaser | ||
|
|
||
| import pages.QuestionPage | ||
| import play.api.libs.json.JsPath | ||
|
|
||
| case object RegistrationNumberPage extends QuestionPage[String] { | ||
|
|
||
| override def path: JsPath = JsPath \ "purchaserCurrent" \ toString | ||
|
|
||
| override def toString: String = "registrationNumber" | ||
| } |
This file contains hidden or 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
43 changes: 43 additions & 0 deletions
43
app/viewmodels/checkAnswers/purchaser/RegistrationNumberSummary.scala
glennsoft2 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,43 @@ | ||
| /* | ||
| * Copyright 2025 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.purchaser | ||
|
|
||
| import controllers.routes | ||
| import models.{CheckMode, UserAnswers} | ||
| import pages.purchaser.RegistrationNumberPage | ||
| import play.api.i18n.Messages | ||
| import play.twirl.api.HtmlFormat | ||
| import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow | ||
| import viewmodels.govuk.summarylist.* | ||
| import viewmodels.implicits.* | ||
|
|
||
| object RegistrationNumberSummary { | ||
|
|
||
| def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = | ||
| answers.get(RegistrationNumberPage).map { | ||
| answer => | ||
|
|
||
| SummaryListRowViewModel( | ||
| key = "purchaser.registrationNumber.checkYourAnswersLabel", | ||
| value = ValueViewModel(HtmlFormat.escape(answer).toString), | ||
| actions = Seq( | ||
| ActionItemViewModel("site.change", controllers.purchaser.routes.RegistrationNumberController.onPageLoad(CheckMode).url) | ||
| .withVisuallyHiddenText(messages("purchaser.registrationNumber.change.hidden")) | ||
| ) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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,52 @@ | ||
| @* | ||
| * Copyright 2025 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.Large | ||
|
|
||
| @this( | ||
| layout: templates.Layout, | ||
| formHelper: FormWithCSRF, | ||
| govukErrorSummary: GovukErrorSummary, | ||
| govukInput: GovukInput, | ||
| govukButton: GovukButton | ||
| ) | ||
|
|
||
| @(form: Form[_], mode: Mode, purchaserName: String)(implicit request: Request[_], messages: Messages) | ||
|
|
||
| @layout(pageTitle = title(form, messages("purchaser.registrationNumber.title"))) { | ||
|
|
||
| @formHelper(action = controllers.purchaser.routes.RegistrationNumberController.onSubmit(mode)) { | ||
|
|
||
| @if(form.errors.nonEmpty) { | ||
| @govukErrorSummary(ErrorSummaryViewModel(form)) | ||
| } | ||
| <span class="govuk-caption-l">@messages("purchaser.registrationNumber.caption")</span> | ||
|
|
||
| @govukInput( | ||
| InputViewModel( | ||
| field = form("registrationNumber"), | ||
| label = LabelViewModel(messages("purchaser.registrationNumber.heading",purchaserName)).asPageHeading(size = Large) | ||
| ) | ||
| .withWidth(Full) | ||
| .withHint(HintViewModel(HtmlContent(Html(messages("purchaser.registrationNumber.hint",purchaserName))))) | ||
| ) | ||
|
|
||
| @govukButton( | ||
| ButtonViewModel(messages("site.save.continue")) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.