Search in sources :

Example 51 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanAdjustmentsIntegrationTest method testWhenACompletedLoanIsAdjustedItGoesBackToBadStandingIfNecessary.

@Test
public void testWhenACompletedLoanIsAdjustedItGoesBackToBadStandingIfNecessary() throws Exception {
    // relates to mifos-3479
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
    loan = createLoan();
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // pay 3 installments
    makePayment(loan, "333.0");
    loan.updateDetails(TestUtils.makeUserWithLocales());
    makeEarlyPayment(loan);
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // ensure loan is in bad standing when reopened
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 11, 13));
    adjustLastLoanPayment(loan);
    loan.updateDetails(TestUtils.makeUserWithLocales());
    AccountStateEntity currentStatus = loan.getAccountState();
    assertTrue("Current Status Should Have Been LOAN_ACTIVE_IN_BAD_STANDING", currentStatus.isInState(AccountState.LOAN_ACTIVE_IN_BAD_STANDING));
}
Also used : AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Test(org.junit.Test)

Example 52 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanScheduleEntityIntegrationTest method testMakeEarlyRepaymentEnteriesForNotPayingFee.

@Test
public void testMakeEarlyRepaymentEnteriesForNotPayingFee() {
    for (AccountActionDateEntity accountAction : groupLoan.getAccountActionDates()) {
        LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction;
        Money preRepaymentInterest = accountActionDateEntity.getInterest();
        Money preRepaymentPenalty = accountActionDateEntity.getPenalty();
        Money preRepaymentMiscFee = accountActionDateEntity.getMiscFee();
        accountActionDateEntity.makeEarlyRepaymentEntries(LoanConstants.DONOT_PAY_FEES_PENALTY_INTEREST, accountActionDateEntity.getInterestDue(), new DateTimeService().getCurrentJavaSqlDate());
        Assert.assertEquals(accountActionDateEntity.getPrincipal(), accountActionDateEntity.getPrincipalPaid());
        Assert.assertEquals(accountActionDateEntity.getInterest(), preRepaymentInterest);
        Assert.assertEquals(accountActionDateEntity.getPenalty(), preRepaymentPenalty);
        Assert.assertEquals(accountActionDateEntity.getMiscFee(), preRepaymentMiscFee);
        Assert.assertTrue(accountActionDateEntity.isPaid());
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) DateTimeService(org.mifos.framework.util.DateTimeService) Test(org.junit.Test)

Example 53 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanScheduleEntityIntegrationTest method testMakeEarlyRepaymentEnteriesForFeePayment.

@Test
public void testMakeEarlyRepaymentEnteriesForFeePayment() {
    for (AccountActionDateEntity accountAction : groupLoan.getAccountActionDates()) {
        LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction;
        accountActionDateEntity.makeEarlyRepaymentEntries(LoanConstants.PAY_FEES_PENALTY_INTEREST, accountActionDateEntity.getInterestDue(), new DateTimeService().getCurrentJavaSqlDate());
        Assert.assertEquals(accountActionDateEntity.getPrincipal(), accountActionDateEntity.getPrincipalPaid());
        Assert.assertEquals(accountActionDateEntity.getInterest(), accountActionDateEntity.getInterestPaid());
        Assert.assertEquals(accountActionDateEntity.getPenalty(), accountActionDateEntity.getPenaltyPaid());
        Assert.assertEquals(accountActionDateEntity.getMiscFee(), accountActionDateEntity.getMiscFeePaid());
        Assert.assertTrue(accountActionDateEntity.isPaid());
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Test(org.junit.Test)

Example 54 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class SavingsBO method createDepositTrxnsForMandatoryAccountsAfterAdjust.

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;
    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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 55 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class SavingsBO method createDepositTrxnsForVolAccountsAfterAdjust.

/*
     * FIXME - keithw - it doesnt make sense to be that voluntary account break up account payments into more than one account transaction
     * just because the amount deposited is greater than the 'recommended' amount.
     *
     * As a result there is no need to make a distinction between the amount deposited (be it less or greater than recommended amount)
     */
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;
    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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8