account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), DepositAccountType.RECURRING_DEPOSIT.resourceName());
if (!changes.isEmpty()) {
updateFDAndRDCommonChanges(changes, command, account);
final MathContext mc = MathContext.DECIMAL64;
final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId(
accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue());
final Calendar calendar = calendarInstance.getCalendar();
final PeriodFrequencyType frequencyType = CalendarFrequencyType.from(CalendarUtils.getFrequency(calendar.getRecurrence()));
Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence());
frequency = frequency == -1 ? 1 : frequency;
account.generateSchedule(frequencyType, frequency, calendar);
final boolean isPreMatureClosure = false;
account.updateMaturityDateAndAmount(mc, isPreMatureClosure,
isSavingsInterestPostingAtCurrentPeriodEnd,
financialYearBeginningMonth);
account.validateApplicableInterestRate();
this.savingAccountRepository.save(account);
}
// update calendar details
if (!account.isCalendarInherited()) {
final LocalDate calendarStartDate = account.depositStartDate();
final Integer frequencyType = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName);
final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType);
final Integer frequency = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName);
final Integer repeatsOnDay = calendarStartDate.getDayOfWeek();
CalendarInstance calendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId(
accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue());
Calendar calendar = calendarInstance.getCalendar();
calendar.updateRepeatingCalendar(calendarStartDate, CalendarFrequencyType.from(periodFrequencyType), frequency,
repeatsOnDay);
this.calendarInstanceRepository.save(calendarInstance);
}