FINERACT-1938: Fix calculating running balance after release amount in batch request
This commit is contained in:
committed by
Adam Saghy
parent
88d2f44cb4
commit
480b9542ed
+2
@@ -1824,6 +1824,8 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
|||||||
|
|
||||||
if (backdatedTxnsAllowedTill) {
|
if (backdatedTxnsAllowedTill) {
|
||||||
this.savingsAccountTransactionRepository.saveAll(account.getSavingsAccountTransactionsWithPivotConfig());
|
this.savingsAccountTransactionRepository.saveAll(account.getSavingsAccountTransactionsWithPivotConfig());
|
||||||
|
} else {
|
||||||
|
account.addTransaction(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.savingAccountRepositoryWrapper.save(account);
|
this.savingAccountRepositoryWrapper.save(account);
|
||||||
|
|||||||
+56
-3
@@ -2024,8 +2024,8 @@ public class BatchApiTest {
|
|||||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||||
|
|
||||||
final BatchRequest getSavingAccountRequest = BatchHelper.getSavingAccount(1L, Long.valueOf(savingsId), "chargeStatus=all", null);
|
final BatchRequest getSavingAccountRequest = BatchHelper.getSavingAccount(1L, Long.valueOf(savingsId), "chargeStatus=all", null);
|
||||||
final BatchRequest depositSavingAccountRequest = BatchHelper.depositSavingAccount(2L, 1L);
|
final BatchRequest depositSavingAccountRequest = BatchHelper.depositSavingAccount(2L, 1L, 100F);
|
||||||
final BatchRequest holdAmountOnSavingAccountRequest = BatchHelper.holdAmountOnSavingAccount(3L, 1L);
|
final BatchRequest holdAmountOnSavingAccountRequest = BatchHelper.holdAmountOnSavingAccount(3L, 1L, 10F);
|
||||||
|
|
||||||
final List<BatchRequest> batchRequests1 = Arrays.asList(getSavingAccountRequest, depositSavingAccountRequest,
|
final List<BatchRequest> batchRequests1 = Arrays.asList(getSavingAccountRequest, depositSavingAccountRequest,
|
||||||
holdAmountOnSavingAccountRequest);
|
holdAmountOnSavingAccountRequest);
|
||||||
@@ -2039,7 +2039,7 @@ public class BatchApiTest {
|
|||||||
final Long holdAmountTransactionId = jsonHelper.parse(responses1.get(2).getBody()).getAsJsonObject().get("resourceId").getAsLong();
|
final Long holdAmountTransactionId = jsonHelper.parse(responses1.get(2).getBody()).getAsJsonObject().get("resourceId").getAsLong();
|
||||||
|
|
||||||
final BatchRequest releaseAmountOnSavingAccountRequest = BatchHelper.releaseAmountOnSavingAccount(2L, 1L, holdAmountTransactionId);
|
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,
|
final List<BatchRequest> batchRequests2 = Arrays.asList(getSavingAccountRequest, releaseAmountOnSavingAccountRequest,
|
||||||
withdrawSavingAccountRequest);
|
withdrawSavingAccountRequest);
|
||||||
@@ -2557,6 +2557,59 @@ public class BatchApiTest {
|
|||||||
Assertions.assertEquals(HttpStatus.SC_CONFLICT, repaymentResponse.get(0).getStatusCode(), "Verify Status Code 409 for Locked Loan");
|
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
|
* Delete datatable
|
||||||
*
|
*
|
||||||
|
|||||||
+20
-11
@@ -1559,13 +1559,17 @@ public final class BatchHelper {
|
|||||||
* the request ID
|
* the request ID
|
||||||
* @param reference
|
* @param reference
|
||||||
* the reference
|
* the reference
|
||||||
|
* @param amount
|
||||||
|
* the transaction amount
|
||||||
* @return BatchRequest the created {@link BatchRequest}
|
* @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 LocalDate transactionDate = LocalDate.now(ZoneId.systemDefault());
|
||||||
final String transactionDateString = transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
final String transactionDateString = transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||||
String json = String.format("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
String json = String.format(
|
||||||
+ "\"transactionDate\": \"%s\", \"transactionAmount\": \"100\", \"paymentTypeId\": \"1\"}", transactionDateString);
|
"{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
||||||
|
+ "\"transactionDate\": \"%s\", \"transactionAmount\": \"%s\", \"paymentTypeId\": \"1\"}",
|
||||||
|
transactionDateString, amount);
|
||||||
return commandSavingAccount(requestId, null, reference, json, "deposit");
|
return commandSavingAccount(requestId, null, reference, json, "deposit");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1577,13 +1581,17 @@ public final class BatchHelper {
|
|||||||
* the request ID
|
* the request ID
|
||||||
* @param reference
|
* @param reference
|
||||||
* the reference
|
* the reference
|
||||||
|
* @param amount
|
||||||
|
* the transaction amount
|
||||||
* @return BatchRequest the created {@link BatchRequest}
|
* @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 LocalDate transactionDate = LocalDate.now(ZoneId.systemDefault());
|
||||||
final String transactionDateString = transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
final String transactionDateString = transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||||
String json = String.format("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
String json = String.format(
|
||||||
+ "\"transactionDate\": \"%s\", \"transactionAmount\": \"80\", \"paymentTypeId\": \"1\"}", transactionDateString);
|
"{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
||||||
|
+ "\"transactionDate\": \"%s\", \"transactionAmount\": \"%s\", \"paymentTypeId\": \"1\"}",
|
||||||
|
transactionDateString, amount);
|
||||||
return commandSavingAccount(requestId, null, reference, json, "withdrawal");
|
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}
|
* Creates and returns a {@link org.apache.fineract.batch.command.internal.SavingsAccountTransactionCommandStrategy}
|
||||||
* request with given request ID.
|
* request with given request ID.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param requestId
|
* @param requestId
|
||||||
* the request ID
|
* the request ID
|
||||||
* @param reference
|
* @param reference
|
||||||
* teh reference
|
* the reference
|
||||||
|
* @param amount
|
||||||
|
* the transaction amount
|
||||||
* @return BatchRequest the created {@link BatchRequest}
|
* @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();
|
final BatchRequest br = new BatchRequest();
|
||||||
|
|
||||||
br.setRequestId(requestId);
|
br.setRequestId(requestId);
|
||||||
@@ -1640,8 +1649,8 @@ public final class BatchHelper {
|
|||||||
final String transactionDateString = transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
final String transactionDateString = transactionDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||||
br.setBody(String.format(
|
br.setBody(String.format(
|
||||||
"{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
"{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
||||||
+ "\"transactionDate\": \"%s\", \"transactionAmount\": \"10\", \"reasonForBlock\": \"test\"}",
|
+ "\"transactionDate\": \"%s\", \"transactionAmount\": \"%s\", \"reasonForBlock\": \"test\"}",
|
||||||
transactionDateString));
|
transactionDateString, amount));
|
||||||
|
|
||||||
return br;
|
return br;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user