Search in sources :

Example 1 with AccountPaymentDto

use of org.mifos.accounts.servicefacade.AccountPaymentDto in project head by mifos.

the class AccountApplyGroupPaymentAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = getUserContext(request);
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    actionForm.setReceiptDate(null);
    actionForm.setReceiptId(null);
    actionForm.setPaymentTypeId(null);
    actionForm.setTransactionDate(DateUtils.makeDateAsSentFromBrowser());
    actionForm.setPrintReceipt(false);
    actionForm.setTruePrintReceipt(false);
    final AccountReferenceDto accountReferenceDto = new AccountReferenceDto(Integer.valueOf(actionForm.getAccountId()));
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountReferenceDto.getAccountId(), request.getParameter(Constants.INPUT), userContext.getLocaleId(), new UserReferenceDto(userContext.getId()), DateUtils.getCurrentJavaDateTime());
    setValuesInSession(request, actionForm, accountPaymentDto);
    actionForm.setLastPaymentDate(accountPaymentDto.getLastPaymentDate());
    actionForm.setAmount(accountPaymentDto.getTotalPaymentDue());
    actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
    LoanBO loan = loanDao.findById(accountReferenceDto.getAccountId());
    if (loan.isGroupLoanAccountParent()) {
        SessionUtils.setAttribute(LOAN_TYPE, PARENT, request);
    } else if (loan.isGroupLoanAccountMember()) {
        SessionUtils.setAttribute(LOAN_TYPE, MEMBER, request);
    }
    List<LoanBO> memberInfos = getMemberAccountsInformation(actionForm.getAccountId());
    SessionUtils.setCollectionAttribute("memberInfos", memberInfos, request);
    if (memberInfos.size() > 0) {
        actionForm.getIndividualValues().clear();
        List<GroupIndividualLoanDto> memberAccounts = groupLoanService.getMemberLoansAndDefaultPayments(Integer.valueOf(actionForm.getAccountId()), new BigDecimal(actionForm.getAmount()));
        for (int i = 0; i < memberAccounts.size(); i++) {
            actionForm.getIndividualValues().put(memberAccounts.get(i).getAccountId(), String.valueOf(memberAccounts.get(i).getDefaultAmount().doubleValue()));
        }
    }
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) GroupIndividualLoanDto(org.mifos.dto.domain.GroupIndividualLoanDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) BigDecimal(java.math.BigDecimal) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with AccountPaymentDto

use of org.mifos.accounts.servicefacade.AccountPaymentDto 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 3 with AccountPaymentDto

use of org.mifos.accounts.servicefacade.AccountPaymentDto 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 AccountPaymentDto

use of org.mifos.accounts.servicefacade.AccountPaymentDto in project head by mifos.

the class AccountApplyGroupIndividualAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    UserContext userContext = getUserContext(request);
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) form;
    actionForm.setReceiptDate(null);
    actionForm.setReceiptId(null);
    actionForm.setPaymentTypeId(null);
    actionForm.setTransactionDate(DateUtils.makeDateAsSentFromBrowser());
    actionForm.setPrintReceipt(false);
    actionForm.setTruePrintReceipt(false);
    final AccountReferenceDto accountReferenceDto = new AccountReferenceDto(Integer.valueOf(actionForm.getAccountId()));
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(accountReferenceDto.getAccountId(), request.getParameter(Constants.INPUT), userContext.getLocaleId(), new UserReferenceDto(userContext.getId()), DateUtils.getCurrentJavaDateTime());
    setValuesInSession(request, actionForm, accountPaymentDto);
    actionForm.setLastPaymentDate(accountPaymentDto.getLastPaymentDate());
    actionForm.setAmount(accountPaymentDto.getTotalPaymentDue());
    actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) UserContext(org.mifos.security.util.UserContext) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with AccountPaymentDto

use of org.mifos.accounts.servicefacade.AccountPaymentDto in project head by mifos.

the class AccountApplyGroupPaymentAction method preparePaymentParametersDto.

private AccountPaymentParametersDto preparePaymentParametersDto(Integer accountId, UserReferenceDto userReferenceDto, String amount, AccountApplyPaymentActionForm actionForm, PaymentTypeDto paymentTypeDto, UserContext userContext, String paymentType) throws InvalidDateException {
    LoanBO acctualMemberAccount = loanDao.findById(accountId);
    LoanBO parrentAccount = acctualMemberAccount.getParentAccount();
    Integer parentAccountId = parrentAccount.getAccountId();
    AccountPaymentDto accountPaymentDto = accountServiceFacade.getAccountPaymentInformation(parentAccountId, paymentType, userContext.getLocaleId(), userReferenceDto, actionForm.getTrxnDate());
    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(), amount);
            } else {
                individualValues.put(member.getAccountId(), ZERO_PAYMENT);
            }
        }
    }
    return new AccountPaymentParametersDto(userReferenceDto, new AccountReferenceDto(parentAccountId), new BigDecimal(amount), actionForm.getTrxnDateAsLocalDate(), paymentTypeDto, AccountConstants.NO_COMMENT, actionForm.getReceiptDateAsLocalDate(), actionForm.getReceiptId(), accountPaymentDto.getCustomerDto(), individualValues);
}
Also used : HashMap(java.util.HashMap) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) BigDecimal(java.math.BigDecimal)

Aggregations

AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)9 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)8 UserContext (org.mifos.security.util.UserContext)8 AccountApplyPaymentActionForm (org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)7 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)7 BigDecimal (java.math.BigDecimal)6 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)5 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)4 ActionForward (org.apache.struts.action.ActionForward)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 CloseSession (org.mifos.framework.util.helpers.CloseSession)3 HashMap (java.util.HashMap)2 Date (java.sql.Date)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LocalDate (org.joda.time.LocalDate)1 Test (org.junit.Test)1 RepayLoanActionForm (org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm)1 GroupIndividualLoanDto (org.mifos.dto.domain.GroupIndividualLoanDto)1