Search in sources :

Example 16 with AccountApplyPaymentActionForm

use of org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm in project head by mifos.

the class AccountApplyGroupIndividualAction 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;
    Integer accountId = Integer.valueOf(actionForm.getAccountId());
    String paymentType = request.getParameter(Constants.INPUT);
    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)) {
        paymentTypeDto = getLoanPaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    } else {
        paymentTypeDto = getFeePaymentTypeDtoForId(Short.valueOf(actionForm.getPaymentTypeId()));
    }
    AccountPaymentParametersDto 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 17 with AccountApplyPaymentActionForm

use of org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm in project head by mifos.

the class AccountApplyPaymentActionTest method loadShouldSetLastPaymentDateOnForm.

@Test
public void loadShouldSetLastPaymentDateOnForm() throws Exception {
    when(accountServiceFacade.getAccountPaymentInformation(Matchers.<Integer>any(), Matchers.<String>any(), Matchers.<Short>any(), Matchers.<UserReferenceDto>any(), Matchers.<Date>any())).thenReturn(new AccountPaymentDto(null, 0, null, null, null, new Date(1234), null, null));
    when(form.getAccountId()).thenReturn("1");
    accountApplyPaymentAction = new AccountApplyPaymentAction(accountServiceFacade, legacyAcceptedPaymentTypeDao) {

        @Override
        protected UserContext getUserContext(HttpServletRequest request) {
            return userContext;
        }

        @Override
        void setValuesInSession(HttpServletRequest request, AccountApplyPaymentActionForm actionForm, AccountPaymentDto accountPaymentDto) throws PageExpiredException {
        }
    };
    accountApplyPaymentAction.load(actionMapping, form, request, response);
    verify(form).setLastPaymentDate(new Date(1234));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserContext(org.mifos.security.util.UserContext) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AccountPaymentDto(org.mifos.accounts.servicefacade.AccountPaymentDto) Date(java.util.Date) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) Test(org.junit.Test)

Example 18 with AccountApplyPaymentActionForm

use of org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm in project head by mifos.

the class ApplyPaymentActionStrutsTest method testApplyPaymentLoad_Fees.

// added for defect 1590 [start]
@Test
public void testApplyPaymentLoad_Fees() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    accountBO = createLoanAccount();
    setRequestPathInfo("/applyPaymentAction");
    addRequestParameter("method", "load");
    addRequestParameter("input", "fee");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward(Constants.LOAD_SUCCESS);
    verifyNoActionErrors();
    Assert.assertNotNull(SessionUtils.getAttribute(MasterConstants.PAYMENT_TYPE, request));
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) request.getSession().getAttribute("applyPaymentActionForm");
    Assert.assertEquals(actionForm.getAmount(), accountBO.getTotalPaymentDue().toString());
}
Also used : AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) Test(org.junit.Test)

Example 19 with AccountApplyPaymentActionForm

use of org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm in project head by mifos.

the class ApplyPaymentActionStrutsTest method xtestApplyPaymentForLoan.

public void xtestApplyPaymentForLoan() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    accountBO = createLoanAccount();
    accountBO.setUserContext(TestObjectFactory.getContext());
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    accountBO.changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "", loggedInUser);
    AccountApplyPaymentActionForm accountApplyPaymentActionForm = new AccountApplyPaymentActionForm();
    accountApplyPaymentActionForm.setAmount("212");
    request.getSession().setAttribute("applyPaymentActionForm", accountApplyPaymentActionForm);
    SessionUtils.setAttribute(Constants.ACCOUNT_VERSION, accountBO.getVersionNo(), request);
    SessionUtils.setAttribute(Constants.ACCOUNT_TYPE, AccountTypes.getAccountType(accountBO.getAccountType().getAccountTypeId()).name(), request);
    SessionUtils.setAttribute(Constants.ACCOUNT_ID, accountBO.getAccountId(), request);
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    setRequestPathInfo("/applyPaymentAction");
    addRequestParameter("input", "loan");
    addRequestParameter("method", "applyPayment");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter("receiptId", "101");
    String currentDate = DateUtils.makeDateAsSentFromBrowser();
    addRequestDateParameter("receiptDate", currentDate);
    addRequestDateParameter("transactionDate", currentDate);
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward("loan_detail_page");
    Assert.assertEquals(new Money(getCurrency()), accountBO.getTotalPaymentDue());
    Assert.assertEquals(0, accountBO.getTotalInstallmentsDue().size());
    Assert.assertEquals(AccountStates.LOANACC_ACTIVEINGOODSTANDING, accountBO.getAccountState().getId().shortValue());
}
Also used : Money(org.mifos.framework.util.helpers.Money) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)

Example 20 with AccountApplyPaymentActionForm

use of org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm in project head by mifos.

the class ApplyPaymentActionStrutsTest method testApplyPaymentLoad_Loan.

@Test
public void testApplyPaymentLoad_Loan() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    accountBO = createLoanAccount();
    setRequestPathInfo("/applyPaymentAction");
    addRequestParameter("method", "load");
    addRequestParameter("input", "loan");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward(Constants.LOAD_SUCCESS);
    verifyNoActionErrors();
    Assert.assertNotNull(SessionUtils.getAttribute(MasterConstants.PAYMENT_TYPE, request));
    AccountApplyPaymentActionForm actionForm = (AccountApplyPaymentActionForm) request.getSession().getAttribute("applyPaymentActionForm");
    Assert.assertEquals(actionForm.getAmount(), accountBO.getTotalPaymentDue().toString());
}
Also used : AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm) Test(org.junit.Test)

Aggregations

AccountApplyPaymentActionForm (org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)21 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)14 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)7 UserContext (org.mifos.security.util.UserContext)7 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)6 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)6 BigDecimal (java.math.BigDecimal)5 Test (org.junit.Test)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)4 ActionForward (org.apache.struts.action.ActionForward)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)3 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)3 CloseSession (org.mifos.framework.util.helpers.CloseSession)3 Money (org.mifos.framework.util.helpers.Money)3 GroupIndividualLoanDto (org.mifos.dto.domain.GroupIndividualLoanDto)2 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AccountBO (org.mifos.accounts.business.AccountBO)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1