Skip to content

Commit

Permalink
FINERACT-2154: Store "Pre-close interest calculation strategy" on loa…
Browse files Browse the repository at this point in the history
…n level
  • Loading branch information
adamsaghy committed Nov 29, 2024
1 parent 8d12bc0 commit f63df47
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
import org.apache.fineract.portfolio.loanproduct.domain.InterestRecalculationCompoundingMethod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreCloseInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductInterestRecalculationDetails;
import org.apache.fineract.portfolio.loanproduct.domain.LoanRescheduleStrategyMethod;
import org.apache.fineract.portfolio.loanproduct.domain.RecalculationFrequencyType;
Expand Down Expand Up @@ -88,6 +91,10 @@ public class LoanInterestRecalculationDetails extends AbstractPersistableCustom<
@Column(name = "allow_compounding_on_eod")
private Boolean allowCompoundingOnEod;

@Column(name = "pre_close_interest_calculation_strategy")
@Enumerated(EnumType.ORDINAL)
private LoanPreCloseInterestCalculationStrategy preCloseInterestCalculationStrategy;

@Column(name = "disallow_interest_calc_on_past_due")
private Boolean disallowInterestCalculationOnPastDue;

Expand All @@ -99,7 +106,8 @@ private LoanInterestRecalculationDetails(final Integer interestRecalculationComp
final Integer restFrequencyType, final Integer restInterval, final Integer restFrequencyNthDay, Integer restFrequencyWeekday,
Integer restFrequencyOnDay, Integer compoundingFrequencyType, Integer compoundingInterval, Integer compoundingFrequencyNthDay,
Integer compoundingFrequencyWeekday, Integer compoundingFrequencyOnDay, final boolean isCompoundingToBePostedAsTransaction,
final boolean allowCompoundingOnEod, final boolean disallowInterestCalculationOnPastDue) {
final boolean allowCompoundingOnEod, final boolean disallowInterestCalculationOnPastDue,
final LoanPreCloseInterestCalculationStrategy preCloseInterestCalculationStrategy) {
this.interestRecalculationCompoundingMethod = interestRecalculationCompoundingMethod;
this.rescheduleStrategyMethod = rescheduleStrategyMethod;
this.restFrequencyNthDay = restFrequencyNthDay;
Expand All @@ -115,6 +123,7 @@ private LoanInterestRecalculationDetails(final Integer interestRecalculationComp
this.isCompoundingToBePostedAsTransaction = isCompoundingToBePostedAsTransaction;
this.allowCompoundingOnEod = allowCompoundingOnEod;
this.disallowInterestCalculationOnPastDue = disallowInterestCalculationOnPastDue;
this.preCloseInterestCalculationStrategy = preCloseInterestCalculationStrategy;
}

public static LoanInterestRecalculationDetails createFrom(
Expand All @@ -132,7 +141,8 @@ public static LoanInterestRecalculationDetails createFrom(
loanProductInterestRecalculationDetails.getCompoundingFrequencyOnDay(),
loanProductInterestRecalculationDetails.getIsCompoundingToBePostedAsTransaction(),
loanProductInterestRecalculationDetails.allowCompoundingOnEod(),
loanProductInterestRecalculationDetails.disallowInterestCalculationOnPastDue());
loanProductInterestRecalculationDetails.disallowInterestCalculationOnPastDue(),
loanProductInterestRecalculationDetails.getPreCloseInterestCalculationStrategy());
}

public void updateLoan(final Loan loan) {
Expand Down Expand Up @@ -198,4 +208,8 @@ public boolean allowCompoundingOnEod() {
public Boolean disallowInterestCalculationOnPastDue() {
return disallowInterestCalculationOnPastDue;
}

public LoanPreCloseInterestCalculationStrategy getPreCloseInterestCalculationStrategy() {
return preCloseInterestCalculationStrategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import org.apache.fineract.portfolio.loanproduct.domain.InterestCalculationPeriodMethod;
import org.apache.fineract.portfolio.loanproduct.domain.InterestMethod;
import org.apache.fineract.portfolio.loanproduct.domain.InterestRecalculationCompoundingMethod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreClosureInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreCloseInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRelatedDetail;
import org.apache.fineract.portfolio.loanproduct.domain.LoanRescheduleStrategyMethod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanSupportedInterestRefundTypes;
Expand Down Expand Up @@ -173,7 +173,7 @@ public final class LoanApplicationTerms {
private BigDecimal principalThresholdForLastInstalment;
private Integer installmentAmountInMultiplesOf;

private LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy;
private LoanPreCloseInterestCalculationStrategy preClosureInterestCalculationStrategy;

private Money approvedPrincipal;

Expand Down Expand Up @@ -450,7 +450,7 @@ public static LoanApplicationTerms assembleFrom(final ApplicationCurrency curren
final InterestRecalculationCompoundingMethod interestRecalculationCompoundingMethod,
final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType,
final BigDecimal principalThresholdForLastInstalment, final Integer installmentAmountInMultiplesOf,
final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar,
final LoanPreCloseInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar,
BigDecimal approvedAmount, List<LoanTermVariationsData> loanTermVariations,
Boolean isInterestChargedFromDateSameAsDisbursalDateEnabled, final Integer numberOfDays,
boolean isSkipRepaymentOnFirstDayOfMonth, final HolidayDetailDTO holidayDetailDTO, final boolean allowCompoundingOnEod,
Expand Down Expand Up @@ -494,7 +494,7 @@ public static LoanApplicationTerms assembleFrom(final ApplicationCurrency applic
final RecalculationFrequencyType recalculationFrequencyType, final CalendarInstance restCalendarInstance,
final InterestRecalculationCompoundingMethod compoundingMethod, final CalendarInstance compoundingCalendarInstance,
final RecalculationFrequencyType compoundingFrequencyType,
final LoanPreClosureInterestCalculationStrategy loanPreClosureInterestCalculationStrategy,
final LoanPreCloseInterestCalculationStrategy loanPreClosureInterestCalculationStrategy,
final LoanRescheduleStrategyMethod rescheduleStrategyMethod, final Calendar loanCalendar, BigDecimal approvedAmount,
BigDecimal annualNominalInterestRate, final List<LoanTermVariationsData> loanTermVariations,
final CalendarHistoryDataWrapper calendarHistoryDataWrapper, final Integer numberOfDays,
Expand Down Expand Up @@ -574,7 +574,7 @@ private LoanApplicationTerms(final ApplicationCurrency currency, final Integer l
final CalendarInstance restCalendarInstance, final RecalculationFrequencyType recalculationFrequencyType,
final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType,
final BigDecimal principalThresholdForLastInstalment, final Integer installmentAmountInMultiplesOf,
final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar,
final LoanPreCloseInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar,
BigDecimal approvedAmount, List<LoanTermVariationsData> loanTermVariations,
final CalendarHistoryDataWrapper calendarHistoryDataWrapper, Boolean isInterestChargedFromDateSameAsDisbursalDateEnabled,
final Integer numberOfDays, final boolean isSkipRepaymentOnFirstDayOfMonth, final HolidayDetailDTO holidayDetailDTO,
Expand Down Expand Up @@ -1795,7 +1795,7 @@ public InterestCalculationPeriodMethod getInterestCalculationPeriodMethod() {
return this.interestCalculationPeriodMethod;
}

public LoanPreClosureInterestCalculationStrategy getPreClosureInterestCalculationStrategy() {
public LoanPreCloseInterestCalculationStrategy getPreClosureInterestCalculationStrategy() {
return this.preClosureInterestCalculationStrategy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import lombok.Getter;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.portfolio.loanproduct.domain.InterestRecalculationCompoundingMethod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreClosureInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreCloseInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanRescheduleStrategyMethod;

@Getter
Expand Down Expand Up @@ -102,7 +102,7 @@ public static LoanProductInterestRecalculationData sensibleDefaultsForNewLoanPro
final boolean isArrearsBasedOnOriginalSchedule = false;
final boolean isCompoundingToBePostedAsTransaction = false;
final EnumOptionData preCloseInterestCalculationStrategy = preCloseInterestCalculationStrategy(
LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE);
LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE);
final boolean allowCompoundingOnEod = false;
final boolean disallowInterestCalculationOnPastDue = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.HashMap;
import java.util.Map;

public enum LoanPreClosureInterestCalculationStrategy {
public enum LoanPreCloseInterestCalculationStrategy {

NONE(0, "loanPreClosureInterestCalculationStrategy.none"), //
TILL_PRE_CLOSURE_DATE(1, "loanPreClosureInterestCalculationStrategy.tillPreClosureDate"), //
Expand All @@ -33,13 +33,13 @@ public enum LoanPreClosureInterestCalculationStrategy {
private final Integer value;
private final String code;

private static final Map<Integer, LoanPreClosureInterestCalculationStrategy> intToEnumMap = new HashMap<>();
private static final Map<Integer, LoanPreCloseInterestCalculationStrategy> intToEnumMap = new HashMap<>();
private static int minValue;
private static int maxValue;

static {
int i = 0;
for (final LoanPreClosureInterestCalculationStrategy type : LoanPreClosureInterestCalculationStrategy.values()) {
for (final LoanPreCloseInterestCalculationStrategy type : LoanPreCloseInterestCalculationStrategy.values()) {
if (i == 0) {
minValue = type.value;
}
Expand All @@ -54,11 +54,11 @@ public enum LoanPreClosureInterestCalculationStrategy {
}
}

public static LoanPreClosureInterestCalculationStrategy fromInt(final Integer ruleTypeValue) {
public static LoanPreCloseInterestCalculationStrategy fromInt(final Integer ruleTypeValue) {
return intToEnumMap.get(ruleTypeValue);
}

LoanPreClosureInterestCalculationStrategy(final Integer value, final String code) {
LoanPreCloseInterestCalculationStrategy(final Integer value, final String code) {
this.value = value;
this.code = code;
}
Expand All @@ -80,10 +80,10 @@ public static int getMaxValue() {
}

public boolean calculateTillRestFrequencyEnabled() {
return this.getValue().equals(LoanPreClosureInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE.getValue());
return this.getValue().equals(LoanPreCloseInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE.getValue());
}

public boolean calculateTillPreClosureDateEnabled() {
return this.getValue().equals(LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue());
return this.getValue().equals(LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1594,10 +1594,10 @@ public boolean isArrearsBasedOnOriginalSchedule() {
return isBasedOnOriginalSchedule;
}

public LoanPreClosureInterestCalculationStrategy preCloseInterestCalculationStrategy() {
LoanPreClosureInterestCalculationStrategy preCloseInterestCalculationStrategy = LoanPreClosureInterestCalculationStrategy.NONE;
public LoanPreCloseInterestCalculationStrategy preCloseInterestCalculationStrategy() {
LoanPreCloseInterestCalculationStrategy preCloseInterestCalculationStrategy = LoanPreCloseInterestCalculationStrategy.NONE;
if (this.isInterestRecalculationEnabled()) {
preCloseInterestCalculationStrategy = getProductInterestRecalculationDetails().preCloseInterestCalculationStrategy();
preCloseInterestCalculationStrategy = getProductInterestRecalculationDetails().getPreCloseInterestCalculationStrategy();
}
return preCloseInterestCalculationStrategy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class LoanProductInterestRecalculationDetails extends AbstractPersistable
private boolean isArrearsBasedOnOriginalSchedule;

@Column(name = "pre_close_interest_calculation_strategy")
private Integer preClosureInterestCalculationStrategy;
private Integer preCloseInterestCalculationStrategy;

@Column(name = "is_compounding_to_be_posted_as_transaction")
private Boolean isCompoundingToBePostedAsTransaction;
Expand Down Expand Up @@ -159,7 +159,7 @@ public static LoanProductInterestRecalculationDetails createFrom(final JsonComma
Integer preCloseInterestCalculationStrategy = command
.integerValueOfParameterNamed(LoanProductConstants.preClosureInterestCalculationStrategyParamName);
if (preCloseInterestCalculationStrategy == null) {
preCloseInterestCalculationStrategy = LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue();
preCloseInterestCalculationStrategy = LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue();
}

final boolean isCompoundingToBePostedAsTransaction = command
Expand Down Expand Up @@ -196,7 +196,7 @@ private LoanProductInterestRecalculationDetails(final Integer interestRecalculat
this.compoundingFrequencyOnDay = compoundingFrequencyOnDay;
this.compoundingFrequencyWeekday = compoundingFrequencyWeekday;
this.isArrearsBasedOnOriginalSchedule = isArrearsBasedOnOriginalSchedule;
this.preClosureInterestCalculationStrategy = preCloseInterestCalculationStrategy;
this.preCloseInterestCalculationStrategy = preCloseInterestCalculationStrategy;
this.isCompoundingToBePostedAsTransaction = isCompoundingToBePostedAsTransaction;
this.allowCompoundingOnEod = allowCompoundingOnEod;
this.disallowInterestCalculationOnPastDue = disallowInterestCalculationOnPastDue;
Expand Down Expand Up @@ -397,13 +397,13 @@ public void update(final JsonCommand command, final Map<String, Object> actualCh
}

if (command.isChangeInIntegerParameterNamed(LoanProductConstants.preClosureInterestCalculationStrategyParamName,
this.preClosureInterestCalculationStrategy)) {
this.preCloseInterestCalculationStrategy)) {
Integer newValue = command.integerValueOfParameterNamed(LoanProductConstants.preClosureInterestCalculationStrategyParamName);
if (newValue == null) {
newValue = LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue();
newValue = LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue();
}
actualChanges.put(LoanProductConstants.preClosureInterestCalculationStrategyParamName, newValue);
this.preClosureInterestCalculationStrategy = newValue;
this.preCloseInterestCalculationStrategy = newValue;
}

if (command.isChangeInBooleanParameterNamed(LoanProductConstants.isCompoundingToBePostedAsTransactionParamName,
Expand Down Expand Up @@ -443,8 +443,8 @@ public boolean isArrearsBasedOnOriginalSchedule() {
return this.isArrearsBasedOnOriginalSchedule;
}

public LoanPreClosureInterestCalculationStrategy preCloseInterestCalculationStrategy() {
return LoanPreClosureInterestCalculationStrategy.fromInt(this.preClosureInterestCalculationStrategy);
public LoanPreCloseInterestCalculationStrategy getPreCloseInterestCalculationStrategy() {
return LoanPreCloseInterestCalculationStrategy.fromInt(this.preCloseInterestCalculationStrategy);
}

public Integer getRestFrequencyNthDay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.apache.fineract.portfolio.loanproduct.domain.InterestCalculationPeriodMethod;
import org.apache.fineract.portfolio.loanproduct.domain.InterestMethod;
import org.apache.fineract.portfolio.loanproduct.domain.InterestRecalculationCompoundingMethod;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreClosureInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanPreCloseInterestCalculationStrategy;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductValueConditionType;
import org.apache.fineract.portfolio.loanproduct.domain.LoanRescheduleStrategyMethod;
import org.apache.fineract.portfolio.loanproduct.domain.RecalculationFrequencyType;
Expand Down Expand Up @@ -175,8 +175,8 @@ public List<EnumOptionData> retrieveInterestRecalculationFrequencyTypeOptions()
@Override
public List<EnumOptionData> retrievePreCloseInterestCalculationStrategyOptions() {

return Arrays.asList(preCloseInterestCalculationStrategy(LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE),
preCloseInterestCalculationStrategy(LoanPreClosureInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE));
return Arrays.asList(preCloseInterestCalculationStrategy(LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE),
preCloseInterestCalculationStrategy(LoanPreCloseInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE));
}

@Override
Expand Down
Loading

0 comments on commit f63df47

Please sign in to comment.