Search in sources :

Example 16 with AccountPaymentParametersDto

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

the class StandardAccountServiceTest method testMakeLoanPayments.

/*
     * IGNORING as is not running as unit tests as it accesses hibernate..
     *
     * Make sure that a payment is made for each DTO passed in
     */
@Ignore
@Test
public void testMakeLoanPayments() throws Exception {
    short userId = 1;
    int accountId = 100;
    String paymentAmount = "100";
    List<AccountPaymentParametersDto> accountPaymentParametersDtoList = new ArrayList<AccountPaymentParametersDto>();
    AccountPaymentParametersDto dto1 = createAccountPaymentParametersDto(userId, accountId, paymentAmount);
    AccountPaymentParametersDto dto2 = createAccountPaymentParametersDto(userId, accountId, paymentAmount);
    accountPaymentParametersDtoList.add(dto1);
    accountPaymentParametersDtoList.add(dto2);
    StandardAccountService standardAccountServiceSpy = spy(standardAccountService);
    doNothing().when(standardAccountServiceSpy).makePaymentNoCommit((AccountPaymentParametersDto) any());
    standardAccountServiceSpy.makePayments(accountPaymentParametersDtoList);
    verify(standardAccountServiceSpy).makePaymentNoCommit(dto1);
    verify(standardAccountServiceSpy).makePaymentNoCommit(dto2);
}
Also used : ArrayList(java.util.ArrayList) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with AccountPaymentParametersDto

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

the class LoanAccountRESTController method disburseLoan.

@RequestMapping(value = "/account/loan/num-{globalAccountNum}/disburse", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> disburseLoan(@PathVariable String globalAccountNum, @RequestParam String disbursalDate, @RequestParam(required = false) Short receiptId, @RequestParam(required = false) String receiptDate, @RequestParam Short disbursePaymentTypeId, @RequestParam(required = false) Short paymentModeOfPayment) throws Exception {
    String format = "dd-MM-yyyy";
    DateTime trnxDate = validateDateString(disbursalDate, format);
    validateDisbursementDate(trnxDate);
    DateTime receiptDateTime = null;
    if (receiptDate != null && !receiptDate.isEmpty()) {
        receiptDateTime = validateDateString(receiptDate, format);
        validateDisbursementDate(receiptDateTime);
    }
    validateDisbursementPaymentTypeId(disbursePaymentTypeId, accountService.getLoanDisbursementTypes());
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LoanBO loan = loanDao.findByGlobalAccountNum(globalAccountNum);
    String comment = "";
    Short paymentTypeId = Short.valueOf(disbursePaymentTypeId);
    Money outstandingBeforeDisbursement = loan.getLoanSummary().getOutstandingBalance();
    CustomerDto customerDto = null;
    PaymentTypeDto paymentType = null;
    AccountPaymentParametersDto loanDisbursement;
    if (receiptId == null || receiptDateTime == null) {
        loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()), new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(), trnxDate.toLocalDate(), paymentType, comment);
    } else {
        loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto((short) user.getUserId()), new AccountReferenceDto(loan.getAccountId()), loan.getLoanAmount().getAmount(), trnxDate.toLocalDate(), paymentType, comment, receiptDateTime.toLocalDate(), receiptId.toString(), customerDto);
    }
    // TODO : Pass the account for transfer id properly
    this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, PaymentTypes.CASH.getValue(), null);
    CustomerBO client = loan.getCustomer();
    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("disbursementDate", trnxDate.toLocalDate().toString());
    map.put("disbursementTime", new DateTime().toLocalTime().toString());
    map.put("disbursementAmount", loan.getLastPmnt().getAmount().toString());
    map.put("disbursementMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
    map.put("outstandingBeforeDisbursement", outstandingBeforeDisbursement.toString());
    map.put("outstandingAfterDisbursement", 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) 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)

Example 18 with AccountPaymentParametersDto

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

the class StandardAccountService method createParentLoanPaymentData.

/**
     * Create parent payment data with member payment data. 
     * 
     */
private AccountPaymentParametersDto createParentLoanPaymentData(AccountBO memberAccount, AccountPaymentParametersDto memberPaymentParametersDto) {
    AccountPaymentParametersDto parentPaymentParametersDto = new AccountPaymentParametersDto(memberPaymentParametersDto.getUserMakingPayment(), new AccountReferenceDto(((LoanBO) memberAccount).getParentAccount().getAccountId()), memberPaymentParametersDto.getPaymentAmount(), memberPaymentParametersDto.getPaymentDate(), memberPaymentParametersDto.getPaymentType(), memberPaymentParametersDto.getComment(), memberPaymentParametersDto.getReceiptDate(), memberPaymentParametersDto.getReceiptId(), memberAccount.getCustomer().toCustomerDto());
    Map<Integer, String> membersPaymentsData = new HashMap<Integer, String>();
    for (AccountBO member : ((LoanBO) memberAccount).getParentAccount().getMemberAccounts()) {
        if (member.isActiveLoanAccount()) {
            if (member.getAccountId().equals(memberPaymentParametersDto.getAccountId())) {
                membersPaymentsData.put(member.getAccountId(), memberPaymentParametersDto.getPaymentAmount().toString());
            } else {
                membersPaymentsData.put(member.getAccountId(), BigDecimal.ZERO.toString());
            }
        }
    }
    parentPaymentParametersDto.setMemberInfo(membersPaymentsData);
    return parentPaymentParametersDto;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) HashMap(java.util.HashMap) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto)

Example 19 with AccountPaymentParametersDto

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

the class StandardAccountService method lookupPayments.

@Override
public List<AccountPaymentParametersDto> lookupPayments(AccountReferenceDto accountRef) throws PersistenceException {
    final int accountId = accountRef.getAccountId();
    final AccountBO account = this.legacyAccountDao.getAccount(accountId);
    List<AccountPaymentParametersDto> paymentDtos = new ArrayList<AccountPaymentParametersDto>();
    for (AccountPaymentEntity paymentEntity : account.getAccountPayments()) {
        paymentDtos.add(makePaymentDto(paymentEntity));
    }
    return paymentDtos;
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto)

Example 20 with AccountPaymentParametersDto

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

the class StandardAccountService method makeImportedPayments.

/**
     * method created for undo transaction import ability MIFOS-5702
     * returns Id of transaction  
     * */
public AccountBO makeImportedPayments(AccountPaymentParametersDto accountPaymentParametersDto, Integer savingsPaymentId) throws PersistenceException, AccountException {
    final int accountId = accountPaymentParametersDto.getAccountId();
    final AccountBO account = this.legacyAccountDao.getAccount(accountId);
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    try {
        personnelDao.checkAccessPermission(userContext, account.getOfficeId(), account.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED, e);
    }
    monthClosingServiceFacade.validateTransactionDate(accountPaymentParametersDto.getPaymentDate().toDateMidnight().toDate());
    /**
         * Handle member payment if parent payment data not provided.
         * Situation may occur when payment is executed directly on group member account (e.g. from transaction import).
         * Loan Group Member payments should be posted after parent payment.
         */
    if (account.isGroupLoanAccountMember()) {
        AccountPaymentParametersDto parentPaymentParametersDto = this.createParentLoanPaymentData(account, accountPaymentParametersDto);
        return makeImportedPayments(parentPaymentParametersDto, savingsPaymentId);
    }
    PersonnelBO loggedInUser = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(accountPaymentParametersDto.getUserMakingPayment().getUserId());
    List<InvalidPaymentReason> validationErrors = validatePayment(accountPaymentParametersDto);
    if (!(account instanceof CustomerAccountBO) && validationErrors.contains(InvalidPaymentReason.INVALID_DATE)) {
        throw new AccountException("errors.invalidTxndate");
    }
    Money overpaymentAmount = null;
    Money amount = new Money(account.getCurrency(), accountPaymentParametersDto.getPaymentAmount());
    if (account instanceof LoanBO && accountPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS) && amount.isGreaterThan(((LoanBO) account).getTotalRepayableAmount())) {
        overpaymentAmount = amount.subtract(((LoanBO) account).getTotalRepayableAmount());
        amount = ((LoanBO) account).getTotalRepayableAmount();
    }
    Date receiptDate = null;
    if (accountPaymentParametersDto.getReceiptDate() != null) {
        receiptDate = accountPaymentParametersDto.getReceiptDate().toDateMidnight().toDate();
    }
    PaymentData paymentData = account.createPaymentData(amount, accountPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), accountPaymentParametersDto.getReceiptId(), receiptDate, accountPaymentParametersDto.getPaymentType().getValue(), loggedInUser);
    if (savingsPaymentId != null) {
        AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
        paymentData.setOtherTransferPayment(withdrawal);
    }
    if (accountPaymentParametersDto.getCustomer() != null) {
        paymentData.setCustomer(customerDao.findCustomerById(accountPaymentParametersDto.getCustomer().getCustomerId()));
    }
    paymentData.setComment(accountPaymentParametersDto.getComment());
    paymentData.setOverpaymentAmount(overpaymentAmount);
    if (accountPaymentParametersDto.getPaymentOptions().contains(PaymentOptions.ALLOW_OVERPAYMENTS)) {
        paymentData.setAllowOverpayment(true);
    }
    AccountPaymentEntity paymentEntity = account.applyPayment(paymentData);
    handleParentGroupLoanPayment(account, accountPaymentParametersDto, savingsPaymentId, paymentEntity);
    this.legacyAccountDao.createOrUpdate(account);
    /*
         * Return null when only overpayment is being apply
         */
    if (amount.isZero() && overpaymentAmount != null && overpaymentAmount.isGreaterThanZero()) {
        return null;
    }
    return account;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) PaymentData(org.mifos.accounts.util.helpers.PaymentData) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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