Search in sources :

Example 1 with AccountPaymentDto

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

the class LoanAdjustmentsIntegrationTest method makeEarlyPayment.

private void makeEarlyPayment(LoanBO loan) throws AccountException {
    loan.makeEarlyRepayment(new AccountPaymentDto(loan.getEarlyRepayAmount().getAmount().doubleValue(), new DateTimeService().getCurrentJavaDateTime(), "", null, (short) 1), testUser().getPersonnelId(), false, new Money(loan.getCurrency(), "0"));
    StaticHibernateUtil.flushSession();
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 2 with AccountPaymentDto

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

the class StandardAccountService method handleParentGroupLoanPayment.

/**
     * Handles parent NOT-GLIM group loan payment.
     */
private void handleParentGroupLoanPayment(AccountBO account, AccountPaymentParametersDto parentPaymentParametersDto, Integer savingsPaymentId, AccountPaymentEntity paymentEntity) throws PersistenceException, AccountException {
    if (account instanceof LoanBO && account.isParentGroupLoanAccount()) {
        if (parentPaymentParametersDto.getMemberInfo() == null || parentPaymentParametersDto.getMemberInfo().isEmpty()) {
            createMembersLoanPaymentsData(parentPaymentParametersDto);
        }
        for (Map.Entry<Integer, String> member : parentPaymentParametersDto.getMemberInfo().entrySet()) {
            AccountBO memberAcc = this.legacyAccountDao.getAccount(member.getKey());
            if (null == parentPaymentParametersDto.getMemberAccountIdToRepay() || (null != parentPaymentParametersDto.getMemberAccountIdToRepay() && !parentPaymentParametersDto.getMemberAccountIdToRepay().equals(memberAcc.getAccountId()))) {
                AccountPaymentParametersDto memberAccountPaymentParametersDto = new AccountPaymentParametersDto(parentPaymentParametersDto.getUserMakingPayment(), new AccountReferenceDto(memberAcc.getAccountId()), new BigDecimal(member.getValue()), parentPaymentParametersDto.getPaymentDate(), parentPaymentParametersDto.getPaymentType(), parentPaymentParametersDto.getComment(), parentPaymentParametersDto.getReceiptDate(), parentPaymentParametersDto.getReceiptId(), memberAcc.getCustomer().toCustomerDto());
                if (parentPaymentParametersDto.getPaymentOptions().contains(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS)) {
                    memberAccountPaymentParametersDto.addPaymentOption(AccountPaymentParametersDto.PaymentOptions.ALLOW_OVERPAYMENTS);
                }
                makePaymentNoCommit(memberAccountPaymentParametersDto, savingsPaymentId, paymentEntity);
            } else {
                AccountPaymentDto paymentDto = new AccountPaymentDto(Double.valueOf(member.getValue()), parentPaymentParametersDto.getPaymentDate().toDateMidnight().toDate(), parentPaymentParametersDto.getReceiptId(), reciptDateNullValidation(parentPaymentParametersDto.getReceiptDate()), parentPaymentParametersDto.getPaymentType().getValue());
                ((LoanBO) memberAcc).makeEarlyRepayment(paymentDto, parentPaymentParametersDto.getUserMakingPayment().getUserId(), parentPaymentParametersDto.getRepayLoanInfoDto().isWaiveInterest(), new Money(account.getCurrency(), parentPaymentParametersDto.getInterestDueForCurrentInstalmanet()));
            }
        }
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Map(java.util.Map) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Example 3 with AccountPaymentDto

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

the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentForNotWaiverInterestLoanProduct.

@Test
public void testMakeEarlyRepaymentForNotWaiverInterestLoanProduct() throws AccountException, PersistenceException {
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    boolean waiveInterest = false;
    when(loanBO.getCurrency()).thenReturn(rupee);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    LoanScheduleEntity loanScheduleEntity = new LoanScheduleEntity() {
    };
    loanScheduleEntity.setInterest(new Money(rupee, 100d));
    when(loanBO.getDetailsOfNextInstallment()).thenReturn(loanScheduleEntity);
    java.sql.Date date = mock(java.sql.Date.class);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    String paymentMethod = "1";
    String receiptNumber = "001";
    AccountPaymentDto paymentDto = new AccountPaymentDto(new Double(100), date, receiptNumber, date, Short.valueOf((short) 1));
    loanAccountServiceFacade.makeEarlyRepayment(new RepayLoanInfoDto("1", "100.0", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.ZERO, BigDecimal.ZERO));
    short userId = (short) 1;
    verify(loanBO).makeEarlyRepayment(paymentDto, userId, waiveInterest, new Money(rupee, 100d));
    verify(loanBusinessService).computeExtraInterest(loanBO, date);
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) Money(org.mifos.framework.util.helpers.Money) RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Test(org.junit.Test)

Example 4 with AccountPaymentDto

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

the class LoanBO method makeEarlyRepayment.

public void makeEarlyRepayment(final AccountPaymentDto paymentDto, final Short personnelId, boolean waiveInterest, Money interestDue, Integer savingsPaymentId, AccountPaymentEntity parentPayment) throws AccountException {
    try {
        PersonnelBO currentUser = legacyPersonnelDao.getPersonnel(personnelId);
        this.setUpdatedBy(personnelId);
        this.setUpdatedDate(paymentDto.getTransactionDate());
        AccountPaymentEntity accountPaymentEntity;
        if (this.isGroupLoanAccount() && null != this.getParentAccount()) {
            accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate(), parentPayment);
        } else {
            accountPaymentEntity = new AccountPaymentEntity(this, new Money(getCurrency(), paymentDto.getTotalAmount()), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), getPaymentTypeEntity(Short.valueOf(paymentDto.getPaymentTypeId())), paymentDto.getTransactionDate());
        }
        if (savingsPaymentId != null) {
            AccountPaymentEntity withdrawal = legacyAccountDao.findPaymentById(savingsPaymentId);
            accountPaymentEntity.setOtherTransferPayment(withdrawal);
        }
        addAccountPayment(accountPaymentEntity);
        makeEarlyRepaymentForArrears(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
        makeEarlyRepaymentForNextInstallment(currentUser, accountPaymentEntity, waiveInterest, interestDue);
        makeEarlyRepaymentForFutureInstallments(accountPaymentEntity, AccountConstants.PAYMENT_RCVD, AccountActionTypes.LOAN_REPAYMENT, currentUser);
        if (getPerformanceHistory() != null) {
            getPerformanceHistory().setNoOfPayments(getPerformanceHistory().getNoOfPayments() + 1);
        }
        LoanActivityEntity loanActivity = buildLoanActivity(accountPaymentEntity.getAccountTrxns(), currentUser, AccountConstants.LOAN_REPAYMENT, paymentDto.getTransactionDate());
        addLoanActivity(loanActivity);
        buildFinancialEntries(accountPaymentEntity.getAccountTrxns());
        AccountStateEntity newAccountState = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET);
        addAccountStatusChangeHistory(new AccountStatusChangeHistoryEntity(getAccountState(), newAccountState, legacyPersonnelDao.getPersonnel(personnelId), this));
        setAccountState(legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_OBLIGATIONSMET));
        changeStateForAllFees(FeeStatus.INACTIVE);
        setClosedDate(paymentDto.getTransactionDate());
        // Client performance entry
        updateCustomerHistoryOnRepayment();
        this.delete(loanArrearsAgingEntity);
        loanArrearsAgingEntity = null;
        // GLIM
        if (this.isGroupLoanAccountParent()) {
            for (Entry<String, AmountWithInterest> entry : paymentDto.getMemberNumWithAmount().entrySet()) {
                AccountPaymentDto memberPayment = new AccountPaymentDto(entry.getValue().getAmount(), paymentDto.getTransactionDate(), paymentDto.getReceiptNumber(), paymentDto.getReceiptDate(), paymentDto.getPaymentTypeId());
                legacyLoanDao.getAccount(Integer.valueOf(entry.getKey())).makeEarlyRepayment(memberPayment, personnelId, waiveInterest, new Money(this.getCurrency(), entry.getValue().getInterest()), null, accountPaymentEntity);
            }
        } else if (hasMemberAccounts() && !this.isGroupLoanAccount()) {
            for (LoanBO memberAccount : this.memberAccounts) {
                BigDecimal fraction = memberAccount.calcFactorOfEntireLoan();
                paymentDto.setTotalAmount(new BigDecimal(paymentDto.getTotalAmount()).divide(fraction, RoundingMode.HALF_UP).doubleValue());
                memberAccount.makeEarlyRepayment(paymentDto, personnelId, waiveInterest, interestDue, null, null);
            }
        }
        this.legacyAccountDao.createOrUpdate(accountPaymentEntity);
        this.legacyAccountDao.createOrUpdate(this);
    } catch (PersistenceException e) {
        throw new AccountException(e);
    }
}
Also used : AmountWithInterest(org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) BigDecimal(java.math.BigDecimal) Money(org.mifos.framework.util.helpers.Money) AccountException(org.mifos.accounts.exceptions.AccountException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto)

Example 5 with AccountPaymentDto

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

the class LoanAccountServiceFacadeWebTierTest method testMakeEarlyRepaymentFromSavings.

@Test
public void testMakeEarlyRepaymentFromSavings() throws AccountException, PersistenceException {
    final String savingsAccGlobalNum = "0001-00000009";
    setMifosUserFromContext();
    when(loanDao.findByGlobalAccountNum("1")).thenReturn(loanBO);
    when(loanDao.findById(0)).thenReturn(loanBO);
    final java.sql.Date date = new java.sql.Date(new Date().getTime());
    when(customerDao.getFirstMeetingDateForCustomer(2)).thenReturn(date);
    when(configurationPersistence.isRepaymentIndepOfMeetingEnabled()).thenReturn(false);
    when(loanBO.getCurrency()).thenReturn(rupee);
    boolean waiveInterest = true;
    when(loanBO.isInterestWaived()).thenReturn(waiveInterest);
    when(loanBO.getOfficeId()).thenReturn((short) 1);
    when(loanBO.getCustomer()).thenReturn(customer);
    when(loanBO.isTrxnDateValid(date, date, false)).thenReturn(true);
    when(customer.getLoanOfficerId()).thenReturn((short) 1);
    when(customer.getCustomerId()).thenReturn(2);
    when(savingsServiceFacade.retrieveSavingsAccountDetails(savingsAccGlobalNum)).thenReturn(savingsAccountDetailDto);
    when(savingsAccountDetailDto.getCustomerId()).thenReturn(2);
    when(savingsAccountDetailDto.getAccountId()).thenReturn(1);
    String paymentMethod = "4";
    String receiptNumber = "001";
    when(savingsServiceFacade.withdraw(any(SavingsWithdrawalDto.class), eq(true))).thenReturn(withdrawal);
    when(withdrawal.getPaymentId()).thenReturn(1);
    loanAccountServiceFacade.makeEarlyRepaymentFromSavings(new RepayLoanInfoDto("1", "100", receiptNumber, date, paymentMethod, (short) 1, waiveInterest, date, BigDecimal.TEN, BigDecimal.ZERO), savingsAccGlobalNum);
    ArgumentCaptor<SavingsWithdrawalDto> withdrawal = ArgumentCaptor.forClass(SavingsWithdrawalDto.class);
    verify(savingsServiceFacade).withdraw(withdrawal.capture(), eq(true));
    final Long savingsId = savingsAccountDetailDto.getAccountId().longValue();
    final Long customerId = savingsAccountDetailDto.getCustomerId().longValue();
    final LocalDate trxnDate = new LocalDate(date);
    final LocalDate receiptDate = new LocalDate(date);
    final Double amount = Double.parseDouble("100");
    final Integer modeOfPayment = 4;
    AccountPaymentDto paymentDto = new AccountPaymentDto(amount, date, receiptNumber, date, Short.valueOf((short) 1));
    assertEquals(withdrawal.getValue().getAmount(), amount);
    assertEquals(withdrawal.getValue().getSavingsId(), savingsId);
    assertEquals(withdrawal.getValue().getCustomerId(), customerId);
    assertEquals(withdrawal.getValue().getDateOfWithdrawal(), trxnDate);
    assertEquals(withdrawal.getValue().getDateOfReceipt(), receiptDate);
    assertEquals(withdrawal.getValue().getModeOfPayment(), modeOfPayment);
    assertEquals(withdrawal.getValue().getPreferredLocale(), userContext.getPreferredLocale());
    verify(loanBO).makeEarlyRepayment(paymentDto, (short) 1, waiveInterest, new Money(rupee, BigDecimal.ZERO), 1, null);
}
Also used : RepayLoanInfoDto(org.mifos.dto.screen.RepayLoanInfoDto) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) Test(org.junit.Test)

Aggregations

AccountPaymentDto (org.mifos.dto.domain.AccountPaymentDto)6 Money (org.mifos.framework.util.helpers.Money)6 Test (org.junit.Test)3 RepayLoanInfoDto (org.mifos.dto.screen.RepayLoanInfoDto)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 LocalDate (org.joda.time.LocalDate)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AccountBO (org.mifos.accounts.business.AccountBO)1 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)1 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)1 AccountStatusChangeHistoryEntity (org.mifos.accounts.business.AccountStatusChangeHistoryEntity)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 LoanBO (org.mifos.accounts.loan.business.LoanBO)1 LoanScheduleEntity (org.mifos.accounts.loan.business.LoanScheduleEntity)1 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 AmountWithInterest (org.mifos.dto.domain.AccountPaymentDto.AmountWithInterest)1 AccountPaymentParametersDto (org.mifos.dto.domain.AccountPaymentParametersDto)1