Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-1106-rework-skip-holiday-for-first-reschedule-date #1328

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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<LoanRepaymentScheduleInstallment> fetchRetainedInstallments(
final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments, final LocalDate rescheduleFrom,
MonetaryCurrency currency) {
Expand Down