This is an automated email from the ASF dual-hosted git repository.
arnold 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 9fba52abb FINERACT-1785: Waive loan charge with same disbursement date
9fba52abb is described below
commit 9fba52abbbb368e6edc231b125d9bdb2a6fb05fb
Author: Jose Alberto Hernandez <[email protected]>
AuthorDate: Wed Dec 14 12:27:23 2022 -0600
FINERACT-1785: Waive loan charge with same disbursement date
---
...tLoanRepaymentScheduleTransactionProcessor.java | 5 +-
.../LoanChargeSpecificDueDateTest.java | 64 ++++++++++++++++++++++
.../common/loans/LoanTransactionHelper.java | 9 +++
3 files changed, 77 insertions(+), 1 deletion(-)
diff --git
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/AbstractLoanRepaymentScheduleTransactionProcessor.java
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/AbstractLoanRepaymentScheduleTransactionProcessor.java
index a4fb6f277..ecb992846 100644
---
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/AbstractLoanRepaymentScheduleTransactionProcessor.java
+++
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/AbstractLoanRepaymentScheduleTransactionProcessor.java
@@ -109,7 +109,10 @@ public abstract class
AbstractLoanRepaymentScheduleTransactionProcessor implemen
LocalDate startDate = disbursementDate;
for (final LoanRepaymentScheduleInstallment installment :
installments) {
for (final LoanCharge loanCharge : transferCharges) {
- if
(loanCharge.isDueForCollectionFromAndUpToAndIncluding(startDate,
installment.getDueDate())) {
+ if
(loanCharge.isDueForCollectionFromAndUpToAndIncluding(startDate,
installment.getDueDate())
+ // Special case for Loan Charges (Due Date)
added the same disbursement date
+ || (startDate.equals(disbursementDate) &&
loanCharge.getDueDate() != null
+ &&
loanCharge.getDueDate().equals(disbursementDate))) {
Money amountForProcess =
loanCharge.getAmount(currency);
if
(amountForProcess.isGreaterThan(loanTransaction.getAmount(currency))) {
amountForProcess =
loanTransaction.getAmount(currency);
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java
index 7f0dcbeca..1b5df8419 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanChargeSpecificDueDateTest.java
@@ -31,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.PostChargesResponse;
+import
org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse;
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
import org.apache.fineract.integrationtests.common.ClientHelper;
@@ -169,6 +170,69 @@ public class LoanChargeSpecificDueDateTest {
}
+ @Test
+ public void
testApplyAndWaiveLoanSpecificDueDatePenaltyWithDisbursementDate() {
+
+ 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);
+
+ // Older date to have more than one overdue installment
+ LocalDate transactionDate = todaysDate;
+ String operationDate = Utils.dateFormatter.format(transactionDate);
+ log.info("Operation 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
+ final 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);
+
+ payloadJSON =
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(chargeId.toString(),
operationDate, feeAmount);
+ PostLoansLoanIdChargesResponse postLoansLoanIdChargesResponse =
loanTransactionHelper.addChargeForLoan(loanId, payloadJSON,
+ responseSpec);
+ assertNotNull(postLoansLoanIdChargesResponse);
+ final Long loanChargeId =
postLoansLoanIdChargesResponse.getResourceId();
+ assertNotNull(loanChargeId);
+
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("10.00"), true);
+
+ // Waive the Loan Charge
+ final PostLoansLoanIdChargesChargeIdResponse
postWaiveLoanChargesResponse =
loanTransactionHelper.applyLoanChargeCommand(loanId,
+ loanChargeId, "waive", Utils.emptyJson());
+ assertNotNull(postWaiveLoanChargesResponse);
+
+ // evaluate the outstanding
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ validateLoanAccount(getLoansLoanIdResponse,
Double.valueOf(principalAmount), Double.valueOf("10.00"), true);
+
+ // Make a full repayment to close the Loan
+ Float amount = Float.valueOf("1010.00");
+ PostLoansLoanIdTransactionsResponse loanIdTransactionsResponse =
loanTransactionHelper.makeLoanRepayment(operationDate, amount,
+ loanId);
+ assertNotNull(loanIdTransactionsResponse);
+ log.info("Loan Transaction Id: {} {}", loanId,
loanIdTransactionsResponse.getResourceId());
+
+ getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec,
responseSpec, loanId);
+ assertNotNull(getLoansLoanIdResponse);
+ loanTransactionHelper.validateLoanStatus(getLoansLoanIdResponse,
"loanStatusType.closed.obligations.met");
+
+ }
+
private GetLoanProductsProductIdResponse createLoanProduct(final
LoanTransactionHelper loanTransactionHelper,
final Integer delinquencyBucketId) {
final HashMap<String, Object> loanProductMap = new
LoanProductTestBuilder().build(null, delinquencyBucketId);
diff --git
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
index 148cf2f7a..bd22b2307 100644
---
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
+++
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java
@@ -814,6 +814,15 @@ public class LoanTransactionHelper extends IntegrationTest
{
return (Integer) response.get("resourceId");
}
+ public PostLoansLoanIdChargesChargeIdResponse applyLoanChargeCommand(final
Integer loanId, final Long loanchargeId, final String commad,
+ final String json) {
+ log.info("--------------------------------- WAIVE CHARGES FOR LOAN
--------------------------------");
+ final String CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId
+ "/charges/" + loanchargeId + "?command=" + commad + "&"
+ + Utils.TENANT_IDENTIFIER;
+ final String response = Utils.performServerPost(requestSpec,
responseSpec, CHARGES_URL, json, null);
+ return GSON.fromJson(response,
PostLoansLoanIdChargesChargeIdResponse.class);
+ }
+
public Integer waiveChargesForLoan(final Integer loanId, final Integer
loanchargeId, final String json) {
log.info("--------------------------------- WAIVE CHARGES FOR LOAN
--------------------------------");
final String CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId
+ "/charges/" + loanchargeId + "?command=waive&"