From 195a32fa8add540b777cca8996b4db5cd6905c44 Mon Sep 17 00:00:00 2001 From: Leonardo Hildt <108893281+leonardohildt@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:12:58 -0300 Subject: [PATCH] Fix for FBR-104 (#219) --- .../fineract/portfolio/charge/domain/Charge.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; } } }