Example usage for org.joda.time LocalDate toDateMidnight

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

Introduction

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

Prototype

@Deprecated
public DateMidnight toDateMidnight() 

Source Link

Document

Converts this LocalDate to a DateMidnight in the default time zone.

Usage

From source file:org.mifos.application.servicefacade.LoanAccountServiceFacadeWebTier.java

License:Open Source License

@Override
public Errors validateLoanDisbursementDate(LocalDate loanDisbursementDate, Integer customerId,
        Integer productId) {//from   w  w w . ja va2  s  . co m

    Errors errors = new Errors();

    if (loanDisbursementDate.isBefore(new LocalDate())) {
        String[] args = { "" };
        errors.addError("dibursementdate.cannot.be.before.todays.date", args);
    }

    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    LocalDate customerActivationDate = new LocalDate(customer.getCustomerActivationDate());
    if (loanDisbursementDate.isBefore(customerActivationDate)) {
        String[] args = { customerActivationDate.toString("dd-MMM-yyyy") };
        errors.addError("dibursementdate.before.customer.activation.date", args);
    }

    LoanOfferingBO loanProduct = this.loanProductDao.findById(productId);
    LocalDate productStartDate = new LocalDate(loanProduct.getStartDate());
    if (loanDisbursementDate.isBefore(productStartDate)) {
        String[] args = { productStartDate.toString("dd-MMM-yyyy") };
        errors.addError("dibursementdate.before.product.startDate", args);
    }

    try {
        this.holidayServiceFacade.validateDisbursementDateForNewLoan(customer.getOfficeId(),
                loanDisbursementDate.toDateMidnight().toDateTime());
    } catch (BusinessRuleException e) {
        String[] args = { "" };
        errors.addError("dibursementdate.falls.on.holiday", args);
    }

    boolean isRepaymentIndependentOfMeetingEnabled = new ConfigurationBusinessService()
            .isRepaymentIndepOfMeetingEnabled();

    LoanDisbursementDateFactory loanDisbursementDateFactory = new LoanDisbursmentDateFactoryImpl();
    LoanDisbursementDateValidator loanDisbursementDateFinder = loanDisbursementDateFactory.create(customer,
            loanProduct, isRepaymentIndependentOfMeetingEnabled, false);

    boolean isValid = loanDisbursementDateFinder
            .isDisbursementDateValidInRelationToSchedule(loanDisbursementDate);
    if (!isValid) {
        String[] args = { "" };
        errors.addError("dibursementdate.invalid.in.relation.to.meeting.schedule", args);
    }

    return errors;
}

From source file:org.mifos.application.servicefacade.LoanAccountServiceFacadeWebTier.java

License:Open Source License

@Override
public Errors validateLoanWithBackdatedPaymentsDisbursementDate(LocalDate loanDisbursementDate,
        Integer customerId, Integer productId) {
    Errors errors = new Errors();

    if (!loanDisbursementDate.isBefore(new LocalDate())) {
        String[] args = { "" };
        errors.addError("dibursementdate.before.todays.date", args);
    }//from  w ww .j  a  va  2 s.  c  o m

    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    LocalDate customerActivationDate = new LocalDate(customer.getCustomerActivationDate());
    if (loanDisbursementDate.isBefore(customerActivationDate)) {
        String[] args = { customerActivationDate.toString("dd-MMM-yyyy") };
        errors.addError("dibursementdate.before.customer.activation.date", args);
    }

    LoanOfferingBO loanProduct = this.loanProductDao.findById(productId);
    LocalDate productStartDate = new LocalDate(loanProduct.getStartDate());
    if (loanDisbursementDate.isBefore(productStartDate)) {
        String[] args = { productStartDate.toString("dd-MMM-yyyy") };
        errors.addError("dibursementdate.before.product.startDate", args);
    }

    try {
        this.holidayServiceFacade.validateDisbursementDateForNewLoan(customer.getOfficeId(),
                loanDisbursementDate.toDateMidnight().toDateTime());
    } catch (BusinessRuleException e) {
        String[] args = { "" };
        errors.addError("dibursementdate.falls.on.holiday", args);
    }

    return errors;
}

From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java

License:Open Source License

private void recalculateInterestPostings(Integer accountId, LocalDate affectingPaymentDate) {

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    PersonnelBO createdBy = this.personnelDao.findPersonnelById(userContext.getId());

    SavingsBO account = this.savingsDao.findById(accountId);

    Date paymentDate = affectingPaymentDate.toDateMidnight().toDate();

    int removedPostings = account.countInterestPostingsForRecalculation(paymentDate);

    if (removedPostings > 0) {
        this.savingsDao.prepareForInterestRecalculation(account, paymentDate);
        this.transactionHelper.flushSession();
        for (int i = 0; i < removedPostings; i++) {
            postInterestForAccount(accountId, userContext, createdBy, true);
        }// ww w.  ja v a  2  s  .c  o  m
    }
}

From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java

License:Open Source License

@Override
public String createSavingsAccount(OpeningBalanceSavingsAccount openingBalanceSavingsAccount) {

    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    LocalDate createdDate = new LocalDate();
    Integer createdById = user.getUserId();
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());

    CustomerBO customer = this.customerDao
            .findCustomerBySystemId(openingBalanceSavingsAccount.getCustomerGlobalId());
    SavingsOfferingBO savingsProduct = this.savingsProductDao
            .findBySystemId(openingBalanceSavingsAccount.getProductGlobalId());

    AccountState savingsAccountState = AccountState.fromShort(openingBalanceSavingsAccount.getAccountState());
    Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(),
            openingBalanceSavingsAccount.getRecommendedOrMandatoryAmount());
    Money openingBalance = new Money(savingsProduct.getCurrency(), new BigDecimal(0));

    LocalDate activationDate = openingBalanceSavingsAccount.getActivationDate();

    CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());

    SavingsAccountActivationDetail activationDetails = SavingsBO.generateAccountActivationDetails(customer,
            savingsProduct, recommendedOrMandatory, savingsAccountState, calendarEvents, activationDate);

    SavingsBO savingsAccount = SavingsBO.createOpeningBalanceIndividualSavingsAccount(customer, savingsProduct,
            recommendedOrMandatory, savingsAccountState, createdDate, createdById, activationDetails, createdBy,
            openingBalance);// w  w w  .j  a v a  2 s  . co m
    savingsAccount.setGlobalAccountNum(openingBalanceSavingsAccount.getAccountNumber());
    savingsAccount.setSavingsBalance(openingBalance);
    DateTimeService dateTimeService = new DateTimeService();
    savingsAccount.setDateTimeService(dateTimeService);
    openingBalance = new Money(savingsProduct.getCurrency(), openingBalanceSavingsAccount.getOpeningBalance());
    if (savingsAccountState.isActiveLoanAccountState()) {
        savingsAccount.resetRecommendedAmountOnFutureInstallments();
    }
    try {
        if (openingBalance.isGreaterThanZero()) {
            PaymentData paymentData = new PaymentData(openingBalance, createdBy, Short.valueOf("1"),
                    activationDate.toDateMidnight().toDate());
            paymentData.setCustomer(customer);
            savingsAccount.applyPayment(paymentData);
        }
        this.transactionHelper.startTransaction();
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.flushSession();
        //savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());

        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
        return savingsAccount.getGlobalAccountNum();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}

From source file:org.mifos.application.servicefacade.SavingsServiceFacadeWebTier.java

License:Open Source License

@Override
public SavingsAccountDepositDueDto retrieveDepositDueDetails(String globalAccountNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);

    SavingsBO savingsAccount = this.savingsDao.findBySystemId(globalAccountNum);

    try {//from   w  ww .ja va 2 s. c o m
        personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(),
                savingsAccount.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(e.getMessage(), e);
    }

    List<DueOnDateDto> previousDueDates = new ArrayList<DueOnDateDto>();

    SavingsScheduleEntity nextInstallment = (SavingsScheduleEntity) savingsAccount
            .getDetailsOfNextInstallment();
    Money totalDepositDue = Money.zero(savingsAccount.getCurrency());
    LocalDate nextDueDate = new LocalDate();
    if (nextInstallment != null) {
        nextDueDate = new LocalDate(nextInstallment.getActionDate());
        totalDepositDue = nextInstallment.getTotalDepositDue();
    }

    List<AccountActionDateEntity> scheduledDeposits = savingsAccount
            .getAccountActionDatesSortedByInstallmentId();
    for (AccountActionDateEntity scheduledDeposit : scheduledDeposits) {
        if (!scheduledDeposit.isPaid() && scheduledDeposit.isBefore(nextDueDate)) {
            SavingsScheduleEntity savingsScheduledDeposit = (SavingsScheduleEntity) scheduledDeposit;
            previousDueDates.add(new DueOnDateDto(scheduledDeposit.getActionDate(),
                    MoneyUtils.currencyRound(savingsScheduledDeposit.getTotalDepositDue()).toString()));
        }
    }

    DueOnDateDto nextDueDetail = new DueOnDateDto(
            new java.sql.Date(nextDueDate.toDateMidnight().toDate().getTime()),
            MoneyUtils.currencyRound(totalDepositDue).toString());

    AccountStateEntity accountStateEntity = savingsAccount.getAccountState();

    return new SavingsAccountDepositDueDto(nextDueDetail, previousDueDates, accountStateEntity.getId(),
            accountStateEntity.getName());
}

From source file:org.mifos.clientportfolio.loan.ui.LoanRepaymentRunningBalance.java

License:Open Source License

public LoanRepaymentRunningBalance(LoanCreationInstallmentDto installmentDetails, BigDecimal total,
        BigDecimal principal, BigDecimal interest, BigDecimal fees, BigDecimal totalInstallment,
        LocalDate paymentDate, Short paymentTypeId) {
    this.installmentDetails = installmentDetails;
    this.total = total;
    this.principal = principal;
    this.interest = interest;
    this.fees = fees;
    this.totalInstallment = totalInstallment;
    this.paymentDate = paymentDate.toDateMidnight().toDate();
    this.paymentTypeId = paymentTypeId;
}

From source file:org.mifos.clientportfolio.newloan.domain.LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl.java

License:Open Source License

@Override
public LocalDate findClosestMatchingDateFromAndInclusiveOf(LocalDate fromAndInclusiveOf) {

    LocalDate closestMatch = nextValidCustomerMeetingDate;
    if (closestMatch.isBefore(fromAndInclusiveOf)) {
        closestMatch = new LocalDate(
                scheduledEvent.nextEventDateAfter(closestMatch.toDateMidnight().toDateTime()));
        while (closestMatch.isBefore(fromAndInclusiveOf)) {
            closestMatch = new LocalDate(
                    scheduledEvent.nextEventDateAfter(closestMatch.toDateMidnight().toDateTime()));
        }//from w w w . j  ava  2 s  .  c om
    }
    return closestMatch;
}

From source file:org.mifos.clientportfolio.newloan.domain.LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl.java

License:Open Source License

@Override
public boolean isDisbursementDateValidInRelationToSchedule(LocalDate disbursementDate) {

    boolean result = false;

    if (disbursementDate.isEqual(this.nextValidCustomerMeetingDate)) {
        result = true;/*  w  w  w  . j  ava2  s  .c om*/
    } else if (disbursementDate.isAfter(this.nextValidCustomerMeetingDate)) {
        LocalDate matchingDate = this.nextValidCustomerMeetingDate;
        matchingDate = new LocalDate(
                scheduledEvent.nextEventDateAfter(matchingDate.toDateMidnight().toDateTime()));
        while (matchingDate.isBefore(disbursementDate)) {
            matchingDate = new LocalDate(
                    scheduledEvent.nextEventDateAfter(matchingDate.toDateMidnight().toDateTime()));
        }

        if (matchingDate.isEqual(disbursementDate)) {
            result = true;
        }
    }

    return result;
}

From source file:org.mifos.clientportfolio.newloan.domain.LoanScheduleRepaymentItemImpl.java

License:Open Source License

public LoanScheduleRepaymentItemImpl(Integer installmentNumber, LocalDate dueOnDate, Money principal,
        Money interest) {/*from  w w w.j  a  v a 2 s .co  m*/
    this.installmentNumber = installmentNumber;
    this.dueOnDate = dueOnDate.toDateMidnight().toDate();
    this.principal = principal;
    this.interest = interest;
    this.principalPaid = Money.zero(principal.getCurrency());
    this.interestPaid = Money.zero(principal.getCurrency());
    this.paymentStatus = PaymentStatus.UNPAID;
    this.paymentMadeOnDate = null;
}

From source file:org.mifos.clientportfolio.newloan.domain.LoanScheduleRepaymentItemImpl.java

License:Open Source License

public void setPaymentMadeOnDate(LocalDate paymentMadeOnDate) {
    this.paymentMadeOnDate = paymentMadeOnDate.toDateMidnight().toDate();
}