Skip to content

Commit

Permalink
Adding Opt in and Opt out links for all scenario in ReportingFrequenc…
Browse files Browse the repository at this point in the history
…yPage (#2665)
  • Loading branch information
chandraAndem authored Nov 28, 2024
1 parent 3ca9b89 commit 0ac5279
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 64 deletions.
23 changes: 14 additions & 9 deletions app/controllers/ReportingFrequencyPageController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import models.admin.ReportingFrequencyPage
import models.optout.{OptOutMultiYearViewModel, OptOutOneYearViewModel}
import play.api.i18n.I18nSupport
import play.api.mvc._
import services.DateService
import services.DateServiceInterface
import services.optIn.OptInService
import services.optout.OptOutService
import views.html.ReportingFrequencyView
import views.html.errorPages.templates.ErrorTemplate
Expand All @@ -36,13 +37,14 @@ import scala.concurrent.ExecutionContext

class ReportingFrequencyPageController @Inject()(
optOutService: OptOutService,
optInService: OptInService,
val authorisedFunctions: FrontendAuthorisedFunctions,
val auth: AuthActions,
dateService: DateService,
errorTemplate: ErrorTemplate,
view: ReportingFrequencyView
)(
implicit val appConfig: FrontendAppConfig,
val dateService: DateServiceInterface,
mcc: MessagesControllerComponents,
val ec: ExecutionContext,
val itvcErrorHandler: ItvcErrorHandler,
Expand All @@ -55,24 +57,27 @@ class ReportingFrequencyPageController @Inject()(
auth.asIndividualOrAgent(isAgent).async { implicit user =>

for {
(checks, optOutJourneyType) <- optOutService.nextUpdatesPageOptOutViewModels()
(optOutProposition, optOutJourneyType) <- optOutService.reportingFrequencyViewModels()
optInTaxYears <- optInService.availableOptInTaxYear()

} yield {
if (isEnabled(ReportingFrequencyPage)) {

val optOutUrl: Option[String] =
val optOutUrl: Option[String] = {
optOutJourneyType.map {
case singleYearModel: OptOutOneYearViewModel =>
case _: OptOutOneYearViewModel =>
controllers.optOut.routes.ConfirmOptOutController.show(user.isAgent()).url
case multiYearModel: OptOutMultiYearViewModel =>
case _: OptOutMultiYearViewModel =>
controllers.optOut.routes.OptOutChooseTaxYearController.show(user.isAgent()).url
}
}

Ok(view(
ReportingFrequencyViewModel(
isAgent = user.isAgent(),
currentTaxYear = dateService.getCurrentTaxYear,
nextTaxYear = dateService.getCurrentTaxYear.nextYear,
optOutJourneyUrl = optOutUrl
optOutJourneyUrl = optOutUrl,
optOutTaxYears = optOutProposition.availableTaxYearsForOptOut,
optInTaxYears = optInTaxYears
)
))
} else {
Expand Down
6 changes: 3 additions & 3 deletions app/models/ReportingFrequencyViewModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import models.incomeSourceDetails.TaxYear

case class ReportingFrequencyViewModel(
isAgent: Boolean,
currentTaxYear: TaxYear,
nextTaxYear: TaxYear,
optOutJourneyUrl: Option[String]
optOutJourneyUrl: Option[String],
optOutTaxYears: Seq[TaxYear],
optInTaxYears: Seq[TaxYear]
)
9 changes: 9 additions & 0 deletions app/services/optout/OptOutService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ class OptOutService @Inject()(itsaStatusUpdateConnector: ITSAStatusUpdateConnect
}.getOrElse(responses.head)
}

def reportingFrequencyViewModels()(implicit user: MtdItUser[_],
hc: HeaderCarrier,
ec: ExecutionContext): Future[(OptOutProposition, Option[OptOutViewModel])] = {
for {
proposition <- fetchOptOutProposition()
_ <- repository.initialiseOptOutJourney(proposition)
}yield (proposition, nextUpdatesOptOutViewModel(proposition))
}

def nextUpdatesPageOptOutViewModels()(implicit user: MtdItUser[_],
hc: HeaderCarrier,
ec: ExecutionContext): Future[(NextUpdatesQuarterlyReportingContentChecks, Option[OptOutViewModel])] = {
Expand Down
30 changes: 24 additions & 6 deletions app/views/ReportingFrequencyView.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*@

@import models.optin.OptInCompletedViewModel
@import uk.gov.hmrc.govukfrontend.views.html.components._
@import views.html.components._
@import views.html.layouts.unifiedLayout
@import models.ReportingFrequencyViewModel
@import services.DateServiceInterface

@this(
mainTemplate: unifiedLayout,
Expand All @@ -31,7 +31,17 @@
govukInsetText : GovukInsetText
)

@(viewModel: ReportingFrequencyViewModel)(implicit messages: Messages, user: auth.MtdItUser[_])
@(viewModel: ReportingFrequencyViewModel)(implicit messages: Messages, user: auth.MtdItUser[_], dateService: DateServiceInterface)

@optInLink = {
@if(viewModel.optInTaxYears.size > 1) {
@linkComponent(controllers.optIn.routes.BeforeYouStartController.show(viewModel.isAgent).url, message = messages("reporting.frequency.manageReportingFrequency.optIn.link.generic"))
} else if (viewModel.optInTaxYears.size == 1 && viewModel.optInTaxYears.head == dateService.getCurrentTaxYear.nextYear) {
@linkComponent(controllers.optIn.routes.BeforeYouStartController.show(viewModel.isAgent).url, message = messages("reporting.frequency.manageReportingFrequency.optIn.link.onwards", viewModel.optInTaxYears.head.startYear.toString, viewModel.optInTaxYears.head.endYear.toString))
} else if (viewModel.optInTaxYears.size == 1) {
@linkComponent(controllers.optIn.routes.BeforeYouStartController.show(viewModel.isAgent).url, message = messages("reporting.frequency.manageReportingFrequency.optIn.link.taxyear", viewModel.optInTaxYears.head.startYear.toString, viewModel.optInTaxYears.head.endYear.toString))
}
}

@manageReportingFrequency = {

Expand All @@ -46,12 +56,20 @@
}

<ul class="govuk-list govuk-list--bullet">
<li>
@linkComponent(controllers.optIn.routes.BeforeYouStartController.show(viewModel.isAgent).url, message = messages("reporting.frequency.manageReportingFrequency.b1.link", viewModel.currentTaxYear.startYear.toString, viewModel.currentTaxYear.endYear.toString))
</li>
@if(optInLink.body.contains(controllers.optIn.routes.BeforeYouStartController.show(viewModel.isAgent).url)) {
<li>
@optInLink
</li>
}
@viewModel.optOutJourneyUrl.map{ url =>
<li>
@linkComponent(url, message = messages("reporting.frequency.manageReportingFrequency.b2.link", viewModel.nextTaxYear.startYear.toString, viewModel.nextTaxYear.endYear.toString))
@if(viewModel.optOutTaxYears.size > 1) {
@linkComponent(url, message = messages("reporting.frequency.manageReportingFrequency.optOut.link.generic"))
} else if (viewModel.optOutTaxYears.size == 1 && viewModel.optOutTaxYears.head == dateService.getCurrentTaxYear.nextYear) {
@linkComponent(url, message = messages("reporting.frequency.manageReportingFrequency.optOut.link.onwards", viewModel.optOutTaxYears.head.startYear.toString, viewModel.optOutTaxYears.head.endYear.toString))
} else if (viewModel.optOutTaxYears.size == 1) {
@linkComponent(url, message = messages("reporting.frequency.manageReportingFrequency.optOut.link.taxyear", viewModel.optOutTaxYears.head.startYear.toString, viewModel.optOutTaxYears.head.endYear.toString))
}
</li>
}
</ul>
Expand Down
8 changes: 6 additions & 2 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -2388,8 +2388,12 @@ reporting.frequency.h2 = Manage your reporting frequency for all your businesses

reporting.frequency.manageReportingFrequency.p1 = If you are reporting annually or voluntarily reporting quarterly, you may be able to change your reporting frequency for specific tax years.
reporting.frequency.manageReportingFrequency.p2 = This is what you can do for all your businesses:
reporting.frequency.manageReportingFrequency.b1.link = Opt in to quarterly reporting for the {0} to {1} tax year
reporting.frequency.manageReportingFrequency.b2.link = Opt out of quarterly reporting and report annually from the {0} to {1} tax year onwards
reporting.frequency.manageReportingFrequency.optIn.link.generic = Opt in to quarterly reporting
reporting.frequency.manageReportingFrequency.optIn.link.taxyear = Opt in to quarterly reporting for the {0} to {1} tax year
reporting.frequency.manageReportingFrequency.optIn.link.onwards = Opt in to quarterly reporting from the {0} to {1} tax year onwards
reporting.frequency.manageReportingFrequency.optOut.link.generic = Opt out of quarterly reporting and report annually
reporting.frequency.manageReportingFrequency.optOut.link.taxyear = Opt out of quarterly reporting and report annually for the {0} to {1} tax year
reporting.frequency.manageReportingFrequency.optOut.link.onwards = Opt out of quarterly reporting and report annually from the {0} to {1} tax year onwards



Expand Down
8 changes: 6 additions & 2 deletions conf/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,10 @@ reporting.frequency.h2 = Rheoli amlder eich adroddiadau ar gyfer eich holl fusne

reporting.frequency.manageReportingFrequency.p1 = Os ydych yn adrodd yn flynyddol, neu’n adrodd yn chwarterol yn wirfoddol, mae’n bosibl y byddwch yn gallu newid amlder eich adroddiadau ar gyfer blynyddoedd treth penodol.
reporting.frequency.manageReportingFrequency.p2 = Yr hyn y gallwch ei wneud ar gyfer eich holl fusnesau:
reporting.frequency.manageReportingFrequency.b1.link = Optio i mewn i adrodd yn chwarterol ar gyfer blwyddyn dreth {0} i {1}
reporting.frequency.manageReportingFrequency.b2.link = Optio allan o adrodd yn chwarterol, a mynd ati i adrodd yn flynyddol o flwyddyn dreth {0} i {1} ymlaen
reporting.frequency.manageReportingFrequency.optIn.link.generic = Optio i mewn i adrodd yn chwarterol
reporting.frequency.manageReportingFrequency.optIn.link.taxyear = Optio i mewn i adrodd yn chwarterol ar gyfer blwyddyn dreth {0} i {1}
reporting.frequency.manageReportingFrequency.optIn.link.onwards = Optio i mewn i adrodd yn chwarterol, a mynd ati i adrodd yn flynyddol o flwyddyn dreth {0} i {1} ymlaen
reporting.frequency.manageReportingFrequency.optOut.link.generic = Optio allan o adrodd yn chwarterol, a mynd ati i adrodd yn flynyddol
reporting.frequency.manageReportingFrequency.optOut.link.taxyear = Opt out of quarterly reporting and report annually for the {0} to {1} tax year
reporting.frequency.manageReportingFrequency.optOut.link.onwards = Optio allan o adrodd yn chwarterol, a mynd ati i adrodd yn flynyddol o flwyddyn dreth {0} i {1} ymlaen

1 change: 1 addition & 0 deletions it/test/controllers/ControllerISpecBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ trait ControllerISpecBase
override def getCurrentDate: LocalDate = LocalDate.of(2023, 4, 5)

override def getCurrentTaxYearEnd: Int = 2023

}

override implicit lazy val app: Application =
Expand Down
Loading

0 comments on commit 0ac5279

Please sign in to comment.