Search in sources :

Example 41 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testSuccessfulMakePayment.

@Test
public void testSuccessfulMakePayment() throws Exception {
    createCenter();
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    Assert.assertNotNull(customerAccount);
    Date transactionDate = new Date(System.currentTimeMillis());
    List<AccountActionDateEntity> dueActionDates = TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate);
    Assert.assertEquals("The size of the due insallments is ", dueActionDates.size(), 1);
    PaymentData accountPaymentDataView = TestObjectFactory.getCustomerAccountPaymentDataView(dueActionDates, TestUtils.createMoney("100.0"), null, center.getPersonnel(), "3424324", Short.valueOf("1"), transactionDate, transactionDate);
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    customerAccount = center.getCustomerAccount();
    IntegrationTestObjectMother.applyAccountPayment(customerAccount, accountPaymentDataView);
    Assert.assertEquals(customerAccount.getCustomerActivitDetails().size(), 1);
    Assert.assertEquals("The size of the payments done is", customerAccount.getAccountPayments().size(), 1);
    Assert.assertEquals("The size of the due insallments after payment is", TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate).size(), 0);
    for (CustomerActivityEntity activity : customerAccount.getCustomerActivitDetails()) {
        Assert.assertEquals(transactionDate, activity.getCreatedDate());
    }
    assertThat(customerAccount.getAccountPayments().size(), is(1));
    for (AccountPaymentEntity accountPayment : customerAccount.getAccountPayments()) {
        assertThat(accountPayment.getAccountTrxns().size(), is(1));
        for (AccountTrxnEntity accountTrxnEntity : accountPayment.getAccountTrxns()) {
            assertThat(accountTrxnEntity.getFinancialTransactions().size(), is(2));
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 42 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method testActivityForMultiplePayments.

@Test
public void testActivityForMultiplePayments() throws Exception {
    // setup
    createCenter();
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    Assert.assertNotNull(customerAccount);
    Date transactionDate = incrementCurrentDate(14);
    final Money paymentForThisInstallmentAndLastTwoInstallmentsInArrears = TestUtils.createMoney("300.0");
    List<AccountActionDateEntity> dueActionDates = TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate);
    Assert.assertEquals("The size of the due insallments is ", dueActionDates.size(), 3);
    PaymentData accountPaymentDataView = TestObjectFactory.getCustomerAccountPaymentDataView(dueActionDates, paymentForThisInstallmentAndLastTwoInstallmentsInArrears, null, center.getPersonnel(), "3424324", Short.valueOf("1"), transactionDate, transactionDate);
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    customerAccount = center.getCustomerAccount();
    // exercise test
    customerAccount.applyPayment(accountPaymentDataView);
    // verification
    assertThat(customerAccount.getCustomerActivitDetails().size(), is(1));
    assertThat("The size of the payments done is", customerAccount.getAccountPayments().size(), is(1));
    assertThat("The size of the due insallments after payment is", TestObjectFactory.getDueActionDatesForAccount(customerAccount.getAccountId(), transactionDate).size(), is(0));
    assertThat(customerAccount.getAccountPayments().size(), is(1));
    for (AccountPaymentEntity accountPayment : customerAccount.getAccountPayments()) {
        assertThat(accountPayment.getAccountTrxns().size(), is(3));
        for (AccountTrxnEntity accountTrxnEntity : accountPayment.getAccountTrxns()) {
            assertThat(accountTrxnEntity.getFinancialTransactions().size(), is(2));
        }
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 43 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class CustomerAccountBOIntegrationTest method applyPayment.

private void applyPayment() throws Exception {
    client = TestObjectFactory.createClient("Client_Active_test", CustomerStatus.CLIENT_ACTIVE, group);
    customerAccountBO = client.getCustomerAccount();
    Date currentDate = new Date(System.currentTimeMillis());
    customerAccountBO.setUserContext(userContext);
    CustomerScheduleEntity accountAction = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(Short.valueOf("1"));
    accountAction.setMiscFeePaid(TestUtils.createMoney(100));
    accountAction.setMiscPenaltyPaid(TestUtils.createMoney(100));
    accountAction.setPaymentDate(currentDate);
    accountAction.setPaymentStatus(PaymentStatus.PAID);
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(customerAccountBO, TestUtils.createMoney(300), "1111", currentDate, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    CustomerTrxnDetailEntity accountTrxnEntity = new CustomerTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.PAYMENT, Short.valueOf("1"), accountAction.getActionDate(), TestObjectFactory.getPersonnel(userContext.getId()), currentDate, TestUtils.createMoney(300), "payment done", null, TestUtils.createMoney(100), TestUtils.createMoney(100));
    for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : accountAction.getAccountFeesActionDetails()) {
        CustomerAccountBOTestUtils.setFeeAmountPaid((CustomerFeeScheduleEntity) accountFeesActionDetailEntity, TestUtils.createMoney(100));
        FeesTrxnDetailEntity feeTrxn = new FeesTrxnDetailEntity(accountTrxnEntity, accountFeesActionDetailEntity.getAccountFee(), accountFeesActionDetailEntity.getFeeAmount());
        accountTrxnEntity.addFeesTrxnDetail(feeTrxn);
    }
    accountPaymentEntity.addAccountTrxn(accountTrxnEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, customerAccountBO);
    TestObjectFactory.updateObject(customerAccountBO);
    StaticHibernateUtil.flushSession();
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity)

Example 44 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class AdminDocumentsServiceImpl method getAdminDocumentsForAccountPayment.

@Override
public List<AdminDocumentDto> getAdminDocumentsForAccountPayment(Integer paymentId) {
    try {
        List<AdminDocumentDto> adminDocuments = new ArrayList<AdminDocumentDto>();
        AccountPaymentEntity accountPaymentEntity = legacyAccountDao.findPaymentById(paymentId);
        Set<AccountTrxnEntity> accountTrxnEntities = accountPaymentEntity.getAccountTrxns();
        for (AccountTrxnEntity accountTrxnEntity : accountTrxnEntities) {
            List<AdminDocumentBO> adminDocumentBOs = legacyAdminDocumentDao.getActiveAdminDocumentsByAccountActionId(accountTrxnEntity.getAccountActionEntity().getId());
            if (adminDocumentBOs != null && !adminDocumentBOs.isEmpty()) {
                for (AdminDocumentBO adminDocumentBO : adminDocumentBOs) {
                    AdminDocumentDto adminDocumentDto = new AdminDocumentDto(adminDocumentBO.getAdmindocId().intValue(), adminDocumentBO.getAdminDocumentName(), adminDocumentBO.getAdminDocumentIdentifier(), BooleanUtils.toBoolean(adminDocumentBO.getIsActive().intValue()));
                    if (!adminDocuments.contains(adminDocumentDto)) {
                        adminDocuments.add(adminDocumentDto);
                    }
                }
            }
        }
        return adminDocuments;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) ArrayList(java.util.ArrayList) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AdminDocumentDto(org.mifos.dto.domain.AdminDocumentDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 45 with AccountPaymentEntity

use of org.mifos.accounts.business.AccountPaymentEntity in project head by mifos.

the class LoanBO method isAdjustPossibleOnLastTrxn.

@Override
public boolean isAdjustPossibleOnLastTrxn() {
    if (!(getAccountState().isLoanActiveInGoodStanding() || getAccountState().isLoanActiveInBadStanding() || getAccountState().isLoanClosedObligationsMet())) {
        logger.debug("State is not active hence adjustment is not possible");
        return false;
    }
    logger.debug("Total payments on this account is  " + getAccountPayments().size());
    AccountPaymentEntity accountPayment = getLastPmntToBeAdjusted();
    if (accountPayment != null) {
        for (AccountTrxnEntity accntTrxn : accountPayment.getAccountTrxns()) {
            LoanTrxnDetailEntity lntrxn = (LoanTrxnDetailEntity) accntTrxn;
            if (lntrxn.getInstallmentId().equals(Short.valueOf("0")) || isAdjustmentForInterestDedAtDisb(lntrxn.getInstallmentId())) {
                return false;
            }
        }
    }
    if (null != getLastPmntToBeAdjusted() && getLastPmntAmntToBeAdjusted() != 0) {
        return true;
    }
    logger.debug("Adjustment is not possible ");
    return false;
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity)

Aggregations

AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)113 Money (org.mifos.framework.util.helpers.Money)56 Date (java.util.Date)43 LocalDate (org.joda.time.LocalDate)41 Test (org.junit.Test)36 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)34 AccountException (org.mifos.accounts.exceptions.AccountException)30 PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)24 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)23 UserContext (org.mifos.security.util.UserContext)23 ArrayList (java.util.ArrayList)22 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)22 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 PaymentData (org.mifos.accounts.util.helpers.PaymentData)18 CustomerBO (org.mifos.customers.business.CustomerBO)18 AccountBO (org.mifos.accounts.business.AccountBO)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 BigDecimal (java.math.BigDecimal)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 Date (java.sql.Date)13