List of usage examples for org.joda.time LocalDate plusMonths
public LocalDate plusMonths(int months)
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 w w .j a v 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; }
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; }/* w ww . ja v a 2 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 {/*w w w . j av a2s . 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.LoanScheduleTestDataHelper.java
License:Apache License
/** * Creates brand new three installment loan: * // w w w . jav a2s . co m * For example: with firstDueDate = 02 July 2011 * * Date Principal Interest Interest Waived * ================================== * ================================================ 02 July 2011 1,000 200 0 * 02 August 2011 1,000 200 0 02 September 2011 1,000 200 0 */ public static List<LoanRepaymentScheduleInstallment> createSimpleLoanSchedule(final LocalDate firstDueDate, final MonetaryCurrency currency) { final LoanRepaymentScheduleInstallment firstInstallment = new LoanRepaymentScheduleInstallmentBuilder( currency).withInstallmentNumber(1).withDueDate(firstDueDate).withPrincipal("1000.00") .withInterest("200.00").build(); final LoanRepaymentScheduleInstallment secondInstallment = new LoanRepaymentScheduleInstallmentBuilder( currency).withInstallmentNumber(2).withDueDate(firstDueDate.plusMonths(1)).withPrincipal("1000.00") .withInterest("200.00").build(); final LoanRepaymentScheduleInstallment thirdInstallment = new LoanRepaymentScheduleInstallmentBuilder( currency).withInstallmentNumber(3).withDueDate(firstDueDate.plusMonths(2)).withPrincipal("1000.00") .withInterest("200.00").build(); return Arrays.asList(firstInstallment, secondInstallment, thirdInstallment); }
From source file:com.gst.portfolio.loanaccount.LoanScheduleTestDataHelper.java
License:Apache License
/** * Creates three installment loan with first installment fully completed: * /* ww w . j ava 2 s. co m*/ * For example: with firstDueDate = 02 July 2011 * * Date Principal Interest Interest Waived Completed * ======================== * ================================================== * ====================================== 02 July 2011 1,000 200 0 true * (principal paid, interest paid) 02 August 2011 1,000 200 0 false 02 * September 2011 1,000 200 0 false */ public static List<LoanRepaymentScheduleInstallment> createSimpleLoanScheduleWithFirstInstallmentFullyPaid( final LocalDate firstDueDate, final MonetaryCurrency currency) { final LoanRepaymentScheduleInstallment firstInstallment = new LoanRepaymentScheduleInstallmentBuilder( currency).withInstallmentNumber(1).withDueDate(firstDueDate).withPrincipal("1000.00") .withInterest("200.00").completed().build(); final LoanRepaymentScheduleInstallment secondInstallment = new LoanRepaymentScheduleInstallmentBuilder( currency).withInstallmentNumber(2).withDueDate(firstDueDate.plusMonths(1)).withPrincipal("1000.00") .withInterest("200.00").build(); final LoanRepaymentScheduleInstallment thirdInstallment = new LoanRepaymentScheduleInstallmentBuilder( currency).withInstallmentNumber(3).withDueDate(firstDueDate.plusMonths(2)).withPrincipal("1000.00") .withInterest("200.00").build(); return Arrays.asList(firstInstallment, secondInstallment, thirdInstallment); }
From source file:com.gst.portfolio.savings.DepositAccountUtils.java
License:Apache License
public static LocalDate calculateNextDepositDate(final LocalDate lastDepositDate, final PeriodFrequencyType frequency, final int recurringEvery) { LocalDate nextDepositDate = lastDepositDate; switch (frequency) { case DAYS:/*from w ww .j a va 2 s . c om*/ nextDepositDate = lastDepositDate.plusDays(recurringEvery); break; case WEEKS: nextDepositDate = lastDepositDate.plusWeeks(recurringEvery); break; case MONTHS: nextDepositDate = lastDepositDate.plusMonths(recurringEvery); break; case YEARS: nextDepositDate = lastDepositDate.plusYears(recurringEvery); break; case INVALID: break; } return nextDepositDate; }
From source file:com.gst.portfolio.savings.domain.FixedDepositAccount.java
License:Apache License
public LocalDate calculateMaturityDate() { final LocalDate startDate = accountSubmittedOrActivationDate(); LocalDate maturityDate = null; final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod(); switch (this.accountTermAndPreClosure.depositPeriodFrequencyType()) { case DAYS:/* w w w .j a va 2s. co m*/ maturityDate = startDate.plusDays(depositPeriod); break; case WEEKS: maturityDate = startDate.plusWeeks(depositPeriod); break; case MONTHS: maturityDate = startDate.plusMonths(depositPeriod); break; case YEARS: maturityDate = startDate.plusYears(depositPeriod); break; case INVALID: break; } return maturityDate; }
From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java
License:Apache License
public LocalDate calculateMaturityDate() { final LocalDate startDate = depositStartDate(); LocalDate maturityDate = null; final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod(); if (depositPeriod == null) { return maturityDate; }//from ww w. j a v a 2s . c o m switch (this.accountTermAndPreClosure.depositPeriodFrequencyType()) { case DAYS: maturityDate = startDate.plusDays(depositPeriod); break; case WEEKS: maturityDate = startDate.plusWeeks(depositPeriod); break; case MONTHS: maturityDate = startDate.plusMonths(depositPeriod); break; case YEARS: maturityDate = startDate.plusYears(depositPeriod); break; case INVALID: break; } return maturityDate; }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
License:Apache License
private Date calculateDateAccountIsLockedUntil(final LocalDate activationLocalDate) { Date lockedInUntilLocalDate = null; final PeriodFrequencyType lockinPeriodFrequencyType = PeriodFrequencyType .fromInt(this.lockinPeriodFrequencyType); switch (lockinPeriodFrequencyType) { case INVALID: break;/*from w ww . jav a2s. com*/ case DAYS: lockedInUntilLocalDate = activationLocalDate.plusDays(this.lockinPeriodFrequency).toDate(); break; case WEEKS: lockedInUntilLocalDate = activationLocalDate.plusWeeks(this.lockinPeriodFrequency).toDate(); break; case MONTHS: lockedInUntilLocalDate = activationLocalDate.plusMonths(this.lockinPeriodFrequency).toDate(); break; case YEARS: lockedInUntilLocalDate = activationLocalDate.plusYears(this.lockinPeriodFrequency).toDate(); break; } return lockedInUntilLocalDate; }
From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java
License:Apache License
private LocalDate calculateNextDueDate(final LocalDate date) { LocalDate nextDueLocalDate = null; if (isAnnualFee()) { nextDueLocalDate = date.withMonthOfYear(this.feeOnMonth).plusYears(1); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); } else if (isMonthlyFee()) { nextDueLocalDate = date.plusMonths(this.feeInterval); nextDueLocalDate = setDayOfMonth(nextDueLocalDate); } else if (isWeeklyFee()) { nextDueLocalDate = date.plusWeeks(this.feeInterval); nextDueLocalDate = setDayOfWeek(nextDueLocalDate); }//from w w w . j a v a 2 s .c o m return nextDueLocalDate; }