Search in sources :

Example 6 with AccountBusinessService

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

the class NotesAction method create.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    NotesActionForm notesActionForm = (NotesActionForm) form;
    UserContext uc = getUserContext(request);
    CreateAccountNote accountNote = (CreateAccountNote) SessionUtils.getAttribute("model.accountNote", request);
    AccountBO accountBO = new AccountBusinessService().getAccount(accountNote.getAccountId());
    if (accountBO.getPersonnel() != null) {
        checkPermissionForAddingNotes(accountBO.getType(), null, uc, accountBO.getOffice().getOfficeId(), accountBO.getPersonnel().getPersonnelId());
    } else {
        checkPermissionForAddingNotes(accountBO.getType(), null, uc, accountBO.getOffice().getOfficeId(), uc.getId());
    }
    if (accountBO.isSavingsAccount()) {
        this.savingsServiceFacade.addNote(accountNote);
    } else {
        this.loanAccountServiceFacade.addNote(accountNote);
    }
    return mapping.findForward(chooseForward(Short.valueOf(notesActionForm.getAccountTypeId())));
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CreateAccountNote(org.mifos.dto.domain.CreateAccountNote) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) UserContext(org.mifos.security.util.UserContext) NotesActionForm(org.mifos.accounts.struts.actionforms.NotesActionForm) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 7 with AccountBusinessService

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

the class NotesAction method getSearchResult.

@Override
protected QueryResult getSearchResult(ActionForm form) throws Exception {
    Integer accountId = Integer.valueOf(((NotesActionForm) form).getAccountId());
    AccountBO account = new AccountBusinessService().getAccount(accountId);
    if (account.isSavingsAccount()) {
        NoteSearchDto noteSearchDto = new NoteSearchDto(accountId, Integer.valueOf(1), Integer.valueOf(10));
        NotesSearchResultsDto noteResults = this.savingsServiceFacade.retrievePagedNotesDto(noteSearchDto);
    }
    return legacyAccountDao.getAllAccountNotes(accountId);
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) NoteSearchDto(org.mifos.dto.domain.NoteSearchDto) NotesSearchResultsDto(org.mifos.dto.screen.NotesSearchResultsDto)

Example 8 with AccountBusinessService

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

the class AccountApplyPaymentActionForm method validateModeOfPaymentSecurity.

private void validateModeOfPaymentSecurity(HttpServletRequest request, ActionErrors errors) {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    AccountBO account = null;
    Short personnelId = userContext.getId();
    try {
        if (accountId != null) {
            account = new AccountBusinessService().getAccount(Integer.valueOf(accountId));
            if (account.getPersonnel() != null) {
                personnelId = account.getPersonnel().getPersonnelId();
            }
        }
    } catch (NumberFormatException e) {
        throw new MifosRuntimeException(e);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
    if (getPaymentTypeId().equals("4") && !ActivityMapper.getInstance().isModeOfPaymentSecurity(userContext, personnelId)) {
        errors.add(AccountConstants.LOAN_TRANSFER_PERMISSION, new ActionMessage(AccountConstants.LOAN_TRANSFER_PERMISSION, getLocalizedMessage("accounts.mode_of_payment_permission")));
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 9 with AccountBusinessService

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

the class WebTierAccountServiceFacade method applyGroupCharge.

@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);
    try {
        AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId())).getParentAccount();
        BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
        BigDecimal membersAmount = BigDecimal.ZERO;
        for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
            LoanBO individual = loanDao.findById(entry.getKey());
            Double chargeAmount = Double.valueOf(entry.getValue());
            if (chargeAmount.equals(0.0)) {
                continue;
            }
            membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
            individual.updateDetails(userContext);
            if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
            } else {
                individual.applyCharge(chargeId, chargeAmount);
            }
        }
        boolean isRateCharge = false;
        if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES)) && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
            if (isPenaltyType) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                if (penalty instanceof RatePenaltyBO) {
                    isRateCharge = true;
                }
            } else {
                FeeBO fee = feeDao.findById(chargeId);
                if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
                    isRateCharge = true;
                }
            }
        }
        Double chargeAmount = null;
        if (!isRateCharge) {
            chargeAmount = sumCharge(idsAndValues);
        } else {
            chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
            BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
            membersAmount = membersAmount.multiply(chargeAmountBig);
            int scale = Money.getInternalPrecision();
            chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
            chargeAmount = chargeAmountBig.doubleValue();
        }
        parentAccount.updateDetails(userContext);
        CustomerLevel customerLevel = null;
        if (parentAccount.isCustomerAccount()) {
            customerLevel = parentAccount.getCustomer().getLevel();
        }
        if (parentAccount.getPersonnel() != null) {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        if (isPenaltyType && parentAccount instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) parentAccount).addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
        } else {
            parentAccount.applyCharge(chargeId, chargeAmount);
        }
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) CustomerLevel(org.mifos.customers.api.CustomerLevel) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with AccountBusinessService

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

the class LoanDisbursementAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
    UserContext uc = getUserContext(request);
    Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
    trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
    Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
    Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
    Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
    AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
    Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
    createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
    try {
        String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
        String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
        Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
        Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
        Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
        final String comment = "";
        final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
        CustomerDto customerDto = null;
        PaymentTypeDto paymentType = null;
        AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
        monthClosingServiceFacade.validateTransactionDate(trxnDate);
        // GLIM
        List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
        for (LoanBO individual : individualLoans) {
            if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
                throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
            }
        }
        this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        for (LoanBO individual : individualLoans) {
            loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
            this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
        }
        if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
            this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
        }
    } catch (BusinessRuleException e) {
        throw new AccountException(e.getMessage());
    } catch (MifosRuntimeException e) {
        if (e.getCause() != null && e.getCause() instanceof AccountException) {
            throw new AccountException(e.getCause().getMessage());
        }
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    } catch (Exception e) {
        String msg = "errors.cannotDisburseLoan.because.disburseFailed";
        logger.error(msg, e);
        throw new AccountException(msg);
    }
    return mapping.findForward(Constants.UPDATE_SUCCESS);
}
Also used : UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) DateUtils.getUserLocaleDate(org.mifos.framework.util.helpers.DateUtils.getUserLocaleDate) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountException(org.mifos.accounts.exceptions.AccountException) ServiceException(org.mifos.framework.exceptions.ServiceException) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) LoanDisbursementActionForm(org.mifos.accounts.loan.struts.actionforms.LoanDisbursementActionForm) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) AccountException(org.mifos.accounts.exceptions.AccountException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) CloseSession(org.mifos.framework.util.helpers.CloseSession) 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