Example usage for org.joda.time LocalDate now

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

Introduction

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

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

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

License:Apache License

public ChangedTransactionDetail disburse(final AppUser currentUser, final JsonCommand command,
        final Map<String, Object> actualChanges, final ScheduleGeneratorDTO scheduleGeneratorDTO,
        final PaymentDetail paymentDetail) {

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

    final LocalDate actualDisbursementDate = command.localDateValueOfParameterNamed("actualDisbursementDate");

    this.loanStatus = statusEnum.getValue();
    actualChanges.put("status", LoanEnumerations.status(this.loanStatus));

    this.disbursedBy = currentUser;
    updateLoanScheduleDependentDerivedFields();

    actualChanges.put("locale", command.locale());
    actualChanges.put("dateFormat", command.dateFormat());
    actualChanges.put("actualDisbursementDate", command.stringValueOfParameterNamed("actualDisbursementDate"));

    HolidayDetailDTO holidayDetailDTO = scheduleGeneratorDTO.getHolidayDetailDTO();

    // validate if disbursement date is a holiday or a non-working day
    validateDisbursementDateIsOnNonWorkingDay(holidayDetailDTO.getWorkingDays(),
            holidayDetailDTO.isAllowTransactionsOnNonWorkingDay());
    validateDisbursementDateIsOnHoliday(holidayDetailDTO.isAllowTransactionsOnHoliday(),
            holidayDetailDTO.getHolidays());

    if (this.repaymentScheduleDetail().isInterestRecalculationEnabled()
            && (fetchRepaymentScheduleInstallment(1).getDueDate().isBefore(LocalDate.now())
                    || isDisbursementMissed())) {
        regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
    }/*from w  w w .  j ava 2 s  . c  om*/

    updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());
    updateLoanRepaymentPeriodsDerivedFields(actualDisbursementDate);
    LocalDateTime createdDate = DateUtils.getLocalDateTimeOfTenant();
    handleDisbursementTransaction(actualDisbursementDate, createdDate, currentUser, paymentDetail);
    updateLoanSummaryDerivedFields();
    final Money interestApplied = Money.of(getCurrency(), this.summary.getTotalInterestCharged());

    /**
     * Add an interest applied transaction of the interest is accrued
     * upfront (Up front accrual), no accounting or cash based accounting is
     * selected
     **/

    if (isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()
            && ((isMultiDisburmentLoan() && getDisbursedLoanDisbursementDetails().size() == 1)
                    || !isMultiDisburmentLoan())) {
        final LoanTransaction interestAppliedTransaction = LoanTransaction.accrueInterest(getOffice(), this,
                interestApplied, actualDisbursementDate, createdDate, currentUser);
        addLoanTransaction(interestAppliedTransaction);
    }

    return reprocessTransactionForDisbursement();

}

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

License:Apache License

private boolean isDisbursementMissed() {
    boolean isDisbursementMissed = false;
    for (LoanDisbursementDetails disbursementDetail : this.disbursementDetails) {
        if (disbursementDetail.actualDisbursementDate() == null
                && LocalDate.now().isAfter(disbursementDetail.expectedDisbursementDateAsLocalDate())) {
            isDisbursementMissed = true;
            break;
        }/*  w w  w. j av a  2 s.c o  m*/
    }
    return isDisbursementMissed;
}

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

License:Apache License

private LoanRepaymentScheduleInstallment getTotalOutstandingOnLoan() {
    Money feeCharges = Money.zero(loanCurrency());
    Money penaltyCharges = Money.zero(loanCurrency());
    Money totalPrincipal = Money.zero(loanCurrency());
    Money totalInterest = Money.zero(loanCurrency());
    final Set<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null;
    List<LoanRepaymentScheduleInstallment> repaymentSchedule = getRepaymentScheduleInstallments();
    for (final LoanRepaymentScheduleInstallment scheduledRepayment : repaymentSchedule) {
        totalPrincipal = totalPrincipal.plus(scheduledRepayment.getPrincipalOutstanding(loanCurrency()));
        totalInterest = totalInterest.plus(scheduledRepayment.getInterestOutstanding(loanCurrency()));
        feeCharges = feeCharges.plus(scheduledRepayment.getFeeChargesOutstanding(loanCurrency()));
        penaltyCharges = penaltyCharges.plus(scheduledRepayment.getPenaltyChargesOutstanding(loanCurrency()));
    }/*from   w ww.  java  2 s .  c o m*/
    return new LoanRepaymentScheduleInstallment(null, 0, LocalDate.now(), LocalDate.now(),
            totalPrincipal.getAmount(), totalInterest.getAmount(), feeCharges.getAmount(),
            penaltyCharges.getAmount(), false, compoundingDetails);
}

From source file:com.gst.portfolio.loanaccount.guarantor.service.GuarantorDomainServiceImpl.java

License:Apache License

/**
 * Method is to recover funds from guarantor's in case loan is unpaid.
 * (Transfers guarantee amount from guarantor's account to loan account and
 * releases guarantor)/*from  w  ww. j av  a 2 s  . c  o m*/
 */
@Override
public void transaferFundsFromGuarantor(final Loan loan) {
    if (loan.getGuaranteeAmount().compareTo(BigDecimal.ZERO) != 1) {
        return;
    }
    final List<Guarantor> existGuarantorList = this.guarantorRepository.findByLoan(loan);
    final boolean isRegularTransaction = true;
    final boolean isExceptionForBalanceCheck = true;
    LocalDate transactionDate = LocalDate.now();
    PortfolioAccountType fromAccountType = PortfolioAccountType.SAVINGS;
    PortfolioAccountType toAccountType = PortfolioAccountType.LOAN;
    final Long toAccountId = loan.getId();
    final String description = "Payment from guarantor savings";
    final Locale locale = null;
    final DateTimeFormatter fmt = null;
    final PaymentDetail paymentDetail = null;
    final Integer fromTransferType = null;
    final Integer toTransferType = null;
    final Long chargeId = null;
    final Integer loanInstallmentNumber = null;
    final Integer transferType = AccountTransferType.LOAN_REPAYMENT.getValue();
    final AccountTransferDetails accountTransferDetails = null;
    final String noteText = null;

    final String txnExternalId = null;
    final SavingsAccount toSavingsAccount = null;

    Long loanId = loan.getId();

    for (Guarantor guarantor : existGuarantorList) {
        final List<GuarantorFundingDetails> fundingDetails = guarantor.getGuarantorFundDetails();
        for (GuarantorFundingDetails guarantorFundingDetails : fundingDetails) {
            if (guarantorFundingDetails.getStatus().isActive()) {
                final SavingsAccount fromSavingsAccount = guarantorFundingDetails.getLinkedSavingsAccount();
                final Long fromAccountId = fromSavingsAccount.getId();
                releaseLoanIds.put(loanId, guarantorFundingDetails.getId());
                try {
                    BigDecimal remainingAmount = guarantorFundingDetails.getAmountRemaining();
                    if (loan.getGuaranteeAmount().compareTo(loan.getPrincpal().getAmount()) == 1) {
                        remainingAmount = remainingAmount.multiply(loan.getPrincpal().getAmount())
                                .divide(loan.getGuaranteeAmount(), MoneyHelper.getRoundingMode());
                    }
                    AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate,
                            remainingAmount, fromAccountType, toAccountType, fromAccountId, toAccountId,
                            description, locale, fmt, paymentDetail, fromTransferType, toTransferType, chargeId,
                            loanInstallmentNumber, transferType, accountTransferDetails, noteText,
                            txnExternalId, loan, toSavingsAccount, fromSavingsAccount, isRegularTransaction,
                            isExceptionForBalanceCheck);
                    transferAmount(accountTransferDTO);
                } finally {
                    releaseLoanIds.remove(loanId);
                }
            }
        }
    }

}

From source file:com.gst.portfolio.loanaccount.guarantor.service.GuarantorWritePlatformServiceJpaRepositoryIImpl.java

License:Apache License

private CommandProcessingResult createGuarantor(final Loan loan, final JsonCommand command,
        final GuarantorCommand guarantorCommand, final Collection<Guarantor> existGuarantorList) {
    try {//from   ww  w.ja  v a2s .c om
        guarantorCommand.validateForCreate();
        validateLoanStatus(loan);
        final List<GuarantorFundingDetails> guarantorFundingDetails = new ArrayList<>();
        AccountAssociations accountAssociations = null;
        if (guarantorCommand.getSavingsId() != null) {
            final SavingsAccount savingsAccount = this.savingsAccountAssembler
                    .assembleFrom(guarantorCommand.getSavingsId());
            accountAssociations = AccountAssociations.associateSavingsAccount(loan, savingsAccount,
                    AccountAssociationType.GUARANTOR_ACCOUNT_ASSOCIATION.getValue(), true);

            GuarantorFundingDetails fundingDetails = new GuarantorFundingDetails(accountAssociations,
                    GuarantorFundStatusType.ACTIVE.getValue(), guarantorCommand.getAmount());
            guarantorFundingDetails.add(fundingDetails);
            if (loan.isDisbursed() || loan.isApproved() && (loan.getGuaranteeAmount() != null
                    || loan.loanProduct().isHoldGuaranteeFundsEnabled())) {
                this.guarantorDomainService.assignGuarantor(fundingDetails, LocalDate.now());
                loan.updateGuaranteeAmount(fundingDetails.getAmount());
            }
        }

        final Long clientRelationshipId = guarantorCommand.getClientRelationshipTypeId();
        CodeValue clientRelationshipType = null;

        if (clientRelationshipId != null) {
            clientRelationshipType = this.codeValueRepositoryWrapper
                    .findOneByCodeNameAndIdWithNotFoundDetection(
                            GuarantorConstants.GUARANTOR_RELATIONSHIP_CODE_NAME, clientRelationshipId);
        }

        final Long entityId = guarantorCommand.getEntityId();
        final Integer guarantorTypeId = guarantorCommand.getGuarantorTypeId();
        Guarantor guarantor = null;
        for (final Guarantor avilableGuarantor : existGuarantorList) {
            if (entityId != null && avilableGuarantor.getEntityId() != null
                    && avilableGuarantor.getEntityId().equals(entityId)
                    && avilableGuarantor.getGurantorType().equals(guarantorTypeId)
                    && avilableGuarantor.isActive()) {
                if (guarantorCommand.getSavingsId() == null
                        || avilableGuarantor.hasGuarantor(guarantorCommand.getSavingsId())) {
                    /** Get the right guarantor based on guarantorType **/
                    String defaultUserMessage = null;
                    if (guarantorTypeId.equals(GuarantorType.STAFF.getValue())) {
                        defaultUserMessage = this.staffRepositoryWrapper.findOneWithNotFoundDetection(entityId)
                                .displayName();
                    } else {
                        defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId)
                                .getDisplayName();
                    }

                    defaultUserMessage = defaultUserMessage + " is already exist as a guarantor for this loan";
                    final String action = loan.client() != null ? "client.guarantor" : "group.guarantor";
                    throw new DuplicateGuarantorException(action, "is.already.exist.same.loan",
                            defaultUserMessage, entityId, loan.getId());
                }
                guarantor = avilableGuarantor;
                break;
            }
        }

        if (guarantor == null) {
            guarantor = Guarantor.fromJson(loan, clientRelationshipType, command, guarantorFundingDetails);
        } else {
            guarantor.addFundingDetails(guarantorFundingDetails);
        }
        validateGuarantorBusinessRules(guarantor);
        for (GuarantorFundingDetails fundingDetails : guarantorFundingDetails) {
            fundingDetails.updateGuarantor(guarantor);
        }

        if (accountAssociations != null) {
            this.accountAssociationsRepository.save(accountAssociations);
        }
        this.guarantorRepository.save(guarantor);
        return new CommandProcessingResultBuilder().withCommandId(command.commandId())
                .withOfficeId(guarantor.getOfficeId()).withEntityId(guarantor.getId()).withLoanId(loan.getId())
                .build();
    } catch (final DataIntegrityViolationException dve) {
        handleGuarantorDataIntegrityIssues(dve);
        return CommandProcessingResult.empty();
    }
}

From source file:com.gst.portfolio.loanaccount.guarantor.service.GuarantorWritePlatformServiceJpaRepositoryIImpl.java

License:Apache License

private void removeguarantorFundDetails(final Guarantor guarantorForDelete,
        final DataValidatorBuilder baseDataValidator, GuarantorFundingDetails guarantorFundingDetails) {
    if (!guarantorFundingDetails.getStatus().isActive()) {
        baseDataValidator//  w ww  .  ja va2s  .c o  m
                .failWithCodeNoParameterAddedToErrorCode(GuarantorConstants.GUARANTOR_NOT_ACTIVE_ERROR);
    }
    GuarantorFundStatusType fundStatusType = GuarantorFundStatusType.DELETED;
    if (guarantorForDelete.getLoan().isDisbursed() || guarantorForDelete.getLoan().isApproved()) {
        fundStatusType = GuarantorFundStatusType.WITHDRAWN;
        this.guarantorDomainService.releaseGuarantor(guarantorFundingDetails, LocalDate.now());
    }
    guarantorForDelete.updateStatus(guarantorFundingDetails, fundStatusType);
}

From source file:com.gst.portfolio.loanaccount.service.LoanAccrualPlatformServiceImpl.java

License:Apache License

@Override
@CronTarget(jobName = JobName.ADD_PERIODIC_ACCRUAL_ENTRIES)
public void addPeriodicAccruals() throws JobExecutionException {
    String errors = addPeriodicAccruals(LocalDate.now());
    if (errors.length() > 0) {
        throw new JobExecutionException(errors);
    }//from ww  w  .ja va2s  .  c om
}

From source file:com.gst.portfolio.loanaccount.service.LoanArrearsAgingServiceImpl.java

License:Apache License

private String constructUpdateStatement(final Loan loan, boolean isInsertStatement) {
    String updateSql = null;//from  w ww  .jav  a  2 s .  co  m
    List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments();
    BigDecimal principalOverdue = BigDecimal.ZERO;
    BigDecimal interestOverdue = BigDecimal.ZERO;
    BigDecimal feeOverdue = BigDecimal.ZERO;
    BigDecimal penaltyOverdue = BigDecimal.ZERO;
    LocalDate overDueSince = LocalDate.now();
    for (LoanRepaymentScheduleInstallment installment : installments) {
        if (installment.getDueDate().isBefore(LocalDate.now())) {
            principalOverdue = principalOverdue
                    .add(installment.getPrincipalOutstanding(loan.getCurrency()).getAmount());
            interestOverdue = interestOverdue
                    .add(installment.getInterestOutstanding(loan.getCurrency()).getAmount());
            feeOverdue = feeOverdue.add(installment.getFeeChargesOutstanding(loan.getCurrency()).getAmount());
            penaltyOverdue = penaltyOverdue
                    .add(installment.getPenaltyChargesOutstanding(loan.getCurrency()).getAmount());
            if (installment.isNotFullyPaidOff() && overDueSince.isAfter(installment.getDueDate())) {
                overDueSince = installment.getDueDate();
            }
        }
    }

    BigDecimal totalOverDue = principalOverdue.add(interestOverdue).add(feeOverdue).add(penaltyOverdue);
    if (totalOverDue.compareTo(BigDecimal.ZERO) == 1) {
        if (isInsertStatement) {
            updateSql = constructInsertStatement(loan.getId(), principalOverdue, interestOverdue, feeOverdue,
                    penaltyOverdue, overDueSince);
        } else {
            updateSql = constructUpdateStatement(loan.getId(), principalOverdue, interestOverdue, feeOverdue,
                    penaltyOverdue, overDueSince);
        }
    }
    return updateSql;
}

From source file:com.gst.portfolio.loanaccount.service.LoanArrearsAgingServiceImpl.java

License:Apache License

private void createInsertStatements(List<String> insertStatement,
        Map<Long, List<LoanSchedulePeriodData>> scheduleDate, boolean isInsertStatement) {
    for (Map.Entry<Long, List<LoanSchedulePeriodData>> entry : scheduleDate.entrySet()) {
        final Long loanId = entry.getKey();
        BigDecimal principalOverdue = BigDecimal.ZERO;
        BigDecimal interestOverdue = BigDecimal.ZERO;
        BigDecimal feeOverdue = BigDecimal.ZERO;
        BigDecimal penaltyOverdue = BigDecimal.ZERO;
        LocalDate overDueSince = LocalDate.now();

        for (LoanSchedulePeriodData loanSchedulePeriodData : entry.getValue()) {
            if (!loanSchedulePeriodData.getComplete()) {
                principalOverdue = principalOverdue.add(
                        loanSchedulePeriodData.principalDue().subtract(loanSchedulePeriodData.principalPaid()));
                interestOverdue = interestOverdue.add(
                        loanSchedulePeriodData.interestDue().subtract(loanSchedulePeriodData.interestPaid()));
                feeOverdue = feeOverdue.add(loanSchedulePeriodData.feeChargesDue()
                        .subtract(loanSchedulePeriodData.feeChargesPaid()));
                penaltyOverdue = penaltyOverdue.add(loanSchedulePeriodData.penaltyChargesDue()
                        .subtract(loanSchedulePeriodData.penaltyChargesPaid()));
                if (overDueSince.isAfter(loanSchedulePeriodData.periodDueDate()) && loanSchedulePeriodData
                        .principalDue().subtract(loanSchedulePeriodData.principalPaid())
                        .compareTo(BigDecimal.ZERO) == 1) {
                    overDueSince = loanSchedulePeriodData.periodDueDate();
                }//from   www . j  a v  a  2 s  .  c om
            }
        }
        if (principalOverdue.compareTo(BigDecimal.ZERO) == 1) {
            String sqlStatement = null;
            if (isInsertStatement) {
                sqlStatement = constructInsertStatement(loanId, principalOverdue, interestOverdue, feeOverdue,
                        penaltyOverdue, overDueSince);
            } else {
                sqlStatement = constructUpdateStatement(loanId, principalOverdue, interestOverdue, feeOverdue,
                        penaltyOverdue, overDueSince);
            }
            insertStatement.add(sqlStatement);
        }

    }
}

From source file:com.gst.portfolio.loanaccount.service.LoanReadPlatformServiceImpl.java

License:Apache License

@Override
public LoanTransactionData retrieveLoanPrePaymentTemplate(final Long loanId, LocalDate onDate) {

    this.context.authenticatedUser();

    final Loan loan = this.loanRepositoryWrapper.findOneWithNotFoundDetection(loanId, true);
    loan.setHelpers(null, null, loanRepaymentScheduleTransactionProcessorFactory);

    final MonetaryCurrency currency = loan.getCurrency();
    final ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository
            .findOneWithNotFoundDetection(currency);

    final CurrencyData currencyData = applicationCurrency.toData();

    final LocalDate earliestUnpaidInstallmentDate = LocalDate.now();
    final LocalDate recalculateFrom = null;
    final ScheduleGeneratorDTO scheduleGeneratorDTO = loanUtilService.buildScheduleGeneratorDTO(loan,
            recalculateFrom);//  w w w.  j a v  a  2s . co  m
    final LoanRepaymentScheduleInstallment loanRepaymentScheduleInstallment = loan
            .fetchPrepaymentDetail(scheduleGeneratorDTO, onDate);
    final LoanTransactionEnumData transactionType = LoanEnumerations
            .transactionType(LoanTransactionType.REPAYMENT);
    final Collection<PaymentTypeData> paymentOptions = this.paymentTypeReadPlatformService
            .retrieveAllPaymentTypes();
    final BigDecimal outstandingLoanBalance = loanRepaymentScheduleInstallment.getPrincipalOutstanding(currency)
            .getAmount();
    final BigDecimal unrecognizedIncomePortion = null;
    return new LoanTransactionData(null, null, null, transactionType, null, currencyData,
            earliestUnpaidInstallmentDate,
            loanRepaymentScheduleInstallment.getTotalOutstanding(currency).getAmount(),
            loanRepaymentScheduleInstallment.getPrincipalOutstanding(currency).getAmount(),
            loanRepaymentScheduleInstallment.getInterestOutstanding(currency).getAmount(),
            loanRepaymentScheduleInstallment.getFeeChargesOutstanding(currency).getAmount(),
            loanRepaymentScheduleInstallment.getPenaltyChargesOutstanding(currency).getAmount(), null,
            unrecognizedIncomePortion, paymentOptions, null, null, null, outstandingLoanBalance, false);
}