Search in sources :

Example 1 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class LegacyAccountDao method search.

public QueryResult search(String queryString, Short officeId) throws PersistenceException {
    AccountBO accountBO = findBySystemId(queryString);
    if (accountBO == null) {
        return null;
    }
    if (accountBO.getType() == AccountTypes.CUSTOMER_ACCOUNT || accountBO.getType() == AccountTypes.INDIVIDUAL_LOAN_ACCOUNT) {
        return null;
    }
    QueryResult queryResult = QueryFactory.getQueryResult(CustomerSearchConstants.LOANACCOUNTIDSEARCH);
    ((QueryResultAccountIdSearch) queryResult).setSearchString(queryString);
    String[] namedQuery = new String[2];
    List<Param> paramList = new ArrayList<Param>();
    QueryInputs queryInputs = new QueryInputs();
    String[] aliasNames = { "customerId", "centerName", "centerGlobalCustNum", "customerType", "branchGlobalNum", "branchName", "loanOfficerName", "loanOffcerGlobalNum", "customerStatus", "groupName", "groupGlobalCustNum", "clientName", "clientGlobalCustNum", "loanGlobalAccountNumber" };
    queryInputs.setPath("org.mifos.customers.business.CustomerSearchDto");
    queryInputs.setAliasNames(aliasNames);
    if (officeId != null) {
        if (officeId.shortValue() == 0) {
            namedQuery[0] = NamedQueryConstants.ACCOUNT_ID_SEARCH_NOOFFICEID_COUNT;
            namedQuery[1] = NamedQueryConstants.ACCOUNT_ID_SEARCH_NOOFFICEID;
        } else {
            namedQuery[0] = NamedQueryConstants.ACCOUNT_ID_SEARCH_COUNT;
            namedQuery[1] = NamedQueryConstants.ACCOUNT_ID_SEARCH;
            paramList.add(typeNameValue("Short", "OFFICEID", officeId));
        }
        paramList.add(typeNameValue("String", "SEARCH_STRING", queryString));
    }
    queryInputs.setQueryStrings(namedQuery);
    queryInputs.setParamList(paramList);
    try {
        queryResult.setQueryInputs(queryInputs);
    } catch (HibernateSearchException e) {
        throw new PersistenceException(e);
    }
    return queryResult;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) QueryResultAccountIdSearch(org.mifos.framework.hibernate.helper.QueryResultAccountIdSearch) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) Param(org.mifos.customers.util.helpers.Param) QueryInputs(org.mifos.framework.hibernate.helper.QueryInputs) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 2 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class LoanAccountServiceFacadeWebTier method removeLoanPenalty.

@Override
public void removeLoanPenalty(Integer loanId, Short penaltyId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(loanId);
        if (account instanceof LoanBO) {
            LoanBO loanAccount = (LoanBO) account;
            List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
            if (individualLoans != null && individualLoans.size() > 0) {
                for (LoanBO individual : individualLoans) {
                    individual.updateDetails(userContext);
                    individual.removePenalty(penaltyId, userContext.getId());
                    this.customerDao.save(individual);
                }
            }
            account.updateDetails(userContext);
            if (account.getPersonnel() != null) {
                new AccountBusinessService().checkPermissionForRemovePenalties(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
            } else {
                new AccountBusinessService().checkPermissionForRemovePenalties(account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
            }
            this.transactionHelper.startTransaction();
            loanAccount.removePenalty(penaltyId, userContext.getId());
            this.loanDao.save(loanAccount);
            this.transactionHelper.commitTransaction();
        }
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (AccountException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class SaveCollectionSheetAssembler method customerAccountAssemblerFromDto.

public List<AccountBO> customerAccountAssemblerFromDto(final List<SaveCollectionSheetCustomerDto> saveCollectionSheetCustomers, final AccountPaymentEntity payment, final List<String> failedCustomerAccountPaymentNums) {
    final List<AccountBO> customerAccountList = new ArrayList<AccountBO>();
    for (SaveCollectionSheetCustomerDto saveCollectionSheetCustomer : saveCollectionSheetCustomers) {
        SaveCollectionSheetCustomerAccountDto saveCollectionSheetCustomerAccount = saveCollectionSheetCustomer.getSaveCollectionSheetCustomerAccount();
        if (null != saveCollectionSheetCustomerAccount) {
            final BigDecimal amount = saveCollectionSheetCustomerAccount.getTotalCustomerAccountCollectionFee();
            if (null != amount && amount.compareTo(BigDecimal.ZERO) > 0) {
                final PaymentData accountPaymentDataView = getCustomerAccountPaymentDataView(new Money(Money.getDefaultCurrency(), amount.toString()), payment);
                final Integer accountId = saveCollectionSheetCustomer.getSaveCollectionSheetCustomerAccount().getAccountId();
                CustomerAccountBO account = null;
                try {
                    account = findCustomerAccountById(accountId);
                    account.applyPayment(accountPaymentDataView);
                    customerAccountList.add(account);
                } catch (AccountException ae) {
                    logger.warn("Payment of collection/fee on account [" + accountId + "] failed. Account changes will not be persisted due to: " + ae.getMessage());
                    failedCustomerAccountPaymentNums.add(accountId.toString());
                    StaticHibernateUtil.getSessionTL().evict(account);
                }
            }
        }
    }
    return customerAccountList;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) PaymentData(org.mifos.accounts.util.helpers.PaymentData) Money(org.mifos.framework.util.helpers.Money) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountException(org.mifos.accounts.exceptions.AccountException) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 4 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class ApplyChargeActionForm method validate.

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    Locale locale = getUserContext(request).getPreferredLocale();
    ActionErrors errors = new ActionErrors();
    String methodCalled = request.getParameter(MethodNameConstants.METHOD);
    boolean groupLoanWithMembers = AccountingRules.isGroupLoanWithMembers();
    AccountBusinessService service = new AccountBusinessService();
    AccountBO accountBO = null;
    if (groupLoanWithMembers) {
        try {
            accountBO = service.getAccount(Integer.valueOf(getAccountId()));
        } catch (ServiceException e) {
            throw new MifosRuntimeException(e);
        }
    }
    if (groupLoanWithMembers && accountBO.isParentGroupLoanAccount()) {
        if (methodCalled != null && methodCalled.equals("divide")) {
            if (StringUtils.isNotBlank(selectedChargeFormula)) {
                validateRate(errors, request);
            }
            validateAmount(errors, locale);
        }
        if (methodCalled != null && methodCalled.equals("update")) {
            validateHashMap(errors);
        }
        if (!errors.isEmpty()) {
            request.setAttribute(Globals.ERROR_KEY, errors);
            if (methodCalled.equals("divide")) {
                request.setAttribute("methodCalled", "update");
            } else if (methodCalled.equals("update")) {
                request.setAttribute("methodCalled", "create");
            } else {
                request.setAttribute("methodCalled", methodCalled);
            }
        }
    } else {
        if (null != methodCalled) {
            if ((Methods.update.toString()).equals(methodCalled)) {
                if (StringUtils.isNotBlank(selectedChargeFormula)) {
                    validateRate(errors, request);
                }
                validateAmount(errors, locale);
            }
        }
        if (!errors.isEmpty()) {
            request.setAttribute(Globals.ERROR_KEY, errors);
            request.setAttribute("methodCalled", methodCalled);
        }
    }
    return errors;
}
Also used : Locale(java.util.Locale) AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ActionErrors(org.apache.struts.action.ActionErrors) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with AccountBO

use of org.mifos.accounts.business.AccountBO in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testSuccessLoadBusinessObject.

@Test
public void testSuccessLoadBusinessObject() throws Exception {
    AccountBO readAccount = legacyAccountDao.getAccount(groupLoan.getAccountId());
    Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, readAccount.getState());
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) Test(org.junit.Test)

Aggregations

AccountBO (org.mifos.accounts.business.AccountBO)106 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)39 LoanBO (org.mifos.accounts.loan.business.LoanBO)35 ArrayList (java.util.ArrayList)30 Money (org.mifos.framework.util.helpers.Money)30 UserContext (org.mifos.security.util.UserContext)29 Test (org.junit.Test)27 MifosRuntimeException (org.mifos.core.MifosRuntimeException)26 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)20 ServiceException (org.mifos.framework.exceptions.ServiceException)19 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)18 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)16 AccountException (org.mifos.accounts.exceptions.AccountException)15 MifosUser (org.mifos.security.MifosUser)14 Date (java.util.Date)13 LocalDate (org.joda.time.LocalDate)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 FeeBO (org.mifos.accounts.fees.business.FeeBO)9