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:com.gst.portfolio.savings.domain.SavingsAccount.java

License:Apache License

public void validateNewApplicationState(final LocalDate todayDateOfTenant, final String resourceName) {

    // validateWithdrawalFeeDetails();
    // validateAnnualFeeDetails();

    final LocalDate submittedOn = getSubmittedOnLocalDate();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(resourceName + SavingsApiConstants.summitalAction);

    validateLockinDetails(baseDataValidator);
    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }/*from w  w w  . j  av a 2s . c  om*/

    if (submittedOn.isAfter(todayDateOfTenant)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.submittedOnDateParamName).value(submittedOn)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");
    }

    if (this.client != null && this.client.isActivatedAfter(submittedOn)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.submittedOnDateParamName)
                .value(this.client.getActivationLocalDate())
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.client.activation.date");
    } else if (this.group != null && this.group.isActivatedAfter(submittedOn)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.submittedOnDateParamName)
                .value(this.group.getActivationLocalDate())
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.client.activation.date");
    }

    if (!dataValidationErrors.isEmpty()) {
        throw new PlatformApiDataValidationException(dataValidationErrors);
    }
}

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

License:Apache License

public Map<String, Object> approveApplication(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.approvalAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//from ww w  . ja  va2 s .  c  om
    }

    this.status = SavingsAccountStatusType.APPROVED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    // only do below if status has changed in the 'approval' case
    final LocalDate approvedOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName);
    final String approvedOnDateChange = command
            .stringValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName);

    this.approvedOnDate = approvedOn.toDate();
    this.approvedBy = currentUser;
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.approvedOnDateParamName, approvedOnDateChange);

    final LocalDate submittalDate = getSubmittedOnLocalDate();
    if (approvedOn.isBefore(submittalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (approvedOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_APPROVED, approvedOn);

    // FIXME - kw - support field officer history for savings accounts
    // if (this.fieldOfficer != null) {
    // final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory =
    // LoanOfficerAssignmentHistory.createNew(this,
    // this.fieldOfficer, approvedOn);
    // this.loanOfficerHistory.add(loanOfficerAssignmentHistory);
    // }
    if (this.savingsOfficer != null) {
        final SavingsOfficerAssignmentHistory savingsOfficerAssignmentHistory = SavingsOfficerAssignmentHistory
                .createNew(this, this.savingsOfficer, approvedOn);
        this.savingsOfficerHistory.add(savingsOfficerAssignmentHistory);
    }
    return actualChanges;
}

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

License:Apache License

public Map<String, Object> rejectApplication(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.rejectAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/* w w w.j  a  v a2 s  . c om*/
    }

    this.status = SavingsAccountStatusType.REJECTED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    final LocalDate rejectedOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName);
    final String rejectedOnAsString = command
            .stringValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName);

    this.rejectedOnDate = rejectedOn.toDate();
    this.rejectedBy = currentUser;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = rejectedOn.toDate();
    this.closedBy = currentUser;

    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.rejectedOnDateParamName, rejectedOnAsString);
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, rejectedOnAsString);

    final LocalDate submittalDate = getSubmittedOnLocalDate();

    if (rejectedOn.isBefore(submittalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (rejectedOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName).value(rejectedOn)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_REJECTED, rejectedOn);

    return actualChanges;
}

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

License:Apache License

public Map<String, Object> applicantWithdrawsFromApplication(final AppUser currentUser,
        final JsonCommand command, final LocalDate tenantsTodayDate) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.withdrawnByApplicantAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*w w w  .  j ava 2 s. com*/
    }

    this.status = SavingsAccountStatusType.WITHDRAWN_BY_APPLICANT.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));

    final LocalDate withdrawnOn = command
            .localDateValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName);
    final String withdrawnOnAsString = command
            .stringValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName);

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = withdrawnOn.toDate();
    this.withdrawnBy = currentUser;
    this.closedOnDate = withdrawnOn.toDate();
    this.closedBy = currentUser;

    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.withdrawnOnDateParamName, withdrawnOnAsString);
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, withdrawnOnAsString);

    final LocalDate submittalDate = getSubmittedOnLocalDate();
    if (withdrawnOn.isBefore(submittalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String submittalDateAsString = formatter.print(submittalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName)
                .value(submittalDateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (withdrawnOn.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName).value(withdrawnOn)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_WITHDRAWAL_BY_CUSTOMER,
            withdrawnOn);

    return actualChanges;
}

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

License:Apache License

public Map<String, Object> activate(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(depositAccountType().resourceName() + SavingsApiConstants.activateAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.APPROVED.hasStateOf(currentStatus)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName)
                .failWithCodeNoParameterAddedToErrorCode("not.in.approved.state");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }/*  w w w.  j  av a  2s  .  c  o  m*/
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate activationDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.activatedOnDateParamName);

    this.status = SavingsAccountStatusType.ACTIVE.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.activatedOnDateParamName, activationDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = null;
    this.closedBy = null;
    this.activatedOnDate = activationDate.toDate();
    this.activatedBy = currentUser;
    this.lockedInUntilDate = calculateDateAccountIsLockedUntil(getActivationLocalDate());

    /*
     * if (annualFeeSettingsSet()) {
     * updateToNextAnnualFeeDueDateFrom(getActivationLocalDate()); }
     */
    if (this.client != null && this.client.isActivatedAfter(activationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(this.client.getActivationLocalDate());
        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.client.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (this.group != null && this.group.isActivatedAfter(activationDate)) {
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(this.client.getActivationLocalDate());
        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.group.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    final LocalDate approvalDate = getApprovedOnLocalDate();
    if (activationDate.isBefore(approvalDate)) {

        final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat())
                .withLocale(command.extractLocale());
        final String dateAsString = formatter.print(approvalDate);

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approval.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }

    if (activationDate.isAfter(tenantsTodayDate)) {

        baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(activationDate)
                .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date");

        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_ACTIVATE, activationDate);

    return actualChanges;
}

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

License:Apache License

public Map<String, Object> close(final AppUser currentUser, final JsonCommand command,
        final LocalDate tenantsTodayDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>();

    final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
    final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
            .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.closeAction);

    final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status);
    if (!SavingsAccountStatusType.ACTIVE.hasStateOf(currentStatus)) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("not.in.active.state");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }//  w  w  w.jav  a2  s.  com
    }

    final Locale locale = command.extractLocale();
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
    final LocalDate closedDate = command
            .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName);

    if (closedDate.isBefore(getActivationLocalDate())) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("must.be.after.activation.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    if (closedDate.isAfter(tenantsTodayDate)) {
        baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                .failWithCode("cannot.be.a.future.date");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    final List<SavingsAccountTransaction> savingsAccountTransactions = retreiveListOfTransactions();
    if (savingsAccountTransactions.size() > 0) {
        final SavingsAccountTransaction accountTransaction = savingsAccountTransactions
                .get(savingsAccountTransactions.size() - 1);
        if (accountTransaction.isAfter(closedDate)) {
            baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate)
                    .failWithCode("must.be.after.last.transaction.date");
            if (!dataValidationErrors.isEmpty()) {
                throw new PlatformApiDataValidationException(dataValidationErrors);
            }
        }
    }
    if (getAccountBalance().doubleValue() != 0) {
        baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("results.in.balance.not.zero");
        if (!dataValidationErrors.isEmpty()) {
            throw new PlatformApiDataValidationException(dataValidationErrors);
        }
    }
    validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_CLOSE_ACCOUNT, closedDate);
    this.status = SavingsAccountStatusType.CLOSED.getValue();
    actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status));
    actualChanges.put(SavingsApiConstants.localeParamName, command.locale());
    actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat());
    actualChanges.put(SavingsApiConstants.closedOnDateParamName, closedDate.toString(fmt));

    this.rejectedOnDate = null;
    this.rejectedBy = null;
    this.withdrawnOnDate = null;
    this.withdrawnBy = null;
    this.closedOnDate = closedDate.toDate();
    this.closedBy = currentUser;

    return actualChanges;
}

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

License:Apache License

public LocalDate getNextDueDateFrom(final LocalDate startingDate) {
    LocalDate nextDueLocalDate = null;
    if (isAnnualFee() || isMonthlyFee()) {
        nextDueLocalDate = startingDate.withMonthOfYear(this.feeOnMonth);
        nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
        while (startingDate.isAfter(nextDueLocalDate)) {
            nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
        }//  w ww  .j  a va  2s. c  o  m
    } else if (isWeeklyFee()) {
        nextDueLocalDate = getDueLocalDate();
        while (startingDate.isAfter(nextDueLocalDate)) {
            nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
        }
    } else {
        nextDueLocalDate = calculateNextDueDate(startingDate);
    }
    return nextDueLocalDate;
}

From source file:com.gst.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  w  w. j  av a2  s  .co m
        if (isDeposit() || isDividendPayoutAndNotReversed()) {
            // 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: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;
                }//from w  w w  . java  2 s  .co  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--;//  ww  w . j a v  a2  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;
}