From f63df474f679440655f0809b085186a461cd0093 Mon Sep 17 00:00:00 2001 From: Adam Saghy Date: Thu, 28 Nov 2024 16:48:21 +0100 Subject: [PATCH] FINERACT-2154: Store "Pre-close interest calculation strategy" on loan level --- .../LoanInterestRecalculationDetails.java | 18 ++++++++- .../domain/LoanApplicationTerms.java | 12 +++--- .../LoanProductInterestRecalculationData.java | 4 +- ...nPreCloseInterestCalculationStrategy.java} | 14 +++---- .../loanproduct/domain/LoanProduct.java | 6 +-- ...anProductInterestRecalculationDetails.java | 16 ++++---- .../LoanDropdownReadPlatformServiceImpl.java | 6 +-- .../loanproduct/service/LoanEnumerations.java | 14 +++---- .../module/loan/module-changelog-master.xml | 1 + ...ore_pre_closure_strategy_to_loan_level.xml | 38 +++++++++++++++++++ ...edPaymentScheduleTransactionProcessor.java | 9 ++--- .../LoanProductDataValidator.java | 4 +- .../DefaultScheduledDateGeneratorTest.java | 2 +- 13 files changed, 98 insertions(+), 46 deletions(-) rename fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/{LoanPreClosureInterestCalculationStrategy.java => LoanPreCloseInterestCalculationStrategy.java} (76%) create mode 100644 fineract-loan/src/main/resources/db/changelog/tenant/module/loan/parts/1025_store_pre_closure_strategy_to_loan_level.xml diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInterestRecalculationDetails.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInterestRecalculationDetails.java index 7823850ea38..20eb8d6e3b0 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInterestRecalculationDetails.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanInterestRecalculationDetails.java @@ -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; @@ -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; @@ -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; @@ -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( @@ -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) { @@ -198,4 +208,8 @@ public boolean allowCompoundingOnEod() { public Boolean disallowInterestCalculationOnPastDue() { return disallowInterestCalculationOnPastDue; } + + public LoanPreCloseInterestCalculationStrategy getPreCloseInterestCalculationStrategy() { + return preCloseInterestCalculationStrategy; + } } diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java index 661076c89a6..f9a3373e125 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java @@ -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; @@ -173,7 +173,7 @@ public final class LoanApplicationTerms { private BigDecimal principalThresholdForLastInstalment; private Integer installmentAmountInMultiplesOf; - private LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy; + private LoanPreCloseInterestCalculationStrategy preClosureInterestCalculationStrategy; private Money approvedPrincipal; @@ -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 loanTermVariations, Boolean isInterestChargedFromDateSameAsDisbursalDateEnabled, final Integer numberOfDays, boolean isSkipRepaymentOnFirstDayOfMonth, final HolidayDetailDTO holidayDetailDTO, final boolean allowCompoundingOnEod, @@ -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 loanTermVariations, final CalendarHistoryDataWrapper calendarHistoryDataWrapper, final Integer numberOfDays, @@ -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 loanTermVariations, final CalendarHistoryDataWrapper calendarHistoryDataWrapper, Boolean isInterestChargedFromDateSameAsDisbursalDateEnabled, final Integer numberOfDays, final boolean isSkipRepaymentOnFirstDayOfMonth, final HolidayDetailDTO holidayDetailDTO, @@ -1795,7 +1795,7 @@ public InterestCalculationPeriodMethod getInterestCalculationPeriodMethod() { return this.interestCalculationPeriodMethod; } - public LoanPreClosureInterestCalculationStrategy getPreClosureInterestCalculationStrategy() { + public LoanPreCloseInterestCalculationStrategy getPreClosureInterestCalculationStrategy() { return this.preClosureInterestCalculationStrategy; } diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductInterestRecalculationData.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductInterestRecalculationData.java index 9820a631613..478cc47c1a1 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductInterestRecalculationData.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductInterestRecalculationData.java @@ -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 @@ -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; diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanPreClosureInterestCalculationStrategy.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanPreCloseInterestCalculationStrategy.java similarity index 76% rename from fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanPreClosureInterestCalculationStrategy.java rename to fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanPreCloseInterestCalculationStrategy.java index 25ce5dd0b4c..fb653f8ed23 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanPreClosureInterestCalculationStrategy.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanPreCloseInterestCalculationStrategy.java @@ -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"), // @@ -33,13 +33,13 @@ public enum LoanPreClosureInterestCalculationStrategy { private final Integer value; private final String code; - private static final Map intToEnumMap = new HashMap<>(); + private static final Map 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; } @@ -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; } @@ -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()); } } diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java index cbc6d2b0786..c28b590fc90 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProduct.java @@ -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; } diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProductInterestRecalculationDetails.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProductInterestRecalculationDetails.java index ecca9c1ddc5..e9bc005f99c 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProductInterestRecalculationDetails.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/domain/LoanProductInterestRecalculationDetails.java @@ -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; @@ -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 @@ -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; @@ -397,13 +397,13 @@ public void update(final JsonCommand command, final Map 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, @@ -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() { diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanDropdownReadPlatformServiceImpl.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanDropdownReadPlatformServiceImpl.java index aa3b6ac0057..af8e2d8b68b 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanDropdownReadPlatformServiceImpl.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanDropdownReadPlatformServiceImpl.java @@ -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; @@ -175,8 +175,8 @@ public List retrieveInterestRecalculationFrequencyTypeOptions() @Override public List 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 diff --git a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java index acf6abb04c1..2711e7bcd0e 100644 --- a/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java +++ b/fineract-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanEnumerations.java @@ -33,7 +33,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.LoanProductParamType; import org.apache.fineract.portfolio.loanproduct.domain.LoanProductValueConditionType; import org.apache.fineract.portfolio.loanproduct.domain.LoanRescheduleStrategyMethod; @@ -522,19 +522,19 @@ public static EnumOptionData interestRecalculationFrequencyType(final Recalculat } public static EnumOptionData preCloseInterestCalculationStrategy(final int id) { - return preCloseInterestCalculationStrategy(LoanPreClosureInterestCalculationStrategy.fromInt(id)); + return preCloseInterestCalculationStrategy(LoanPreCloseInterestCalculationStrategy.fromInt(id)); } - public static EnumOptionData preCloseInterestCalculationStrategy(final LoanPreClosureInterestCalculationStrategy type) { + public static EnumOptionData preCloseInterestCalculationStrategy(final LoanPreCloseInterestCalculationStrategy type) { EnumOptionData optionData = null; switch (type) { case TILL_PRE_CLOSURE_DATE: - optionData = new EnumOptionData(LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue().longValue(), - LoanPreClosureInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getCode(), "Till Pre-Close Date"); + optionData = new EnumOptionData(LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getValue().longValue(), + LoanPreCloseInterestCalculationStrategy.TILL_PRE_CLOSURE_DATE.getCode(), "Till Pre-Close Date"); break; case TILL_REST_FREQUENCY_DATE: - optionData = new EnumOptionData(LoanPreClosureInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE.getValue().longValue(), - LoanPreClosureInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE.getCode(), "Till Rest Frequency Date"); + optionData = new EnumOptionData(LoanPreCloseInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE.getValue().longValue(), + LoanPreCloseInterestCalculationStrategy.TILL_REST_FREQUENCY_DATE.getCode(), "Till Rest Frequency Date"); break; case NONE: break; diff --git a/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/module-changelog-master.xml b/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/module-changelog-master.xml index 49f9f17fc5a..3ee2905cdc1 100644 --- a/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/module-changelog-master.xml +++ b/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/module-changelog-master.xml @@ -47,4 +47,5 @@ + diff --git a/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/parts/1025_store_pre_closure_strategy_to_loan_level.xml b/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/parts/1025_store_pre_closure_strategy_to_loan_level.xml new file mode 100644 index 00000000000..c243c2ba7bb --- /dev/null +++ b/fineract-loan/src/main/resources/db/changelog/tenant/module/loan/parts/1025_store_pre_closure_strategy_to_loan_level.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + UPDATE m_loan_recalculation_details SET pre_close_interest_calculation_strategy = 2 WHERE loan_id IN ( + SELECT ml.id FROM m_loan ml, m_product_loan_recalculation_details plrd WHERE plrd.product_id = ml.product_id AND plrd.pre_close_interest_calculation_strategy = 2 + ) + + + diff --git a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java index b88f6b3cb4c..6d78a6c9d58 100644 --- a/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java +++ b/fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/transactionprocessor/impl/AdvancedPaymentScheduleTransactionProcessor.java @@ -93,7 +93,7 @@ import org.apache.fineract.portfolio.loanproduct.domain.CreditAllocationTransactionType; import org.apache.fineract.portfolio.loanproduct.domain.DueType; import org.apache.fineract.portfolio.loanproduct.domain.FutureInstallmentAllocationRule; -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.PaymentAllocationType; import org.springframework.transaction.annotation.Propagation; @@ -1657,10 +1657,10 @@ private void updateRepaymentPeriodBalances(PaymentAllocationType paymentAllocati private LocalDate calculateNewPayDateInCaseOfInAdvancePayment(LoanTransaction loanTransaction, LoanRepaymentScheduleInstallment inAdvanceInstallment) { - LoanPreClosureInterestCalculationStrategy strategy = loanTransaction.getLoan().getLoanProduct() - .preCloseInterestCalculationStrategy(); + LoanPreCloseInterestCalculationStrategy strategy = loanTransaction.getLoan().getLoanInterestRecalculationDetails() + .getPreCloseInterestCalculationStrategy(); - LocalDate payDate = switch (strategy) { + return switch (strategy) { case TILL_PRE_CLOSURE_DATE -> loanTransaction.getTransactionDate(); // TODO use isInPeriod case TILL_REST_FREQUENCY_DATE -> loanTransaction.getTransactionDate().isAfter(inAdvanceInstallment.getFromDate()) // @@ -1669,7 +1669,6 @@ private LocalDate calculateNewPayDateInCaseOfInAdvancePayment(LoanTransaction lo : loanTransaction.getTransactionDate(); // case NONE -> throw new IllegalStateException("Unexpected PreClosureInterestCalculationStrategy: NONE"); }; - return payDate; } @NotNull diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java index 51813bb313c..f967e897b91 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/serialization/LoanProductDataValidator.java @@ -61,7 +61,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.LoanProduct; import org.apache.fineract.portfolio.loanproduct.domain.LoanProductPaymentAllocationRule; import org.apache.fineract.portfolio.loanproduct.domain.LoanProductValueConditionType; @@ -1224,7 +1224,7 @@ private void validateInterestRecalculationParams(final JsonElement element, fina .extractIntegerWithLocaleNamed(LoanProductConstants.preClosureInterestCalculationStrategyParamName, element); baseDataValidator.reset().parameter(LoanProductConstants.preClosureInterestCalculationStrategyParamName) .value(preCloseInterestCalculationStrategy).ignoreIfNull().inMinMaxRange( - LoanPreClosureInterestCalculationStrategy.getMinValue(), LoanPreClosureInterestCalculationStrategy.getMaxValue()); + LoanPreCloseInterestCalculationStrategy.getMinValue(), LoanPreCloseInterestCalculationStrategy.getMaxValue()); } public void validateForUpdate(final JsonCommand command, final LoanProduct loanProduct) { diff --git a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGeneratorTest.java b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGeneratorTest.java index 61cd464f937..3cdf6995cff 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGeneratorTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/DefaultScheduledDateGeneratorTest.java @@ -29,7 +29,7 @@ import static org.apache.fineract.portfolio.loanproduct.domain.AmortizationMethod.EQUAL_PRINCIPAL; import static org.apache.fineract.portfolio.loanproduct.domain.InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD; import static org.apache.fineract.portfolio.loanproduct.domain.InterestMethod.FLAT; -import static org.apache.fineract.portfolio.loanproduct.domain.LoanPreClosureInterestCalculationStrategy.NONE; +import static org.apache.fineract.portfolio.loanproduct.domain.LoanPreCloseInterestCalculationStrategy.NONE; import static org.apache.fineract.portfolio.loanproduct.domain.RepaymentStartDateType.DISBURSEMENT_DATE; import static org.apache.fineract.util.TimeZoneConstants.ASIA_MANILA_ID; import static org.apache.fineract.util.TimeZoneConstants.EUROPE_BERLIN_ID;