diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/ProgressiveLoanInterestScheduleModel.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/ProgressiveLoanInterestScheduleModel.java index c096ee2c6cd..db7aeac6a59 100644 --- a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/ProgressiveLoanInterestScheduleModel.java +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/ProgressiveLoanInterestScheduleModel.java @@ -27,6 +27,8 @@ import java.util.Optional; import java.util.TreeSet; import java.util.function.Consumer; + +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.experimental.Accessors; import org.apache.fineract.infrastructure.core.service.DateUtils; @@ -34,6 +36,8 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleProcessingWrapper; import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRelatedDetail; +import static org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleProcessingWrapper.isInPeriod; + @Data @Accessors(fluent = true) public class ProgressiveLoanInterestScheduleModel { @@ -211,4 +215,10 @@ public Money getTotalPaidInterest() { public Money getTotalPaidPrincipal() { return repaymentPeriods().stream().map(RepaymentPeriod::getPaidPrincipal).reduce(getZero(), Money::plus); } + + public Optional findRepaymentPeriod(@NotNull LocalDate transactionDate) { + return repaymentPeriods.stream() // + .filter(period -> isInPeriod(transactionDate, period.getFromDate(), period.getDueDate(), period.isFirstRepaymentPeriod()))// + .findFirst(); + } } diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/RepaymentPeriod.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/RepaymentPeriod.java index d037ade24bb..860669eb493 100644 --- a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/RepaymentPeriod.java +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/data/RepaymentPeriod.java @@ -207,9 +207,9 @@ public InterestPeriod getLastInterestPeriod() { } public Optional findInterestPeriod(@NotNull LocalDate transactionDate) { - return interestPeriods.stream()// - .filter(interestPeriod -> isInPeriod(transactionDate, interestPeriod.getFromDate(), interestPeriod.getDueDate(), false))// - .findFirst(); + return interestPeriods.stream() // + .filter(interestPeriod -> isInPeriod(transactionDate, interestPeriod.getFromDate(), interestPeriod.getDueDate(), isFirstRepaymentPeriod() && interestPeriod.isFirstInterestPeriod()))// + .reduce((one, two) -> two); } public boolean isFirstRepaymentPeriod() { diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java index e6ab6e11837..496626669a9 100644 --- a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/calc/ProgressiveEMICalculator.java @@ -262,11 +262,7 @@ private ProgressiveLoanInterestScheduleModel recalculateScheduleModelTillDate( @NotNull private static Optional findInterestPeriod(ProgressiveLoanInterestScheduleModel scheduleModel, LocalDate targetDate) { - return scheduleModel.repaymentPeriods().stream()// - .filter(rp -> isInPeriod(targetDate, rp.getFromDate(), rp.getDueDate(), false)).findFirst()// - .flatMap(rp -> rp.getInterestPeriods().stream()// - .filter(ip -> isInPeriod(targetDate, ip.getFromDate(), ip.getDueDate(), false)) // - .reduce((one, two) -> two)); + return scheduleModel.findRepaymentPeriod(targetDate).flatMap(rp -> rp.findInterestPeriod(targetDate)); } /**