josehernandezfintecheandomx commented on code in PR #2908:
URL: https://github.com/apache/fineract/pull/2908#discussion_r1090622573
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java:
##########
@@ -233,6 +236,109 @@ public void
testApplyAndWaiveLoanSpecificDueDatePenaltyWithDisbursementDate() {
}
+ @Test
+ public void testApplyFeeAccrualOnClosedDate() {
+
+ final LocalDate todaysDate = Utils.getLocalDateOfTenant();
+
+ // Client and Loan account creation
+ final Integer clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec, "01 January 2012");
+ final GetLoanProductsProductIdResponse getLoanProductsProductResponse
= createLoanProduct(loanTransactionHelper, null);
+ assertNotNull(getLoanProductsProductResponse);
+
+ LocalDate transactionDate =
LocalDate.of(Utils.getLocalDateOfTenant().getYear(), 1, 1);
+ String operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Disbursement date {}", transactionDate);
+
+ // Create Loan Account
+ final Integer loanId = createLoanAccount(loanTransactionHelper,
clientId.toString(),
+ getLoanProductsProductResponse.getId().toString(),
operationDate);
+
+ // Get loan details
+ GetLoansLoanIdResponse getLoansLoanIdResponse =
loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("0.00"), true);
+
+ // Apply Loan Charge with specific due date
+ String feeAmount = "10.00";
+ String payloadJSON =
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT,
feeAmount, true);
+ final PostChargesResponse postChargesResponse =
ChargesHelper.createLoanCharge(requestSpec, responseSpec, payloadJSON);
+ assertNotNull(postChargesResponse);
+ final Long chargeId = postChargesResponse.getResourceId();
+ assertNotNull(chargeId);
+
+ // First Loan Charge
+ transactionDate = transactionDate.plusDays(1);
+ operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation date {}", transactionDate);
+ payloadJSON =
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(),
operationDate, feeAmount);
+ PostLoansLoanIdChargesResponse postLoansLoanIdChargesResponse =
loanTransactionHelper.addChargeForLoan(loanId, payloadJSON,
+ responseSpec);
+ assertNotNull(postLoansLoanIdChargesResponse);
+ final Long loanChargeId01 =
postLoansLoanIdChargesResponse.getResourceId();
+ assertNotNull(loanChargeId01);
+
+ // Run Accruals
+ log.info("Running Periodic Accrual for date {}", transactionDate);
+
periodicAccrualAccountingHelper.runPeriodicAccrualAccounting(operationDate);
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse,
"loanTransactionType.accrual", Double.valueOf("10.00"));
+
+ // Repay the first charge fully, 10
+ Float amount = Float.valueOf("10.00");
+ transactionDate = transactionDate.plusDays(1);
+ operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation date {}", transactionDate);
+ PostLoansLoanIdTransactionsResponse loanIdTransactionsResponse =
loanTransactionHelper.makeLoanRepayment(operationDate, amount,
+ loanId);
+ assertNotNull(loanIdTransactionsResponse);
+ log.info("Loan Transaction Id: {} {}", loanId,
loanIdTransactionsResponse.getResourceId());
+
+ // Second Loan Charge
+ feeAmount = "15.00";
+ transactionDate = transactionDate.plusDays(1);
+ operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation date {}", transactionDate);
+ payloadJSON =
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(),
operationDate, feeAmount);
+ postLoansLoanIdChargesResponse =
loanTransactionHelper.addChargeForLoan(loanId, payloadJSON, responseSpec);
+ assertNotNull(postLoansLoanIdChargesResponse);
+ final Long loanChargeId02 =
postLoansLoanIdChargesResponse.getResourceId();
+ assertNotNull(loanChargeId02);
+
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("15.00"), true);
+
+ // Run Accruals
+ log.info("Running Periodic Accrual for date {}", transactionDate);
+
periodicAccrualAccountingHelper.runPeriodicAccrualAccounting(operationDate);
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse,
"loanTransactionType.accrual", Double.valueOf("25.00"));
+
+ // Third Loan Charge
+ feeAmount = "25.00";
+ transactionDate = transactionDate.plusDays(1);
+ operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation date {}", transactionDate);
+ payloadJSON =
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(),
operationDate, feeAmount);
+ postLoansLoanIdChargesResponse =
loanTransactionHelper.addChargeForLoan(loanId, payloadJSON, responseSpec);
+ assertNotNull(postLoansLoanIdChargesResponse);
+ final Long loanChargeId03 =
postLoansLoanIdChargesResponse.getResourceId();
+ assertNotNull(loanChargeId03);
+
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("40.00"), true);
+
loanTransactionHelper.evaluateLoanTransactionData(getLoansLoanIdResponse,
"loanTransactionType.accrual", Double.valueOf("50.00"));
Review Comment:
In my opinion and as I have seen in other cases the `runaccrual` call runs
separately and when it is executed in the test, we already have passed the add
the third Loan Charge
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]