FINERACT-2090: refactor and cleanup Loan entity
This commit is contained in:
committed by
Adam Saghy
parent
369b809700
commit
c9f0799a06
+1070
-1035
File diff suppressed because it is too large
Load Diff
+16
-21
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.loanaccount.service;
|
||||
|
||||
import static org.apache.fineract.portfolio.loanproduct.domain.RecalculationFrequencyType.SAME_AS_REPAYMENT_PERIOD;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -236,28 +238,21 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa
|
||||
private void createCalendar(final Loan loan, LocalDate calendarStartDate, Integer recalculationFrequencyNthDay,
|
||||
final Integer repeatsOnDay, final RecalculationFrequencyType recalculationFrequencyType, Integer frequency,
|
||||
CalendarEntityType calendarEntityType, final String title) {
|
||||
CalendarFrequencyType calendarFrequencyType = CalendarFrequencyType.INVALID;
|
||||
Integer updatedRepeatsOnDay = repeatsOnDay;
|
||||
switch (recalculationFrequencyType) {
|
||||
case DAILY:
|
||||
calendarFrequencyType = CalendarFrequencyType.DAILY;
|
||||
break;
|
||||
case MONTHLY:
|
||||
calendarFrequencyType = CalendarFrequencyType.MONTHLY;
|
||||
break;
|
||||
case SAME_AS_REPAYMENT_PERIOD:
|
||||
frequency = loan.repaymentScheduleDetail().getRepayEvery();
|
||||
calendarFrequencyType = CalendarFrequencyType.from(loan.repaymentScheduleDetail().getRepaymentPeriodFrequencyType());
|
||||
calendarStartDate = loan.getExpectedDisbursedOnLocalDate();
|
||||
if (updatedRepeatsOnDay == null) {
|
||||
updatedRepeatsOnDay = calendarStartDate.get(ChronoField.DAY_OF_WEEK);
|
||||
}
|
||||
break;
|
||||
case WEEKLY:
|
||||
calendarFrequencyType = CalendarFrequencyType.WEEKLY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
final CalendarFrequencyType calendarFrequencyType = switch (recalculationFrequencyType) {
|
||||
case DAILY -> CalendarFrequencyType.DAILY;
|
||||
case WEEKLY -> CalendarFrequencyType.WEEKLY;
|
||||
case MONTHLY -> CalendarFrequencyType.MONTHLY;
|
||||
case SAME_AS_REPAYMENT_PERIOD -> CalendarFrequencyType.from(loan.repaymentScheduleDetail().getRepaymentPeriodFrequencyType());
|
||||
case INVALID -> CalendarFrequencyType.INVALID;
|
||||
};
|
||||
|
||||
if (recalculationFrequencyType == SAME_AS_REPAYMENT_PERIOD) {
|
||||
frequency = loan.repaymentScheduleDetail().getRepayEvery();
|
||||
calendarStartDate = loan.getExpectedDisbursedOnLocalDate();
|
||||
if (updatedRepeatsOnDay == null) {
|
||||
updatedRepeatsOnDay = calendarStartDate.get(ChronoField.DAY_OF_WEEK);
|
||||
}
|
||||
}
|
||||
|
||||
final Calendar calendar = Calendar.createRepeatingCalendar(title, calendarStartDate, CalendarType.COLLECTION.getValue(),
|
||||
|
||||
+9
-5
@@ -971,11 +971,15 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo
|
||||
final String defaultUserMessage = "Installment charge cannot be added to the loan.";
|
||||
throw new LoanChargeCannotBeAddedException("loanCharge", "overdue.charge", defaultUserMessage, null,
|
||||
chargeDefinition.getName());
|
||||
} else if (loanCharge.getDueLocalDate() != null
|
||||
&& DateUtils.isBefore(loanCharge.getDueLocalDate(), loan.getLastUserTransactionForChargeCalc())) {
|
||||
final String defaultUserMessage = "charge with date before last transaction date can not be added to loan.";
|
||||
throw new LoanChargeCannotBeAddedException("loanCharge", "date.is.before.last.transaction.date", defaultUserMessage, null,
|
||||
chargeDefinition.getName());
|
||||
} else if (loanCharge.getDueLocalDate() != null) {
|
||||
// TODO: Review, error message seems not valid if interest recalculation is not enabled.
|
||||
LocalDate validationDate = loan.repaymentScheduleDetail().isInterestRecalculationEnabled() ? loan.getLastUserTransactionDate()
|
||||
: loan.getDisbursementDate();
|
||||
if (DateUtils.isBefore(loanCharge.getDueLocalDate(), validationDate)) {
|
||||
final String defaultUserMessage = "charge with date before last transaction date can not be added to loan.";
|
||||
throw new LoanChargeCannotBeAddedException("loanCharge", "date.is.before.last.transaction.date", defaultUserMessage, null,
|
||||
chargeDefinition.getName());
|
||||
}
|
||||
} else if (loan.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
|
||||
if (loanCharge.isInstalmentFee() && loan.getStatus().isActive()) {
|
||||
final String defaultUserMessage = "installment charge addition not allowed after disbursement";
|
||||
|
||||
Reference in New Issue
Block a user