Example usage for org.joda.time LocalDate isAfter

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

Introduction

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

Prototype

public boolean isAfter(ReadablePartial partial) 

Source Link

Document

Is this partial later than the specified partial.

Usage

From source file:org.apache.fineract.portfolio.savings.domain.interest.PostingPeriod.java

License:Apache License

public static PostingPeriod createFrom(final LocalDateInterval periodInterval,
        final Money periodStartingBalance, final List<SavingsAccountTransaction> orderedListOfTransactions,
        final MonetaryCurrency currency,
        final SavingsCompoundingInterestPeriodType interestCompoundingPeriodType,
        final SavingsInterestCalculationType interestCalculationType, final BigDecimal interestRateAsFraction,
        final long daysInYear, final LocalDate upToInterestCalculationDate,
        Collection<Long> interestPostTransactions, boolean isInterestTransfer,
        final Money minBalanceForInterestCalculation, final boolean isSavingsInterestPostingAtCurrentPeriodEnd,
        final BigDecimal overdraftInterestRateAsFraction, final Money minOverdraftForInterestCalculation) {

    final List<EndOfDayBalance> accountEndOfDayBalances = new ArrayList<>();
    boolean interestTransfered = false;
    Money openingDayBalance = periodStartingBalance;
    Money closeOfDayBalance = openingDayBalance;
    for (final SavingsAccountTransaction transaction : orderedListOfTransactions) {

        if (transaction.fallsWithin(periodInterval)) {
            // the balance of the transaction falls entirely within this
            // period so no need to do any cropping/bounding
            final EndOfDayBalance endOfDayBalance = transaction.toEndOfDayBalance(openingDayBalance);
            accountEndOfDayBalances.add(endOfDayBalance);

            openingDayBalance = endOfDayBalance.closingBalance();

        } else if (transaction.spansAnyPortionOf(periodInterval)) {
            final EndOfDayBalance endOfDayBalance = transaction.toEndOfDayBalanceBoundedBy(openingDayBalance,
                    periodInterval);// ww  w.j a v a  2 s .c o  m
            accountEndOfDayBalances.add(endOfDayBalance);

            closeOfDayBalance = endOfDayBalance.closingBalance();
            openingDayBalance = closeOfDayBalance;
        }

        // this check is to make sure to add interest if withdrawal is
        // happened for already
        if (transaction.occursOn(periodInterval.endDate().plusDays(1))) {
            if (transaction.getId() == null) {
                interestTransfered = isInterestTransfer;
            } else if (interestPostTransactions.contains(transaction.getId())) {
                interestTransfered = true;
            }
        }

    }

    if (accountEndOfDayBalances.isEmpty()) {
        LocalDate balanceStartDate = periodInterval.startDate();
        LocalDate balanceEndDate = periodInterval.endDate();
        Integer numberOfDaysOfBalance = periodInterval.daysInPeriodInclusiveOfEndDate();

        if (balanceEndDate.isAfter(upToInterestCalculationDate)) {
            balanceEndDate = upToInterestCalculationDate;
            final LocalDateInterval spanOfBalance = LocalDateInterval.create(balanceStartDate, balanceEndDate);
            numberOfDaysOfBalance = spanOfBalance.daysInPeriodInclusiveOfEndDate();
        }

        final EndOfDayBalance endOfDayBalance = EndOfDayBalance.from(balanceStartDate, openingDayBalance,
                closeOfDayBalance, numberOfDaysOfBalance);

        accountEndOfDayBalances.add(endOfDayBalance);

        closeOfDayBalance = endOfDayBalance.closingBalance();
        openingDayBalance = closeOfDayBalance;
    }

    final List<CompoundingPeriod> compoundingPeriods = compoundingPeriodsInPostingPeriod(periodInterval,
            interestCompoundingPeriodType, accountEndOfDayBalances, upToInterestCalculationDate);

    return new PostingPeriod(periodInterval, currency, periodStartingBalance, openingDayBalance,
            interestCompoundingPeriodType, interestCalculationType, interestRateAsFraction, daysInYear,
            compoundingPeriods, interestTransfered, minBalanceForInterestCalculation,
            isSavingsInterestPostingAtCurrentPeriodEnd, overdraftInterestRateAsFraction,
            minOverdraftForInterestCalculation);
}

From source file:org.apache.fineract.portfolio.savings.domain.RecurringDepositAccount.java

License:Apache License

public void postMaturityInterest(final boolean isSavingsInterestPostingAtCurrentPeriodEnd,
        final Integer financialYearBeginningMonth, final LocalDate closeDate) {
    LocalDate interestPostingUpToDate = maturityDate();
    if (interestPostingUpToDate == null) {
        interestPostingUpToDate = closeDate;
    }/*from  www.  j a  v  a2 s.  c o  m*/
    final MathContext mc = MathContext.DECIMAL64;
    boolean isInterestTransfer = false;
    final List<PostingPeriod> postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate.minusDays(1),
            isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);

    Money interestPostedToDate = Money.zero(this.currency);

    boolean recalucateDailyBalanceDetails = false;

    for (final PostingPeriod interestPostingPeriod : postingPeriods) {

        LocalDate interestPostingTransactionDate = interestPostingPeriod.dateOfPostingTransaction();
        interestPostingTransactionDate = interestPostingTransactionDate.isAfter(interestPostingUpToDate)
                ? interestPostingUpToDate
                : interestPostingTransactionDate;
        final Money interestEarnedToBePostedForPeriod = interestPostingPeriod.getInterestEarned();

        interestPostedToDate = interestPostedToDate.plus(interestEarnedToBePostedForPeriod);

        final SavingsAccountTransaction postingTransaction = findInterestPostingTransactionFor(
                interestPostingTransactionDate);
        if (postingTransaction == null) {
            final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction.interestPosting(
                    this, office(), interestPostingTransactionDate, interestEarnedToBePostedForPeriod);
            this.transactions.add(newPostingTransaction);
            recalucateDailyBalanceDetails = true;
        } else {
            final boolean correctionRequired = postingTransaction
                    .hasNotAmount(interestEarnedToBePostedForPeriod);
            if (correctionRequired) {
                postingTransaction.reverse();
                final SavingsAccountTransaction newPostingTransaction = SavingsAccountTransaction
                        .interestPosting(this, office(), interestPostingTransactionDate,
                                interestEarnedToBePostedForPeriod);
                this.transactions.add(newPostingTransaction);
                recalucateDailyBalanceDetails = true;
            }
        }
    }

    if (recalucateDailyBalanceDetails) {
        // update existing transactions so derived balance fields are
        // correct.
        recalculateDailyBalances(Money.zero(this.currency), interestPostingUpToDate);
    }

    this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions);
}

From source file:org.apache.fineract.portfolio.savings.domain.RecurringDepositAccount.java

License:Apache License

public void generateSchedule(final PeriodFrequencyType frequency, final Integer recurringEvery,
        final Calendar calendar) {
    final List<RecurringDepositScheduleInstallment> depositScheduleInstallments = depositScheduleInstallments();
    depositScheduleInstallments.clear();
    LocalDate installmentDate = null;
    if (this.isCalendarInherited()) {
        installmentDate = CalendarUtils.getNextScheduleDate(calendar, accountSubmittedOrActivationDate());
    } else {//  w w w .  j a  v  a  2s .c  om
        installmentDate = depositStartDate();
    }

    int installmentNumber = 1;
    final LocalDate maturityDate = calcualteScheduleTillDate(frequency, recurringEvery);
    final BigDecimal depositAmount = this.recurringDetail.mandatoryRecommendedDepositAmount();
    while (maturityDate.isAfter(installmentDate)) {
        final RecurringDepositScheduleInstallment installment = RecurringDepositScheduleInstallment
                .installment(this, installmentNumber, installmentDate.toDate(), depositAmount);
        depositScheduleInstallments.add(installment);
        installmentDate = DepositAccountUtils.calculateNextDepositDate(installmentDate, frequency,
                recurringEvery);
        installmentNumber += 1;
    }
}

From source file:org.apache.fineract.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public void postInterest(final MathContext mc, final LocalDate interestPostingUpToDate,
        final boolean isInterestTransfer, final boolean isSavingsInterestPostingAtCurrentPeriodEnd,
        final Integer financialYearBeginningMonth) {

    final List<PostingPeriod> postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate,
            isInterestTransfer, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);

    Money interestPostedToDate = Money.zero(this.currency);

    boolean recalucateDailyBalanceDetails = false;

    for (final PostingPeriod interestPostingPeriod : postingPeriods) {

        final LocalDate interestPostingTransactionDate = interestPostingPeriod.dateOfPostingTransaction();
        final Money interestEarnedToBePostedForPeriod = interestPostingPeriod.getInterestEarned();

        if (!interestPostingTransactionDate.isAfter(interestPostingUpToDate)) {

            interestPostedToDate = interestPostedToDate.plus(interestEarnedToBePostedForPeriod);

            final SavingsAccountTransaction postingTransaction = findInterestPostingTransactionFor(
                    interestPostingTransactionDate);
            if (postingTransaction == null) {
                SavingsAccountTransaction newPostingTransaction;
                if (interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency))) {
                    newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(),
                            interestPostingTransactionDate, interestEarnedToBePostedForPeriod);
                } else {
                    newPostingTransaction = SavingsAccountTransaction.overdraftInterest(this, office(),
                            interestPostingTransactionDate, interestEarnedToBePostedForPeriod.negated());
                }//from www  .  jav  a 2s  .co m
                this.transactions.add(newPostingTransaction);
                recalucateDailyBalanceDetails = true;
            } else {
                boolean correctionRequired = false;
                if (postingTransaction.isInterestPostingAndNotReversed()) {
                    correctionRequired = postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod);
                } else {
                    correctionRequired = postingTransaction
                            .hasNotAmount(interestEarnedToBePostedForPeriod.negated());
                }
                if (correctionRequired) {
                    postingTransaction.reverse();
                    SavingsAccountTransaction newPostingTransaction;
                    if (interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency))) {
                        newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(),
                                interestPostingTransactionDate, interestEarnedToBePostedForPeriod);
                    } else {
                        newPostingTransaction = SavingsAccountTransaction.overdraftInterest(this, office(),
                                interestPostingTransactionDate, interestEarnedToBePostedForPeriod.negated());
                    }
                    this.transactions.add(newPostingTransaction);
                    recalucateDailyBalanceDetails = true;
                }
            }
        }
    }

    if (recalucateDailyBalanceDetails) {
        // no openingBalance concept supported yet but probably will to
        // allow
        // for migrations.
        final Money openingAccountBalance = Money.zero(this.currency);

        // update existing transactions so derived balance fields are
        // correct.
        recalculateDailyBalances(openingAccountBalance, interestPostingUpToDate);
    }

    this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions);
}

From source file:org.apache.fineract.portfolio.savings.domain.SavingsAccountTransaction.java

License:Apache License

public EndOfDayBalance toEndOfDayBalanceBoundedBy(final Money openingBalance,
        final LocalDateInterval boundedBy) {

    final MonetaryCurrency currency = openingBalance.getCurrency();
    Money endOfDayBalance = openingBalance.copy();

    int numberOfDaysOfBalance = this.balanceNumberOfDays;

    LocalDate balanceStartDate = getTransactionLocalDate();
    LocalDate balanceEndDate = getEndOfBalanceLocalDate();

    if (boundedBy.startDate().isAfter(balanceStartDate)) {
        balanceStartDate = boundedBy.startDate();
        final LocalDateInterval spanOfBalance = LocalDateInterval.create(balanceStartDate, balanceEndDate);
        numberOfDaysOfBalance = spanOfBalance.daysInPeriodInclusiveOfEndDate();
    } else {/*from  w  ww  .  ja  v a 2s .c  o m*/
        if (isDeposit()) {
            // endOfDayBalance = openingBalance.plus(getAmount(currency));
            // if (endOfDayBalance.isLessThanZero()) {
            endOfDayBalance = endOfDayBalance.plus(getAmount(currency));
            // }
        } else if (isWithdrawal() || isChargeTransactionAndNotReversed()) {
            // endOfDayBalance = openingBalance.minus(getAmount(currency));
            if (endOfDayBalance.isGreaterThanZero()) {
                endOfDayBalance = endOfDayBalance.minus(getAmount(currency));
            } else {
                endOfDayBalance = Money.of(currency, this.runningBalance);
            }
        }
    }

    if (balanceEndDate.isAfter(boundedBy.endDate())) {
        balanceEndDate = boundedBy.endDate();
        final LocalDateInterval spanOfBalance = LocalDateInterval.create(balanceStartDate, balanceEndDate);
        numberOfDaysOfBalance = spanOfBalance.daysInPeriodInclusiveOfEndDate();
    }

    return EndOfDayBalance.from(balanceStartDate, openingBalance, endOfDayBalance, numberOfDaysOfBalance);
}

From source file:org.apache.fineract.portfolio.savings.domain.SavingsHelper.java

License:Apache License

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

    final List<LocalDateInterval> postingPeriods = new ArrayList<>();

    LocalDate periodStartDate = startInterestCalculationLocalDate;
    LocalDate periodEndDate = periodStartDate;

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

        final LocalDate interestPostingLocalDate = determineInterestPostingPeriodEndDateFrom(periodStartDate,
                postingPeriodType, interestPostingUpToDate, financialYearBeginningMonth);
        periodEndDate = interestPostingLocalDate.minusDays(1);

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

        periodEndDate = interestPostingLocalDate;
        periodStartDate = interestPostingLocalDate;
    }//from ww w  .  j  a  va 2  s .co  m

    return postingPeriods;
}

From source file:org.apache.fineract.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--;//ww  w.j a  v a2  s  .  c  o 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;
}

From source file:org.apache.fineract.portfolio.savings.service.SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private void validateSubmittedOnDate(final SavingsAccount savingsAccount) {
    final LocalDate startDate = savingsAccount.savingsProduct().getStartDate();
    final LocalDate closeDate = savingsAccount.savingsProduct().getCloseDate();
    final LocalDate submittedOnDate = savingsAccount.getSubmittedOnDate();

    String defaultUserMessage = "";
    if (startDate != null && submittedOnDate.isBefore(startDate)) {
        defaultUserMessage = "submittedOnDate cannot be before the savings product startDate.";
        throw new SavingsApplicationDateException(
                "submitted.on.date.cannot.be.before.the.savings.product.start.date", defaultUserMessage,
                submittedOnDate.toString(), startDate.toString());
    }/*  ww  w  .ja  v a 2 s  . c  o m*/

    if (closeDate != null && submittedOnDate.isAfter(closeDate)) {
        defaultUserMessage = "submittedOnDate cannot be after the savings product closeDate.";
        throw new SavingsApplicationDateException(
                "submitted.on.date.cannot.be.after.the.savings.product.close.date", defaultUserMessage,
                submittedOnDate.toString(), closeDate.toString());
    }
}

From source file:org.datacleaner.beans.DateAndTimeAnalyzerColumnDelegate.java

License:Open Source License

public synchronized void run(final Date value, final InputRow row, final int distinctCount) {
    _numRows += distinctCount;//from w  w  w  .  j  a v a  2s. co m
    if (value == null) {
        _annotationFactory.annotate(row, distinctCount, _nullAnnotation);
    } else {
        final long timestamp = value.getTime();

        for (int i = 0; i < distinctCount; i++) {
            if (_statistics instanceof DescriptiveStatistics) {
                ((DescriptiveStatistics) _statistics).addValue(timestamp);
            } else {
                ((SummaryStatistics) _statistics).addValue(timestamp);
            }
        }

        LocalDate localDate = new LocalDate(value);
        LocalTime localTime = new LocalTime(value);
        if (_minDate == null) {
            // first non-null value
            _minDate = localDate;
            _maxDate = localDate;
            _minTime = localTime;
            _maxTime = localTime;
        } else {
            if (localDate.isAfter(_maxDate)) {
                _maxDate = localDate;
                _annotationFactory.resetAnnotation(_maxDateAnnotation);
            } else if (localDate.isBefore(_minDate)) {
                _minDate = localDate;
                _annotationFactory.resetAnnotation(_minDateAnnotation);
            }

            if (localTime.isAfter(_maxTime)) {
                _maxTime = localTime;
                _annotationFactory.resetAnnotation(_maxTimeAnnotation);
            } else if (localTime.isBefore(_minTime)) {
                _minTime = localTime;
                _annotationFactory.resetAnnotation(_minTimeAnnotation);
            }
        }

        if (localDate.isEqual(_maxDate)) {
            _annotationFactory.annotate(row, distinctCount, _maxDateAnnotation);
        }
        if (localDate.isEqual(_minDate)) {
            _annotationFactory.annotate(row, distinctCount, _minDateAnnotation);
        }

        if (localTime.isEqual(_maxTime)) {
            _annotationFactory.annotate(row, distinctCount, _maxTimeAnnotation);
        }
        if (localTime.isEqual(_minTime)) {
            _annotationFactory.annotate(row, distinctCount, _minTimeAnnotation);
        }
    }
}

From source file:org.devmaster.elasticsearch.index.mapper.Recurring.java

License:Apache License

public boolean hasOccurrencesAt(final LocalDate date) throws ParseException {
    if (this.rrule != null) {
        LocalDate end = date.plusDays(1);
        LocalDateIterator it = LocalDateIteratorFactory.createLocalDateIterator(rrule,
                new LocalDate(this.startDate), false);
        it.advanceTo(date);/*from   ww w  .j  a  v a2  s.  c om*/
        return it.hasNext() && it.next().isBefore(end);
    } else if (this.endDate != null) {
        LocalDate start = new LocalDate(this.startDate);
        LocalDate end = new LocalDate(this.endDate);
        return !date.isBefore(start) && !date.isAfter(end);
    } else {
        return new LocalDate(this.startDate).isEqual(date);
    }
}