Example usage for org.joda.time LocalDate plusDays

List of usage examples for org.joda.time LocalDate plusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusDays.

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:com.gst.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Apache License

private void validateMinimumDaysBetweenDisbursalAndFirstRepayment(final LocalDate disbursalDate,
        final LocalDate firstRepaymentDate, final Integer minimumDaysBetweenDisbursalAndFirstRepayment) {

    final LocalDate minimumFirstRepaymentDate = disbursalDate
            .plusDays(minimumDaysBetweenDisbursalAndFirstRepayment);
    if (firstRepaymentDate.isBefore(minimumFirstRepaymentDate)) {
        throw new MinDaysBetweenDisbursalAndFirstRepaymentViolationException(disbursalDate, firstRepaymentDate,
                minimumDaysBetweenDisbursalAndFirstRepayment);
    }//w w w  .j a  va2 s.c  o  m
}

From source file:com.gst.portfolio.loanaccount.service.LoanWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

public LoanOverdueDTO applyChargeToOverdueLoanInstallment(final Long loanId, final Long loanChargeId,
        final Integer periodNumber, final JsonCommand command, Loan loan,
        final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds) {
    boolean runInterestRecalculation = false;
    final Charge chargeDefinition = this.chargeRepository.findOneWithNotFoundDetection(loanChargeId);

    Collection<Integer> frequencyNumbers = loanChargeReadPlatformService
            .retrieveOverdueInstallmentChargeFrequencyNumber(loanId, chargeDefinition.getId(), periodNumber);

    Integer feeFrequency = chargeDefinition.feeFrequency();
    final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator();
    Map<Integer, LocalDate> scheduleDates = new HashMap<>();
    final Long penaltyWaitPeriodValue = this.configurationDomainService.retrievePenaltyWaitPeriod();
    final Long penaltyPostingWaitPeriodValue = this.configurationDomainService
            .retrieveGraceOnPenaltyPostingPeriod();
    final LocalDate dueDate = command.localDateValueOfParameterNamed("dueDate");
    Long diff = penaltyWaitPeriodValue + 1 - penaltyPostingWaitPeriodValue;
    if (diff < 0) {
        diff = 0L;/*from w ww . j a v a2  s  . c  o  m*/
    }
    LocalDate startDate = dueDate.plusDays(penaltyWaitPeriodValue.intValue() + 1);
    Integer frequencyNunber = 1;
    if (feeFrequency == null) {
        scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue()));
    } else {
        while (DateUtils.getLocalDateOfTenant().isAfter(startDate)) {
            scheduleDates.put(frequencyNunber++, startDate.minusDays(diff.intValue()));
            LocalDate scheduleDate = scheduledDateGenerator.getRepaymentPeriodDate(
                    PeriodFrequencyType.fromInt(feeFrequency), chargeDefinition.feeInterval(), startDate, null,
                    null);

            startDate = scheduleDate;
        }
    }

    for (Integer frequency : frequencyNumbers) {
        scheduleDates.remove(frequency);
    }

    LoanRepaymentScheduleInstallment installment = null;
    LocalDate lastChargeAppliedDate = dueDate;
    if (!scheduleDates.isEmpty()) {
        if (loan == null) {
            loan = this.loanAssembler.assembleFrom(loanId);
            checkClientOrGroupActive(loan);
            existingTransactionIds.addAll(loan.findExistingTransactionIds());
            existingReversedTransactionIds.addAll(loan.findExistingReversedTransactionIds());
        }
        installment = loan.fetchRepaymentScheduleInstallment(periodNumber);
        lastChargeAppliedDate = installment.getDueDate();
    }
    LocalDate recalculateFrom = DateUtils.getLocalDateOfTenant();

    if (loan != null) {
        this.businessEventNotifierService.notifyBusinessEventToBeExecuted(
                BUSINESS_EVENTS.LOAN_APPLY_OVERDUE_CHARGE, constructEntityMap(BUSINESS_ENTITY.LOAN, loan));
        for (Map.Entry<Integer, LocalDate> entry : scheduleDates.entrySet()) {

            final LoanCharge loanCharge = LoanCharge.createNewFromJson(loan, chargeDefinition, command,
                    entry.getValue());

            LoanOverdueInstallmentCharge overdueInstallmentCharge = new LoanOverdueInstallmentCharge(loanCharge,
                    installment, entry.getKey());
            loanCharge.updateOverdueInstallmentCharge(overdueInstallmentCharge);

            boolean isAppliedOnBackDate = addCharge(loan, chargeDefinition, loanCharge);
            runInterestRecalculation = runInterestRecalculation || isAppliedOnBackDate;
            if (entry.getValue().isBefore(recalculateFrom)) {
                recalculateFrom = entry.getValue();
            }
            if (entry.getValue().isAfter(lastChargeAppliedDate)) {
                lastChargeAppliedDate = entry.getValue();
            }
        }
    }

    return new LoanOverdueDTO(loan, runInterestRecalculation, recalculateFrom, lastChargeAppliedDate);
}

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:// w w w .java2  s .  com
        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://from ww  w.ja v  a  2 s . c  o  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.interest.EndOfDayBalance.java

License:Apache License

/**
 * @param compoundingPeriodInterval/*from   ww  w. j  a  v  a 2 s .  c o m*/
 * @param upToInterestCalculationDate
 *            : For calculating maturity details in advance
 *            upToInterestCalculationDate will be maturity date else it will
 *            be DateUtils.getLocalDateOfTenant().
 * @return
 */
public EndOfDayBalance upTo(final LocalDateInterval compoundingPeriodInterval,
        final LocalDate upToInterestCalculationDate) {

    Money startingBalance = this.openingBalance;
    LocalDate balanceStartDate = this.date;

    LocalDate oldBalanceEndDate = this.date.plusDays(this.numberOfDays - 1);

    int daysOfBalance = this.numberOfDays;

    if (this.date.isBefore(compoundingPeriodInterval.startDate())) {
        balanceStartDate = compoundingPeriodInterval.startDate();
        startingBalance = this.endOfDayBalance;
        final LocalDateInterval balancePeriodInterval = LocalDateInterval.create(balanceStartDate,
                oldBalanceEndDate);
        daysOfBalance = balancePeriodInterval.daysInPeriodInclusiveOfEndDate();
    }

    LocalDate balanceEndDate = balanceStartDate.plusDays(daysOfBalance - 1);
    if (balanceEndDate.isAfter(compoundingPeriodInterval.endDate())) {
        balanceEndDate = compoundingPeriodInterval.endDate();
        final LocalDateInterval balancePeriodInterval = LocalDateInterval.create(balanceStartDate,
                balanceEndDate);
        daysOfBalance = balancePeriodInterval.daysInPeriodInclusiveOfEndDate();
    }
    if (balanceEndDate.isAfter(upToInterestCalculationDate)) {
        balanceEndDate = upToInterestCalculationDate;
        final LocalDateInterval balancePeriodInterval = LocalDateInterval.create(balanceStartDate,
                balanceEndDate);
        daysOfBalance = balancePeriodInterval.daysInPeriodInclusiveOfEndDate();
    }

    return new EndOfDayBalance(balanceStartDate, startingBalance, this.endOfDayBalance, daysOfBalance);
}

From source file:com.gst.portfolio.savings.domain.interest.PostingPeriod.java

License:Apache License

private static List<CompoundingPeriod> compoundingPeriodsInPostingPeriod(
        final LocalDateInterval postingPeriodInterval,
        final SavingsCompoundingInterestPeriodType interestPeriodType,
        final List<EndOfDayBalance> allEndOfDayBalances, final LocalDate upToInterestCalculationDate) {

    final List<CompoundingPeriod> compoundingPeriods = new ArrayList<>();

    CompoundingPeriod compoundingPeriod = null;
    switch (interestPeriodType) {
    case INVALID:
        break;/*from  w  w w .ja v a 2 s .  c  o  m*/
    case DAILY:
        compoundingPeriod = DailyCompoundingPeriod.create(postingPeriodInterval, allEndOfDayBalances,
                upToInterestCalculationDate);
        compoundingPeriods.add(compoundingPeriod);
        break;
    case MONTHLY:

        final LocalDate postingPeriodEndDate = postingPeriodInterval.endDate();

        LocalDate periodStartDate = postingPeriodInterval.startDate();
        LocalDate periodEndDate = periodStartDate;

        while (!periodStartDate.isAfter(postingPeriodEndDate) && !periodEndDate.isAfter(postingPeriodEndDate)) {

            periodEndDate = determineInterestPeriodEndDateFrom(periodStartDate, interestPeriodType,
                    upToInterestCalculationDate);
            if (periodEndDate.isAfter(postingPeriodEndDate)) {
                periodEndDate = postingPeriodEndDate;
            }

            final LocalDateInterval compoundingPeriodInterval = LocalDateInterval.create(periodStartDate,
                    periodEndDate);
            if (postingPeriodInterval.contains(compoundingPeriodInterval)) {

                compoundingPeriod = MonthlyCompoundingPeriod.create(compoundingPeriodInterval,
                        allEndOfDayBalances, upToInterestCalculationDate);
                compoundingPeriods.add(compoundingPeriod);
            }

            // move periodStartDate forward to day after this period
            periodStartDate = periodEndDate.plusDays(1);
        }
        break;
    // case WEEKLY:
    // break;
    // case BIWEEKLY:
    // break;
    case QUATERLY:
        final LocalDate qPostingPeriodEndDate = postingPeriodInterval.endDate();

        periodStartDate = postingPeriodInterval.startDate();
        periodEndDate = periodStartDate;

        while (!periodStartDate.isAfter(qPostingPeriodEndDate)
                && !periodEndDate.isAfter(qPostingPeriodEndDate)) {

            periodEndDate = determineInterestPeriodEndDateFrom(periodStartDate, interestPeriodType,
                    upToInterestCalculationDate);
            if (periodEndDate.isAfter(qPostingPeriodEndDate)) {
                periodEndDate = qPostingPeriodEndDate;
            }

            final LocalDateInterval compoundingPeriodInterval = LocalDateInterval.create(periodStartDate,
                    periodEndDate);
            if (postingPeriodInterval.contains(compoundingPeriodInterval)) {

                compoundingPeriod = QuarterlyCompoundingPeriod.create(compoundingPeriodInterval,
                        allEndOfDayBalances, upToInterestCalculationDate);
                compoundingPeriods.add(compoundingPeriod);
            }

            // move periodStartDate forward to day after this period
            periodStartDate = periodEndDate.plusDays(1);
        }
        break;
    case BI_ANNUAL:
        final LocalDate bPostingPeriodEndDate = postingPeriodInterval.endDate();

        periodStartDate = postingPeriodInterval.startDate();
        periodEndDate = periodStartDate;

        while (!periodStartDate.isAfter(bPostingPeriodEndDate)
                && !periodEndDate.isAfter(bPostingPeriodEndDate)) {

            periodEndDate = determineInterestPeriodEndDateFrom(periodStartDate, interestPeriodType,
                    upToInterestCalculationDate);
            if (periodEndDate.isAfter(bPostingPeriodEndDate)) {
                periodEndDate = bPostingPeriodEndDate;
            }

            final LocalDateInterval compoundingPeriodInterval = LocalDateInterval.create(periodStartDate,
                    periodEndDate);
            if (postingPeriodInterval.contains(compoundingPeriodInterval)) {

                compoundingPeriod = BiAnnualCompoundingPeriod.create(compoundingPeriodInterval,
                        allEndOfDayBalances, upToInterestCalculationDate);
                compoundingPeriods.add(compoundingPeriod);
            }

            // move periodStartDate forward to day after this period
            periodStartDate = periodEndDate.plusDays(1);
        }
        break;
    case ANNUAL:
        final LocalDate aPostingPeriodEndDate = postingPeriodInterval.endDate();

        periodStartDate = postingPeriodInterval.startDate();
        periodEndDate = periodStartDate;

        while (!periodStartDate.isAfter(aPostingPeriodEndDate)
                && !periodEndDate.isAfter(aPostingPeriodEndDate)) {

            periodEndDate = determineInterestPeriodEndDateFrom(periodStartDate, interestPeriodType,
                    upToInterestCalculationDate);
            if (periodEndDate.isAfter(aPostingPeriodEndDate)) {
                periodEndDate = aPostingPeriodEndDate;
            }

            final LocalDateInterval compoundingPeriodInterval = LocalDateInterval.create(periodStartDate,
                    periodEndDate);
            if (postingPeriodInterval.contains(compoundingPeriodInterval)) {

                compoundingPeriod = AnnualCompoundingPeriod.create(compoundingPeriodInterval,
                        allEndOfDayBalances, upToInterestCalculationDate);
                compoundingPeriods.add(compoundingPeriod);
            }

            // move periodStartDate forward to day after this period
            periodStartDate = periodEndDate.plusDays(1);
        }
        break;
    // case NO_COMPOUNDING_SIMPLE_INTEREST:
    // break;
    }

    return compoundingPeriods;
}

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   w  w w  .j  a v a 2  s  . c  om*/
    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;// w  w  w.ja  v a2 s.c  om
    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.SavingsHelper.java

License:Apache License

public List<LocalDateInterval> determineInterestPostingPeriods(
        final LocalDate startInterestCalculationLocalDate, final LocalDate interestPostingUpToDate,
        final SavingsPostingInterestPeriodType postingPeriodType, final Integer financialYearBeginningMonth,
        List<LocalDate> postInterestAsOn) {

    final List<LocalDateInterval> postingPeriods = new ArrayList<>();
    LocalDate periodStartDate = startInterestCalculationLocalDate;
    LocalDate periodEndDate = periodStartDate;
    LocalDate actualPeriodStartDate = periodStartDate;

    while (!periodStartDate.isAfter(interestPostingUpToDate)
            && !periodEndDate.isAfter(interestPostingUpToDate)) {

        final LocalDate interestPostingLocalDate = determineInterestPostingPeriodEndDateFrom(periodStartDate,
                postingPeriodType, interestPostingUpToDate, financialYearBeginningMonth);

        periodEndDate = interestPostingLocalDate.minusDays(1);

        if (!postInterestAsOn.isEmpty()) {
            for (LocalDate transactiondate : postInterestAsOn) {
                if (periodStartDate.isBefore(transactiondate)
                        && (periodEndDate.isAfter(transactiondate) || periodEndDate.isEqual(transactiondate))) {
                    periodEndDate = transactiondate.minusDays(1);
                    actualPeriodStartDate = periodEndDate;
                    break;
                }// w  w  w  .  j  a v  a  2 s  .  c  o  m
            }
        }

        postingPeriods.add(LocalDateInterval.create(periodStartDate, periodEndDate));

        if (actualPeriodStartDate.isEqual(periodEndDate)) {
            periodEndDate = actualPeriodStartDate.plusDays(1);
            periodStartDate = actualPeriodStartDate.plusDays(1);
        } else {
            periodEndDate = interestPostingLocalDate;
            periodStartDate = interestPostingLocalDate;
        }
    }

    return postingPeriods;
}

From source file:com.gst.portfolio.savings.domain.SavingsHelper.java

License:Apache License

private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate,
        final SavingsPostingInterestPeriodType interestPostingPeriodType,
        final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) {

    LocalDate periodEndDate = interestPostingUpToDate;
    final Integer monthOfYear = periodStartDate.getMonthOfYear();
    financialYearBeginningMonth--;/* w ww  . j a  va 2  s .co  m*/
    if (financialYearBeginningMonth == 0)
        financialYearBeginningMonth = 12;

    final ArrayList<LocalDate> quarterlyDates = new ArrayList<>();
    quarterlyDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(quarterlyDates);

    final ArrayList<LocalDate> biannualDates = new ArrayList<>();
    biannualDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(biannualDates);
    boolean isEndDateSet = false;

    switch (interestPostingPeriodType) {
    case INVALID:
        break;
    case MONTHLY:
        // produce period end date on last day of current month
        periodEndDate = periodStartDate.dayOfMonth().withMaximumValue();
        break;
    case QUATERLY:
        for (LocalDate quarterlyDate : quarterlyDates) {
            if (quarterlyDate.isAfter(periodStartDate)) {
                periodEndDate = quarterlyDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case BIANNUAL:
        for (LocalDate biannualDate : biannualDates) {
            if (biannualDate.isAfter(periodStartDate)) {
                periodEndDate = biannualDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case ANNUAL:
        if (financialYearBeginningMonth < monthOfYear) {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
            periodEndDate = periodEndDate.plusYears(1);
        } else {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
        }
        periodEndDate = periodEndDate.dayOfMonth().withMaximumValue();
        break;
    }
    // interest posting always occurs on next day after the period end date.
    periodEndDate = periodEndDate.plusDays(1);
    return periodEndDate;
}