Search in sources :

Example 16 with UserReferenceDto

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

the class AccountApplyPaymentAction 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()) {
        if (accountPaymentDto.getAccountType().equals(AccountTypeDto.LOAN_ACCOUNT)) {
            findForward = mapping.findForward(getForward("PRINT"));
        } else {
            request.getSession().setAttribute("clientSystemId", accountPaymentDto.getCustomerDto().getGlobalCustNum());
            findForward = mapping.findForward(getForward("PRINT_CLIENT"));
        }
    } 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 UserReferenceDto

use of org.mifos.dto.domain.UserReferenceDto 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 18 with UserReferenceDto

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

the class StandardAccountServiceIntegrationTest method testMakePaymentForLoanAccount.

@Test
public void testMakePaymentForLoanAccount() throws Exception {
    String payemntAmount = "700";
    CustomerDto clientDto = new CustomerDto();
    clientDto.setCustomerId(client.getCustomerId());
    LocalDate paymentDate = new LocalDate();
    LocalDate receiptDate = new LocalDate().minusDays(3);
    String receiptNumber = "AA/03/UX-9Q";
    AccountPaymentParametersDto loanPayment = new AccountPaymentParametersDto(new UserReferenceDto(groupLoan.getPersonnel().getPersonnelId()), new AccountReferenceDto(groupLoan.getAccountId()), new BigDecimal(payemntAmount), paymentDate, defaultPaymentType, "comment", receiptDate, receiptNumber, clientDto);
    standardAccountService.makePayment(loanPayment);
    TestObjectFactory.updateObject(groupLoan);
    Assert.assertEquals("The amount returned for the payment should have been " + payemntAmount, Double.parseDouble(payemntAmount), groupLoan.getLastPmntAmnt());
    Assert.assertEquals(1, groupLoan.getAccountPayments().size());
    for (AccountPaymentEntity payment : groupLoan.getAccountPayments()) {
        Assert.assertEquals(TestUtils.createMoney(payemntAmount), payment.getAmount());
        Assert.assertEquals(paymentDate.toDateMidnight().toDate(), payment.getPaymentDate());
        Assert.assertEquals(defaultPaymentType.getName(), payment.getPaymentType().getName());
        Assert.assertEquals("comment", payment.getComment());
        Assert.assertEquals(groupLoan, payment.getAccount());
        Assert.assertEquals(groupLoan.getPersonnel(), payment.getCreatedByUser());
        Assert.assertEquals(receiptDate.toDateMidnight().toDate(), payment.getReceiptDate());
        Assert.assertEquals(receiptNumber, payment.getReceiptNumber());
        Assert.assertNull(payment.getCheckNumber());
        Assert.assertNull(payment.getBankName());
        Assert.assertNull(payment.getVoucherNumber());
        Assert.assertFalse(payment.isSavingsDeposit());
        Assert.assertFalse(payment.isSavingsWithdrawal());
        Assert.assertFalse(payment.isSavingsDepositOrWithdrawal());
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            Assert.assertEquals(group.getCustomerId(), accountTrxn.getCustomer().getCustomerId());
        }
    }
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) CustomerDto(org.mifos.dto.domain.CustomerDto) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 19 with UserReferenceDto

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

the class StandardAccountServiceIntegrationTest method testValidatePaymentWithInvalidPaymentType.

@Test
public void testValidatePaymentWithInvalidPaymentType() throws Exception {
    String paymentAmount = "700";
    PaymentTypeDto invalidPaymentType = new PaymentTypeDto((short) -1, "pseudo payment type! Not cash, check, etc.");
    AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(new UserReferenceDto(groupLoan.getPersonnel().getPersonnelId()), new AccountReferenceDto(groupLoan.getAccountId()), new BigDecimal(paymentAmount), new LocalDate(), invalidPaymentType, "");
    List<InvalidPaymentReason> errors = standardAccountService.validatePayment(accountPaymentParametersDto);
    Assert.assertTrue(errors.contains(InvalidPaymentReason.UNSUPPORTED_PAYMENT_TYPE));
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 20 with UserReferenceDto

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

the class StandardAccountServiceIntegrationTest method testValidateValidPayment.

@Test
public void testValidateValidPayment() throws Exception {
    String paymentAmount = "10";
    AccountPaymentParametersDto accountPaymentParametersDto = new AccountPaymentParametersDto(new UserReferenceDto(groupLoan.getPersonnel().getPersonnelId()), new AccountReferenceDto(groupLoan.getAccountId()), new BigDecimal(paymentAmount), new LocalDate(), defaultPaymentType, "");
    List<InvalidPaymentReason> errors = standardAccountService.validatePayment(accountPaymentParametersDto);
    Assert.assertEquals(0, errors.size());
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)24 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)22 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)18 BigDecimal (java.math.BigDecimal)17 LocalDate (org.joda.time.LocalDate)15 Test (org.junit.Test)11 PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)11 UserContext (org.mifos.security.util.UserContext)8 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)7 CustomerDto (org.mifos.dto.domain.CustomerDto)7 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7 LoanBO (org.mifos.accounts.loan.business.LoanBO)6 AccountApplyPaymentActionForm (org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)6 Money (org.mifos.framework.util.helpers.Money)6 CloseSession (org.mifos.framework.util.helpers.CloseSession)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ActionForward (org.apache.struts.action.ActionForward)3 MifosUser (org.mifos.security.MifosUser)3 DateTime (org.joda.time.DateTime)2