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.accounts.savings.business.SavingsBO.java

License:Open Source License

/**
 * Responsible for creating savings account in valid initial state.
 *///from w w  w  .  ja v a2s.  co m
public static SavingsBO createIndividalSavingsAccount(CustomerBO customer, SavingsOfferingBO savingsProduct,
        Money recommendedOrMandatoryAmount, AccountState savingsAccountState, LocalDate createdDate,
        Integer createdById, CalendarEvent calendarEvents, PersonnelBO createdBy) {

    LocalDate activationDate = new LocalDate();
    SavingsAccountActivationDetail activationDetails = determineAccountActivationDetails(customer,
            savingsProduct, recommendedOrMandatoryAmount, savingsAccountState, calendarEvents, activationDate);

    Money startingBalance = Money.zero(savingsProduct.getCurrency());
    RecommendedAmountUnit recommendedAmountUnit = RecommendedAmountUnit.COMPLETE_GROUP;
    CreationDetail creationDetail = new CreationDetail(createdDate.toDateMidnight().toDateTime(), createdById);
    SavingsBO savingsAccount = new SavingsBO(savingsAccountState, customer, activationDetails, creationDetail,
            savingsProduct, recommendedAmountUnit, recommendedOrMandatoryAmount, createdBy, startingBalance);

    return savingsAccount;
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

public static SavingsBO createJointSavingsAccount(CustomerBO customer, SavingsOfferingBO savingsProduct,
        Money recommendedOrMandatoryAmount, AccountState savingsAccountState, LocalDate createdDate,
        Integer createdById, CalendarEvent calendarEvents, PersonnelBO createdBy,
        List<CustomerBO> activeAndOnHoldClients) {

    SavingsAccountActivationDetail activationDetails = determineAccountActivationDetails(customer,
            savingsProduct, recommendedOrMandatoryAmount, savingsAccountState, calendarEvents,
            activeAndOnHoldClients);//  www  .j  av a  2  s  . com

    Money startingBalance = Money.zero(savingsProduct.getCurrency());
    RecommendedAmountUnit recommendedAmountUnit = RecommendedAmountUnit.PER_INDIVIDUAL;
    CreationDetail creationDetail = new CreationDetail(createdDate.toDateMidnight().toDateTime(), createdById);
    SavingsBO savingsAccount = new SavingsBO(savingsAccountState, customer, activationDetails, creationDetail,
            savingsProduct, recommendedAmountUnit, recommendedOrMandatoryAmount, createdBy, startingBalance);

    return savingsAccount;
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

private void doPostInterest(LocalDate currentPostingDate, Money actualInterestToBePosted,
        PersonnelBO loggedInUser) {//  ww w  .  ja  va  2  s. co m
    this.savingsBalance = this.savingsBalance.add(actualInterestToBePosted);
    this.savingsPerformance.setTotalInterestDetails(actualInterestToBePosted);

    SavingsActivityEntity savingsActivity = SavingsActivityEntity.savingsInterestPosting(this, personnel,
            this.savingsBalance, actualInterestToBePosted, currentPostingDate.toDateMidnight().toDate());
    savingsActivityDetails.add(savingsActivity);

    AccountPaymentEntity interestPayment = AccountPaymentEntity.savingsInterestPosting(this,
            actualInterestToBePosted, currentPostingDate.toDateMidnight().toDate(), loggedInUser);

    DateTime dueDate = new DateTime();
    SavingsTrxnDetailEntity interestPostingTransaction = SavingsTrxnDetailEntity.savingsInterestPosting(
            interestPayment, this.customer, this.savingsBalance, currentPostingDate.toDateMidnight().toDate(),
            dueDate, loggedInUser);

    interestPayment.addAccountTrxn(interestPostingTransaction);
    this.addAccountPayment(interestPayment);

    // NOTE: financial Transaction Processing should be decoupled from application domain model.
    try {
        BaseFinancialActivity baseFinancialActivity = new SavingsInterestPostingFinancialActivity(
                interestPostingTransaction);
        baseFinancialActivity.buildAccountEntries();
    } catch (FinancialException e) {
        throw new MifosRuntimeException(e);
    }
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

public void updatePostingDetails(LocalDate nextPostingDate) {
    this.lastIntPostDate = this.nextIntPostDate;
    this.nextIntPostDate = nextPostingDate.toDateMidnight().toDate();
    this.interestToBePosted = Money.zero(this.getCurrency());
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

private Set<AccountTrxnEntity> createNewAccountPaymentWithAdjustedAmount(Money amountAdjustedTo,
        PersonnelBO updatedBy, AccountPaymentEntity payment, AccountActionTypes savingsTransactionType,
        Date adjustedOn, LocalDate adjustmentDate) {

    AccountPaymentEntity newAccountPayment = new AccountPaymentEntity(this, amountAdjustedTo,
            payment.getReceiptNumber(), payment.getReceiptDate(), payment.getPaymentType(),
            adjustmentDate.toDateMidnight().toDate());
    newAccountPayment.setCreatedByUser(updatedBy);
    newAccountPayment.setAmount(amountAdjustedTo);

    Set<AccountTrxnEntity> accountTrxns = new HashSet<AccountTrxnEntity>();
    if (isMandatory() && savingsTransactionType.equals(AccountActionTypes.SAVINGS_DEPOSIT)) {
        accountTrxns = createDepositTrxnsForMandatoryAccountsAfterAdjust(newAccountPayment, payment,
                amountAdjustedTo, adjustmentDate, updatedBy);
    } else if (isVoluntary() && savingsTransactionType.equals(AccountActionTypes.SAVINGS_DEPOSIT)) {
        accountTrxns = createDepositTrxnsForVolAccountsAfterAdjust(newAccountPayment, payment, amountAdjustedTo,
                adjustmentDate, updatedBy);
    } else {//from www  .  ja  va 2  s . co  m
        accountTrxns = createWithdrawalTrxnsAfterAdjust(newAccountPayment, payment, amountAdjustedTo,
                adjustmentDate, updatedBy);
    }

    for (AccountTrxnEntity accountTrxn : accountTrxns) {
        newAccountPayment.addAccountTrxn(accountTrxn);
    }

    this.addAccountPayment(newAccountPayment);

    AccountActionEntity depositOrWithdrawalTransactionType = new AccountActionEntity(savingsTransactionType);
    SavingsActivityEntity depositOrWithdrawalActivity = new SavingsActivityEntity(updatedBy,
            depositOrWithdrawalTransactionType, amountAdjustedTo, this.savingsBalance, adjustedOn, this);
    this.savingsActivityDetails.add(depositOrWithdrawalActivity);
    return newAccountPayment.getAccountTrxns();
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

private Set<AccountTrxnEntity> createWithdrawalTrxnsAfterAdjust(final AccountPaymentEntity newAccountPayment,
        final AccountPaymentEntity lastAccountPayment, final Money newAmount, final LocalDate adjustmentDate,
        PersonnelBO loggedInUser) {/*  w  w  w  . j av a 2  s .  c  om*/

    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;

    // create transaction for withdrawal
    SavingsTrxnDetailEntity oldSavingsAccntTrxn = null;

    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;
        break;
    }

    this.savingsBalance = this.savingsBalance.subtract(newAmount);

    Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
    accountTrxn = SavingsTrxnDetailEntity.savingsWithdrawal(newAccountPayment,
            oldSavingsAccntTrxn.getCustomer(), newAmount, newAmount, loggedInUser,
            oldSavingsAccntTrxn.getDueDate(), adjustmentDate.toDateMidnight().toDate(), transactionCreatedDate);

    this.savingsPerformance.setTotalWithdrawals(
            this.savingsPerformance.getTotalWithdrawals().add(accountTrxn.getWithdrawlAmount()));
    newTrxns.add(accountTrxn);
    return newTrxns;
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

private Set<AccountTrxnEntity> createDepositTrxnsForMandatoryAccountsAfterAdjust(
        final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment,
        Money newAmount, LocalDate adjustmentDate, PersonnelBO createdBy) {

    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;
    CustomerBO customer = null;// w ww. j a v a  2s  . c  o  m
    Date trxnDate = adjustmentDate.toDateMidnight().toDate();

    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        customer = oldAccntTrxn.getCustomer();
        break;
    }

    List<AccountActionDateEntity> accountActionList = getAccountActions(lastAccountPayment.getPaymentDate(),
            customer.getCustomerId());
    for (AccountActionDateEntity accountActionDateEntity : accountActionList) {
        SavingsScheduleEntity accountAction = (SavingsScheduleEntity) accountActionDateEntity;
        if (newAmount.isZero()) {
            break;
        }
        accountTrxn = null;

        // if payment covers required deposit
        if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {
            this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());

            Short installmentId = accountAction.getInstallmentId();
            Date dueDate = accountAction.getActionDate();
            Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
            accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer,
                    this.savingsBalance, accountAction.getDeposit(), createdBy, dueDate, trxnDate,
                    transactionCreatedDate, installmentId);

            newAmount = newAmount.subtract(accountAction.getDeposit());

            accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
            accountAction.setPaymentStatus(PaymentStatus.PAID);

        } else {
            this.savingsBalance = this.savingsBalance.add(newAmount);

            Short installmentId = accountAction.getInstallmentId();
            Date dueDate = accountAction.getActionDate();
            Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
            accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer,
                    this.savingsBalance, newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate,
                    installmentId);

            newAmount = newAmount.subtract(newAmount);
            accountAction.setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
            accountAction.setPaymentStatus(PaymentStatus.UNPAID);
        }
        accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
        getSavingsPerformance().setTotalDeposits(
                getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
        newTrxns.add(accountTrxn);
    }

    // add trxn for excess amount
    if (newAmount.isGreaterThanZero()) {
        this.savingsBalance = this.savingsBalance.add(newAmount);
        Short installmentId = null;
        Date dueDate = null;
        Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();
        accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance,
                newAmount, createdBy, dueDate, trxnDate, transactionCreatedDate, installmentId);

        newAmount = newAmount.subtract(newAmount);
        getSavingsPerformance().setTotalDeposits(
                getSavingsPerformance().getTotalDeposits().add(accountTrxn.getDepositAmount()));
        newTrxns.add(accountTrxn);
    }
    return newTrxns;
}

From source file:org.mifos.accounts.savings.business.SavingsBO.java

License:Open Source License

private Set<AccountTrxnEntity> createDepositTrxnsForVolAccountsAfterAdjust(
        final AccountPaymentEntity newAccountPayment, final AccountPaymentEntity lastAccountPayment,
        Money newAmount, LocalDate adjustmentDate, PersonnelBO loggedInUser) {

    Set<AccountTrxnEntity> newTrxns = new LinkedHashSet<AccountTrxnEntity>();
    SavingsTrxnDetailEntity accountTrxn = null;
    CustomerBO customer = null;//  www .j a  va 2s.  c  o  m
    Date trxnDate = adjustmentDate.toDateMidnight().toDate();

    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {
        customer = oldAccntTrxn.getCustomer();
        break;
    }

    Short installmentId = null;
    Date dueDate = null;
    Date transactionCreatedDate = new DateTimeService().getCurrentJavaDateTime();

    for (AccountTrxnEntity oldAccntTrxn : lastAccountPayment.getAccountTrxns()) {

        if (oldAccntTrxn.getAccountActionEntity().getId()
                .equals(AccountActionTypes.SAVINGS_DEPOSIT.getValue())) {
            SavingsTrxnDetailEntity oldSavingsAccntTrxn = (SavingsTrxnDetailEntity) oldAccntTrxn;

            if (oldAccntTrxn.getInstallmentId() != null) {
                SavingsScheduleEntity accountAction = (SavingsScheduleEntity) getAccountActionDate(
                        oldSavingsAccntTrxn.getInstallmentId(),
                        oldSavingsAccntTrxn.getCustomer().getCustomerId());

                installmentId = accountAction.getInstallmentId();
                dueDate = accountAction.getActionDate();

                // if recommended amount is covered by payment
                if (accountAction.getDeposit().isLessThanOrEqual(newAmount)) {

                    this.savingsBalance = this.savingsBalance.add(accountAction.getDeposit());

                    accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer,
                            this.savingsBalance, accountAction.getDeposit(), loggedInUser, dueDate, trxnDate,
                            transactionCreatedDate, installmentId);

                    newAmount = newAmount.subtract(accountAction.getDeposit());
                    accountAction
                            .setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
                    accountAction.setPaymentStatus(PaymentStatus.PAID);
                    accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
                    this.savingsPerformance.setTotalDeposits(
                            this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
                } else if (newAmount.isNonZero()) {
                    // not zero and amount paid is less that recommended amount
                    this.savingsBalance = this.savingsBalance.add(newAmount);

                    accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer,
                            this.savingsBalance, newAmount, loggedInUser, dueDate, trxnDate,
                            transactionCreatedDate, installmentId);

                    newAmount = newAmount.subtract(newAmount);
                    accountAction
                            .setDepositPaid(accountAction.getDepositPaid().add(accountTrxn.getDepositAmount()));
                    accountAction.setPaymentStatus(PaymentStatus.UNPAID);
                    accountAction.setPaymentDate(new DateTimeService().getCurrentJavaSqlDate());
                    this.savingsPerformance.setTotalDeposits(
                            this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
                }
                break;
            }
        }
    }

    if (accountTrxn != null) {
        newTrxns.add(accountTrxn);
    }

    // Create a new transaction with remaining amount
    if (newAmount.isGreaterThanZero()) {
        this.savingsBalance = this.savingsBalance.add(newAmount);

        accountTrxn = SavingsTrxnDetailEntity.savingsDeposit(newAccountPayment, customer, this.savingsBalance,
                newAmount, loggedInUser, dueDate, trxnDate, transactionCreatedDate, installmentId);

        this.savingsPerformance.setTotalDeposits(
                this.savingsPerformance.getTotalDeposits().add(accountTrxn.getDepositAmount()));
        newTrxns.add(accountTrxn);
    }
    return newTrxns;
}

From source file:org.mifos.accounts.savings.persistence.SavingsDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   ww  w .  j  a  va  2 s  .com
public List<Integer> retrieveAllActiveAndInActiveSavingsAccountsPendingInterestPostingOn(
        LocalDate interestPostingDate) {

    List<Integer> postingPendingAccounts = new ArrayList<Integer>();

    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("currentDate", interestPostingDate.toDateMidnight().toDate());
    List<Integer> queryResult = (List<Integer>) this.baseDao
            .executeNamedQuery("accounts.retrieveSavingsAccountsIntPost", queryParameters);
    if (queryResult != null) {
        postingPendingAccounts = new ArrayList<Integer>(queryResult);
    }

    return postingPendingAccounts;
}

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

License:Open Source License

@Override
public void applyLoanRepayment(String globalAccountNumber, LocalDate paymentDate, BigDecimal repaymentAmount,
        String receiptId, LocalDate receiptDate, Short modeOfPayment) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {/*from  w ww  .  j a v  a 2  s.  c o m*/
        this.transactionHelper.startTransaction();
        LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNumber);
        PersonnelBO personnel = personnelDao.findPersonnelById((short) user.getUserId());

        Money outstandingOverpayment = loan.applyNewPaymentMechanism(paymentDate, repaymentAmount, personnel,
                receiptId, receiptDate, modeOfPayment);

        // 3. pay off principal of next installment and recalculate interest if 'over paid'
        if (outstandingOverpayment.isGreaterThanZero()) {

            Money totalPrincipalDueNow = loan.getTotalPrincipalDue().subtract(outstandingOverpayment);

            // assemble into domain entities
            LoanOfferingBO loanProduct = this.loanProductDao
                    .findById(loan.getLoanOffering().getPrdOfferingId().intValue());
            CustomerBO customer = this.customerDao.findCustomerById(loan.getCustomer().getCustomerId());

            List<AccountFeesEntity> accountFeeEntities = new ArrayList<AccountFeesEntity>();

            Integer unpaidInstallments = loan.getDetailsOfUnpaidInstallmentsOn(paymentDate).size();

            Integer gracePeriodDiff = loan.getNoOfInstallments().intValue()
                    - loan.getGracePeriodDuration().intValue();

            Integer gracePeriodsRemaining = unpaidInstallments - gracePeriodDiff;

            LocalDate disbursementDate = new LocalDate(loan.getDetailsOfUpcomigInstallment().getActionDate());

            LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(totalPrincipalDueNow,
                    disbursementDate, loan.getInterestRate(), unpaidInstallments, gracePeriodsRemaining,
                    accountFeeEntities, new ArrayList<AccountPenaltiesEntity>());

            Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
            boolean loanScheduleIndependentOfCustomerMeetingEnabled = false;

            MeetingBO loanMeeting = customer.getCustomerMeetingValue();
            if (loanScheduleIndependentOfCustomerMeetingEnabled) {
                RecurringSchedule createLoanSchedule = new MonthlyOnDayOfMonthSchedule(Integer.valueOf(1),
                        Integer.valueOf(5));
                loanMeeting = this.createNewMeetingForRepaymentDay(disbursementDate, createLoanSchedule,
                        customer);

                if (loanProduct.isVariableInstallmentsAllowed()) {
                    loanMeeting.setMeetingStartDate(disbursementDate.toDateMidnight().toDate());
                }
            }

            LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(
                    loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);

            Short userBranchOfficeId = userContext.getBranchId();

            LoanSchedule loanSchedule = this.loanScheduleService.generate(loanProduct, customer, loanMeeting,
                    overridenDetail, configuration, userBranchOfficeId, accountFeeEntities, disbursementDate);

            loan.rescheduleRemainingUnpaidInstallments(loanSchedule, paymentDate);

            loan.recordOverpayment(outstandingOverpayment, paymentDate, personnel, receiptId, receiptDate,
                    modeOfPayment);
        }

        this.loanDao.save(loan);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (AccountException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.transactionHelper.closeSession();
    }
}