Search in sources :

Example 6 with AccountState

use of org.mifos.accounts.util.helpers.AccountState 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)

Example 7 with AccountState

use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.

the class LoanBO method openGroupMemberLoanAccount.

public static LoanBO openGroupMemberLoanAccount(LoanBO parentLoan, LoanOfferingBO loanProduct, ClientBO member, MeetingBO repaymentDayMeeting, LoanSchedule loanSchedule, LoanProductOverridenDetail overridenDetail, LoanScheduleConfiguration configuration, InstallmentRange installmentRange, AmountRange loanAmountRange, CreationDetail creationDetail, PersonnelBO createdBy) {
    AccountState loanState = AccountState.LOAN_PENDING_APPROVAL;
    LoanBO groupMemberLoan = new LoanBO(loanProduct, member, loanState, overridenDetail, repaymentDayMeeting, loanSchedule, configuration, installmentRange, loanAmountRange, creationDetail, AccountTypes.GROUP_LOAN_ACCOUNT);
    groupMemberLoan.setParentAccount(parentLoan);
    groupMemberLoan.markAsIndividualLoanAccount();
    groupMemberLoan.addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(groupMemberLoan.getAccountState(), groupMemberLoan.getAccountState(), createdBy, groupMemberLoan));
    return groupMemberLoan;
}
Also used : AccountState(org.mifos.accounts.util.helpers.AccountState) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity)

Example 8 with AccountState

use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method assembleLoanAccountDetail.

private LoanAccountDetail assembleLoanAccountDetail(CreateGroupLoanAccount loanAccountInfo) {
    CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getGroupLoanAccountDetails().getCustomerId());
    LoanOfferingBO loanProduct = this.loanProductDao.findById(loanAccountInfo.getGroupLoanAccountDetails().getProductId());
    Money loanAmount = new Money(loanProduct.getCurrency(), loanAccountInfo.getGroupLoanAccountDetails().getLoanAmount());
    AccountState accountStateType = AccountState.fromShort(loanAccountInfo.getGroupLoanAccountDetails().getAccountState().shortValue());
    FundBO fund = null;
    if (loanAccountInfo.getGroupLoanAccountDetails().getSourceOfFundId() != null) {
        fund = this.fundDao.findById(loanAccountInfo.getGroupLoanAccountDetails().getSourceOfFundId().shortValue());
    }
    return new LoanAccountDetail(customer, loanProduct, loanAmount, accountStateType, fund);
}
Also used : Money(org.mifos.framework.util.helpers.Money) FundBO(org.mifos.accounts.fund.business.FundBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LoanAccountDetail(org.mifos.clientportfolio.newloan.domain.LoanAccountDetail) AccountState(org.mifos.accounts.util.helpers.AccountState)

Example 9 with AccountState

use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.

the class LoanAccountServiceFacadeWebTier method updateLoanAccountStatus.

@Override
public String updateLoanAccountStatus(AccountUpdateStatus updateStatus, Date transactionDate) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    LoanBO loanAccount = this.loanDao.findById(updateStatus.getSavingsId().intValue());
    loanAccount.updateDetails(userContext);
    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(loanAccount);
        AccountState newStatus = AccountState.fromShort(updateStatus.getNewStatusId());
        loanAccount.changeStatus(newStatus, updateStatus.getFlagId(), updateStatus.getComment(), loggedInUser, transactionDate);
        this.loanDao.save(loanAccount);
        this.transactionHelper.commitTransaction();
        return loanAccount.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();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) AccountState(org.mifos.accounts.util.helpers.AccountState) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) PropertyNotFoundException(org.mifos.framework.exceptions.PropertyNotFoundException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with AccountState

use of org.mifos.accounts.util.helpers.AccountState in project head by mifos.

the class AccountStateIntegrationTest method testRetrieveAllAccountStateList.

/*
     * Check that the values in the enumerated type AccountState match with the
     * Entity values in terms of ids, state names, and the text that they
     * eventually resolve to.
     */
@Test
public void testRetrieveAllAccountStateList() throws NumberFormatException, PersistenceException {
    List<AccountStateEntity> accountStateEntityList = legacyAccountDao.retrieveAllAccountStateList(ProductType.SAVINGS.getValue());
    Assert.assertNotNull(accountStateEntityList);
    Assert.assertEquals(6, accountStateEntityList.size());
    List<AccountStateEntity> accountStateEntityList2 = legacyAccountDao.retrieveAllAccountStateList(ProductType.LOAN.getValue());
    Assert.assertNotNull(accountStateEntityList2);
    Assert.assertEquals(12, accountStateEntityList2.size());
    accountStateEntityList.addAll(accountStateEntityList2);
    // order by id
    Collections.sort(accountStateEntityList, new Comparator<AccountStateEntity>() {

        @Override
        public int compare(AccountStateEntity state1, AccountStateEntity state2) {
            return state1.getId().compareTo(state2.getId());
        }
    });
    Assert.assertEquals(AccountState.values().length, accountStateEntityList.size());
    Iterator<AccountStateEntity> stateListIterator = accountStateEntityList.iterator();
    for (AccountState state : AccountState.values()) {
        AccountStateEntity stateInDatabase = stateListIterator.next();
        Assert.assertEquals(state.getValue(), stateInDatabase.getId());
        Assert.assertEquals(state.getPropertiesKey(), stateInDatabase.getLookUpValue().getLookUpName());
        Assert.assertEquals(ApplicationContextProvider.getBean(MessageLookup.class).lookup(state), ApplicationContextProvider.getBean(MessageLookup.class).lookup(stateInDatabase));
    }
}
Also used : AccountState(org.mifos.accounts.util.helpers.AccountState) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Test(org.junit.Test)

Aggregations

AccountState (org.mifos.accounts.util.helpers.AccountState)14 AccountException (org.mifos.accounts.exceptions.AccountException)5 CustomerBO (org.mifos.customers.business.CustomerBO)5 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 Money (org.mifos.framework.util.helpers.Money)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)4 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)4 ServiceException (org.mifos.framework.exceptions.ServiceException)4 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)4 MifosUser (org.mifos.security.MifosUser)4 BusinessRuleException (org.mifos.service.BusinessRuleException)4 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)3 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)3 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)3 UserContext (org.mifos.security.util.UserContext)3 LocalDate (org.joda.time.LocalDate)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2