Search in sources :

Example 66 with AccountBO

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

the class ApplyAdjustment method loadAdjustment.

@TransactionDemarcate(joinToken = true)
public ActionForward loadAdjustment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    request.setAttribute("method", "loadAdjustment");
    UserContext userContext = getUserContext(request);
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
    AccountPaymentEntity payment = null;
    if (request.getParameter(Constants.ADJ_TYPE_KEY) != null && request.getParameter(Constants.ADJ_TYPE_KEY).equals(Constants.ADJ_SPECIFIC)) {
        Integer paymentId = appAdjustActionForm.getPaymentId();
        payment = accnt.findPaymentById(paymentId);
        AccountPaymentEntity previous = null;
        AccountPaymentEntity next = null;
        boolean getPrevious = false;
        for (AccountPaymentEntity p : accnt.getAccountPayments()) {
            if (!p.getAmount().equals(Money.zero())) {
                if (getPrevious) {
                    previous = p;
                    break;
                } else if (p.getPaymentId().equals(payment.getPaymentId())) {
                    getPrevious = true;
                } else {
                    next = p;
                }
            }
        }
        Date previousPaymentDate = (previous == null) ? null : previous.getPaymentDate();
        Date nextPaymentDate = (next == null) ? null : next.getPaymentDate();
        appAdjustActionForm.setPreviousPaymentDate(previousPaymentDate);
        appAdjustActionForm.setNextPaymentDate(nextPaymentDate);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, payment.getAmount().getAmount(), request);
        Short transferPaymentTypeId = legacyAcceptedPaymentTypeDao.getSavingsTransferId();
        if (payment.getPaymentType().getId().equals(transferPaymentTypeId)) {
            List<ListItem<Short>> paymentTypeList = this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId());
            for (Iterator<ListItem<Short>> it = paymentTypeList.iterator(); it.hasNext(); ) {
                ListItem<Short> listItem = it.next();
                if (!listItem.getId().equals(transferPaymentTypeId)) {
                    it.remove();
                }
            }
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, paymentTypeList, request);
        } else {
            SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
        }
    } else {
        SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, this.accountServiceFacade.constructPaymentTypeListForLoanRepayment(userContext.getLocaleId()), request);
        payment = accnt.getLastPmntToBeAdjusted();
        appAdjustActionForm.setPaymentId(null);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, accnt.getLastPmntAmntToBeAdjusted(), request);
    }
    if (accnt.isParentGroupLoanAccount()) {
        SessionUtils.setAttribute(Constants.TYPE_OF_GROUP_LOAN, "parentAcc", request);
    } else if (accnt.isGroupLoanAccountMember()) {
        appAdjustActionForm.setGroupLoanMember(Boolean.TRUE);
    }
    populateForm(appAdjustActionForm, payment);
    return mapping.findForward("loadadjustment_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) ListItem(org.mifos.application.servicefacade.ListItem) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 67 with AccountBO

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

the class ApplyAdjustment method loadAdjustmentWhenObligationMet.

/*
     * This method do the same thing as loadAdjustment, but added to allow
     * handling permission : can adjust payment when account is closed
     * obligation met
     */
@TransactionDemarcate(joinToken = true)
public ActionForward loadAdjustmentWhenObligationMet(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyAdjustmentActionForm appAdjustActionForm = (ApplyAdjustmentActionForm) form;
    AccountBO accnt = getBizService().findBySystemId(appAdjustActionForm.getGlobalAccountNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accnt, request);
    request.setAttribute("method", "loadAdjustmentWhenObligationMet");
    AccountPaymentEntity payment = null;
    if (request.getParameter(Constants.ADJ_TYPE_KEY) != null && request.getParameter(Constants.ADJ_TYPE_KEY).equals(Constants.ADJ_SPECIFIC)) {
        Integer paymentId = appAdjustActionForm.getPaymentId();
        payment = accnt.findPaymentById(paymentId);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, payment.getAmount().getAmount(), request);
    } else {
        payment = accnt.getLastPmntToBeAdjusted();
        appAdjustActionForm.setPaymentId(null);
        SessionUtils.setAttribute(Constants.ADJUSTED_AMOUNT, accnt.getLastPmntAmntToBeAdjusted(), request);
    }
    appAdjustActionForm.setAdjustData(false);
    populateForm(appAdjustActionForm, payment);
    return mapping.findForward("loadadjustment_success");
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) ApplyAdjustmentActionForm(org.mifos.accounts.struts.actionforms.ApplyAdjustmentActionForm) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 68 with AccountBO

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

the class ApplyChargeAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ApplyChargeActionForm applyChargeActionForm = (ApplyChargeActionForm) form;
    Short feeId = Short.valueOf(applyChargeActionForm.getFeeId());
    Double chargeAmount = 0.0;
    AccountBO account = new AccountBusinessService().getAccount(Integer.valueOf(applyChargeActionForm.getAccountId()));
    if (!(account instanceof CustomerAccountBO) && null == ((LoanBO) account).getParentAccount() && account.isGroupLoanAccount()) {
        this.accountServiceFacade.applyGroupCharge(applyChargeActionForm.getIndividualValues(), feeId, applyChargeActionForm.isPenaltyType());
    } else {
        chargeAmount = getDoubleValue(request.getParameter("charge"));
        this.accountServiceFacade.applyCharge(account.getAccountId(), feeId, chargeAmount, applyChargeActionForm.isPenaltyType());
    }
    AccountTypeCustomerLevelDto accountTypeCustomerLevel = accountServiceFacade.getAccountTypeCustomerLevelDto(account.getAccountId());
    return mapping.findForward(getDetailAccountPage(accountTypeCustomerLevel));
}
Also used : AccountTypeCustomerLevelDto(org.mifos.dto.screen.AccountTypeCustomerLevelDto) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplyChargeActionForm(org.mifos.accounts.struts.actionforms.ApplyChargeActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 69 with AccountBO

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

the class EditStatusAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = getUserContext(request);
    EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
    Integer accountId = Integer.valueOf(editStatusActionForm.getAccountId());
    AccountBO accountBO = new AccountBusinessService().getAccount(accountId);
    Short flagId = null;
    Short newStatusId = null;
    String updateComment = editStatusActionForm.getNotes();
    if (StringUtils.isNotBlank(editStatusActionForm.getFlagId())) {
        flagId = getShortValue(editStatusActionForm.getFlagId());
    }
    if (StringUtils.isNotBlank(editStatusActionForm.getNewStatusId())) {
        newStatusId = getShortValue(editStatusActionForm.getNewStatusId());
    }
    Date trxnDate = editStatusActionForm.getTransactionDateValue(userContext.getPreferredLocale());
    if (editStatusActionForm.getNewStatusId().equals(AccountState.LOAN_APPROVED) && !AccountingRules.isBackDatedApprovalAllowed()) {
        trxnDate = new DateTimeService().getCurrentJavaDateTime();
    }
    checkPermission(accountBO, getUserContext(request), newStatusId, flagId);
    if (accountBO.isLoanAccount() || accountBO.isGroupLoanAccount()) {
        initializeLoanQuestionnaire(accountBO.getGlobalAccountNum(), newStatusId != null ? newStatusId.toString() : null);
        loanQuestionnaire.saveResponses(request, editStatusActionForm, accountId);
        //GLIM
        List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(accountId);
        List<AccountUpdateStatus> updateStatus = new ArrayList<AccountUpdateStatus>(individualLoans.size() + 1);
        updateStatus.add(new AccountUpdateStatus(accountId.longValue(), newStatusId, flagId, updateComment));
        for (LoanBO individual : individualLoans) {
            updateStatus.add(new AccountUpdateStatus(individual.getAccountId().longValue(), newStatusId, flagId, updateComment));
        }
        try {
            if (individualLoans.size() == 0) {
                this.loanAccountServiceFacade.updateSingleLoanAccountStatus(updateStatus.get(0), trxnDate);
            } else {
                this.loanAccountServiceFacade.updateSeveralLoanAccountStatuses(updateStatus, trxnDate);
            }
        } catch (AccessDeniedException e) {
            throw new ServiceException(SecurityConstants.KEY_ACTIVITY_APPROVE_LOAN_NOT_ALLOWED);
        }
        return mapping.findForward(ActionForwards.loan_detail_page.toString());
    }
    if (accountBO.isSavingsAccount()) {
        AccountUpdateStatus updateStatus = new AccountUpdateStatus(accountId.longValue(), newStatusId, flagId, updateComment);
        this.savingsServiceFacade.updateSavingsAccountStatus(updateStatus);
        return mapping.findForward(ActionForwards.savings_details_page.toString());
    }
    // nothing but loan of savings account should be detected. customer account status change goes through separate action.
    return null;
}
Also used : AccountUpdateStatus(org.mifos.dto.domain.AccountUpdateStatus) EditStatusActionForm(org.mifos.accounts.struts.actionforms.EditStatusActionForm) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) Date(java.util.Date) AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) DateTimeService(org.mifos.framework.util.DateTimeService) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 70 with AccountBO

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

the class ApplyChargeActionForm method getChargeCurrency.

private MifosCurrency getChargeCurrency() {
    try {
        AccountBusinessService service = new AccountBusinessService();
        AccountBO accountBO = service.getAccount(Integer.valueOf(getAccountId()));
        return accountBO.getCurrency();
    } catch (Exception ex) {
        return null;
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ServiceException(org.mifos.framework.exceptions.ServiceException)

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