Search in sources :

Example 1 with AccountBusinessService

use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.

the class SavingsServiceFacadeWebTier method retrieveDepositWithdrawalReferenceData.

@Override
public DepositWithdrawalReferenceDto retrieveDepositWithdrawalReferenceData(Long savingsId, Integer customerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        SavingsBO savingsAccount = savingsDao.findById(savingsId);
        String depositDue = savingsAccount.getTotalPaymentDue(customerId).toString();
        String withdrawalDue = "0";
        List<ListElement> clients = new ArrayList<ListElement>();
        if (savingsAccount.isGroupModelWithIndividualAccountability()) {
            List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
            for (CustomerBO client : activeAndOnHoldClients) {
                clients.add(new ListElement(client.getCustomerId(), client.getDisplayName()));
            }
        }
        List<AccountActionEntity> trxnTypes = new ArrayList<AccountActionEntity>();
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_DEPOSIT.getValue(), userContext.getLocaleId()));
        trxnTypes.add(new AccountBusinessService().getAccountAction(AccountActionTypes.SAVINGS_WITHDRAWAL.getValue(), userContext.getLocaleId()));
        List<ListElement> transactionTypes = new ArrayList<ListElement>();
        for (AccountActionEntity accountActionEntity : trxnTypes) {
            LookUpValueEntity lookupValue = accountActionEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            transactionTypes.add(new ListElement(accountActionEntity.getId().intValue(), messageText));
        }
        List<ListElement> depositPaymentTypes = retrieveDepositPaymentTypes(userContext);
        List<ListElement> withdrawalPaymentTypes = new ArrayList<ListElement>();
        List<PaymentTypeEntity> withdrawalPaymentEntityTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
        for (PaymentTypeEntity paymentTypeEntity : withdrawalPaymentEntityTypes) {
            LookUpValueEntity lookupValue = paymentTypeEntity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            withdrawalPaymentTypes.add(new ListElement(paymentTypeEntity.getId().intValue(), messageText));
        }
        boolean backDatedTransactionsAllowed = AccountingRules.isBackDatedTxnAllowed();
        LocalDate defaultTransactionDate = new LocalDate();
        return new DepositWithdrawalReferenceDto(transactionTypes, depositPaymentTypes, withdrawalPaymentTypes, clients, backDatedTransactionsAllowed, defaultTransactionDate, depositDue, withdrawalDue);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DepositWithdrawalReferenceDto(org.mifos.dto.screen.DepositWithdrawalReferenceDto) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with AccountBusinessService

use of org.mifos.accounts.business.service.AccountBusinessService 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 AccountBusinessService

use of org.mifos.accounts.business.service.AccountBusinessService 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 4 with AccountBusinessService

use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.

the class BirtAdminDocumentUploadAction method updateSelectedStatus.

@TransactionDemarcate(joinToken = true)
private void updateSelectedStatus(HttpServletRequest request, BirtAdminDocumentUploadActionForm uploadForm) throws PageExpiredException, ServiceException {
    List selectList = null;
    if (uploadForm.getStatusList() != null) {
        Short accountTypeId = Short.valueOf(uploadForm.getAccountTypeId());
        if (accountTypeId.shortValue() <= 2) {
            selectList = new ArrayList<AccountStateEntity>();
            List<AccountStateEntity> masterList = new AccountBusinessService().retrieveAllActiveAccountStateList(AccountTypes.getAccountType(accountTypeId));
            for (AccountStateEntity product : masterList) {
                for (String productStatusId : uploadForm.getStatusList()) {
                    if (productStatusId != null && product.getId().intValue() == Integer.valueOf(productStatusId).intValue()) {
                        selectList.add(product);
                    }
                }
            }
        } else {
            Short currentLocaleId = (Short) SessionUtils.getAttribute("CURRENT_LOCALE_ID", request);
            selectList = new ArrayList<AccountActionEntity>();
            List<AccountActionEntity> masterList = getAvailableLoanTransactions(currentLocaleId);
            for (String accountActionId : uploadForm.getStatusList()) {
                AccountActionTypes accountActionType = AccountActionTypes.fromInt(Integer.valueOf(accountActionId));
                AccountActionEntity accountAction = new AccountBusinessService().getAccountAction(accountActionType.getValue(), currentLocaleId);
                if (masterList.contains(accountAction)) {
                    selectList.add(accountAction);
                }
            }
        }
    }
    SessionUtils.setCollectionAttribute("SelectedStatus", selectList, request);
}
Also used : AccountActionTypes(org.mifos.accounts.util.helpers.AccountActionTypes) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ArrayList(java.util.ArrayList) List(java.util.List) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with AccountBusinessService

use of org.mifos.accounts.business.service.AccountBusinessService in project head by mifos.

the class NotesAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    clearActionForm(form);
    NotesActionForm notesActionForm = (NotesActionForm) form;
    Integer accountId = Integer.valueOf(notesActionForm.getAccountId());
    AccountBO account = new AccountBusinessService().getAccount(accountId);
    if (account.isLoanAccount() || account.isGroupLoanAccount()) {
        LoanAccountDetailDto loanAccountDto = this.loanAccountServiceFacade.retrieveLoanAccountNotes(accountId.longValue());
        if (account.isLoanAccount()) {
            notesActionForm.setAccountTypeId(AccountTypes.LOAN_ACCOUNT.getValue().toString());
        } else {
            notesActionForm.setAccountTypeId(AccountTypes.GROUP_LOAN_ACCOUNT.getValue().toString());
        }
        notesActionForm.setGlobalAccountNum(loanAccountDto.getGlobalAccountNum());
        notesActionForm.setPrdOfferingName(loanAccountDto.getProductDetails().getPrdOfferingName());
    } else if (account.isSavingsAccount()) {
        SavingsAccountDetailDto savingsAccountDto = this.savingsServiceFacade.retrieveSavingsAccountNotes(accountId.longValue());
        notesActionForm.setPrdOfferingName(savingsAccountDto.getProductDetails().getProductDetails().getName());
        notesActionForm.setAccountTypeId(AccountTypes.SAVINGS_ACCOUNT.getValue().toString());
        notesActionForm.setGlobalAccountNum(savingsAccountDto.getGlobalAccountNum());
    }
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) NotesActionForm(org.mifos.accounts.struts.actionforms.NotesActionForm) LoanAccountDetailDto(org.mifos.dto.screen.LoanAccountDetailDto) SavingsAccountDetailDto(org.mifos.dto.domain.SavingsAccountDetailDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)26 AccountBO (org.mifos.accounts.business.AccountBO)20 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 ServiceException (org.mifos.framework.exceptions.ServiceException)16 UserContext (org.mifos.security.util.UserContext)16 MifosUser (org.mifos.security.MifosUser)11 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)10 LoanBO (org.mifos.accounts.loan.business.LoanBO)8 BusinessRuleException (org.mifos.service.BusinessRuleException)7 ArrayList (java.util.ArrayList)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 ApplicationException (org.mifos.framework.exceptions.ApplicationException)6 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)5 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 BigDecimal (java.math.BigDecimal)3 Date (java.util.Date)3 List (java.util.List)3 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)3 EditStatusActionForm (org.mifos.accounts.struts.actionforms.EditStatusActionForm)3 CloseSession (org.mifos.framework.util.helpers.CloseSession)3