Skip to content

Commit

Permalink
FINERACT-2060: Accrual reverse replay logic and Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Jankovics committed Nov 18, 2024
1 parent f6f480c commit c8e6683
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
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;
import org.apache.fineract.organisation.monetary.domain.Money;
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 {
Expand Down Expand Up @@ -211,4 +215,10 @@ public Money getTotalPaidInterest() {
public Money getTotalPaidPrincipal() {
return repaymentPeriods().stream().map(RepaymentPeriod::getPaidPrincipal).reduce(getZero(), Money::plus);
}

public Optional<RepaymentPeriod> findRepaymentPeriod(@NotNull LocalDate transactionDate) {
return repaymentPeriods.stream() //
.filter(period -> isInPeriod(transactionDate, period.getFromDate(), period.getDueDate(), period.isFirstRepaymentPeriod()))//
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public InterestPeriod getLastInterestPeriod() {
}

public Optional<InterestPeriod> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,7 @@ private ProgressiveLoanInterestScheduleModel recalculateScheduleModelTillDate(

@NotNull
private static Optional<InterestPeriod> 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));
}

/**
Expand Down

0 comments on commit c8e6683

Please sign in to comment.