List of usage examples for org.joda.time LocalDate plusYears
public LocalDate plusYears(int years)
From source file:cherry.foundation.bizcal.SimpleBizYearStrategy.java
License:Apache License
@Override public Range<LocalDate> rangeOfBizYear(int bizYear) { LocalDate firstDate = new LocalDate(bizYear + yearOfFirstOffset, monthOfFirst, dayOfFirst); LocalDate lastDate = firstDate.plusYears(1).minusDays(1); return between(firstDate, lastDate); }
From source file:com.axelor.apps.base.service.scheduler.SchedulerService.java
License:Open Source License
/** * Mthode qui dtermine la prochaine date d'xcution d'un planificateur pour un rythme annuel * * @param scheduler//from w w w. ja v a 2s . c om * Instance de planificateur * @param date * Derniere date d'xcution thorique * * @return LocalDate * Prochaine date d'xcution */ private LocalDate getAnnualComputeDate(Scheduler scheduler, LocalDate date) { int monthOfYear = 0; if (scheduler.getMonthAnnuallySelect().equals(IAdministration.JAN)) monthOfYear = DateTimeConstants.JANUARY; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.FEB)) monthOfYear = DateTimeConstants.FEBRUARY; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.MAR)) monthOfYear = DateTimeConstants.MARCH; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.APR)) monthOfYear = DateTimeConstants.APRIL; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.MAY)) monthOfYear = DateTimeConstants.MAY; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.JUN)) monthOfYear = DateTimeConstants.JUNE; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.JUL)) monthOfYear = DateTimeConstants.JULY; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.AUG)) monthOfYear = DateTimeConstants.AUGUST; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.SEP)) monthOfYear = DateTimeConstants.SEPTEMBER; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.OCT)) monthOfYear = DateTimeConstants.OCTOBER; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.NOV)) monthOfYear = DateTimeConstants.NOVEMBER; else if (scheduler.getMonthAnnuallySelect().equals(IAdministration.DEC)) monthOfYear = DateTimeConstants.DECEMBER; if (monthOfYear != 0) { int start = date.plusWeeks(scheduler.getWeekWeekly()).dayOfMonth().getMinimumValue(); int end = date.plusWeeks(scheduler.getWeekWeekly()).dayOfMonth().getMaximumValue(); if (start <= scheduler.getDayAnnually() && scheduler.getDayAnnually() <= end) return date.plusYears(scheduler.getYearAnnually()).withMonthOfYear(monthOfYear) .withDayOfMonth(scheduler.getDayAnnually()); else if (scheduler.getDayMonthly() < start) return date.plusYears(scheduler.getYearAnnually()).withMonthOfYear(monthOfYear).dayOfMonth() .withMinimumValue(); else if (scheduler.getDayMonthly() > end) return date.plusYears(scheduler.getYearAnnually()).withMonthOfYear(monthOfYear).dayOfMonth() .withMaximumValue(); } return null; }
From source file:com.gst.portfolio.account.service.StandingInstructionWritePlatformServiceImpl.java
License:Apache License
@Override @CronTarget(jobName = JobName.EXECUTE_STANDING_INSTRUCTIONS) public void executeStandingInstructions() throws JobExecutionException { Collection<StandingInstructionData> instructionDatas = this.standingInstructionReadPlatformService .retrieveAll(StandingInstructionStatus.ACTIVE.getValue()); final StringBuilder sb = new StringBuilder(); for (StandingInstructionData data : instructionDatas) { boolean isDueForTransfer = false; AccountTransferRecurrenceType recurrenceType = data.recurrenceType(); StandingInstructionType instructionType = data.instructionType(); LocalDate transactionDate = new LocalDate(); if (recurrenceType.isPeriodicRecurrence()) { final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator(); PeriodFrequencyType frequencyType = data.recurrenceFrequency(); LocalDate startDate = data.validFrom(); if (frequencyType.isMonthly()) { startDate = startDate.withDayOfMonth(data.recurrenceOnDay()); if (startDate.isBefore(data.validFrom())) { startDate = startDate.plusMonths(1); }//w w w .j a v a 2 s.c om } else if (frequencyType.isYearly()) { startDate = startDate.withDayOfMonth(data.recurrenceOnDay()) .withMonthOfYear(data.recurrenceOnMonth()); if (startDate.isBefore(data.validFrom())) { startDate = startDate.plusYears(1); } } isDueForTransfer = scheduledDateGenerator.isDateFallsInSchedule(frequencyType, data.recurrenceInterval(), startDate, transactionDate); } BigDecimal transactionAmount = data.amount(); if (data.toAccountType().isLoanAccount() && (recurrenceType.isDuesRecurrence() || (isDueForTransfer && instructionType.isDuesAmoutTransfer()))) { StandingInstructionDuesData standingInstructionDuesData = this.standingInstructionReadPlatformService .retriveLoanDuesData(data.toAccount().accountId()); if (data.instructionType().isDuesAmoutTransfer()) { transactionAmount = standingInstructionDuesData.totalDueAmount(); } if (recurrenceType.isDuesRecurrence()) { isDueForTransfer = new LocalDate().equals(standingInstructionDuesData.dueDate()); } } if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) { final SavingsAccount fromSavingsAccount = null; final boolean isRegularTransaction = true; final boolean isExceptionForBalanceCheck = false; AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount, data.fromAccountType(), data.toAccountType(), data.fromAccount().accountId(), data.toAccount().accountId(), data.name() + " Standing instruction trasfer ", null, null, null, null, data.toTransferType(), null, null, data.transferType().getValue(), null, null, null, null, null, fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck); final boolean transferCompleted = transferAmount(sb, accountTransferDTO, data.getId()); if (transferCompleted) { final String updateQuery = "UPDATE m_account_transfer_standing_instructions SET last_run_date = ? where id = ?"; this.jdbcTemplate.update(updateQuery, transactionDate.toDate(), data.getId()); } } } if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); } }
From source file:com.gst.portfolio.calendar.service.CalendarReadPlatformServiceImpl.java
License:Apache License
private LocalDate getPeriodEndDate(LocalDate endDate, LocalDate tillDate) { LocalDate periodEndDate = endDate; final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); if (tillDate != null) { if (endDate != null) { if (endDate.isAfter(tillDate)) { // to retrieve meeting dates tillspecified date (tillDate) periodEndDate = tillDate; }//from w w w .ja v a 2s .c o m } else { // end date is null then fetch meeting dates tillDate periodEndDate = tillDate; } } else if (endDate == null || endDate.isAfter(currentDate.plusYears(1))) { periodEndDate = currentDate.plusYears(1); } return periodEndDate; }
From source file:com.gst.portfolio.calendar.service.CalendarUtils.java
License:Apache License
public static LocalDate getRecentEligibleMeetingDate(final String recurringRule, final LocalDate seedDate, final boolean isSkipMeetingOnFirstDay, final Integer numberOfDays) { LocalDate currentDate = DateUtils.getLocalDateOfTenant(); final Recur recur = CalendarUtils.getICalRecur(recurringRule); if (recur == null) { return null; }// ww w . j ava 2s . c om if (isValidRecurringDate(recur, seedDate, currentDate, isSkipMeetingOnFirstDay, numberOfDays)) { return currentDate; } if (recur.getFrequency().equals(Recur.DAILY)) { currentDate = currentDate.plusDays(recur.getInterval()); } else if (recur.getFrequency().equals(Recur.WEEKLY)) { currentDate = currentDate.plusWeeks(recur.getInterval()); } else if (recur.getFrequency().equals(Recur.MONTHLY)) { currentDate = currentDate.plusMonths(recur.getInterval()); } else if (recur.getFrequency().equals(Recur.YEARLY)) { currentDate = currentDate.plusYears(recur.getInterval()); } return getNextRecurringDate(recur, seedDate, currentDate); }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private LocalDate getMaxDateLimitForNewRepayment(final PeriodFrequencyType periodFrequencyType, final Integer loanRepaymentInterval, final LocalDate startDate) { LocalDate dueRepaymentPeriodDate = startDate; final Integer repaidEvery = 2 * loanRepaymentInterval; switch (periodFrequencyType) { case DAYS:/*ww w. j av a 2 s . co m*/ dueRepaymentPeriodDate = startDate.plusDays(repaidEvery); break; case WEEKS: dueRepaymentPeriodDate = startDate.plusWeeks(repaidEvery); break; case MONTHS: dueRepaymentPeriodDate = startDate.plusMonths(repaidEvery); break; case YEARS: dueRepaymentPeriodDate = startDate.plusYears(repaidEvery); break; case INVALID: break; } return dueRepaymentPeriodDate.minusDays(1);// get 2n-1 range date from // startDate }
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 ww .ja va 2 s . 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.DefaultScheduledDateGenerator.java
License:Apache License
@Override public Boolean isDateFallsInSchedule(final PeriodFrequencyType frequency, final int repaidEvery, final LocalDate startDate, final LocalDate date) { boolean isScheduledDate = false; switch (frequency) { case DAYS:/*from w ww . j a v a 2 s . co m*/ int diff = Days.daysBetween(startDate, date).getDays(); isScheduledDate = (diff % repaidEvery) == 0; break; case WEEKS: int weekDiff = Weeks.weeksBetween(startDate, date).getWeeks(); isScheduledDate = (weekDiff % repaidEvery) == 0; if (isScheduledDate) { LocalDate modifiedDate = startDate.plusWeeks(weekDiff); isScheduledDate = modifiedDate.isEqual(date); } break; case MONTHS: int monthDiff = Months.monthsBetween(startDate, date).getMonths(); isScheduledDate = (monthDiff % repaidEvery) == 0; if (isScheduledDate) { LocalDate modifiedDate = startDate.plusMonths(monthDiff); isScheduledDate = modifiedDate.isEqual(date); } break; case YEARS: int yearDiff = Years.yearsBetween(startDate, date).getYears(); isScheduledDate = (yearDiff % repaidEvery) == 0; if (isScheduledDate) { LocalDate modifiedDate = startDate.plusYears(yearDiff); isScheduledDate = modifiedDate.isEqual(date); } break; case INVALID: break; } return isScheduledDate; }
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://from w ww . ja v a 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://from w w w . j av a 2 s . c o 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; }