This is an automated email from the ASF dual-hosted git repository.
adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 7c618a69d process current and previous standing instructions on loans
7c618a69d is described below
commit 7c618a69d5baa9b079f49c85725b8169ea12d53e
Author: Wilfred Kigenyi <[email protected]>
AuthorDate: Tue Mar 26 11:58:45 2024 +0300
process current and previous standing instructions on loans
---
.../ExecuteStandingInstructionsTasklet.java | 7 ++-
...eOverdueAndCurrentStandingInstructionsTest.java | 63 ++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java
index 888ba2d92..5b5550f81 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteStandingInstructionsTasklet.java
@@ -97,7 +97,7 @@ public class ExecuteStandingInstructionsTasklet implements
Tasklet {
transactionAmount =
standingInstructionDuesData.totalDueAmount();
}
if (recurrenceType.isDuesRecurrence()) {
- isDueForTransfer =
LocalDate.now(DateUtils.getDateTimeZoneOfTenant()).equals(standingInstructionDuesData.dueDate());
+ isDueForTransfer =
isDueForTransfer(standingInstructionDuesData);
}
}
@@ -164,4 +164,9 @@ public class ExecuteStandingInstructionsTasklet implements
Tasklet {
jdbcTemplate.update(updateQuery.toString());
return transferCompleted;
}
+
+ public boolean isDueForTransfer(StandingInstructionDuesData
standingInstructionDuesData) {
+ return standingInstructionDuesData.dueDate() != null
+ &&
!standingInstructionDuesData.dueDate().isAfter(LocalDate.now(DateUtils.getDateTimeZoneOfTenant()));
+ }
}
diff --git
a/fineract-provider/src/test/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteOverdueAndCurrentStandingInstructionsTest.java
b/fineract-provider/src/test/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteOverdueAndCurrentStandingInstructionsTest.java
new file mode 100644
index 000000000..8b730538a
--- /dev/null
+++
b/fineract-provider/src/test/java/org/apache/fineract/portfolio/account/jobs/executestandinginstructions/ExecuteOverdueAndCurrentStandingInstructionsTest.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.fineract.portfolio.account.jobs.executestandinginstructions;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.math.BigDecimal;
+import java.time.Clock;
+import java.time.LocalDate;
+import org.apache.fineract.infrastructure.core.domain.ActionContext;
+import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import org.apache.fineract.portfolio.account.data.StandingInstructionDuesData;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ExecuteOverdueAndCurrentStandingInstructionsTest {
+
+ private final LocalDate currentDate = LocalDate.now(Clock.systemUTC());
+ private final LocalDate previousDate = currentDate.minusDays(2);
+
+ @BeforeEach
+ public void setUp() {
+ ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L,
"default", "Default", "Africa/Kampala", null));
+ ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
+ }
+
+ @AfterEach
+ public void tearDown() {
+ ThreadLocalContextUtil.reset();
+ }
+
+ @Test
+ public void testAcceptPreviousDateAsDue() {
+ ExecuteStandingInstructionsTasklet tasklet = new
ExecuteStandingInstructionsTasklet(null, null, null, null);
+ boolean isDueForTransfer = tasklet.isDueForTransfer(new
StandingInstructionDuesData(previousDate, BigDecimal.ONE));
+ assertThat(isDueForTransfer).isTrue().describedAs("Earlier
instructions are accepted as due");
+ }
+
+ @Test
+ public void testAcceptCurrentDateAsDue() {
+ ExecuteStandingInstructionsTasklet tasklet = new
ExecuteStandingInstructionsTasklet(null, null, null, null);
+ boolean isDueForTransfer = tasklet.isDueForTransfer(new
StandingInstructionDuesData(currentDate, BigDecimal.ONE));
+ assertThat(isDueForTransfer).isTrue().describedAs("Current day
instructions are accepted as due");
+ }
+}