Skip to content

Commit fd137d3

Browse files
[PIL-2800] - change time period calculation logic to previous 7 years (#634)
… instead of reg date for OutstandingPaymentsController
1 parent 517a415 commit fd137d3

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

app/controllers/payments/OutstandingPaymentsController.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import services.{FinancialDataService, ReferenceNumberService, SubscriptionServi
3232
import uk.gov.hmrc.http.HeaderCarrier
3333
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
3434
import uk.gov.hmrc.play.http.HeaderCarrierConverter
35+
import utils.Constants.SubmissionAccountingPeriods
3536
import views.html.outstandingpayments.OutstandingPaymentsView
3637

3738
import java.time.LocalDate.now
@@ -123,7 +124,7 @@ class OutstandingPaymentsController @Inject() (
123124
subscriptionData <- OptionT.liftF(subscriptionService.readSubscription(plrRef))
124125
outstandingPaymentsResult <-
125126
OptionT.liftF(
126-
retrieveOutstandingPayments(plrRef, subscriptionData.upeDetails.registrationDate, now())
127+
retrieveOutstandingPayments(plrRef, LocalDate.now.minusYears(SubmissionAccountingPeriods), now())
127128
)
128129
} yield outstandingPaymentsResult match {
129130
case Left(accountActivityResponse) =>

test/controllers/payments/OutstandingPaymentsControllerSpec.scala

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,49 @@ class OutstandingPaymentsControllerSpec extends SpecBase {
8484
}
8585
}
8686

87+
"return Ok and display correct view for a GET with outstanding payments that existed before company registration date" in {
88+
val subscriptionData = SubscriptionData(
89+
formBundleNumber = "form bundle",
90+
upeDetails = UpeDetails(None, None, None, "orgName", LocalDate.of(2024, 1, 1), domesticOnly = false, filingMember = false),
91+
upeCorrespAddressDetails = UpeCorrespAddressDetails("middle", None, Some("lane"), None, None, "obv"),
92+
primaryContactDetails = ContactDetailsType("shadow", Some("dota2"), "shadow@fiend.com"),
93+
secondaryContactDetails = None,
94+
filingMemberDetails = None,
95+
accountingPeriod = AccountingPeriod(LocalDate.of(2024, 1, 1), LocalDate.of(2024, 12, 31)),
96+
accountStatus = Some(AccountStatus.ActiveAccount)
97+
)
98+
99+
val application = applicationBuilder(enrolments = enrolments, additionalData = Map("features.useAccountActivityApi" -> false))
100+
.overrides(
101+
bind[SessionRepository].toInstance(mockSessionRepository),
102+
bind[FinancialDataService].toInstance(mockFinancialDataService),
103+
bind[SubscriptionService].toInstance(mockSubscriptionService)
104+
)
105+
.build()
106+
107+
running(application) {
108+
when(mockFinancialDataService.retrieveFinancialData(any(), any(), any())(using any[HeaderCarrier]))
109+
.thenReturn(Future.successful(samplePreRegistrationChargeTransaction))
110+
when(mockSubscriptionService.readSubscription(any())(using any[HeaderCarrier]))
111+
.thenReturn(Future.successful(subscriptionData))
112+
when(mockSessionRepository.get(any())).thenReturn(Future.successful(Some(emptyUserAnswers)))
113+
114+
val request = FakeRequest(GET, controllers.payments.routes.OutstandingPaymentsController.onPageLoad.url)
115+
val result = route(application, request).value
116+
117+
val view = application.injector.instanceOf[OutstandingPaymentsView]
118+
119+
status(result) mustEqual OK
120+
contentAsString(result) mustEqual
121+
view(preRegistrationOverdueTables, pillar2Id, BigDecimal(1000.00), hasOverdueReturnPayment = true)(
122+
request,
123+
applicationConfig,
124+
messages(application),
125+
isAgent = false
126+
).toString
127+
}
128+
}
129+
87130
"redirect to Journey Recovery when service call fails" in {
88131
val subscriptionData = SubscriptionData(
89132
formBundleNumber = "form bundle",
@@ -327,6 +370,21 @@ object OutstandingPaymentsControllerSpec {
327370
)
328371
)
329372

373+
val samplePreRegistrationChargeTransaction: FinancialData =
374+
FinancialData(
375+
Seq(
376+
FinancialTransaction.OutstandingCharge.UktrMainOutstandingCharge(
377+
accountingPeriod = AccountingPeriod(LocalDate.of(2020, 1, 1), LocalDate.of(2020, 12, 31)),
378+
subTransactionRef = EtmpSubtransactionRef.Dtt,
379+
outstandingAmount = BigDecimal(1000.00),
380+
chargeItems = OutstandingCharge.FinancialItems(
381+
earliestDueDate = LocalDate.of(2020, 12, 31),
382+
Seq(FinancialItem(dueDate = Some(LocalDate.of(2020, 12, 31)), clearingDate = None))
383+
)
384+
)
385+
)
386+
)
387+
330388
val overdueFinancialSummary: Seq[FinancialSummary] = Seq(
331389
FinancialSummary(
332390
AccountingPeriod(LocalDate.of(2024, 1, 1), LocalDate.of(2024, 12, 31)),
@@ -345,5 +403,14 @@ object OutstandingPaymentsControllerSpec {
345403
)
346404
)
347405

406+
val preRegistrationOverdueTables: Seq[OutstandingPaymentsTable] = Seq(
407+
OutstandingPaymentsTable(
408+
accountingPeriod = AccountingPeriod(LocalDate.of(2020, 1, 1), LocalDate.of(2020, 12, 31)),
409+
rows = Seq(
410+
OutstandingPaymentsRow(description = "UKTR - DTT", outstandingAmount = BigDecimal(1000.00), dueDate = LocalDate.of(2020, 12, 31))
411+
)
412+
)
413+
)
414+
348415
val amountDue: BigDecimal = samplePaymentsData.flatMap(_.transactions.map(_.outstandingAmount)).sum.max(0)
349416
}

0 commit comments

Comments
 (0)