Search in sources :

Example 51 with AccountBO

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

the class EditStatusAction method preview.

@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    AccountBO accountBO = (AccountBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
    // FIXME - ElsieF - KEITHW - is checklist functionality being removed from application?
    List<AccountCheckListBO> checklist = new AccountBusinessService().getStatusChecklist(getShortValue(editStatusActionForm.getNewStatusId()), getShortValue(editStatusActionForm.getAccountTypeId()));
    SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_CHECK_LIST, checklist, request);
    String newStatusId = editStatusActionForm.getNewStatusId();
    String newStatusName = null;
    if (StringUtils.isNotBlank(editStatusActionForm.getNewStatusId())) {
        newStatusName = new AccountBusinessService().getStatusName(AccountState.fromShort(getShortValue(editStatusActionForm.getNewStatusId())), accountBO.getType());
    }
    SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, newStatusName, request);
    initializeLoanQuestionnaire(accountBO.getGlobalAccountNum(), newStatusId);
    if (loanApproved(newStatusId) || loanClosed(newStatusId)) {
        return loanQuestionnaire.fetchAppliedQuestions(mapping, editStatusActionForm, request, ActionForwards.preview_success);
    }
    return mapping.findForward(ActionForwards.preview_success.toString());
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) EditStatusActionForm(org.mifos.accounts.struts.actionforms.EditStatusActionForm) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) AccountCheckListBO(org.mifos.customers.checklist.business.AccountCheckListBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 52 with AccountBO

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

the class StandardAccountService method createParentLoanPaymentData.

/**
     * Create parent payment data with member payment data. 
     * 
     */
private AccountPaymentParametersDto createParentLoanPaymentData(AccountBO memberAccount, AccountPaymentParametersDto memberPaymentParametersDto) {
    AccountPaymentParametersDto parentPaymentParametersDto = new AccountPaymentParametersDto(memberPaymentParametersDto.getUserMakingPayment(), new AccountReferenceDto(((LoanBO) memberAccount).getParentAccount().getAccountId()), memberPaymentParametersDto.getPaymentAmount(), memberPaymentParametersDto.getPaymentDate(), memberPaymentParametersDto.getPaymentType(), memberPaymentParametersDto.getComment(), memberPaymentParametersDto.getReceiptDate(), memberPaymentParametersDto.getReceiptId(), memberAccount.getCustomer().toCustomerDto());
    Map<Integer, String> membersPaymentsData = new HashMap<Integer, String>();
    for (AccountBO member : ((LoanBO) memberAccount).getParentAccount().getMemberAccounts()) {
        if (member.isActiveLoanAccount()) {
            if (member.getAccountId().equals(memberPaymentParametersDto.getAccountId())) {
                membersPaymentsData.put(member.getAccountId(), memberPaymentParametersDto.getPaymentAmount().toString());
            } else {
                membersPaymentsData.put(member.getAccountId(), BigDecimal.ZERO.toString());
            }
        }
    }
    parentPaymentParametersDto.setMemberInfo(membersPaymentsData);
    return parentPaymentParametersDto;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) HashMap(java.util.HashMap) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto)

Example 53 with AccountBO

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

the class StandardAccountService method validatePayment.

@Override
public List<InvalidPaymentReason> validatePayment(AccountPaymentParametersDto payment) throws PersistenceException, AccountException {
    List<InvalidPaymentReason> errors = new ArrayList<InvalidPaymentReason>();
    AccountBO accountBo = this.legacyAccountDao.getAccount(payment.getAccountId());
    Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(accountBo.getCustomer().getCustomerId());
    boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
    if (!accountBo.isTrxnDateValid(payment.getPaymentDate().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
        errors.add(InvalidPaymentReason.INVALID_DATE);
    }
    if (accountBo instanceof LoanBO) {
        if (((LoanBO) accountBo).paymentsNotAllowed()) {
            errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
        }
    }
    if (accountBo instanceof SavingsBO) {
        if (!accountBo.getState().equals(AccountState.SAVINGS_ACTIVE)) {
            errors.add(InvalidPaymentReason.INVALID_LOAN_STATE);
        }
    }
    if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.LOAN_ACCOUNT) {
        if (!getLoanPaymentTypes().contains(payment.getPaymentType())) {
            errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
        }
    } else if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.SAVINGS_ACCOUNT) {
        if (!getSavingsPaymentTypes().contains(payment.getPaymentType())) {
            errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
        }
    } else if (AccountTypes.getAccountType(accountBo.getAccountType().getAccountTypeId()) == AccountTypes.CUSTOMER_ACCOUNT) {
        if (!getFeePaymentTypes().contains(payment.getPaymentType())) {
            errors.add(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE);
        }
    }
    if (!accountBo.paymentAmountIsValid(new Money(accountBo.getCurrency(), payment.getPaymentAmount()), payment.getPaymentOptions())) {
        errors.add(InvalidPaymentReason.INVALID_PAYMENT_AMOUNT);
    }
    return errors;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 54 with AccountBO

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

the class StandardAccountService method lookupLoanAccountReferencesFromClientPhoneNumberAndWithdrawAmount.

/**
     * Warning - this should be only used from MPESA plugin!
     */
@Override
public List<AccountReferenceDto> lookupLoanAccountReferencesFromClientPhoneNumberAndWithdrawAmount(String phoneNumber, BigDecimal withdrawAmount) throws Exception {
    List<AccountBO> accounts = this.legacyAccountDao.findApprovedLoansForClientWithPhoneNumber(phoneNumber);
    List<AccountReferenceDto> result = new ArrayList<AccountReferenceDto>();
    for (AccountBO account : accounts) {
        LoanBO loanAccount = (LoanBO) account;
        if (loanAccount.getLoanAmount().getAmount().compareTo(computeWithdrawnForMPESA(withdrawAmount, loanAccount)) == 0) {
            result.add(new AccountReferenceDto(account.getAccountId()));
        }
    }
    return result;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList)

Example 55 with AccountBO

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

the class StandardAccountService method lookupPayments.

@Override
public List<AccountPaymentParametersDto> lookupPayments(AccountReferenceDto accountRef) throws PersistenceException {
    final int accountId = accountRef.getAccountId();
    final AccountBO account = this.legacyAccountDao.getAccount(accountId);
    List<AccountPaymentParametersDto> paymentDtos = new ArrayList<AccountPaymentParametersDto>();
    for (AccountPaymentEntity paymentEntity : account.getAccountPayments()) {
        paymentDtos.add(makePaymentDto(paymentEntity));
    }
    return paymentDtos;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto)

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