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.loanaccount.domain.Loan.java

License:Apache License

public void applyHolidayToRepaymentScheduleDates(final Holiday holiday) {
    // first repayment's from date is same as disbursement date.
    LocalDate tmpFromDate = getDisbursementDate();
    // Loop through all loanRepayments
    List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
    for (final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : installments) {
        final LocalDate oldDueDate = loanRepaymentScheduleInstallment.getDueDate();

        // update from date if it's not same as previous installament's due
        // date.//from  w  ww.j a  v a 2s .  c o  m
        if (!loanRepaymentScheduleInstallment.getFromDate().isEqual(tmpFromDate)) {
            loanRepaymentScheduleInstallment.updateFromDate(tmpFromDate);
        }
        if (oldDueDate.isAfter(holiday.getToDateLocalDate())) {
            break;
        }

        if (oldDueDate.equals(holiday.getFromDateLocalDate()) || oldDueDate.equals(holiday.getToDateLocalDate())
                || oldDueDate.isAfter(holiday.getFromDateLocalDate())
                        && oldDueDate.isBefore(holiday.getToDateLocalDate())) {
            // FIXME: AA do we need to apply non-working days.
            // Assuming holiday's repayment reschedule to date cannot be
            // created on a non-working day.
            final LocalDate newRepaymentDate = holiday.getRepaymentsRescheduledToLocalDate();
            loanRepaymentScheduleInstallment.updateDueDate(newRepaymentDate);
        }
        tmpFromDate = loanRepaymentScheduleInstallment.getDueDate();
    }
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private void validateActivityNotBeforeLastTransactionDate(final LoanEvent event, final LocalDate activityDate) {
    if (!(this.repaymentScheduleDetail().isInterestRecalculationEnabled()
            || this.loanProduct().isHoldGuaranteeFundsEnabled())) {
        return;/*from   w  w w.  ja va 2s  . c o  m*/
    }
    LocalDate lastTransactionDate = getLastUserTransactionDate();
    final LocalDate clientOfficeJoiningDate = this.client.getOfficeJoiningLocalDate();
    if (lastTransactionDate.isAfter(activityDate)) {
        String errorMessage = null;
        String action = null;
        String postfix = null;
        switch (event) {
        case LOAN_REPAYMENT_OR_WAIVER:
            errorMessage = "The date on which a repayment or waiver is made cannot be earlier than last transaction date";
            action = "repayment.or.waiver";
            postfix = "cannot.be.made.before.last.transaction.date";
            break;
        case WRITE_OFF_OUTSTANDING:
            errorMessage = "The date on which a write off is made cannot be earlier than last transaction date";
            action = "writeoff";
            postfix = "cannot.be.made.before.last.transaction.date";
            break;
        case LOAN_CHARGE_PAYMENT:
            errorMessage = "The date on which a charge payment is made cannot be earlier than last transaction date";
            action = "charge.payment";
            postfix = "cannot.be.made.before.last.transaction.date";
            break;
        default:
            break;
        }
        throw new InvalidLoanStateTransitionException(action, postfix, errorMessage, clientOfficeJoiningDate);
    }
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

public void regenerateRepaymentScheduleWithInterestRecalculation(final ScheduleGeneratorDTO generatorDTO,
        final AppUser currentUser) {

    LocalDate lastTransactionDate = getLastUserTransactionDate();
    final LoanScheduleDTO loanSchedule = getRecalculatedSchedule(generatorDTO);
    if (loanSchedule == null) {
        return;//from ww  w. j a  v  a2 s.  c  o  m
    }
    updateLoanSchedule(loanSchedule.getInstallments(), currentUser);
    this.interestRecalculatedOn = DateUtils.getDateOfTenant();
    LocalDate lastRepaymentDate = this.getLastRepaymentPeriodDueDate(true);
    Set<LoanCharge> charges = this.charges();
    for (LoanCharge loanCharge : charges) {
        if (!loanCharge.isDueAtDisbursement()) {
            updateOverdueScheduleInstallment(loanCharge);
            if (loanCharge.getDueLocalDate() == null
                    || (!lastRepaymentDate.isBefore(loanCharge.getDueLocalDate()))) {
                if (!loanCharge.isWaived() && (loanCharge.getDueLocalDate() == null
                        || !lastTransactionDate.isAfter(loanCharge.getDueLocalDate()))) {
                    recalculateLoanCharge(loanCharge, generatorDTO.getPenaltyWaitPeriod());
                    loanCharge.updateWaivedAmount(getCurrency());
                }
            } else {
                loanCharge.setActive(false);
            }
        }
    }

    processPostDisbursementTransactions();
    processIncomeTransactions(currentUser);
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private ChangedTransactionDetail handleRefundTransaction(final LoanTransaction loanTransaction,
        final LoanLifecycleStateMachine loanLifecycleStateMachine, final LoanTransaction adjustedTransaction) {

    ChangedTransactionDetail changedTransactionDetail = null;

    final LoanStatus statusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_REFUND,
            LoanStatus.fromInt(this.loanStatus));
    this.loanStatus = statusEnum.getValue();

    loanTransaction.updateLoan(this);

    // final boolean isTransactionChronologicallyLatest =
    // isChronologicallyLatestRefund(loanTransaction,
    // this.loanTransactions);

    if (status().isOverpaid() || status().isClosed()) {

        final String errorMessage = "This refund option is only for active loans ";
        throw new InvalidLoanStateTransitionException("transaction", "is.exceeding.overpaid.amount",
                errorMessage, this.totalOverpaid, loanTransaction.getAmount(getCurrency()).getAmount());

    } else if (this.getTotalPaidInRepayments().isZero()) {
        final String errorMessage = "Cannot refund when no payment has been made";
        throw new InvalidLoanStateTransitionException("transaction", "no.payment.yet.made.for.loan",
                errorMessage);/*  w  ww  . j a v a2s .  c  om*/
    }

    if (loanTransaction.isNotZero(loanCurrency())) {
        addLoanTransaction(loanTransaction);
    }

    if (loanTransaction.isNotRefundForActiveLoan()) {
        final String errorMessage = "A transaction of type refund was expected but not received.";
        throw new InvalidLoanTransactionTypeException("transaction", "is.not.a.refund.transaction",
                errorMessage);
    }

    final LocalDate loanTransactionDate = loanTransaction.getTransactionDate();
    if (loanTransactionDate.isBefore(getDisbursementDate())) {
        final String errorMessage = "The transaction date cannot be before the loan disbursement date: "
                + getApprovedOnDate().toString();
        throw new InvalidLoanStateTransitionException("transaction", "cannot.be.before.disbursement.date",
                errorMessage, loanTransactionDate, getDisbursementDate());
    }

    if (loanTransactionDate.isAfter(DateUtils.getLocalDateOfTenant())) {
        final String errorMessage = "The transaction date cannot be in the future.";
        throw new InvalidLoanStateTransitionException("transaction", "cannot.be.a.future.date", errorMessage,
                loanTransactionDate);
    }

    if (this.loanProduct.isMultiDisburseLoan() && adjustedTransaction == null) {
        BigDecimal totalDisbursed = getDisbursedAmount();
        if (totalDisbursed.compareTo(this.summary.getTotalPrincipalRepaid()) < 0) {
            final String errorMessage = "The transaction cannot be done before the loan disbursement: "
                    + getApprovedOnDate().toString();
            throw new InvalidLoanStateTransitionException("transaction", "cannot.be.done.before.disbursement",
                    errorMessage);
        }
    }

    final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
            .determineProcessor(this.transactionProcessingStrategy);

    // If is a refund
    if (adjustedTransaction == null) {
        loanRepaymentScheduleTransactionProcessor.handleRefund(loanTransaction, getCurrency(),
                getRepaymentScheduleInstallments(), charges());
    } else {
        final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
        changedTransactionDetail = loanRepaymentScheduleTransactionProcessor.handleTransaction(
                getDisbursementDate(), allNonContraTransactionsPostDisbursement, getCurrency(),
                getRepaymentScheduleInstallments(), charges());
        for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail
                .getNewTransactionMappings().entrySet()) {
            mapEntry.getValue().updateLoan(this);
        }

    }

    updateLoanSummaryDerivedFields();

    doPostLoanTransactionChecks(loanTransaction.getTransactionDate(), loanLifecycleStateMachine);

    return changedTransactionDetail;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

public Money retrieveAccruedAmountAfterDate(final LocalDate tillDate) {
    Money totalAmountAccrued = Money.zero(getCurrency());
    Money actualAmountTobeAccrued = Money.zero(getCurrency());
    for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
        totalAmountAccrued = totalAmountAccrued.plus(installment.getInterestAccrued(getCurrency()));

        if (tillDate.isAfter(installment.getFromDate()) && tillDate.isBefore(installment.getDueDate())) {
            int daysInPeriod = Days.daysBetween(installment.getFromDate(), installment.getDueDate()).getDays();
            int tillDays = Days.daysBetween(installment.getFromDate(), tillDate).getDays();
            double interest = calculateInterestForDays(daysInPeriod,
                    installment.getInterestCharged(getCurrency()).getAmount(), tillDays);
            actualAmountTobeAccrued = actualAmountTobeAccrued.plus(interest);
        } else if ((tillDate.isAfter(installment.getFromDate()) && tillDate.isEqual(installment.getDueDate()))
                || (tillDate.isEqual(installment.getFromDate()) && tillDate.isEqual(installment.getDueDate()))
                || (tillDate.isAfter(installment.getFromDate())
                        && tillDate.isAfter(installment.getDueDate()))) {
            actualAmountTobeAccrued = actualAmountTobeAccrued
                    .plus(installment.getInterestAccrued(getCurrency()));
        }//w w w .j  a  va  2  s  . c  om
    }
    Money accredAmountAfterDate = totalAmountAccrued.minus(actualAmountTobeAccrued);
    if (accredAmountAfterDate.isLessThanZero()) {
        accredAmountAfterDate = Money.zero(getCurrency());
    }
    return accredAmountAfterDate;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

public void validateForForeclosure(final LocalDate transactionDate) {

    if (isInterestRecalculationEnabledForProduct()) {
        final String defaultUserMessage = "The loan with interest recalculation enabled cannot be foreclosed.";
        throw new LoanForeclosureException("loan.with.interest.recalculation.enabled.cannot.be.foreclosured",
                defaultUserMessage, getId());
    }/*w w  w. j ava  2s  . c  o  m*/

    LocalDate lastUserTransactionDate = getLastUserTransactionDate();

    if (DateUtils.isDateInTheFuture(transactionDate)) {
        final String defaultUserMessage = "The transactionDate cannot be in the future.";
        throw new LoanForeclosureException("loan.foreclosure.transaction.date.is.in.future", defaultUserMessage,
                transactionDate);
    }

    if (lastUserTransactionDate.isAfter(transactionDate)) {
        final String defaultUserMessage = "The transactionDate cannot be in the future.";
        throw new LoanForeclosureException(
                "loan.foreclosure.transaction.date.cannot.before.the.last.transaction.date", defaultUserMessage,
                transactionDate);
    }
}

From source file:com.gst.portfolio.loanaccount.domain.LoanAccountDomainServiceJpa.java

License:Apache License

private void generateLoanScheduleAccrualData(final LocalDate accruedTill,
        final Collection<LoanScheduleAccrualData> loanScheduleAccrualDatas, final Long loanId, Long officeId,
        final LocalDate accrualStartDate, final PeriodFrequencyType repaymentFrequency,
        final Integer repayEvery, final LocalDate interestCalculatedFrom, final Long loanProductId,
        final MonetaryCurrency currency, final CurrencyData currencyData, final Set<LoanCharge> loanCharges,
        final LoanRepaymentScheduleInstallment installment) {

    if (!accruedTill.isBefore(installment.getDueDate()) || (accruedTill.isAfter(installment.getFromDate())
            && !accruedTill.isAfter(installment.getDueDate()))) {
        BigDecimal dueDateFeeIncome = BigDecimal.ZERO;
        BigDecimal dueDatePenaltyIncome = BigDecimal.ZERO;
        LocalDate chargesTillDate = installment.getDueDate();
        if (!accruedTill.isAfter(installment.getDueDate())) {
            chargesTillDate = accruedTill;
        }//w  ww. j  a va  2  s  .  c  o m

        for (final LoanCharge loanCharge : loanCharges) {
            if (loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(),
                    chargesTillDate)) {
                if (loanCharge.isFeeCharge()) {
                    dueDateFeeIncome = dueDateFeeIncome.add(loanCharge.amount());
                } else if (loanCharge.isPenaltyCharge()) {
                    dueDatePenaltyIncome = dueDatePenaltyIncome.add(loanCharge.amount());
                }
            }
        }
        LoanScheduleAccrualData accrualData = new LoanScheduleAccrualData(loanId, officeId,
                installment.getInstallmentNumber(), accrualStartDate, repaymentFrequency, repayEvery,
                installment.getDueDate(), installment.getFromDate(), installment.getId(), loanProductId,
                installment.getInterestCharged(currency).getAmount(),
                installment.getFeeChargesCharged(currency).getAmount(),
                installment.getPenaltyChargesCharged(currency).getAmount(),
                installment.getInterestAccrued(currency).getAmount(),
                installment.getFeeAccrued(currency).getAmount(),
                installment.getPenaltyAccrued(currency).getAmount(), currencyData, interestCalculatedFrom,
                installment.getInterestWaived(currency).getAmount());
        loanScheduleAccrualDatas.add(accrualData);

    }
}

From source file:com.gst.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment.java

License:Apache License

private boolean isLatePayment(final LocalDate transactionDate) {
    return transactionDate.isAfter(getDueDate());
}

From source file:com.gst.portfolio.loanaccount.domain.LoanSummaryWrapper.java

License:Apache License

public LocalDate determineOverdueSinceDateFrom(
        final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments,
        final MonetaryCurrency currency, final LocalDate from) {

    LocalDate overdueSince = null;
    final Money totalOverdue = calculateTotalOverdueOn(repaymentScheduleInstallments, currency, from);
    if (totalOverdue.isGreaterThanZero()) {
        for (final LoanRepaymentScheduleInstallment installment : repaymentScheduleInstallments) {
            if (installment.isOverdueOn(from)) {
                if (overdueSince == null || overdueSince.isAfter(installment.getDueDate())) {
                    overdueSince = installment.getDueDate();
                }//from www  .  j a  v  a 2 s .  c  om
            }
        }
    }

    return overdueSince;
}

From source file:com.gst.portfolio.loanaccount.domain.transactionprocessor.AbstractLoanRepaymentScheduleTransactionProcessor.java

License:Apache License

/**
 * This method is responsible for checking if the current transaction is 'an
 * advance/early payment' based on the details passed through.
 * //from  www  .  j  a va 2s  .  c om
 * Default implementation simply processes transactions as 'Late' if the
 * transaction date is after the installment due date.
 */
protected boolean isTransactionALateRepaymentOnInstallment(final int installmentIndex,
        final List<LoanRepaymentScheduleInstallment> installments, final LocalDate transactionDate) {

    final LoanRepaymentScheduleInstallment currentInstallment = installments.get(installmentIndex);

    return transactionDate.isAfter(currentInstallment.getDueDate());
}