Search in sources :

Example 46 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class CustomerAccountBOIntegrationTest method verifyExpectedMessageThrown.

private void verifyExpectedMessageThrown(final CustomerBO customer, final Money paymentAmount, final Integer numberOfDaysForward, final String expectedErrorMessage) throws Exception {
    CustomerAccountBO customerAccount = customer.getCustomerAccount();
    Date transactionDate = incrementCurrentDate(numberOfDaysForward);
    PaymentData paymentData = PaymentData.createPaymentData(paymentAmount, customer.getPersonnel(), Short.valueOf("1"), transactionDate);
    paymentData.setCustomer(customer);
    String actualErrorMessage = "No Error Message";
    try {
        customerAccount.makePayment(paymentData);
    } catch (AccountException e) {
        actualErrorMessage = (String) e.getValues()[0];
    }
    Assert.assertEquals(expectedErrorMessage, actualErrorMessage);
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) Date(java.sql.Date)

Example 47 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class LoanBO method waiveFeeAmountDue.

private void waiveFeeAmountDue() throws AccountException {
    List<AccountActionDateEntity> accountActionDateList = getApplicableIdsForNextInstallmentAndArrears();
    LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountActionDateList.get(accountActionDateList.size() - 1);
    Money chargeWaived = accountActionDateEntity.waiveFeeCharges();
    Money principal = new Money(getCurrency());
    Money interest = new Money(getCurrency());
    Money penalty = new Money(getCurrency());
    if (chargeWaived != null && chargeWaived.isGreaterThanZero()) {
        updateTotalFeeAmount(chargeWaived);
        updateAccountActivity(principal, interest, chargeWaived, penalty, userContext.getId(), LoanConstants.FEE_WAIVED);
        waiveChargesFromMemberAccounts(LoanConstants.FEE_WAIVED);
    }
    try {
        getlegacyLoanDao().createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 48 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class LoanBO method getLastUnpaidInstallment.

private AccountActionDateEntity getLastUnpaidInstallment() throws AccountException {
    Set<AccountActionDateEntity> accountActionDateSet = getAccountActionDates();
    List<AccountActionDateEntity> objectList = Arrays.asList(accountActionDateSet.toArray(new AccountActionDateEntity[accountActionDateSet.size()]));
    for (int i = objectList.size() - 1; i >= 0; i--) {
        AccountActionDateEntity accountActionDateEntity = objectList.get(i);
        if (accountActionDateEntity.isNotPaid()) {
            return accountActionDateEntity;
        }
    }
    throw new AccountException(AccountConstants.NOMOREINSTALLMENTS);
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException)

Example 49 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class LoanBO method changeLoanStatus.

private void changeLoanStatus(final AccountState newAccountState, final PersonnelBO personnel) throws AccountException {
    AccountStateEntity accountState = this.getAccountState();
    try {
        setAccountState(legacyMasterDao.getPersistentObject(AccountStateEntity.class, newAccountState.getValue()));
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
    if (newAccountState.isClosedLoanAccountState() || newAccountState.isCancelledLoanAccountState()) {
        changeStateForAllFees(FeeStatus.INACTIVE);
    } else if (newAccountState.isActiveLoanAccountState()) {
        changeStateForAllFees(FeeStatus.ACTIVE);
    }
    this.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(accountState, this.getAccountState(), personnel, this));
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity)

Example 50 with AccountException

use of org.mifos.accounts.exceptions.AccountException in project head by mifos.

the class LoanBO method updateInstallmentAfterAdjustment.

@Override
protected void updateInstallmentAfterAdjustment(final List<AccountTrxnEntity> reversedTrxns, PersonnelBO loggedInUser) throws AccountException {
    Money increaseInterest = new Money(this.getCurrency());
    Money increaseFees = new Money(this.getCurrency());
    Money increasePenalty = new Money(this.getCurrency());
    int numberOfFullPayments = 0;
    short numberOfInstalments = (short) reversedTrxns.size();
    List<AccountActionDateEntity> allInstallments = this.getAllInstallments();
    if (isNotEmpty(reversedTrxns)) {
        for (AccountTrxnEntity reversedTrxn : reversedTrxns) {
            Short prevInstallmentId = null;
            Short currentInstallmentId = reversedTrxn.getInstallmentId();
            numberOfFullPayments = getIncrementedNumberOfFullPaymentsIfPaid(numberOfFullPayments, allInstallments, prevInstallmentId, currentInstallmentId);
            if (!reversedTrxn.isTrxnForReversalOfLoanDisbursal()) {
                LoanTrxnDetailEntity loanReverseTrxn = (LoanTrxnDetailEntity) reversedTrxn;
                loanSummary.updatePaymentDetails(loanReverseTrxn);
                if (loanReverseTrxn.isNotEmptyTransaction()) {
                    LoanScheduleEntity installment = (LoanScheduleEntity) getAccountActionDate(loanReverseTrxn.getInstallmentId());
                    installment.updatePaymentDetailsForAdjustment(loanReverseTrxn);
                    if (installment.isPaid()) {
                        increaseInterest = increaseInterest.add(installment.getInterestDue().add(installment.getExtraInterestDue())).add(loanReverseTrxn.getInterestAmount());
                        increaseFees = increaseFees.add(installment.getTotalFeesDue());
                        if (!this.noOfInstallments.equals(numberOfInstalments)) {
                            increaseFees = increaseFees.add(installment.getMiscFeeDue()).add(loanReverseTrxn.getMiscFeeAmount());
                            increasePenalty = increasePenalty.add(installment.getPenaltyDue()).add(loanReverseTrxn.getPenaltyAmount());
                        }
                    }
                    installment.recordForAdjustment();
                    if (installment.hasFees()) {
                        for (AccountFeesActionDetailEntity accntFeesAction : installment.getAccountFeesActionDetails()) {
                            loanReverseTrxn.adjustFees(accntFeesAction);
                        }
                    }
                    if (installment.hasPenalties()) {
                        for (LoanPenaltyScheduleEntity entity : installment.getLoanPenaltyScheduleEntities()) {
                            loanReverseTrxn.adjustPenalties(entity);
                        }
                    }
                }
            }
        }
        AccountStateEntity currentAccountState = this.getAccountState();
        AccountStateEntity newAccountState = currentAccountState;
        boolean statusChangeNeeded = false;
        if (isLoanActiveWithStatusChangeHistory()) {
            AccountStatusChangeHistoryEntity lastAccountStatusChange = getLastAccountStatusChange();
            if (lastAccountStatusChange.isLoanActive()) {
                statusChangeNeeded = true;
            } else if (currentAccountState.isLoanClosedObligationsMet()) {
                statusChangeNeeded = true;
                newAccountState = lastAccountStatusChange.getOldStatus();
            }
        }
        boolean accountReOpened = isAccountReOpened(currentAccountState, newAccountState);
        updatePerformanceHistory(accountReOpened);
        /*
             * John W - mifos-1986 - see related comment above
             */
        if (accountReOpened) {
            loanSummary.increaseBy(null, increaseInterest, increasePenalty, increaseFees);
            // fix for MIFOS-3287
            this.setClosedDate(null);
        }
        // Else reverse payments equal to number of transactions reversed.
        if (accountReOpened) {
            updatePerformanceHistoryOnAdjustment(1);
        } else if (reversedTrxns.size() > 0) {
            updatePerformanceHistoryOnAdjustment(numberOfFullPayments);
        }
        if (statusChangeNeeded) {
            Short daysInArrears = getDaysInArrears(accountReOpened);
            if (currentAccountState.isLoanClosedObligationsMet()) {
                AccountState newStatus = AccountState.LOAN_ACTIVE_IN_BAD_STANDING;
                if (daysInArrears == 0) {
                    newStatus = AccountState.LOAN_ACTIVE_IN_GOOD_STANDING;
                }
                changeStatus(newStatus, null, "Account Reopened", loggedInUser);
            } else {
                if (daysInArrears == 0) {
                    if (!currentAccountState.isLoanActiveInGoodStanding()) {
                        changeStatus(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, null, "Account Adjusted", loggedInUser);
                    }
                } else {
                    if (!currentAccountState.isLoanActiveInBadStanding()) {
                        changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "Account Adjusted", loggedInUser);
                        handleArrearsAging();
                    }
                }
            }
        }
        try {
            PersonnelBO personnel = legacyPersonnelDao.getPersonnel(getUserContext().getId());
            addLoanActivity(buildLoanActivity(reversedTrxns, personnel, AccountConstants.LOAN_ADJUSTED, DateUtils.getCurrentDateWithoutTimeStamp()));
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    }
}
Also used : AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) AccountState(org.mifos.accounts.util.helpers.AccountState) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Aggregations

AccountException (org.mifos.accounts.exceptions.AccountException)115 MifosRuntimeException (org.mifos.core.MifosRuntimeException)47 UserContext (org.mifos.security.util.UserContext)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)42 Money (org.mifos.framework.util.helpers.Money)42 MifosUser (org.mifos.security.MifosUser)38 LoanBO (org.mifos.accounts.loan.business.LoanBO)31 ArrayList (java.util.ArrayList)30 LocalDate (org.joda.time.LocalDate)30 BusinessRuleException (org.mifos.service.BusinessRuleException)29 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)26 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)25 Date (java.util.Date)22 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)21 CustomerBO (org.mifos.customers.business.CustomerBO)19 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)17 PaymentData (org.mifos.accounts.util.helpers.PaymentData)17 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)16 ServiceException (org.mifos.framework.exceptions.ServiceException)16 BigDecimal (java.math.BigDecimal)14