diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/domain/Charge.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/domain/Charge.java index 249c1993759..9c13ecb90ea 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/domain/Charge.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/charge/domain/Charge.java @@ -25,6 +25,8 @@ import java.time.MonthDay; import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; @@ -832,6 +834,10 @@ public Pair getAddOnDisbursementChargeRate(LocalDate disbur int defaultDays = LoanProductConstants.DEFAULT_LIMIT_OF_DAYS_FOR_ADDON; int daysAddOnApplicable = 0; + // Sort the list by the minDay attribute + final Comparator orderByMinDay = Comparator.comparing(ChargeRange::getMinDay); + Collections.sort(this.chargeRanges, orderByMinDay); + if (isDisbursementCharge() && isAddOnDisbursementType() && this.chargeRanges != null && !this.chargeRanges.isEmpty()) { // calculate days since disbursement date int numberOfDays = Math.toIntExact(daysBetween(disbursementDate, firstRepaymentDate)); @@ -843,6 +849,10 @@ public Pair getAddOnDisbursementChargeRate(LocalDate disbur && (chargeRange.getMaxDay() != null && daysAddOnApplicable <= chargeRange.getMaxDay())) { addOnDisbursementChargeRate = chargeRange.getFeeRate(); break; + } else if (chargeRange.getMinDay() != null && daysAddOnApplicable >= chargeRange.getMinDay() + && (chargeRange.getMaxDay() == null)) { + addOnDisbursementChargeRate = chargeRange.getFeeRate(); + break; } } }