Search in sources :

Example 1 with AccountPaymentParametersDto

use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.

the class AccountApplyGroupPaymentAction method applyPayment.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward applyPayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    String paymentType = request.getParameter(Constants.INPUT);
    Integer accountId;
    if (actionForm.getAccountId().isEmpty() || actionForm.getAccountId() == null) {
        accountId = loanDao.findByGlobalAccountNum(actionForm.getGlobalAccountNum()).getAccountId();
    } else {
        accountId = Integer.valueOf(actionForm.getAccountId());
    }
    UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountId, paymentType, userContext.getLocaleId(), userReferenceDto, actionForm.getTrxnDate());
    validateAccountPayment(accountPaymentDto, accountId, request);
    validateAmount(accountPaymentDto, actionForm.getAmount());
    PaymentTypeDto paymentTypeDto;
    String amount = actionForm.getAmount();
    if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT) || accountPaymentDto.getAccountType().equals(AccountTypeDto.GROUP_LOAN_ACCOUNT)) {
        paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    } else {
        paymentTypeDto = getFeePaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    }
    AccountPaymentParametersDto accountPaymentParametersDto;
    if (isGroupParentAccount(accountId)) {
        accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto(), actionForm.getIndividualValues());
    } else if (isGroupMemberAccount(accountId)) {
        accountPaymentParametersDto = preparePaymentParametersDto(accountId, userReferenceDto, amount, actionForm, paymentTypeDto, userContext, paymentType);
    } else {
        accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(accountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto());
    }
    if (paymentTypeDto.getValue().equals(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId())) {
        this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, actionForm.getAccountForTransfer());
    } else {
        this.accountServiceFacade.makePayment(accountPaymentParametersDto);
    }
    request.getSession().setAttribute("globalAccountNum", ((AccountApplyPaymentActionForm) form).getGlobalAccountNum());
    ActionForward findForward;
    if (actionForm.getPrintReceipt()) {
        findForward = mapping.findForward(getForward("PRINT"));
    } else {
        findForward = mapping.findForward(getForward(((AccountApplyPaymentActionForm) form).getInput()));
    }
    return findForward;
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) ActionForward(org.apache.struts.action.ActionForward) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with AccountPaymentParametersDto

use of org.mifos.dto.domain.AccountPaymentParametersDto 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)

Example 3 with AccountPaymentParametersDto

use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.

the class RepayLoanAction method makeGroupMemberRepayment.

public ActionForward makeGroupMemberRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.info("Performing loan repayment");
    UserContext userContext = getUserContext(request);
    UserReferenceDto userReferenceDto = new UserReferenceDto(userContext.getId());
    RepayLoanActionForm repayLoanActionForm = (RepayLoanActionForm) form;
    String globalAccountNum = request.getParameter("globalAccountNum");
    String forward = Constants.UPDATE_SUCCESS;
    Date receiptDate = null;
    if (StringUtils.isNotEmpty(repayLoanActionForm.getReceiptDate())) {
        receiptDate = repayLoanActionForm.getReceiptDateValue(userContext.getPreferredLocale());
    }
    PaymentTypeDto paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(repayLoanActionForm.getPaymentTypeId()));
    LoanBO acctualMemberAccount = loanDao.findByGlobalAccountNum(globalAccountNum);
    Integer accountId = acctualMemberAccount.getAccountId();
    AccountPaymentDto accountPaymentDto = this.accountServiceFacade.getAccountPaymentInformation(accountId, repayLoanActionForm.getPaymentTypeId(), userContext.getLocaleId(), userReferenceDto, repayLoanActionForm.getDateOfPaymentValue(defaultLocale));
    LoanBO parrentAccount = acctualMemberAccount.getParentAccount();
    Integer parentAccountId = parrentAccount.getAccountId();
    AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(parentAccountId), new BigDecimal(repayLoanActionForm.getAmount()), new LocalDate(DateUtils.getDate(repayLoanActionForm.getDateOfPayment())), paymentTypeDto, AccountConstants.NO_COMMENT, new LocalDate(DateUtils.getDate(repayLoanActionForm.getReceiptDate())), repayLoanActionForm.getReceiptNumber(), accountPaymentDto.getCustomerDto());
    BigDecimal totalRepaymentAmount = ((Money) SessionUtils.getAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request)).getAmount();
    BigDecimal waivedAmount = ((Money) SessionUtils.getAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request)).getAmount();
    RepayLoanInfoDto repayLoanInfoDto = new RepayLoanInfoDto(globalAccountNum, repayLoanActionForm.getAmount(), repayLoanActionForm.getReceiptNumber(), receiptDate, repayLoanActionForm.getPaymentTypeId(), userContext.getId(), repayLoanActionForm.isWaiverInterest(), repayLoanActionForm.getDateOfPaymentValue(userContext.getPreferredLocale()), totalRepaymentAmount, waivedAmount);
    HashMap<Integer, String> individualValues = new HashMap<Integer, String>();
    for (LoanBO member : loanDao.findIndividualLoans(parentAccountId)) {
        if (member.isAccountActive()) {
            if (member.getAccountId().equals(acctualMemberAccount.getAccountId())) {
                individualValues.put(member.getAccountId(), repayLoanActionForm.getAmount());
            } else {
                individualValues.put(member.getAccountId(), "0.0");
            }
        }
    }
    accountPaymentParametersDto.setMemberInfo(individualValues);
    accountPaymentParametersDto.setMemberAccountIdToRepay(accountId);
    accountPaymentParametersDto.setRepayLoanInfoDto(repayLoanInfoDto);
    accountPaymentParametersDto.setInterestDueForCurrentInstalmanet(this.loanAccountServiceFacade.calculateInterestDueForCurrentInstalmanet(repayLoanInfoDto));
    if (repayLoanActionForm.isSavingsTransfer()) {
        this.accountServiceFacade.makePaymentFromSavingsAcc(accountPaymentParametersDto, repayLoanActionForm.getAccountForTransfer());
    } else {
        this.accountServiceFacade.makePayment(accountPaymentParametersDto);
    }
    SessionUtils.removeAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, request);
    SessionUtils.removeAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, request);
    SessionUtils.removeAttribute(Constants.ACCOUNTS_FOR_TRANSFER, request);
    request.getSession().setAttribute("globalAccountNum", globalAccountNum);
    if (repayLoanActionForm.getPrintReceipt()) {
        return mapping.findForward(ActionForwards.printPaymentReceipt.toString());
    }
    return mapping.findForward(forward);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) HashMap(java.util.HashMap) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto)

Example 4 with AccountPaymentParametersDto

use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.

the class StandardAccountService method makePayments.

@Override
public void makePayments(List<AccountPaymentParametersDto> accountPaymentParametersDtoList) throws PersistenceException, AccountException {
    /*
         * We're counting on rollback on exception behavior in BaseAction. If we want to expose makePayments via a
         * non-Mifos-Web-UI service, we'll need to handle the rollback here.
         */
    StaticHibernateUtil.startTransaction();
    for (AccountPaymentParametersDto accountPaymentParametersDTO : accountPaymentParametersDtoList) {
        makePaymentNoCommit(accountPaymentParametersDTO);
    }
    StaticHibernateUtil.commitTransaction();
}
Also used : AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto)

Example 5 with AccountPaymentParametersDto

use of org.mifos.dto.domain.AccountPaymentParametersDto in project head by mifos.

the class StandardAccountService method handleParentGroupLoanPayment.

/**
     * Handles parent NOT-GLIM group loan payment.
     */
private void handleParentGroupLoanPayment(AccountBO account, AccountPaymentParametersDto parentPaymentParametersDto, Integer savingsPaymentId, AccountPaymentEntity paymentEntity) throws PersistenceException, AccountException {
    if (account instanceof LoanBO && account.isParentGroupLoanAccount()) {
        if (parentPaymentParametersDto.getMemberInfo() == null || parentPaymentParametersDto.getMemberInfo().isEmpty()) {
            createMembersLoanPaymentsData(parentPaymentParametersDto);
        }
        for (Map.Entry<Integer, String> member : parentPaymentParametersDto.getMemberInfo().entrySet()) {
            AccountBO memberAcc = this.legacyAccountDao.getAccount(member.getKey());
            if (null == parentPaymentParametersDto.getMemberAccountIdToRepay() || (null != parentPaymentParametersDto.getMemberAccountIdToRepay() && !parentPaymentParametersDto.getMemberAccountIdToRepay().equals(memberAcc.getAccountId()))) {
                AccountPaymentParametersDto memberAccountPaymentParametersDto = new AccountPaymentParametersDto(parentPaymentParametersDto.getUserMakingPayment(), new AccountReferenceDto(memberAcc.getAccountId()), new BigDecimal(member.getValue()), parentPaymentParametersDto.getPaymentDate(), parentPaymentParametersDto.getPaymentType(), parentPaymentParametersDto.getComment(), parentPaymentParametersDto.getReceiptDate(), parentPaymentParametersDto.getReceiptId(), memberAcc.getCustomer().toCustomerDto());
                if (parentPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS)) {
                    memberAccountPaymentParametersDto.addPaymentOption(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS);
                }
                makePaymentNoCommit(memberAccountPaymentParametersDto, savingsPaymentId, paymentEntity);
            } else {
                AccountPaymentDto paymentDto = new AccountPaymentDto(Double.valueOf(member.getValue()), parentPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), parentPaymentParametersDto.getReceiptId(), reciptDateNullValidation(parentPaymentParametersDto.getReceiptDate()), parentPaymentParametersDto.getPaymentType().getValue());
                ((LoanBO) memberAcc).makeEarlyRepayment(paymentDto, parentPaymentParametersDto.getUserMakingPayment().getUserId(), parentPaymentParametersDto.getRepayLoanInfoDto().isWaiveInterest(), new Money(account.getCurrency(), parentPaymentParametersDto.getInterestDueForCurrentInstalmanet()));
            }
        }
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Map(java.util.Map) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Aggregations

AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)29 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)21 BigDecimal (java.math.BigDecimal)18 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)18 LocalDate (org.joda.time.LocalDate)17 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)12 Test (org.junit.Test)11 LoanBO (org.mifos.accounts.loan.business.LoanBO)10 Money (org.mifos.framework.util.helpers.Money)8 UserContext (org.mifos.security.util.UserContext)8 AccountBO (org.mifos.accounts.business.AccountBO)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)6 CustomerDto (org.mifos.dto.domain.CustomerDto)6 MifosUser (org.mifos.security.MifosUser)6 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)5 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)5 Date (java.util.Date)4 AccountException (org.mifos.accounts.exceptions.AccountException)4