Search in sources :

Example 11 with PaymentTypeDto

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

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

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

the class StandardAccountServiceTest method testDisbursalAmountMustMatchFullLoanAmount.

@Test
public void testDisbursalAmountMustMatchFullLoanAmount() throws Exception {
    when(mockLoanAccount.getLoanAmount()).thenReturn(new Money(TestUtils.EURO, "300"));
    AccountPaymentParametersDto disbursal = new AccountPaymentParametersDto(new UserReferenceDto((short) 1), new AccountReferenceDto(1), new BigDecimal("299"), new LocalDate(), new PaymentTypeDto((short) 1, "CASH"), "");
    List<InvalidPaymentReason> errors = new ArrayList<InvalidPaymentReason>();
    standardAccountService.disbursalAmountMatchesFullLoanAmount(disbursal.getPaymentAmount(), errors, mockLoanAccount);
    assertThat(errors.get(0), is(InvalidPaymentReason.INVALID_LOAN_DISBURSAL_AMOUNT));
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) ArrayList(java.util.ArrayList) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 14 with PaymentTypeDto

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

the class K2RESTController method processLoanPayment.

private Map<String, String> processLoanPayment(LoanBO loanBO, String k2TransactionId, String acNo, String mmSystemId, LocalDate transactionDate, BigDecimal amount, String currency) throws Exception {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserReferenceDto userDto = new UserReferenceDto((short) user.getUserId());
    AccountReferenceDto accountReferenceDto = new AccountReferenceDto(loanBO.getAccountId());
    PaymentTypeDto paymentTypeDto = null;
    List<PaymentTypeDto> loanPaymentTypes = accountService.getLoanPaymentTypes();
    for (PaymentTypeDto paymentTypeDtoIterator : loanPaymentTypes) {
        if (paymentTypeDtoIterator.getName().equals(mmSystemId)) {
            paymentTypeDto = paymentTypeDtoIterator;
            break;
        }
    }
    if (paymentTypeDto == null || !loanBO.getCurrency().getCurrencyCode().equals(currency)) {
        return invalidPayment();
    }
    CustomerDto customerDto = loanBO.getCustomer().toCustomerDto();
    LocalDate receiptLocalDate = transactionDate;
    String receiptIdString = k2TransactionId;
    AccountPaymentParametersDto payment = new AccountPaymentParametersDto(userDto, accountReferenceDto, amount, transactionDate, paymentTypeDto, acNo, receiptLocalDate, receiptIdString, customerDto);
    accountService.makePayment(payment);
    return accepted();
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) CustomerDto(org.mifos.dto.domain.CustomerDto) MifosUser(org.mifos.security.MifosUser) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate)

Example 15 with PaymentTypeDto

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

the class LoanAccountRESTController method repay.

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/repay", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> repay(@PathVariable String globalAccountNum, @RequestParam BigDecimal amount, @RequestParam(required = false) String paymentDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam(required = false) Short paymentModeId) throws Exception {
    validateAmount(amount);
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    validateLoanAccountState(loan);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserReferenceDto userDto = new UserReferenceDto((short) user.getUserId());
    Money outstandingBeforePayment = loan.getLoanSummary().getOutstandingBalance();
    AccountReferenceDto accountDto = new AccountReferenceDto(loan.getAccountId());
    DateTime today = new DateTime();
    DateTime paymentDateTime = today;
    if (paymentDate != null && !paymentDate.isEmpty()) {
        paymentDateTime = validateDateString(paymentDate, format);
    }
    String receiptIdString = null;
    if (receiptId != null) {
        receiptIdString = receiptId.toString();
    }
    LocalDate receiptLocalDate = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptLocalDate = validateDateString(receiptDate, format).toLocalDate();
    }
    PaymentTypeDto paymentType = new PaymentTypeDto(paymentModeId, "");
    validatePaymentTypeId(paymentType, accountService.getLoanPaymentTypes());
    CustomerBO client = loan.getCustomer();
    CustomerDto customer = new CustomerDto();
    customer.setCustomerId(client.getCustomerId());
    AccountPaymentParametersDto payment = new AccountPaymentParametersDto(userDto, accountDto, amount, paymentDateTime.toLocalDate(), paymentType, globalAccountNum, receiptLocalDate, receiptIdString, customer);
    accountService.makePayment(payment);
    Map<String, String> map = new HashMap<String, String>();
    map.put("status", "success");
    map.put("clientName", client.getDisplayName());
    map.put("clientNumber", client.getGlobalCustNum());
    map.put("loanDisplayName", loan.getLoanOffering().getPrdOfferingName());
    map.put("paymentDate", today.toLocalDate().toString());
    map.put("paymentTime", today.toLocalTime().toString());
    map.put("paymentAmount", loan.getLastPmnt().getAmount().toString());
    map.put("paymentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforePayment", outstandingBeforePayment.toString());
    map.put("outstandingAfterPayment", loan.getLoanSummary().getOutstandingBalance().toString());
    return map;
}
Also used : HashMap(java.util.HashMap) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) MifosUser(org.mifos.security.MifosUser) PaymentTypeDto(org.mifos.dto.domain.PaymentTypeDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) Money(org.mifos.framework.util.helpers.Money) CustomerBO(org.mifos.customers.business.CustomerBO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PaymentTypeDto (org.mifos.dto.domain.PaymentTypeDto)15 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)12 AccountReferenceDto (org.mifos.dto.domain.AccountReferenceDto)11 UserReferenceDto (org.mifos.dto.domain.UserReferenceDto)11 BigDecimal (java.math.BigDecimal)9 LocalDate (org.joda.time.LocalDate)9 UserContext (org.mifos.security.util.UserContext)6 ArrayList (java.util.ArrayList)5 LoanBO (org.mifos.accounts.loan.business.LoanBO)5 Money (org.mifos.framework.util.helpers.Money)5 AccountPaymentDto (org.mifos.accounts.servicefacade.AccountPaymentDto)4 CustomerDto (org.mifos.dto.domain.CustomerDto)4 CloseSession (org.mifos.framework.util.helpers.CloseSession)4 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)4 MifosUser (org.mifos.security.MifosUser)4 HashMap (java.util.HashMap)3 ActionForward (org.apache.struts.action.ActionForward)3 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 AccountException (org.mifos.accounts.exceptions.AccountException)3