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 480b9542e FINERACT-1938: Fix calculating running balance after release 
amount in batch request
480b9542e is described below

commit 480b9542edab009feb6aa3668c5d7a0ac839366f
Author: mariiaKraievska <[email protected]>
AuthorDate: Fri Sep 29 16:11:18 2023 +0300

    FINERACT-1938: Fix calculating running balance after release amount in 
batch request
---
 ...countWritePlatformServiceJpaRepositoryImpl.java |  2 +
 .../fineract/integrationtests/BatchApiTest.java    | 59 ++++++++++++++++++++--
 .../integrationtests/common/BatchHelper.java       | 31 ++++++++----
 3 files changed, 78 insertions(+), 14 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
index 4e2e981f4..e21382667 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
@@ -1824,6 +1824,8 @@ public class 
SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
 
         if (backdatedTxnsAllowedTill) {
             
this.savingsAccountTransactionRepository.saveAll(account.getSavingsAccountTransactionsWithPivotConfig());
+        } else {
+            account.addTransaction(transaction);
         }
 
         this.savingAccountRepositoryWrapper.save(account);
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
index 1e99077e9..765e4a03e 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java
@@ -2024,8 +2024,8 @@ public class BatchApiTest {
         SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
 
         final BatchRequest getSavingAccountRequest = 
BatchHelper.getSavingAccount(1L, Long.valueOf(savingsId), "chargeStatus=all", 
null);
-        final BatchRequest depositSavingAccountRequest = 
BatchHelper.depositSavingAccount(2L, 1L);
-        final BatchRequest holdAmountOnSavingAccountRequest = 
BatchHelper.holdAmountOnSavingAccount(3L, 1L);
+        final BatchRequest depositSavingAccountRequest = 
BatchHelper.depositSavingAccount(2L, 1L, 100F);
+        final BatchRequest holdAmountOnSavingAccountRequest = 
BatchHelper.holdAmountOnSavingAccount(3L, 1L, 10F);
 
         final List<BatchRequest> batchRequests1 = 
Arrays.asList(getSavingAccountRequest, depositSavingAccountRequest,
                 holdAmountOnSavingAccountRequest);
@@ -2039,7 +2039,7 @@ public class BatchApiTest {
         final Long holdAmountTransactionId = 
jsonHelper.parse(responses1.get(2).getBody()).getAsJsonObject().get("resourceId").getAsLong();
 
         final BatchRequest releaseAmountOnSavingAccountRequest = 
BatchHelper.releaseAmountOnSavingAccount(2L, 1L, holdAmountTransactionId);
-        final BatchRequest withdrawSavingAccountRequest = 
BatchHelper.withdrawSavingAccount(3L, 1L);
+        final BatchRequest withdrawSavingAccountRequest = 
BatchHelper.withdrawSavingAccount(3L, 1L, 80F);
 
         final List<BatchRequest> batchRequests2 = 
Arrays.asList(getSavingAccountRequest, releaseAmountOnSavingAccountRequest,
                 withdrawSavingAccountRequest);
@@ -2557,6 +2557,59 @@ public class BatchApiTest {
         Assertions.assertEquals(HttpStatus.SC_CONFLICT, 
repaymentResponse.get(0).getStatusCode(), "Verify Status Code 409 for Locked 
Loan");
     }
 
+    @Test
+    public void verifyCalculatingRunningBalanceAfterBatchWithReleaseAmount() {
+        final float holdAmount = 10F;
+        final float withdrawalAmount = 80F;
+        final BatchRequest getSavingAccountRequest = 
BatchHelper.getSavingAccount(1L, 2L, "chargeStatus=all", null);
+        final BatchRequest depositSavingAccountRequest = 
BatchHelper.depositSavingAccount(2L, 1L, 300F);
+        final BatchRequest holdAmountOnSavingAccountRequest = 
BatchHelper.holdAmountOnSavingAccount(3L, 1L, holdAmount);
+
+        final List<BatchRequest> batchRequests1 = 
Arrays.asList(getSavingAccountRequest, depositSavingAccountRequest,
+                holdAmountOnSavingAccountRequest);
+        final List<BatchResponse> responses1 = 
BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, 
this.responseSpec,
+                BatchHelper.toJsonString(batchRequests1));
+
+        Assertions.assertEquals(HttpStatus.SC_OK, 
responses1.get(1).getStatusCode(), "Verify Status Code 200 for deposit saving 
account");
+        Assertions.assertEquals(HttpStatus.SC_OK, 
responses1.get(2).getStatusCode(),
+                "Verify Status Code 200 for hold amount on saving account");
+        final FromJsonHelper jsonHelper = new FromJsonHelper();
+        final Long holdAmountTransactionId = 
jsonHelper.parse(responses1.get(2).getBody()).getAsJsonObject().get("resourceId").getAsLong();
+
+        final SavingsAccountHelper savingsAccountHelper = new 
SavingsAccountHelper(this.requestSpec, this.responseSpec);
+        HashMap accountDetails = savingsAccountHelper.getSavingsDetails(2);
+        ArrayList<HashMap<String, Object>> transactions = 
(ArrayList<HashMap<String, Object>>) accountDetails.get("transactions");
+        final float runningBalanceBeforeBatch = (float) 
transactions.get(0).get("runningBalance");
+
+        final BatchRequest releaseAmountOnSavingAccountRequest = 
BatchHelper.releaseAmountOnSavingAccount(2L, 1L, holdAmountTransactionId);
+        final BatchRequest withdrawSavingAccountRequest1 = 
BatchHelper.withdrawSavingAccount(3L, 1L, withdrawalAmount);
+        final BatchRequest withdrawSavingAccountRequest2 = 
BatchHelper.withdrawSavingAccount(4L, 1L, withdrawalAmount);
+
+        final List<BatchRequest> batchRequests2 = 
Arrays.asList(getSavingAccountRequest, releaseAmountOnSavingAccountRequest,
+                withdrawSavingAccountRequest1, withdrawSavingAccountRequest2);
+        final List<BatchResponse> responses2 = 
BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, 
this.responseSpec,
+                BatchHelper.toJsonString(batchRequests2));
+
+        Assertions.assertEquals(HttpStatus.SC_OK, 
responses2.get(0).getStatusCode(),
+                "Verify Status Code 200 for release amount on saving account");
+        Assertions.assertEquals(HttpStatus.SC_OK, 
responses2.get(1).getStatusCode(), "Verify Status Code 200 for withdraw saving 
account");
+        Assertions.assertEquals(HttpStatus.SC_OK, 
responses2.get(2).getStatusCode(), "Verify Status Code 200 for withdraw saving 
account");
+
+        accountDetails = savingsAccountHelper.getSavingsDetails(2);
+        transactions = (ArrayList<HashMap<String, Object>>) 
accountDetails.get("transactions");
+
+        final HashMap<String, Object> transactionRelease = transactions.get(2);
+        final HashMap<String, Object> transactionWithdrawal1 = 
transactions.get(1);
+        final HashMap<String, Object> transactionWithdrawal2 = 
transactions.get(0);
+
+        assertEquals(runningBalanceBeforeBatch + holdAmount, 
transactionRelease.get("runningBalance"),
+                "Verify running balance after release amount");
+        assertEquals(runningBalanceBeforeBatch + holdAmount - 
withdrawalAmount, transactionWithdrawal1.get("runningBalance"),
+                "Verify running balance after first withdrawal");
+        assertEquals(runningBalanceBeforeBatch + holdAmount - withdrawalAmount 
- withdrawalAmount,
+                transactionWithdrawal2.get("runningBalance"), "Verify running 
balance after second withdrawal");
+    }
+
     /**
      * Delete datatable
      *
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BatchHelper.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BatchHelper.java
index 996b69429..8a61564e0 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BatchHelper.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/BatchHelper.java
@@ -1559,13 +1559,17 @@ public final class BatchHelper {
      *            the request ID
      * @param reference
      *            the reference
+     * @param amount
+     *            the transaction amount
      * @return BatchRequest the created {@link BatchRequest}
      */
-    public static BatchRequest depositSavingAccount(final Long requestId, 
final Long reference) {
+    public static BatchRequest depositSavingAccount(final Long requestId, 
final Long reference, final float amount) {
         final LocalDate transactionDate = 
LocalDate.now(ZoneId.systemDefault());
         final String transactionDateString = 
transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
-        String json = String.format("{\"locale\": \"en\", \"dateFormat\": \"dd 
MMMM yyyy\", "
-                + "\"transactionDate\": \"%s\", \"transactionAmount\": 
\"100\", \"paymentTypeId\": \"1\"}", transactionDateString);
+        String json = String.format(
+                "{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
+                        + "\"transactionDate\": \"%s\", \"transactionAmount\": 
\"%s\", \"paymentTypeId\": \"1\"}",
+                transactionDateString, amount);
         return commandSavingAccount(requestId, null, reference, json, 
"deposit");
     }
 
@@ -1577,13 +1581,17 @@ public final class BatchHelper {
      *            the request ID
      * @param reference
      *            the reference
+     * @param amount
+     *            the transaction amount
      * @return BatchRequest the created {@link BatchRequest}
      */
-    public static BatchRequest withdrawSavingAccount(final Long requestId, 
final Long reference) {
+    public static BatchRequest withdrawSavingAccount(final Long requestId, 
final Long reference, final float amount) {
         final LocalDate transactionDate = 
LocalDate.now(ZoneId.systemDefault());
         final String transactionDateString = 
transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
-        String json = String.format("{\"locale\": \"en\", \"dateFormat\": \"dd 
MMMM yyyy\", "
-                + "\"transactionDate\": \"%s\", \"transactionAmount\": \"80\", 
\"paymentTypeId\": \"1\"}", transactionDateString);
+        String json = String.format(
+                "{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
+                        + "\"transactionDate\": \"%s\", \"transactionAmount\": 
\"%s\", \"paymentTypeId\": \"1\"}",
+                transactionDateString, amount);
         return commandSavingAccount(requestId, null, reference, json, 
"withdrawal");
     }
 
@@ -1622,14 +1630,15 @@ public final class BatchHelper {
      * Creates and returns a {@link 
org.apache.fineract.batch.command.internal.SavingsAccountTransactionCommandStrategy}
      * request with given request ID.
      *
-     *
      * @param requestId
      *            the request ID
      * @param reference
-     *            teh reference
+     *            the reference
+     * @param amount
+     *            the transaction amount
      * @return BatchRequest the created {@link BatchRequest}
      */
-    public static BatchRequest holdAmountOnSavingAccount(final Long requestId, 
final Long reference) {
+    public static BatchRequest holdAmountOnSavingAccount(final Long requestId, 
final Long reference, final float amount) {
         final BatchRequest br = new BatchRequest();
 
         br.setRequestId(requestId);
@@ -1640,8 +1649,8 @@ public final class BatchHelper {
         final String transactionDateString = 
transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
         br.setBody(String.format(
                 "{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
-                        + "\"transactionDate\": \"%s\", \"transactionAmount\": 
\"10\", \"reasonForBlock\": \"test\"}",
-                transactionDateString));
+                        + "\"transactionDate\": \"%s\", \"transactionAmount\": 
\"%s\", \"reasonForBlock\": \"test\"}",
+                transactionDateString, amount));
 
         return br;
     }

Reply via email to