From 2db6e6d8b7863f1ff15ddbafba5d744e79797d32 Mon Sep 17 00:00:00 2001 From: Manoj Date: Mon, 14 Sep 2020 00:09:58 +0530 Subject: [PATCH] FINERACT-1106-rework-skip-holiday-for-first-reschedule-date --- .../domain/AbstractLoanScheduleGenerator.java | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java index 62f6158be87..4168dd4fbc5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java @@ -29,15 +29,12 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; -import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException; import org.apache.fineract.infrastructure.core.service.DateUtils; -import org.apache.fineract.organisation.holiday.service.HolidayUtil; import org.apache.fineract.organisation.monetary.domain.ApplicationCurrency; import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency; import org.apache.fineract.organisation.monetary.domain.Money; import org.apache.fineract.organisation.workingdays.data.AdjustedDateDetailsDTO; import org.apache.fineract.organisation.workingdays.domain.RepaymentRescheduleType; -import org.apache.fineract.organisation.workingdays.service.WorkingDaysUtil; import org.apache.fineract.portfolio.calendar.domain.CalendarInstance; import org.apache.fineract.portfolio.calendar.service.CalendarUtils; import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType; @@ -204,6 +201,12 @@ private LoanScheduleModel generate(final MathContext mc, final LoanApplicationTe previousRepaymentDate, scheduledDueDate, interestRatesForInstallments, this.paymentPeriodsInOneYearCalculator, mc); scheduledDueDate = termVariationParams.getScheduledDueDate(); + if (!loanApplicationTerms.isFirstRepaymentDateAllowedOnHoliday()) { + AdjustedDateDetailsDTO adjustedDateDetailsDTO1 = this.scheduledDateGenerator.adjustRepaymentDate(scheduledDueDate, + loanApplicationTerms, holidayDetailDTO); + scheduledDueDate = adjustedDateDetailsDTO1.getChangedScheduleDate(); + } + // Updates total days in term scheduleParams.addLoanTermInDays(Days.daysBetween(scheduleParams.getPeriodStartDate(), scheduledDueDate).getDays()); if (termVariationParams.isSkipPeriod()) { @@ -2362,10 +2365,6 @@ private LoanScheduleDTO rescheduleNextInstallments(final MathContext mc, final L periods.clear(); } LoanScheduleModel loanScheduleModel = generate(mc, loanApplicationTerms, loan.charges(), holidayDetailDTO, loanScheduleParams); - // check if first installment after reschedule is a holiday - if (!loanApplicationTerms.isFirstRepaymentDateAllowedOnHoliday()) { - checkIfFirstRepaymentDateisOnHolidayOrNonWorkingDay(holidayDetailDTO, loanScheduleModel); - } for (LoanScheduleModelPeriod loanScheduleModelPeriod : loanScheduleModel.getPeriods()) { if (loanScheduleModelPeriod.isRepaymentPeriod()) { @@ -2378,24 +2377,6 @@ private LoanScheduleDTO rescheduleNextInstallments(final MathContext mc, final L return LoanScheduleDTO.from(retainedInstallments, loanScheduleModelwithPeriodChanges); } - private void checkIfFirstRepaymentDateisOnHolidayOrNonWorkingDay(HolidayDetailDTO holidayDetailDTO, - LoanScheduleModel loanScheduleModel) { - - if (loanScheduleModel != null && loanScheduleModel.getPeriods() != null && loanScheduleModel.getPeriods().iterator() != null - && loanScheduleModel.getPeriods().iterator().next() != null - && loanScheduleModel.getPeriods().iterator().next().periodDueDate() != null) { - - if (WorkingDaysUtil.isNonWorkingDay(holidayDetailDTO.getWorkingDays(), - loanScheduleModel.getPeriods().iterator().next().periodDueDate()) - || HolidayUtil.getApplicableHoliday(loanScheduleModel.getPeriods().iterator().next().periodDueDate(), - holidayDetailDTO.getHolidays()) != null) { - throw new GeneralPlatformDomainRuleException("error.msg.first.installment.date.after.reschedule.should.be.a.working.day", - "As per configiration, the first repayment date after reschedule should be a working day"); - } - } - - } - public List fetchRetainedInstallments( final List repaymentScheduleInstallments, final LocalDate rescheduleFrom, MonetaryCurrency currency) {