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:com.gst.organisation.holiday.service.HolidayUtil.java

License:Apache License

private static LocalDate getRepaymentRescheduleDateIfHoliday(final LocalDate repaymentDate,
        final List<Holiday> holidays) {

    for (final Holiday holiday : holidays) {
        if (repaymentDate.equals(holiday.getFromDateLocalDate())
                || repaymentDate.equals(holiday.getToDateLocalDate())
                || (repaymentDate.isAfter(holiday.getFromDateLocalDate())
                        && repaymentDate.isBefore(holiday.getToDateLocalDate()))) {
            // should be take from holiday
            return holiday.getRepaymentsRescheduledToLocalDate();
        }//from   w  w  w . j  av  a2  s . c o m
    }
    return repaymentDate;
}

From source file:com.gst.portfolio.calendar.domain.Calendar.java

License:Apache License

@SuppressWarnings("null")
public Map<String, Object> updateRepeatingCalendar(final LocalDate calendarStartDate,
        final CalendarFrequencyType frequencyType, final Integer interval, final Integer repeatsOnDay,
        final Integer repeatsOnNthDay) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>(9);

    if (calendarStartDate != null & this.startDate != null) {
        if (!calendarStartDate.equals(this.getStartDateLocalDate())) {
            actualChanges.put("startDate", calendarStartDate);
            this.startDate = calendarStartDate.toDate();
        }/*from  w w  w . j ava2  s . co m*/
    }

    final String newRecurrence = Calendar.constructRecurrence(frequencyType, interval, repeatsOnDay,
            repeatsOnNthDay);
    if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) {
        actualChanges.put("recurrence", newRecurrence);
        this.recurrence = newRecurrence;
    }
    return actualChanges;
}

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

License:Apache License

public void regenerateScheduleOnDisbursement(final ScheduleGeneratorDTO scheduleGeneratorDTO,
        final boolean recalculateSchedule, final LocalDate actualDisbursementDate, BigDecimal emiAmount,
        final AppUser currentUser, LocalDate nextPossibleRepaymentDate, Date rescheduledRepaymentDate) {
    boolean isEmiAmountChanged = false;
    if ((this.loanProduct.isMultiDisburseLoan() || this.loanProduct.canDefineInstallmentAmount())
            && emiAmount != null && emiAmount.compareTo(retriveLastEmiAmount()) != 0) {
        if (this.loanProduct.isMultiDisburseLoan()) {
            final Date dateValue = null;
            final boolean isSpecificToInstallment = false;
            final Boolean isChangeEmiIfRepaymentDateSameAsDisbursementDateEnabled = scheduleGeneratorDTO
                    .isChangeEmiIfRepaymentDateSameAsDisbursementDateEnabled();
            Date effectiveDateFrom = actualDisbursementDate.toDate();
            if (!isChangeEmiIfRepaymentDateSameAsDisbursementDateEnabled
                    && actualDisbursementDate.equals(nextPossibleRepaymentDate)) {
                effectiveDateFrom = nextPossibleRepaymentDate.plusDays(1).toDate();
            }/*from w  w  w .  j  a v a 2s  .  c om*/
            LoanTermVariations loanVariationTerms = new LoanTermVariations(
                    LoanTermVariationType.EMI_AMOUNT.getValue(), effectiveDateFrom, emiAmount, dateValue,
                    isSpecificToInstallment, this, LoanStatus.ACTIVE.getValue());
            this.loanTermVariations.add(loanVariationTerms);
        } else {
            this.fixedEmiAmount = emiAmount;
        }
        isEmiAmountChanged = true;
    }
    if (rescheduledRepaymentDate != null && this.loanProduct.isMultiDisburseLoan()) {
        final boolean isSpecificToInstallment = false;
        LoanTermVariations loanVariationTerms = new LoanTermVariations(
                LoanTermVariationType.DUE_DATE.getValue(), nextPossibleRepaymentDate.toDate(), emiAmount,
                rescheduledRepaymentDate, isSpecificToInstallment, this, LoanStatus.ACTIVE.getValue());
        this.loanTermVariations.add(loanVariationTerms);
    }

    if (isRepaymentScheduleRegenerationRequiredForDisbursement(actualDisbursementDate) || recalculateSchedule
            || isEmiAmountChanged || rescheduledRepaymentDate != null) {
        if (this.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
            regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
        } else {
            regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser);
        }
    }
}

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

License:Apache License

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

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

    /***/*from ww  w .j  a va2 s . c om*/
     * 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,
            paymentDetail, disbursedOn, null, createdDate, currentUser);
    final Integer installmentNumber = null;
    for (final LoanCharge charge : charges()) {
        Date actualDisbursementDate = getActualDisbursementDate(charge);
        if ((charge.getCharge().getChargeTimeType() == ChargeTimeType.DISBURSEMENT.getValue()
                && disbursedOn.equals(new LocalDate(actualDisbursementDate)) && actualDisbursementDate != null
                && !charge.isWaived() && !charge.isFullyPaid())
                || (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);
        addLoanTransaction(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:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

private LoanRepaymentScheduleInstallment fetchLoanRepaymentScheduleInstallment(LocalDate dueDate) {
    LoanRepaymentScheduleInstallment installment = null;
    List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
    for (LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment : installments) {
        if (dueDate.equals(loanRepaymentScheduleInstallment.getDueDate())) {
            installment = loanRepaymentScheduleInstallment;
            break;
        }/* w  ww . j  a  v  a2s  .c o  m*/
    }
    return installment;
}

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 2 s  . 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

/**
 * Reverse only disbursement, accruals, and repayments at disbursal
 * transactions/* w w  w .j a  v  a  2  s.co m*/
 * 
 * @param actualDisbursementDate
 * @return
 */
public List<LoanTransaction> reverseExistingTransactionsTillLastDisbursal(LocalDate actualDisbursementDate) {
    final List<LoanTransaction> reversedTransactions = new ArrayList<>();
    for (final LoanTransaction transaction : this.loanTransactions) {
        if ((actualDisbursementDate.equals(transaction.getTransactionDate())
                || actualDisbursementDate.isBefore(transaction.getTransactionDate()))
                && transaction.isAllowTypeTransactionAtTheTimeOfLastUndo()) {
            reversedTransactions.add(transaction);
            transaction.reverse();
        }
    }
    return reversedTransactions;
}

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

License:Apache License

private void updateLoanToLastDisbursalState(LocalDate actualDisbursementDate) {

    for (final LoanCharge charge : charges()) {
        if (charge.isOverdueInstallmentCharge()) {
            charge.setActive(false);//from  w  ww  . ja  v  a 2s .co m
        } else if (charge.isTrancheDisbursementCharge() && actualDisbursementDate.equals(new LocalDate(
                charge.getTrancheDisbursementCharge().getloanDisbursementDetails().actualDisbursementDate()))) {
            charge.resetToOriginal(loanCurrency());
        }
    }
    for (final LoanDisbursementDetails details : this.disbursementDetails) {
        if (actualDisbursementDate.equals(new LocalDate(details.actualDisbursementDate()))) {
            this.loanRepaymentScheduleDetail.setPrincipal(getDisbursedAmount().subtract(details.principal()));
            details.updateActualDisbursementDate(null);
        }
    }
    updateLoanSummaryDerivedFields();
}

From source file:com.gst.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);/* ww w . j  a  v  a 2  s  .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()));
        }

        scheduleParams.getCompoundingDateVariations().put(periodStartDateApplicableForInterest,
                new TreeMap<>(scheduleParams.getCompoundingMap()));
        scheduleParams.getCompoundingMap().clear();
        populateCompoundingDatesInPeriod(periodStartDateApplicableForInterest, calculateTill,
                loanApplicationTerms, holidayDetailDTO, scheduleParams, loanCharges,
                totalInterestChargedForFullLoanTerm.getCurrency());

        // this is to make sure we are recalculating using correct interest rate 
        // once calculation is done system will set the actual interest rate
        BigDecimal currentInterestRate = loanApplicationTerms.getAnnualNominalInterestRate();
        for (LoanTermVariationsData interestRate : interestRates) {
            if (interestRate.isApplicable(periodStartDateApplicableForInterest)) {
                loanApplicationTerms.updateAnnualNominalInterestRate(interestRate.getDecimalValue());
            }
        }

        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);
        loanApplicationTerms.updateAnnualNominalInterestRate(currentInterestRate);

        // 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()) {
            updateCompoundingDetails(scheduleParams, periodStartDateApplicableForInterest);
        } else {
            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:com.gst.portfolio.loanaccount.serialization.LoanApplicationCommandFromApiJsonHelper.java

License:Apache License

public void validateLoanMultiDisbursementdate(final JsonElement element,
        final DataValidatorBuilder baseDataValidator, LocalDate expectedDisbursement,
        BigDecimal totalPrincipal) {

    this.validateDisbursementsAreDatewiseOrdered(element, baseDataValidator);

    final JsonObject topLevelJsonElement = element.getAsJsonObject();
    final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
    final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
    if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.disbursementDataParameterName, element)
            && expectedDisbursement != null && totalPrincipal != null) {
        BigDecimal tatalDisbursement = BigDecimal.ZERO;
        boolean isFirstinstallmentOnExpectedDisbursementDate = false;
        final JsonArray variationArray = this.fromApiJsonHelper
                .extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName, element);
        List<LocalDate> expectedDisbursementDates = new ArrayList<>();
        if (variationArray != null && variationArray.size() > 0) {
            int i = 0;
            do {//  w  w w.  ja  v a  2 s .  co m
                final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
                if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)
                        && jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)) {
                    LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
                            LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
                    if (expectedDisbursementDates.contains(expectedDisbursementDate)) {
                        baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
                                .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR);
                    }
                    if (expectedDisbursementDate.isBefore(expectedDisbursement)) {
                        baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                                .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR);
                    }
                    expectedDisbursementDates.add(expectedDisbursementDate);

                    BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalNamed(
                            LoanApiConstants.disbursementPrincipalParameterName, jsonObject, locale);
                    baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                            .parameterAtIndexArray(LoanApiConstants.disbursementPrincipalParameterName, i)
                            .value(principal).notBlank();
                    if (principal != null) {
                        tatalDisbursement = tatalDisbursement.add(principal);
                    }

                    baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
                            .parameterAtIndexArray(LoanApiConstants.disbursementDateParameterName, i)
                            .value(expectedDisbursementDate).notNull();

                    if (expectedDisbursement.equals(expectedDisbursementDate)) {
                        isFirstinstallmentOnExpectedDisbursementDate = true;
                    }

                }
                i++;
            } while (i < variationArray.size());
            if (!isFirstinstallmentOnExpectedDisbursementDate) {
                baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
                        .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_START_WITH_ERROR);
            }

            if (tatalDisbursement.compareTo(totalPrincipal) == 1) {
                baseDataValidator.reset().parameter(LoanApiConstants.disbursementPrincipalParameterName)
                        .failWithCode(LoanApiConstants.APPROVED_AMOUNT_IS_LESS_THAN_SUM_OF_TRANCHES);
            }
            final String interestTypeParameterName = "interestType";
            final Integer interestType = this.fromApiJsonHelper
                    .extractIntegerSansLocaleNamed(interestTypeParameterName, element);
            baseDataValidator.reset().parameter(interestTypeParameterName).value(interestType).ignoreIfNull()
                    .integerSameAsNumber(InterestMethod.DECLINING_BALANCE.getValue());

        }

    }

}