List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.AbstractLoanScheduleGenerator.java
License:Apache License
private Money updateCompoundingDetailsForPartialScheduleGeneration( final LoanRepaymentScheduleInstallment installment, LoanApplicationTerms loanApplicationTerms, Map<LocalDate, Money> principalMap, final Map<LocalDate, Map<LocalDate, Money>> compoundingDateVariations, final Money uncompoundedAmount, final Collection<RecalculationDetail> applicableTransactions, LocalDate lastRestDate, HolidayDetailDTO holidayDetailDTO) { Money uncompounded = uncompoundedAmount; MonetaryCurrency currency = uncompoundedAmount.getCurrency(); for (RecalculationDetail detail : applicableTransactions) { LocalDate applicableDate = getNextRestScheduleDate(detail.getTransactionDate().minusDays(1), loanApplicationTerms, holidayDetailDTO); adjustCompoundedAmountWithPaidDetail(principalMap, lastRestDate, applicableDate, detail.getTransaction(), loanApplicationTerms, currency); }//from ww w. j av a2 s . c o m Money amountCharged = getIncomeForCompounding(loanApplicationTerms, currency, installment); final Set<LoanInterestRecalcualtionAdditionalDetails> details = installment.getLoanCompoundingDetails(); Money totalCompounded = Money.zero(currency); Map<LocalDate, Money> compoundingMap = new TreeMap<>(); for (LoanInterestRecalcualtionAdditionalDetails additionalDetails : details) { LocalDate effectiveDate = additionalDetails.getEffectiveDate(); if (loanApplicationTerms.allowCompoundingOnEod()) { effectiveDate = effectiveDate.plusDays(1); } compoundingMap.put(effectiveDate, Money.of(currency, additionalDetails.getAmount())); totalCompounded = totalCompounded.plus(additionalDetails.getAmount()); updateMapWithAmount(principalMap, Money.of(currency, additionalDetails.getAmount()).negated(), effectiveDate); } compoundingDateVariations.put(installment.getFromDate(), compoundingMap); if (totalCompounded.isGreaterThanZero()) { final boolean isPastDate = installment.getDueDate().isBefore(DateUtils.getLocalDateOfTenant()); final LocalDate restDate = getNextRestScheduleDate(installment.getDueDate().minusDays(1), loanApplicationTerms, holidayDetailDTO); if (isPastDate) { updateMapWithAmount(principalMap, totalCompounded, lastRestDate); } else { updateMapWithAmount(principalMap, totalCompounded, restDate); } uncompounded = amountCharged.plus(uncompounded).minus(totalCompounded); } else { uncompounded = uncompounded.plus(amountCharged); } return uncompounded; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.AbstractLoanScheduleGenerator.java
License:Apache License
private LocalDate getNextCompoundScheduleDate(LocalDate startDate, LoanApplicationTerms loanApplicationTerms, final HolidayDetailDTO holidayDetailDTO) { LocalDate nextScheduleDate = null; if (!loanApplicationTerms.getInterestRecalculationCompoundingMethod().isCompoundingEnabled()) { return null; }/*from w w w . j ava2s. c o m*/ if (loanApplicationTerms.getCompoundingFrequencyType().isSameAsRepayment()) { nextScheduleDate = this.scheduledDateGenerator.generateNextScheduleDateStartingFromDisburseDate( startDate, loanApplicationTerms, holidayDetailDTO); } else { CalendarInstance calendarInstance = loanApplicationTerms.getCompoundingCalendarInstance(); nextScheduleDate = CalendarUtils.getNextScheduleDate(calendarInstance.getCalendar(), startDate); if (loanApplicationTerms.allowCompoundingOnEod()) { nextScheduleDate = nextScheduleDate.plusDays(1); } } return nextScheduleDate; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultPaymentPeriodsInOneYearCalculator.java
License:Apache License
@Override public double calculatePortionOfRepaymentPeriodInterestChargingGrace(final LocalDate repaymentPeriodStartDate, final LocalDate scheduledDueDate, final LocalDate interestChargedFromLocalDate, final PeriodFrequencyType repaymentPeriodFrequencyType, final Integer repaidEvery) { Double periodFraction = Double.valueOf("0.0"); final LocalDateInterval repaymentPeriod = new LocalDateInterval(repaymentPeriodStartDate, scheduledDueDate); if (interestChargedFromLocalDate != null && repaymentPeriod.fallsBefore(interestChargedFromLocalDate.plusDays(1))) { periodFraction = Double.valueOf("1.0"); } else if (interestChargedFromLocalDate != null && repaymentPeriod.contains(interestChargedFromLocalDate)) { final int numberOfDaysInterestCalculationGraceInPeriod = Days .daysBetween(repaymentPeriodStartDate, interestChargedFromLocalDate).getDays(); periodFraction = calculateRepaymentPeriodFraction(repaymentPeriodFrequencyType, repaidEvery, numberOfDaysInterestCalculationGraceInPeriod); }/* w ww.j a v a 2s .com*/ return periodFraction; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
@Override public LocalDate generateNextRepaymentDate(final LocalDate lastRepaymentDate, final LoanApplicationTerms loanApplicationTerms, boolean isFirstRepayment, final HolidayDetailDTO holidayDetailDTO) { final LocalDate firstRepaymentPeriodDate = loanApplicationTerms .getCalculatedRepaymentsStartingFromLocalDate(); LocalDate dueRepaymentPeriodDate = null; Calendar currentCalendar = loanApplicationTerms.getLoanCalendar(); if (isFirstRepayment && firstRepaymentPeriodDate != null) { dueRepaymentPeriodDate = firstRepaymentPeriodDate; } else {//from w ww . j a v a 2 s . c om dueRepaymentPeriodDate = getRepaymentPeriodDate(loanApplicationTerms.getRepaymentPeriodFrequencyType(), loanApplicationTerms.getRepaymentEvery(), lastRepaymentDate, null, null); dueRepaymentPeriodDate = CalendarUtils.adjustDate(dueRepaymentPeriodDate, loanApplicationTerms.getSeedDate(), loanApplicationTerms.getRepaymentPeriodFrequencyType()); if (currentCalendar != null) { // If we have currentCalendar object, this means there is a // calendar associated with // the loan, and we should use it in order to calculate next // repayment CalendarHistory calendarHistory = null; CalendarHistoryDataWrapper calendarHistoryDataWrapper = loanApplicationTerms .getCalendarHistoryDataWrapper(); if (calendarHistoryDataWrapper != null) { calendarHistory = loanApplicationTerms.getCalendarHistoryDataWrapper() .getCalendarHistory(dueRepaymentPeriodDate); } // get the start date from the calendar history LocalDate seedDate = null; String reccuringString = null; if (calendarHistory == null) { seedDate = currentCalendar.getStartDateLocalDate(); reccuringString = currentCalendar.getRecurrence(); } else { seedDate = calendarHistory.getStartDateLocalDate(); reccuringString = calendarHistory.getRecurrence(); } dueRepaymentPeriodDate = CalendarUtils.getNewRepaymentMeetingDate(reccuringString, seedDate, lastRepaymentDate.plusDays(1), loanApplicationTerms.getRepaymentEvery(), CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType( loanApplicationTerms.getLoanTermPeriodFrequencyType()), holidayDetailDTO.getWorkingDays(), loanApplicationTerms.isSkipRepaymentOnFirstDayofMonth(), loanApplicationTerms.getNumberOfdays()); } } if (currentCalendar == null && holidayDetailDTO.getWorkingDays().getExtendTermForRepaymentsOnHolidays()) { boolean repaymentDateIsOnHoliday = false; // compile the list of holidays into Intervals to see if this date lands on a holiday final List<Interval> holidayInterval = new ArrayList<>(); for (Holiday holiday : holidayDetailDTO.getHolidays()) { holidayInterval.add(new Interval(holiday.getFromDateLocalDate().toDateTimeAtStartOfDay(), holiday.getToDateLocalDate().toDateTime(LocalTime.parse("23:59:59")))); } while (intervalListContainsDate(holidayInterval, dueRepaymentPeriodDate)) { LocalDate previousDate = dueRepaymentPeriodDate; dueRepaymentPeriodDate = getRepaymentPeriodDate( loanApplicationTerms.getRepaymentPeriodFrequencyType(), loanApplicationTerms.getRepaymentEvery(), dueRepaymentPeriodDate, loanApplicationTerms.getNthDay(), loanApplicationTerms.getWeekDayType()); } } return dueRepaymentPeriodDate; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
@Override public LocalDate getRepaymentPeriodDate(final PeriodFrequencyType frequency, final int repaidEvery, final LocalDate startDate, Integer nthDay, DayOfWeekType dayOfWeek) { LocalDate dueRepaymentPeriodDate = startDate; switch (frequency) { case DAYS:/* w w w.ja va 2s.c o m*/ dueRepaymentPeriodDate = startDate.plusDays(repaidEvery); break; case WEEKS: dueRepaymentPeriodDate = startDate.plusWeeks(repaidEvery); break; case MONTHS: dueRepaymentPeriodDate = startDate.plusMonths(repaidEvery); if (!(nthDay == null || dayOfWeek == null || dayOfWeek == DayOfWeekType.INVALID)) { dueRepaymentPeriodDate = adjustToNthWeekDay(dueRepaymentPeriodDate, nthDay, dayOfWeek.getValue()); } break; case YEARS: dueRepaymentPeriodDate = startDate.plusYears(repaidEvery); break; case INVALID: break; } return dueRepaymentPeriodDate; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
private LocalDate getPeriodEndDate(final LocalDate startDate) { LocalDate dueRepaymentPeriodDate = startDate; switch (this.repaymentPeriodFrequencyType) { case DAYS:/*ww w . java 2s .c o m*/ dueRepaymentPeriodDate = startDate.plusDays(this.repaymentEvery); break; case WEEKS: dueRepaymentPeriodDate = startDate.plusWeeks(this.repaymentEvery); break; case MONTHS: dueRepaymentPeriodDate = startDate.plusMonths(this.repaymentEvery); break; case YEARS: dueRepaymentPeriodDate = startDate.plusYears(this.repaymentEvery); break; case INVALID: break; } return dueRepaymentPeriodDate; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
public BigDecimal calculatePeriodsBetweenDates(final LocalDate startDate, final LocalDate endDate) { BigDecimal numberOfPeriods = BigDecimal.ZERO; switch (this.repaymentPeriodFrequencyType) { case DAYS:// w ww. j av a 2s . co m int numOfDays = Days.daysBetween(startDate, endDate).getDays(); numberOfPeriods = BigDecimal.valueOf((double) numOfDays); break; case WEEKS: int numberOfWeeks = Weeks.weeksBetween(startDate, endDate).getWeeks(); int daysLeftAfterWeeks = Days.daysBetween(startDate.plusWeeks(numberOfWeeks), endDate).getDays(); numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfWeeks)) .add(BigDecimal.valueOf((double) daysLeftAfterWeeks / 7)); break; case MONTHS: int numberOfMonths = Months.monthsBetween(startDate, endDate).getMonths(); LocalDate startDateAfterConsideringMonths = null; LocalDate endDateAfterConsideringMonths = null; int diffDays = 0; if (this.loanCalendar == null) { startDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths); startDateAfterConsideringMonths = CalendarUtils.adjustDate(startDateAfterConsideringMonths, getSeedDate(), this.repaymentPeriodFrequencyType); endDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths + 1); endDateAfterConsideringMonths = CalendarUtils.adjustDate(endDateAfterConsideringMonths, getSeedDate(), this.repaymentPeriodFrequencyType); } else { LocalDate expectedStartDate = startDate; if (!CalendarUtils.isValidRedurringDate(loanCalendar.getRecurrence(), loanCalendar.getStartDateLocalDate().minusMonths(getRepaymentEvery()), startDate)) { expectedStartDate = CalendarUtils.getNewRepaymentMeetingDate(loanCalendar.getRecurrence(), startDate.minusMonths(getRepaymentEvery()), startDate.minusMonths(getRepaymentEvery()), getRepaymentEvery(), CalendarUtils .getMeetingFrequencyFromPeriodFrequencyType(getLoanTermPeriodFrequencyType()), this.holidayDetailDTO.getWorkingDays(), isSkipRepaymentOnFirstDayOfMonth, numberOfDays); } if (!expectedStartDate.isEqual(startDate)) { diffDays = Days.daysBetween(startDate, expectedStartDate).getDays(); } if (numberOfMonths == 0) { startDateAfterConsideringMonths = expectedStartDate; } else { startDateAfterConsideringMonths = CalendarUtils.getNewRepaymentMeetingDate( loanCalendar.getRecurrence(), expectedStartDate, expectedStartDate.plusMonths(numberOfMonths), getRepaymentEvery(), CalendarUtils .getMeetingFrequencyFromPeriodFrequencyType(getLoanTermPeriodFrequencyType()), this.holidayDetailDTO.getWorkingDays(), isSkipRepaymentOnFirstDayOfMonth, numberOfDays); } endDateAfterConsideringMonths = CalendarUtils.getNewRepaymentMeetingDate( loanCalendar.getRecurrence(), startDateAfterConsideringMonths, startDateAfterConsideringMonths.plusDays(1), getRepaymentEvery(), CalendarUtils.getMeetingFrequencyFromPeriodFrequencyType(getLoanTermPeriodFrequencyType()), this.holidayDetailDTO.getWorkingDays(), isSkipRepaymentOnFirstDayOfMonth, numberOfDays); } int daysLeftAfterMonths = Days.daysBetween(startDateAfterConsideringMonths, endDate).getDays() + diffDays; int daysInPeriodAfterMonths = Days .daysBetween(startDateAfterConsideringMonths, endDateAfterConsideringMonths).getDays(); numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfMonths)) .add(BigDecimal.valueOf((double) daysLeftAfterMonths / daysInPeriodAfterMonths)); break; case YEARS: int numberOfYears = Years.yearsBetween(startDate, endDate).getYears(); LocalDate startDateAfterConsideringYears = startDate.plusYears(numberOfYears); LocalDate endDateAfterConsideringYears = startDate.plusYears(numberOfYears + 1); int daysLeftAfterYears = Days.daysBetween(startDateAfterConsideringYears, endDate).getDays(); int daysInPeriodAfterYears = Days .daysBetween(startDateAfterConsideringYears, endDateAfterConsideringYears).getDays(); numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfYears)) .add(BigDecimal.valueOf((double) daysLeftAfterYears / daysInPeriodAfterYears)); break; default: break; } return numberOfPeriods; }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
private boolean isFallingInRepaymentPeriod(LocalDate fromDate, LocalDate toDate) { boolean isSameAsRepaymentPeriod = false; if (this.interestCalculationPeriodMethod.getValue() .equals(InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD.getValue())) { switch (this.repaymentPeriodFrequencyType) { case WEEKS: int days = Days.daysBetween(fromDate, toDate).getDays(); isSameAsRepaymentPeriod = (days % 7) == 0; break; case MONTHS: boolean isFromDateOnEndDate = false; if (fromDate.getDayOfMonth() > fromDate.plusDays(1).getDayOfMonth()) { isFromDateOnEndDate = true; }//from w w w . ja v a2 s. c om boolean isToDateOnEndDate = false; if (toDate.getDayOfMonth() > toDate.plusDays(1).getDayOfMonth()) { isToDateOnEndDate = true; } if (isFromDateOnEndDate && isToDateOnEndDate) { isSameAsRepaymentPeriod = true; } else { int months = getPeriodsBetween(fromDate, toDate); fromDate = fromDate.plusMonths(months); isSameAsRepaymentPeriod = fromDate.isEqual(toDate); } break; default: break; } } return isSameAsRepaymentPeriod; }
From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java
License:Apache License
private LocalDate deriveFirstRepaymentDate(final AccountType loanType, final Integer repaymentEvery, final LocalDate expectedDisbursementDate, final PeriodFrequencyType repaymentPeriodFrequencyType, final Integer minimumDaysBetweenDisbursalAndFirstRepayment, final Calendar calendar) { LocalDate derivedFirstRepayment = null; final LocalDate dateBasedOnMinimumDaysBetweenDisbursalAndFirstRepayment = expectedDisbursementDate .plusDays(minimumDaysBetweenDisbursalAndFirstRepayment); if (calendar != null) { final LocalDate refernceDateForCalculatingFirstRepaymentDate = expectedDisbursementDate; derivedFirstRepayment = deriveFirstRepaymentDateForLoans(repaymentEvery, expectedDisbursementDate, refernceDateForCalculatingFirstRepaymentDate, repaymentPeriodFrequencyType, minimumDaysBetweenDisbursalAndFirstRepayment, calendar); } /*** Individual or group account, or JLG not linked to a meeting ***/ else {//ww w . j a va2s. c o m LocalDate dateBasedOnRepaymentFrequency; // Derive the first repayment date as greater date among // (disbursement date + plus frequency) or // (disbursement date + minimum between disbursal and first // repayment ) if (repaymentPeriodFrequencyType.isDaily()) { dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusDays(repaymentEvery); } else if (repaymentPeriodFrequencyType.isWeekly()) { dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusWeeks(repaymentEvery); } else if (repaymentPeriodFrequencyType.isMonthly()) { dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusMonths(repaymentEvery); } /** yearly loan **/ else { dateBasedOnRepaymentFrequency = expectedDisbursementDate.plusYears(repaymentEvery); } derivedFirstRepayment = dateBasedOnRepaymentFrequency.isAfter( dateBasedOnMinimumDaysBetweenDisbursalAndFirstRepayment) ? dateBasedOnRepaymentFrequency : dateBasedOnMinimumDaysBetweenDisbursalAndFirstRepayment; } return derivedFirstRepayment; }
From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java
License:Apache License
private LocalDate deriveFirstRepaymentDateForLoans(final Integer repaymentEvery, final LocalDate expectedDisbursementDate, final LocalDate refernceDateForCalculatingFirstRepaymentDate, final PeriodFrequencyType repaymentPeriodFrequencyType, final Integer minimumDaysBetweenDisbursalAndFirstRepayment, final Calendar calendar) { boolean isMeetingSkipOnFirstDayOfMonth = configurationDomainService .isSkippingMeetingOnFirstDayOfMonthEnabled(); int numberOfDays = configurationDomainService.retreivePeroidInNumberOfDaysForSkipMeetingDate().intValue(); final String frequency = CalendarUtils .getMeetingFrequencyFromPeriodFrequencyType(repaymentPeriodFrequencyType); final LocalDate derivedFirstRepayment = CalendarUtils.getFirstRepaymentMeetingDate(calendar, refernceDateForCalculatingFirstRepaymentDate, repaymentEvery, frequency, isMeetingSkipOnFirstDayOfMonth, numberOfDays); final LocalDate minimumFirstRepaymentDate = expectedDisbursementDate .plusDays(minimumDaysBetweenDisbursalAndFirstRepayment); return minimumFirstRepaymentDate.isBefore(derivedFirstRepayment) ? derivedFirstRepayment : deriveFirstRepaymentDateForLoans(repaymentEvery, expectedDisbursementDate, derivedFirstRepayment, repaymentPeriodFrequencyType, minimumDaysBetweenDisbursalAndFirstRepayment, calendar); }