Example usage for org.joda.time LocalDate equals

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

Introduction

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

Prototype

public boolean equals(Object partial) 

Source Link

Document

Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.

Usage

From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java

License:Apache License

private void handleDisbursementTransaction(final LocalDate disbursedOn, final LocalDateTime createdDate,
        final AppUser currentUser) {

    // add repayment transaction to track incoming money from client to mfi
    // for (charges due at time of disbursement)

    /***//ww  w . j a  va 2s.  c  o  m
     * TODO Vishwas: do we need to be able to pass in payment type details
     * for repayments at disbursements too?
     ***/

    final Money totalFeeChargesDueAtDisbursement = this.summary
            .getTotalFeeChargesDueAtDisbursement(loanCurrency());
    /**
     * all Charges repaid at disbursal is marked as repaid and
     * "APPLY Charge" transactions are created for all other fees ( which
     * are created during disbursal but not repaid)
     **/

    Money disbursentMoney = Money.zero(getCurrency());
    final LoanTransaction chargesPayment = LoanTransaction.repaymentAtDisbursement(getOffice(), disbursentMoney,
            null, disbursedOn, null, createdDate, currentUser);
    final Integer installmentNumber = null;
    for (final LoanCharge charge : charges()) {
        Date actualDisbursementDate = getActualDisbursementDate(charge);
        if (charge.getCharge().getChargeTimeType() == ChargeTimeType.DISBURSEMENT.getValue()
                || (charge.getCharge().getChargeTimeType() == ChargeTimeType.TRANCHE_DISBURSEMENT.getValue()
                        && disbursedOn.equals(new LocalDate(actualDisbursementDate))
                        && actualDisbursementDate != null && !charge.isWaived() && !charge.isFullyPaid())) {
            if (totalFeeChargesDueAtDisbursement.isGreaterThanZero()
                    && !charge.getChargePaymentMode().isPaymentModeAccountTransfer()) {
                charge.markAsFullyPaid();
                // Add "Loan Charge Paid By" details to this transaction
                final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(chargesPayment, charge,
                        charge.amount(), installmentNumber);
                chargesPayment.getLoanChargesPaid().add(loanChargePaidBy);
                disbursentMoney = disbursentMoney.plus(charge.amount());
            }
        } else if (disbursedOn.equals(new LocalDate(this.actualDisbursementDate))) {
            /**
             * create a Charge applied transaction if Up front Accrual, None
             * or Cash based accounting is enabled
             **/
            if (isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()) {
                handleChargeAppliedTransaction(charge, disbursedOn, currentUser);
            }
        }
    }

    if (disbursentMoney.isGreaterThanZero()) {
        final Money zero = Money.zero(getCurrency());
        chargesPayment.updateComponentsAndTotal(zero, zero, disbursentMoney, zero);
        chargesPayment.updateLoan(this);
        this.loanTransactions.add(chargesPayment);
        updateLoanOutstandingBalaces();
    }

    if (getApprovedOnDate() != null && disbursedOn.isBefore(getApprovedOnDate())) {
        final String errorMessage = "The date on which a loan is disbursed cannot be before its approval date: "
                + getApprovedOnDate().toString();
        throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.before.approval.date",
                errorMessage, disbursedOn, getApprovedOnDate());
    }

    if (getExpectedFirstRepaymentOnDate() != null
            && (disbursedOn.isAfter(this.fetchRepaymentScheduleInstallment(1).getDueDate())
                    || disbursedOn.isAfter(getExpectedFirstRepaymentOnDate()))
            && disbursedOn.toDate().equals(this.actualDisbursementDate)) {
        final String errorMessage = "submittedOnDate cannot be after the loans  expectedFirstRepaymentOnDate: "
                + getExpectedFirstRepaymentOnDate().toString();
        throw new InvalidLoanStateTransitionException("disbursal",
                "cannot.be.after.expected.first.repayment.date", errorMessage, disbursedOn,
                getExpectedFirstRepaymentOnDate());
    }

    validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_DISBURSED, disbursedOn);

    if (disbursedOn.isAfter(new LocalDate())) {
        final String errorMessage = "The date on which a loan with identifier : " + this.accountNumber
                + " is disbursed cannot be in the future.";
        throw new InvalidLoanStateTransitionException("disbursal", "cannot.be.a.future.date", errorMessage,
                disbursedOn);
    }

}

From source file:org.apache.fineract.portfolio.loanaccount.domain.Loan.java

License:Apache License

private LoanRepaymentScheduleInstallment fetchLoanRepaymentScheduleInstallment(LocalDate dueDate) {
    LoanRepaymentScheduleInstallment installment = null;
    for (LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : this.repaymentScheduleInstallments) {
        if (dueDate.equals(loanRepaymentScheduleInstallment.getDueDate())) {
            installment = loanRepaymentScheduleInstallment;
            break;
        }//  w  w w .  ja  va  2  s. c  o  m
    }
    return installment;
}

From source file:org.apache.fineract.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
    for (final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : this.repaymentScheduleInstallments) {
        final LocalDate oldDueDate = loanRepaymentScheduleInstallment.getDueDate();

        // update from date if it's not same as previous installament's due
        // date./*from   w  ww.j  av  a 2s.  c  om*/
        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:org.apache.fineract.portfolio.loanaccount.loanschedule.domain.AbstractLoanScheduleGenerator.java

License:Apache License

private LoanScheduleModelPeriod handlePrepaymentOfLoan(final MathContext mc,
        final LoanApplicationTerms loanApplicationTerms, final HolidayDetailDTO holidayDetailDTO,
        final LoanScheduleParams scheduleParams, final Money totalInterestChargedForFullLoanTerm,
        final LocalDate scheduledDueDate, LocalDate periodStartDateApplicableForInterest,
        final double interestCalculationGraceOnRepaymentPeriodFraction,
        final ScheduleCurrentPeriodParams currentPeriodParams,
        final Money lastTotalOutstandingInterestPaymentDueToGrace, final LocalDate transactionDate,
        final LoanScheduleModelPeriod installment, Set<LoanCharge> loanCharges) {
    LoanScheduleModelPeriod modifiedInstallment = installment;
    if (!scheduleParams.getOutstandingBalance().isGreaterThan(currentPeriodParams.getInterestForThisPeriod())
            && !scheduledDueDate.equals(transactionDate)) {
        final Collection<LoanTermVariationsData> interestRates = loanApplicationTerms.getLoanTermVariations()
                .getInterestRateChanges();
        LocalDate calculateTill = transactionDate;
        if (loanApplicationTerms.getPreClosureInterestCalculationStrategy()
                .calculateTillRestFrequencyEnabled()) {
            calculateTill = getNextRestScheduleDate(calculateTill.minusDays(1), loanApplicationTerms,
                    holidayDetailDTO);//from   w  ww.ja  v a  2s . c  om
        }
        if (scheduleParams.getCompoundingDateVariations().containsKey(periodStartDateApplicableForInterest)) {
            scheduleParams.getCompoundingMap().clear();
            scheduleParams.getCompoundingMap().putAll(
                    scheduleParams.getCompoundingDateVariations().get(periodStartDateApplicableForInterest));
        }
        if (currentPeriodParams.isEmiAmountChanged()) {
            updateFixedInstallmentAmount(mc, loanApplicationTerms, scheduleParams.getPeriodNumber(),
                    loanApplicationTerms.getPrincipal().minus(scheduleParams.getTotalCumulativePrincipal()));
        }
        PrincipalInterest interestTillDate = calculatePrincipalInterestComponentsForPeriod(
                this.paymentPeriodsInOneYearCalculator, interestCalculationGraceOnRepaymentPeriodFraction,
                scheduleParams.getTotalCumulativePrincipal(), scheduleParams.getTotalCumulativeInterest(),
                totalInterestChargedForFullLoanTerm, lastTotalOutstandingInterestPaymentDueToGrace,
                scheduleParams.getOutstandingBalanceAsPerRest(), loanApplicationTerms,
                scheduleParams.getPeriodNumber(), mc, mergeVariationsToMap(scheduleParams),
                scheduleParams.getCompoundingMap(), periodStartDateApplicableForInterest, calculateTill,
                interestRates);
        // applies charges for the period
        final ScheduleCurrentPeriodParams tempPeriod = new ScheduleCurrentPeriodParams(
                totalInterestChargedForFullLoanTerm.getCurrency(),
                interestCalculationGraceOnRepaymentPeriodFraction);
        tempPeriod.setInterestForThisPeriod(interestTillDate.interest());
        applyChargesForCurrentPeriod(loanCharges, totalInterestChargedForFullLoanTerm.getCurrency(),
                scheduleParams, calculateTill, tempPeriod);
        Money interestDiff = currentPeriodParams.getInterestForThisPeriod()
                .minus(tempPeriod.getInterestForThisPeriod());
        Money chargeDiff = currentPeriodParams.getFeeChargesForInstallment()
                .minus(tempPeriod.getFeeChargesForInstallment());
        Money penaltyDiff = currentPeriodParams.getPenaltyChargesForInstallment()
                .minus(tempPeriod.getPenaltyChargesForInstallment());

        Money diff = interestDiff.plus(chargeDiff).plus(penaltyDiff);
        if (!scheduleParams.getOutstandingBalance().minus(diff).isGreaterThanZero()) {
            scheduleParams.reduceOutstandingBalance(diff);
            currentPeriodParams.minusInterestForThisPeriod(interestDiff);
            currentPeriodParams.minusFeeChargesForInstallment(chargeDiff);
            currentPeriodParams.minusPenaltyChargesForInstallment(penaltyDiff);
            currentPeriodParams.plusPrincipalForThisPeriod(diff);

            // create and replaces repayment period
            // from parts
            modifiedInstallment = LoanScheduleModelRepaymentPeriod.repayment(
                    scheduleParams.getInstalmentNumber(), scheduleParams.getPeriodStartDate(), transactionDate,
                    currentPeriodParams.getPrincipalForThisPeriod(), scheduleParams.getOutstandingBalance(),
                    currentPeriodParams.getInterestForThisPeriod(),
                    currentPeriodParams.getFeeChargesForInstallment(),
                    currentPeriodParams.getPenaltyChargesForInstallment(),
                    currentPeriodParams.fetchTotalAmountForPeriod(), false);
            scheduleParams
                    .setTotalOutstandingInterestPaymentDueToGrace(interestTillDate.interestPaymentDueToGrace());
        }

    }
    return modifiedInstallment;
}

From source file:org.estatio.dom.index.IndexBase.java

License:Apache License

public void modifyStartDate(final LocalDate startDate) {
    final LocalDate currentStartDate = getStartDate();
    if (startDate == null || startDate.equals(currentStartDate)) {
        return;/*  w  w w .j  a  va 2s . co  m*/
    }
    setStartDate(startDate);
}

From source file:org.estatio.dom.lease.LeaseItem.java

License:Apache License

@Programmatic
public LeaseTerm findTerm(final LocalDate startDate) {
    for (LeaseTerm term : getTerms()) {
        if (startDate.equals(term.getStartDate())) {
            return term;
        }/*w  w w .  j  a v  a  2  s  . com*/
    }
    return null;
}

From source file:org.estatio.dom.tax.TaxRates.java

License:Apache License

@Programmatic
public TaxRate newRate(final Tax tax, final LocalDate startDate, final BigDecimal percentage) {
    TaxRate currentRate = tax.taxRateFor(startDate);
    TaxRate rate;/*w w  w  . j  a v a2 s.  co m*/
    if (currentRate == null || !startDate.equals(currentRate.getStartDate())) {
        rate = newTransientInstance(TaxRate.class);
        rate.setTax(tax);
        rate.setStartDate(startDate);
        persist(rate);
    } else {
        rate = currentRate;
    }
    rate.setPercentage(percentage);
    if (currentRate != null) {
        TaxRate currentNextRate = currentRate.getNext();
        currentRate.modifyNext(rate);
        rate.modifyNext(currentNextRate);
    }
    return rate;
}

From source file:org.fenixedu.treasury.domain.paymentcodes.PaymentReferenceCode.java

License:Open Source License

public static Stream<PaymentReferenceCode> findByBeginDate(final LocalDate beginDate,
        FinantialInstitution finantialInstitution) {
    return findAll().filter(i -> beginDate.equals(i.getBeginDate()))
            .filter(x -> x.getPaymentCodePool().getFinantialInstitution().equals(finantialInstitution));
}

From source file:org.fenixedu.treasury.domain.paymentcodes.PaymentReferenceCode.java

License:Open Source License

public static Stream<PaymentReferenceCode> findByEndDate(final LocalDate endDate,
        FinantialInstitution finantialInstitution) {
    return findAll().filter(i -> endDate.equals(i.getEndDate()))
            .filter(x -> x.getPaymentCodePool().getFinantialInstitution().equals(finantialInstitution));
}

From source file:org.fenixedu.treasury.domain.paymentcodes.SibsReportFile.java

License:Open Source License

public static Stream<SibsReportFile> findByWhenProcessedBySibs(final LocalDate whenProcessedBySibs) {
    return findAll().filter(i -> whenProcessedBySibs.equals(i.getWhenProcessedBySibs()));
}