Example usage for org.joda.time LocalDate toDate

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

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

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

License:Apache License

public ChangedTransactionDetail updateDisbursementDateAndAmountForTranche(
        final LoanDisbursementDetails disbursementDetails, final JsonCommand command,
        final Map<String, Object> actualChanges, final ScheduleGeneratorDTO scheduleGeneratorDTO,
        final AppUser currentUser) {
    final Locale locale = command.extractLocale();
    validateAccountStatus(LoanEvent.LOAN_EDIT_MULTI_DISBURSE_DATE);
    final BigDecimal principal = command.bigDecimalValueOfParameterNamed(
            LoanApiConstants.updatedDisbursementPrincipalParameterName, locale);
    final LocalDate expectedDisbursementDate = command
            .localDateValueOfParameterNamed(LoanApiConstants.updatedDisbursementDateParameterName);
    disbursementDetails.updateExpectedDisbursementDateAndAmount(expectedDisbursementDate.toDate(), principal);
    actualChanges.put(LoanApiConstants.disbursementDateParameterName,
            command.stringValueOfParameterNamed(LoanApiConstants.disbursementDateParameterName));
    actualChanges.put(LoanApiConstants.disbursementIdParameterName,
            command.stringValueOfParameterNamed(LoanApiConstants.disbursementIdParameterName));
    actualChanges.put(LoanApiConstants.disbursementPrincipalParameterName, command
            .bigDecimalValueOfParameterNamed(LoanApiConstants.disbursementPrincipalParameterName, locale));

    Collection<LoanDisbursementDetails> loanDisburseDetails = this.getDisbursementDetails();
    BigDecimal setPrincipalAmount = BigDecimal.ZERO;
    for (LoanDisbursementDetails details : loanDisburseDetails) {
        if (details.actualDisbursementDate() != null) {
            setPrincipalAmount = setPrincipalAmount.add(details.principal());
        }//from  w  w w. j a v a  2s.c o m
    }

    this.loanRepaymentScheduleDetail.setPrincipal(setPrincipalAmount);
    if (this.repaymentScheduleDetail().isInterestRecalculationEnabled()) {
        regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
    } else {
        regenerateRepaymentSchedule(scheduleGeneratorDTO, currentUser);
    }

    final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
            .determineProcessor(this.transactionProcessingStrategy);
    final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
    ChangedTransactionDetail changedTransactionDetail = loanRepaymentScheduleTransactionProcessor
            .handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement, getCurrency(),
                    getRepaymentScheduleInstallments(), charges());
    for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings()
            .entrySet()) {
        mapEntry.getValue().updateLoan(this);
        addLoanTransaction(mapEntry.getValue());
    }

    return changedTransactionDetail;
}

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

License:Apache License

public void updateRescheduledOnDate(LocalDate rescheduledOnDate) {

    if (rescheduledOnDate != null) {
        this.rescheduledOnDate = rescheduledOnDate.toDate();
    }/*  w ww .  j  ava2s  .  c  om*/
}

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

License:Apache License

public Map<String, Object> undoLastDisbursal(ScheduleGeneratorDTO scheduleGeneratorDTO,
        List<Long> existingTransactionIds, List<Long> existingReversedTransactionIds, AppUser currentUser,
        Loan loan) {//from  w  ww. j  a  va  2 s  .  c  o m

    validateAccountStatus(LoanEvent.LOAN_DISBURSAL_UNDO_LAST);
    existingTransactionIds.addAll(findExistingTransactionIds());
    existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());
    final Map<String, Object> actualChanges = new LinkedHashMap<>();
    validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_DISBURSAL_UNDO_LAST,
            getDisbursementDate());
    LocalDate actualDisbursementDate = null;
    LocalDate lastTransactionDate = getDisbursementDate();
    List<LoanTransaction> loanTransactions = retreiveListOfTransactionsExcludeAccruals();
    Collections.reverse(loanTransactions);
    for (final LoanTransaction previousTransaction : loanTransactions) {
        if (lastTransactionDate.isBefore(previousTransaction.getTransactionDate())) {
            if (previousTransaction.isRepayment() || previousTransaction.isWaiver()
                    || previousTransaction.isChargePayment()) {
                throw new UndoLastTrancheDisbursementException(previousTransaction.getId());
            }
        }
        if (previousTransaction.isDisbursement()) {
            lastTransactionDate = previousTransaction.getTransactionDate();
            break;
        }
    }
    actualDisbursementDate = lastTransactionDate;
    updateLoanToLastDisbursalState(actualDisbursementDate);
    for (Iterator<LoanTermVariations> iterator = this.loanTermVariations.iterator(); iterator.hasNext();) {
        LoanTermVariations loanTermVariations = iterator.next();
        if (loanTermVariations.getTermType().isDueDateVariation()
                && loanTermVariations.fetchDateValue().isAfter(actualDisbursementDate)
                || loanTermVariations.getTermType().isEMIAmountVariation()
                        && loanTermVariations.getTermApplicableFrom().equals(actualDisbursementDate.toDate())
                || loanTermVariations.getTermApplicableFrom().after(actualDisbursementDate.toDate())) {
            iterator.remove();
        }
    }
    reverseExistingTransactionsTillLastDisbursal(actualDisbursementDate);
    loan.recalculateScheduleFromLastTransaction(scheduleGeneratorDTO, existingTransactionIds,
            existingReversedTransactionIds, currentUser);
    actualChanges.put("undolastdisbursal", "true");
    actualChanges.put("disbursedAmount", this.getDisbursedAmount());
    updateLoanSummaryDerivedFields();

    return actualChanges;
}

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

License:Apache License

@Override
@Transactional//from   w  w w.java 2  s  . co m
public LoanTransaction makeChargePayment(final Loan loan, final Long chargeId, final LocalDate transactionDate,
        final BigDecimal transactionAmount, final PaymentDetail paymentDetail, final String noteText,
        final String txnExternalId, final Integer transactionType, Integer installmentNumber) {
    AppUser currentUser = getAppUserIfPresent();
    boolean isAccountTransfer = true;
    checkClientOrGroupActive(loan);
    this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.LOAN_CHARGE_PAYMENT,
            constructEntityMap(BUSINESS_ENTITY.LOAN, loan));
    final List<Long> existingTransactionIds = new ArrayList<>();
    final List<Long> existingReversedTransactionIds = new ArrayList<>();

    final Money paymentAmout = Money.of(loan.getCurrency(), transactionAmount);
    final LoanTransactionType loanTransactionType = LoanTransactionType.fromInt(transactionType);

    final LoanTransaction newPaymentTransaction = LoanTransaction.loanPayment(null, loan.getOffice(),
            paymentAmout, paymentDetail, transactionDate, txnExternalId, loanTransactionType,
            DateUtils.getLocalDateTimeOfTenant(), currentUser);

    if (loanTransactionType.isRepaymentAtDisbursement()) {
        loan.handlePayDisbursementTransaction(chargeId, newPaymentTransaction, existingTransactionIds,
                existingReversedTransactionIds);
    } else {
        final boolean allowTransactionsOnHoliday = this.configurationDomainService
                .allowTransactionsOnHolidayEnabled();
        final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(
                loan.getOfficeId(), transactionDate.toDate(), HolidayStatusType.ACTIVE.getValue());
        final WorkingDays workingDays = this.workingDaysRepository.findOne();
        final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService
                .allowTransactionsOnNonWorkingDayEnabled();
        final boolean isHolidayEnabled = this.configurationDomainService
                .isRescheduleRepaymentsOnHolidaysEnabled();
        HolidayDetailDTO holidayDetailDTO = new HolidayDetailDTO(isHolidayEnabled, holidays, workingDays,
                allowTransactionsOnHoliday, allowTransactionsOnNonWorkingDay);

        loan.makeChargePayment(chargeId, defaultLoanLifecycleStateMachine(), existingTransactionIds,
                existingReversedTransactionIds, holidayDetailDTO, newPaymentTransaction, installmentNumber);
    }
    saveLoanTransactionWithDataIntegrityViolationChecks(newPaymentTransaction);
    saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

    if (StringUtils.isNotBlank(noteText)) {
        final Note note = Note.loanTransactionNote(loan, newPaymentTransaction, noteText);
        this.noteRepository.save(note);
    }

    postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
    recalculateAccruals(loan);
    this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.LOAN_CHARGE_PAYMENT,
            constructEntityMap(BUSINESS_ENTITY.LOAN_TRANSACTION, newPaymentTransaction));
    return newPaymentTransaction;
}

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

License:Apache License

@Override
public LoanTransaction makeRefund(final Long accountId, final CommandProcessingResultBuilder builderResult,
        final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail,
        final String noteText, final String txnExternalId) {
    AppUser currentUser = getAppUserIfPresent();
    boolean isAccountTransfer = true;
    final Loan loan = this.loanAccountAssembler.assembleFrom(accountId);
    checkClientOrGroupActive(loan);/*from  ww w .ja v a  2 s .  com*/
    this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.LOAN_REFUND,
            constructEntityMap(BUSINESS_ENTITY.LOAN, loan));
    final List<Long> existingTransactionIds = new ArrayList<>();
    final List<Long> existingReversedTransactionIds = new ArrayList<>();

    final Money refundAmount = Money.of(loan.getCurrency(), transactionAmount);
    final LoanTransaction newRefundTransaction = LoanTransaction.refund(loan.getOffice(), refundAmount,
            paymentDetail, transactionDate, txnExternalId, DateUtils.getLocalDateTimeOfTenant(), currentUser);
    final boolean allowTransactionsOnHoliday = this.configurationDomainService
            .allowTransactionsOnHolidayEnabled();
    final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(),
            transactionDate.toDate(), HolidayStatusType.ACTIVE.getValue());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();
    final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService
            .allowTransactionsOnNonWorkingDayEnabled();

    loan.makeRefund(newRefundTransaction, defaultLoanLifecycleStateMachine(), existingTransactionIds,
            existingReversedTransactionIds, allowTransactionsOnHoliday, holidays, workingDays,
            allowTransactionsOnNonWorkingDay);

    saveLoanTransactionWithDataIntegrityViolationChecks(newRefundTransaction);
    this.loanRepositoryWrapper.save(loan);

    if (StringUtils.isNotBlank(noteText)) {
        final Note note = Note.loanTransactionNote(loan, newRefundTransaction, noteText);
        this.noteRepository.save(note);
    }

    postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, isAccountTransfer);
    this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.LOAN_REFUND,
            constructEntityMap(BUSINESS_ENTITY.LOAN_TRANSACTION, newRefundTransaction));
    builderResult.withEntityId(newRefundTransaction.getId()) //
            .withOfficeId(loan.getOfficeId()) //
            .withClientId(loan.getClientId()) //
            .withGroupId(loan.getGroupId()); //

    return newRefundTransaction;
}

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

License:Apache License

@Override
public LoanTransaction makeRefundForActiveLoan(Long accountId, CommandProcessingResultBuilder builderResult,
        LocalDate transactionDate, BigDecimal transactionAmount, PaymentDetail paymentDetail, String noteText,
        String txnExternalId) {/*from   w  w w. ja  v a2 s.c  o  m*/
    final Loan loan = this.loanAccountAssembler.assembleFrom(accountId);
    checkClientOrGroupActive(loan);
    this.businessEventNotifierService.notifyBusinessEventToBeExecuted(BUSINESS_EVENTS.LOAN_REFUND,
            constructEntityMap(BUSINESS_ENTITY.LOAN, loan));
    final List<Long> existingTransactionIds = new ArrayList<>();
    final List<Long> existingReversedTransactionIds = new ArrayList<>();
    AppUser currentUser = getAppUserIfPresent();

    final Money refundAmount = Money.of(loan.getCurrency(), transactionAmount);
    final LoanTransaction newRefundTransaction = LoanTransaction.refundForActiveLoan(loan.getOffice(),
            refundAmount, paymentDetail, transactionDate, txnExternalId, DateUtils.getLocalDateTimeOfTenant(),
            currentUser);
    final boolean allowTransactionsOnHoliday = this.configurationDomainService
            .allowTransactionsOnHolidayEnabled();
    final List<Holiday> holidays = this.holidayRepository.findByOfficeIdAndGreaterThanDate(loan.getOfficeId(),
            transactionDate.toDate(), HolidayStatusType.ACTIVE.getValue());
    final WorkingDays workingDays = this.workingDaysRepository.findOne();
    final boolean allowTransactionsOnNonWorkingDay = this.configurationDomainService
            .allowTransactionsOnNonWorkingDayEnabled();

    loan.makeRefundForActiveLoan(newRefundTransaction, defaultLoanLifecycleStateMachine(),
            existingTransactionIds, existingReversedTransactionIds, allowTransactionsOnHoliday, holidays,
            workingDays, allowTransactionsOnNonWorkingDay);

    this.loanTransactionRepository.save(newRefundTransaction);
    this.loanRepositoryWrapper.save(loan);

    if (StringUtils.isNotBlank(noteText)) {
        final Note note = Note.loanTransactionNote(loan, newRefundTransaction, noteText);
        this.noteRepository.save(note);
    }

    postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds, false);
    recalculateAccruals(loan);
    this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.LOAN_REFUND,
            constructEntityMap(BUSINESS_ENTITY.LOAN_TRANSACTION, newRefundTransaction));

    builderResult.withEntityId(newRefundTransaction.getId()) //
            .withOfficeId(loan.getOfficeId()) //
            .withClientId(loan.getClientId()) //
            .withGroupId(loan.getGroupId()); //

    return newRefundTransaction;
}

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

License:Apache License

public LoanCharge(final Loan loan, final Charge chargeDefinition, final BigDecimal loanPrincipal,
        final BigDecimal amount, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation,
        final LocalDate dueDate, final ChargePaymentMode chargePaymentMode, final Integer numberOfRepayments,
        final BigDecimal loanCharge) {
    this.loan = loan;
    this.charge = chargeDefinition;
    this.penaltyCharge = chargeDefinition.isPenalty();
    this.minCap = chargeDefinition.getMinCap();
    this.maxCap = chargeDefinition.getMaxCap();

    this.chargeTime = chargeDefinition.getChargeTimeType();
    if (chargeTime != null) {
        this.chargeTime = chargeTime.getValue();
    }/* ww  w . j  a  va 2 s  .  c o  m*/

    if (ChargeTimeType.fromInt(this.chargeTime).equals(ChargeTimeType.SPECIFIED_DUE_DATE)
            || ChargeTimeType.fromInt(this.chargeTime).equals(ChargeTimeType.OVERDUE_INSTALLMENT)) {

        if (dueDate == null) {
            final String defaultUserMessage = "Loan charge is missing due date.";
            throw new LoanChargeWithoutMandatoryFieldException("loanCharge", "dueDate", defaultUserMessage,
                    chargeDefinition.getId(), chargeDefinition.getName());
        }

        this.dueDate = dueDate.toDate();
    } else {
        this.dueDate = null;
    }

    this.chargeCalculation = chargeDefinition.getChargeCalculation();
    if (chargeCalculation != null) {
        this.chargeCalculation = chargeCalculation.getValue();
    }

    BigDecimal chargeAmount = chargeDefinition.getAmount();
    if (amount != null) {
        chargeAmount = amount;
    }

    this.chargePaymentMode = chargeDefinition.getChargePaymentMode();
    if (chargePaymentMode != null) {
        this.chargePaymentMode = chargePaymentMode.getValue();
    }
    populateDerivedFields(loanPrincipal, chargeAmount, numberOfRepayments, loanCharge);
    this.paid = determineIfFullyPaid();
}

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

License:Apache License

public void update(final BigDecimal amount, final LocalDate dueDate, final BigDecimal loanPrincipal,
        Integer numberOfRepayments, BigDecimal loanCharge) {
    if (dueDate != null) {
        this.dueDate = dueDate.toDate();
    }/*w  w  w.j a v a 2s  .c o  m*/

    if (amount != null) {
        switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
            break;
        case FLAT:
            if (isInstalmentFee()) {
                if (numberOfRepayments == null) {
                    numberOfRepayments = this.loan.fetchNumberOfInstallmensAfterExceptions();
                }
                this.amount = amount.multiply(BigDecimal.valueOf(numberOfRepayments));
            } else {
                this.amount = amount;
            }
            break;
        case PERCENT_OF_AMOUNT:
        case PERCENT_OF_AMOUNT_AND_INTEREST:
        case PERCENT_OF_INTEREST:
        case PERCENT_OF_DISBURSEMENT_AMOUNT:
            this.percentage = amount;
            this.amountPercentageAppliedTo = loanPrincipal;
            if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
                loanCharge = percentageOf(this.amountPercentageAppliedTo);
            }
            this.amount = minimumAndMaximumCap(loanCharge);
            break;
        }
        this.amountOrPercentage = amount;
        this.amountOutstanding = calculateOutstanding();
        if (this.loan != null && isInstalmentFee()) {
            updateInstallmentCharges();
        }
    }
}

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

License:Apache License

public Map<String, Object> update(final JsonCommand command, final BigDecimal amount) {

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

    final String dateFormatAsInput = command.dateFormat();
    final String localeAsInput = command.locale();

    final String dueDateParamName = "dueDate";
    if (command.isChangeInLocalDateParameterNamed(dueDateParamName, getDueLocalDate())) {
        final String valueAsInput = command.stringValueOfParameterNamed(dueDateParamName);
        actualChanges.put(dueDateParamName, valueAsInput);
        actualChanges.put("dateFormat", dateFormatAsInput);
        actualChanges.put("locale", localeAsInput);

        final LocalDate newValue = command.localDateValueOfParameterNamed(dueDateParamName);
        this.dueDate = newValue.toDate();
    }//from  www  . j  a va 2  s. co m

    final String amountParamName = "amount";
    if (command.isChangeInBigDecimalParameterNamed(amountParamName, this.amount)) {
        final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountParamName);
        BigDecimal loanCharge = null;
        actualChanges.put(amountParamName, newValue);
        actualChanges.put("locale", localeAsInput);
        switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
        case INVALID:
            break;
        case FLAT:
            if (isInstalmentFee()) {
                this.amount = newValue
                        .multiply(BigDecimal.valueOf(this.loan.fetchNumberOfInstallmensAfterExceptions()));
            } else {
                this.amount = newValue;
            }
            this.amountOutstanding = calculateOutstanding();
            break;
        case PERCENT_OF_AMOUNT:
        case PERCENT_OF_AMOUNT_AND_INTEREST:
        case PERCENT_OF_INTEREST:
        case PERCENT_OF_DISBURSEMENT_AMOUNT:
            this.percentage = newValue;
            this.amountPercentageAppliedTo = amount;
            loanCharge = BigDecimal.ZERO;
            if (isInstalmentFee()) {
                loanCharge = this.loan.calculatePerInstallmentChargeAmount(
                        ChargeCalculationType.fromInt(this.chargeCalculation), this.percentage);
            }
            if (loanCharge.compareTo(BigDecimal.ZERO) == 0) {
                loanCharge = percentageOf(this.amountPercentageAppliedTo);
            }
            this.amount = minimumAndMaximumCap(loanCharge);
            this.amountOutstanding = calculateOutstanding();
            break;
        }
        this.amountOrPercentage = newValue;
        if (isInstalmentFee()) {
            updateInstallmentCharges();
        }
    }
    return actualChanges;
}

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

License:Apache License

public LoanInterestRecalcualtionAdditionalDetails(final LocalDate effectiveDate, final BigDecimal amount) {
    if (effectiveDate != null) {
        this.effectiveDate = effectiveDate.toDate();
    }//from   w w  w .jav  a 2  s .c om
    this.amount = amount;
}