FINERACT-1981: progressive loan disbursement charge fixes
- Update PutChargesChargeIdRequest swagger def - undo disbursement fix - non-tranche multidisburse fix - disbursement transaction order fix
This commit is contained in:
+42
@@ -157,6 +157,48 @@ final class ChargesApiResourceSwagger {
|
|||||||
|
|
||||||
@Schema(example = "Loan service fee(changed)")
|
@Schema(example = "Loan service fee(changed)")
|
||||||
public String name;
|
public String name;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer chargeAppliesTo;
|
||||||
|
@Schema(example = "USD")
|
||||||
|
public String currencyCode;
|
||||||
|
@Schema(example = "en")
|
||||||
|
public String locale;
|
||||||
|
@Schema(example = "230.56")
|
||||||
|
public Double amount;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer chargeTimeType;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer chargeCalculationType;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer chargePaymentMode;
|
||||||
|
@Schema(example = "true")
|
||||||
|
public boolean active;
|
||||||
|
@Schema(example = "false")
|
||||||
|
public boolean penalty;
|
||||||
|
@Schema(example = "dd MMMM")
|
||||||
|
public String monthDayFormat;
|
||||||
|
@Schema(example = "01 March")
|
||||||
|
public String feeOnMonthDay;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer feeInterval;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public String feeFrequency;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer freeWithdrawalFrequency;
|
||||||
|
@Schema(example = "10")
|
||||||
|
public Integer restartCountFrequency;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Integer countFrequencyType;
|
||||||
|
@Schema(example = "true")
|
||||||
|
public boolean enableFreeWithdrawalCharge;
|
||||||
|
@Schema(example = "true")
|
||||||
|
public boolean enablePaymentType;
|
||||||
|
@Schema(example = "1")
|
||||||
|
public Long paymentTypeId;
|
||||||
|
@Schema(example = "10.0")
|
||||||
|
public Double minCap;
|
||||||
|
@Schema(example = "120.0")
|
||||||
|
public Double maxCap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schema(description = "PutChargesChargeIdResponse")
|
@Schema(description = "PutChargesChargeIdResponse")
|
||||||
|
|||||||
+2
-2
@@ -24,8 +24,8 @@ public enum ChargeCalculationType {
|
|||||||
FLAT(1, "chargeCalculationType.flat"), //
|
FLAT(1, "chargeCalculationType.flat"), //
|
||||||
PERCENT_OF_AMOUNT(2, "chargeCalculationType.percent.of.amount"), //
|
PERCENT_OF_AMOUNT(2, "chargeCalculationType.percent.of.amount"), //
|
||||||
PERCENT_OF_AMOUNT_AND_INTEREST(3, "chargeCalculationType.percent.of.amount.and.interest"), //
|
PERCENT_OF_AMOUNT_AND_INTEREST(3, "chargeCalculationType.percent.of.amount.and.interest"), //
|
||||||
PERCENT_OF_INTEREST(4, "chargeCalculationType.percent.of.interest"), PERCENT_OF_DISBURSEMENT_AMOUNT(5,
|
PERCENT_OF_INTEREST(4, "chargeCalculationType.percent.of.interest"), //
|
||||||
"chargeCalculationType.percent.of.disbursement.amount");
|
PERCENT_OF_DISBURSEMENT_AMOUNT(5, "chargeCalculationType.percent.of.disbursement.amount");
|
||||||
|
|
||||||
private final Integer value;
|
private final Integer value;
|
||||||
private final String code;
|
private final String code;
|
||||||
|
|||||||
+2
-1
@@ -307,7 +307,8 @@ public class LoanTransaction extends AbstractAuditableWithUTCDateTimeCustom<Long
|
|||||||
loanTransaction.feeChargesPortion, loanTransaction.penaltyChargesPortion, loanTransaction.overPaymentPortion,
|
loanTransaction.feeChargesPortion, loanTransaction.penaltyChargesPortion, loanTransaction.overPaymentPortion,
|
||||||
loanTransaction.reversed, loanTransaction.paymentDetail, loanTransaction.externalId);
|
loanTransaction.reversed, loanTransaction.paymentDetail, loanTransaction.externalId);
|
||||||
|
|
||||||
if (LoanTransactionType.CHARGE_PAYMENT.equals(loanTransaction.getTypeOf())) {
|
if (LoanTransactionType.CHARGE_PAYMENT.equals(loanTransaction.getTypeOf())
|
||||||
|
|| LoanTransactionType.REPAYMENT_AT_DISBURSEMENT.equals(loanTransaction.getTypeOf())) {
|
||||||
newTransaction.getLoanChargesPaid().addAll(loanTransaction.getLoanChargesPaid());
|
newTransaction.getLoanChargesPaid().addAll(loanTransaction.getLoanChargesPaid());
|
||||||
}
|
}
|
||||||
if (LoanTransactionType.REAGE.equals(loanTransaction.getTypeOf())) {
|
if (LoanTransactionType.REAGE.equals(loanTransaction.getTypeOf())) {
|
||||||
|
|||||||
+2
-2
@@ -1225,8 +1225,8 @@ final class LoansApiResourceSwagger {
|
|||||||
|
|
||||||
private PostLoansDisbursementData() {}
|
private PostLoansDisbursementData() {}
|
||||||
|
|
||||||
@Schema(example = "[2013, 11, 1]")
|
@Schema(example = "1 November 2023")
|
||||||
public LocalDate expectedDisbursementDate;
|
public String expectedDisbursementDate;
|
||||||
@Schema(example = "1000.00")
|
@Schema(example = "1000.00")
|
||||||
public Double principal;
|
public Double principal;
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-18
@@ -30,6 +30,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
import org.apache.fineract.infrastructure.core.api.JsonCommand;
|
||||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||||
@@ -142,34 +143,46 @@ public class LoanChargeAssembler {
|
|||||||
expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
|
expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
|
||||||
LoanApiConstants.expectedDisbursementDateParameterName, disbursementDataElement, dateFormat,
|
LoanApiConstants.expectedDisbursementDateParameterName, disbursementDataElement, dateFormat,
|
||||||
locale);
|
locale);
|
||||||
|
} else {
|
||||||
|
expectedDisbursementDate = this.fromApiJsonHelper
|
||||||
|
.extractLocalDateNamed(LoanApiConstants.expectedDisbursementDateParameterName, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ChargeTimeType.DISBURSEMENT.getValue().equals(chargeDefinition.getChargeTimeType())) {
|
if (ChargeTimeType.DISBURSEMENT.getValue().equals(chargeDefinition.getChargeTimeType())) {
|
||||||
for (LoanDisbursementDetails disbursementDetail : disbursementDetails) {
|
if (CollectionUtils.isEmpty(disbursementDetails)) {
|
||||||
LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null;
|
// non-tranche
|
||||||
if (chargeDefinition.isPercentageOfApprovedAmount()
|
final LoanCharge loanCharge = createNewWithoutLoan(chargeDefinition, principal, amount, chargeTime,
|
||||||
&& disbursementDetail.expectedDisbursementDateAsLocalDate().equals(expectedDisbursementDate)) {
|
chargeCalculation, dueDate, chargePaymentModeEnum, numberOfRepayments, externalId);
|
||||||
final LoanCharge loanCharge = createNewWithoutLoan(chargeDefinition, principal, amount, chargeTime,
|
loanCharges.add(loanCharge);
|
||||||
chargeCalculation, dueDate, chargePaymentModeEnum, numberOfRepayments, externalId);
|
} else {
|
||||||
loanCharges.add(loanCharge);
|
// tranche
|
||||||
if (loanCharge.isTrancheDisbursementCharge()) {
|
for (LoanDisbursementDetails disbursementDetail : disbursementDetails) {
|
||||||
loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(loanCharge,
|
LoanTrancheDisbursementCharge loanTrancheDisbursementCharge = null;
|
||||||
disbursementDetail);
|
if (chargeDefinition.isPercentageOfApprovedAmount() && disbursementDetail
|
||||||
loanCharge.updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge);
|
.expectedDisbursementDateAsLocalDate().equals(expectedDisbursementDate)) {
|
||||||
}
|
final LoanCharge loanCharge = createNewWithoutLoan(chargeDefinition, principal, amount,
|
||||||
} else {
|
chargeTime, chargeCalculation, dueDate, chargePaymentModeEnum, numberOfRepayments,
|
||||||
if (disbursementDetail.expectedDisbursementDateAsLocalDate().equals(expectedDisbursementDate)) {
|
externalId);
|
||||||
final LoanCharge loanCharge = createNewWithoutLoan(chargeDefinition,
|
|
||||||
disbursementDetail.principal(), amount, chargeTime, chargeCalculation,
|
|
||||||
disbursementDetail.expectedDisbursementDateAsLocalDate(), chargePaymentModeEnum,
|
|
||||||
numberOfRepayments, externalId);
|
|
||||||
loanCharges.add(loanCharge);
|
loanCharges.add(loanCharge);
|
||||||
if (loanCharge.isTrancheDisbursementCharge()) {
|
if (loanCharge.isTrancheDisbursementCharge()) {
|
||||||
loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(loanCharge,
|
loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(loanCharge,
|
||||||
disbursementDetail);
|
disbursementDetail);
|
||||||
loanCharge.updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge);
|
loanCharge.updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (disbursementDetail.expectedDisbursementDateAsLocalDate().equals(expectedDisbursementDate)) {
|
||||||
|
final LoanCharge loanCharge = createNewWithoutLoan(chargeDefinition,
|
||||||
|
disbursementDetail.principal(), amount, chargeTime, chargeCalculation,
|
||||||
|
disbursementDetail.expectedDisbursementDateAsLocalDate(), chargePaymentModeEnum,
|
||||||
|
numberOfRepayments, externalId);
|
||||||
|
loanCharges.add(loanCharge);
|
||||||
|
if (loanCharge.isTrancheDisbursementCharge()) {
|
||||||
|
loanTrancheDisbursementCharge = new LoanTrancheDisbursementCharge(loanCharge,
|
||||||
|
disbursementDetail);
|
||||||
|
loanCharge.updateLoanTrancheDisbursementCharge(loanTrancheDisbursementCharge);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -399,6 +399,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
txnExternalId, loan.getTotalOverpaidAsMoney());
|
txnExternalId, loan.getTotalOverpaidAsMoney());
|
||||||
disbursementTransaction.updateLoan(loan);
|
disbursementTransaction.updateLoan(loan);
|
||||||
loan.addLoanTransaction(disbursementTransaction);
|
loan.addLoanTransaction(disbursementTransaction);
|
||||||
|
loanTransactionRepository.saveAndFlush(disbursementTransaction);
|
||||||
}
|
}
|
||||||
if (loan.getRepaymentScheduleInstallments().isEmpty()) {
|
if (loan.getRepaymentScheduleInstallments().isEmpty()) {
|
||||||
/*
|
/*
|
||||||
@@ -425,10 +426,6 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
|
|||||||
loanAccrualsProcessingService.processIncomePostingAndAccruals(loan);
|
loanAccrualsProcessingService.processIncomePostingAndAccruals(loan);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disbursementTransaction != null) {
|
|
||||||
loanTransactionRepository.saveAndFlush(disbursementTransaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loan.isAutoRepaymentForDownPaymentEnabled() && !isWithoutAutoPayment) {
|
if (loan.isAutoRepaymentForDownPaymentEnabled() && !isWithoutAutoPayment) {
|
||||||
// updating linked savings account for auto down payment transaction for disbursement to savings account
|
// updating linked savings account for auto down payment transaction for disbursement to savings account
|
||||||
if (isAccountTransfer && loan.shouldCreateStandingInstructionAtDisbursement()) {
|
if (isAccountTransfer && loan.shouldCreateStandingInstructionAtDisbursement()) {
|
||||||
|
|||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* 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.integrationtests;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import org.apache.fineract.client.models.ChargeRequest;
|
||||||
|
import org.apache.fineract.client.models.PostChargesResponse;
|
||||||
|
import org.apache.fineract.client.models.PostClientsResponse;
|
||||||
|
import org.apache.fineract.client.models.PostLoanProductsResponse;
|
||||||
|
import org.apache.fineract.client.models.PostLoansLoanIdRequest;
|
||||||
|
import org.apache.fineract.client.models.PostLoansRequestChargeData;
|
||||||
|
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||||
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class ProgressiveLoanUndoDisbursementTest extends BaseLoanIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProgressiveLoanUndoDisbursementWithChargeAtDisbursement() {
|
||||||
|
final PostClientsResponse client = clientHelper.createClient(ClientHelper.defaultClientCreationRequest());
|
||||||
|
|
||||||
|
final AtomicReference<Long> loanIdRef = new AtomicReference<>();
|
||||||
|
|
||||||
|
final PostLoanProductsResponse loanProductsResponse = loanProductHelper.createLoanProduct(create4IProgressive());
|
||||||
|
|
||||||
|
final PostChargesResponse disbCharge = chargesHelper.createCharges(new ChargeRequest().active(true).chargeAppliesTo(1)
|
||||||
|
.chargeCalculationType(1).chargePaymentMode(0).chargeTimeType(1).currencyCode("EUR").amount(10.0d)
|
||||||
|
.name(Utils.randomStringGenerator("FEE_" + Calendar.getInstance().getTimeInMillis(), 5)).locale("en"));
|
||||||
|
|
||||||
|
runAt("01 January 2025", () -> {
|
||||||
|
Long loanId = applyAndApproveProgressiveLoan(client.getClientId(), loanProductsResponse.getResourceId(), "01 January 2025",
|
||||||
|
430.0, 7.0, 6, l -> l.setCharges(
|
||||||
|
List.of(new PostLoansRequestChargeData().chargeId(disbCharge.getResourceId()).amount(new BigDecimal("10.0")))));
|
||||||
|
|
||||||
|
loanIdRef.set(loanId);
|
||||||
|
|
||||||
|
disburseLoan(loanId, BigDecimal.valueOf(430), "01 January 2025");
|
||||||
|
verifyRepaymentSchedule(loanId, installment(430.0, 0.0, 10.0, 0, null, "01 January 2025"), //
|
||||||
|
installment(70.63, 2.51, 73.14, false, "01 February 2025"), //
|
||||||
|
installment(71.04, 2.1, 73.14, false, "01 March 2025"), //
|
||||||
|
installment(71.46, 1.68, 73.14, false, "01 April 2025"), //
|
||||||
|
installment(71.87, 1.27, 73.14, false, "01 May 2025"), //
|
||||||
|
installment(72.29, 0.85, 73.14, false, "01 June 2025"), //
|
||||||
|
installment(72.71, 0.42, 73.13, false, "01 July 2025"));
|
||||||
|
Assertions.assertDoesNotThrow(() -> loanTransactionHelper.undoDisbursalLoan(loanId, new PostLoansLoanIdRequest()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user