Search in sources :

Example 31 with AccountPaymentEntity

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

the class FinancialBusinessServiceIntegrationTest method testLoanWriteOffAccountingEntries.

@Test
public void testLoanWriteOffAccountingEntries() throws Exception {
    loan = getLoanAccount();
    loan.setUserContext(TestUtils.makeUser());
    AccountPaymentEntity accountPaymentEntity = new AccountPaymentEntity(loan, TestUtils.createMoney(630), null, null, new PaymentTypeEntity(Short.valueOf("1")), new Date(System.currentTimeMillis()));
    FinancialBusinessService financialBusinessService = new FinancialBusinessService();
    AccountActionDateEntity accountActionDateEntity = loan.getAccountActionDate(Short.valueOf("1"));
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(loan.getUserContext().getId());
    LoanTrxnDetailEntity loanTrxnDetailEntity = new LoanTrxnDetailEntity(accountPaymentEntity, AccountActionTypes.WRITEOFF, accountActionDateEntity.getInstallmentId(), accountActionDateEntity.getActionDate(), personnel, new Date(System.currentTimeMillis()), ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), "Loan Written Off", null, ((LoanScheduleEntity) accountActionDateEntity).getPrincipal(), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), new Money(getCurrency()), null, null);
    accountPaymentEntity.addAccountTrxn(loanTrxnDetailEntity);
    AccountTestUtils.addAccountPayment(accountPaymentEntity, loan);
    financialBusinessService.buildAccountingEntries(loanTrxnDetailEntity);
    TestObjectFactory.updateObject(loan);
    Set<FinancialTransactionBO> finTrxnSet = loanTrxnDetailEntity.getFinancialTransactions();
    Assert.assertEquals(finTrxnSet.size(), 2);
    for (FinancialTransactionBO finTrxn : finTrxnSet) {
        if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("22")) && finTrxn.isCreditEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("22"));
        } else if (finTrxn.getFinancialAction().getId().equals(Short.valueOf("22")) && finTrxn.isDebitEntry()) {
            Assert.assertEquals(finTrxn.getPostedAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getBalanceAmount(), TestUtils.createMoney("100"));
            Assert.assertEquals(finTrxn.getGlcode().getGlcodeId(), Short.valueOf("24"));
        } else {
        //--fail("There should not be any other entry");
        }
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LoanTrxnDetailEntity(org.mifos.accounts.loan.business.LoanTrxnDetailEntity) Date(java.sql.Date) Test(org.junit.Test)

Example 32 with AccountPaymentEntity

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

the class SavingsCloseTest method whenClosingAccountShouldWithdrawRemainingBalanceOnAccount.

@Test
public void whenClosingAccountShouldWithdrawRemainingBalanceOnAccount() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // pre verification
    assertTrue(savingsAccount.getAccountPayments().isEmpty());
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertFalse(savingsAccount.getAccountPayments().isEmpty());
    AccountPaymentEntity withdrawalPayment = savingsAccount.getAccountPayments().get(0);
    assertThat(withdrawalPayment.getAmount(), is(TestUtils.createMoney("100")));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 33 with AccountPaymentEntity

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

the class SavingsCloseTest method whenClosingAccountShouldSetClosedDate.

@Test
public void whenClosingAccountShouldSetClosedDate() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertThat(new LocalDate(savingsAccount.getClosedDate()), is(new LocalDate()));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) LocalDate(org.joda.time.LocalDate) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 34 with AccountPaymentEntity

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

the class SavingsCloseTest method whenClosingAccountShouldPostInterestWhenRemainingSavingsBalanceIsLessThanAmountBeingWithdrawn.

@Test
public void whenClosingAccountShouldPostInterestWhenRemainingSavingsBalanceIsLessThanAmountBeingWithdrawn() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    Money withdrawalAtCloseAmount = TestUtils.createMoney("105.56");
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(withdrawalAtCloseAmount).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // pre verification
    assertTrue(savingsAccount.getAccountPayments().isEmpty());
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertFalse(savingsAccount.getAccountPayments().isEmpty());
    assertThat(savingsAccount.getAccountPayments().size(), is(2));
    AccountPaymentEntity interestPayment = savingsAccount.getAccountPayments().get(0);
    assertThat(interestPayment.getAmount(), is(TestUtils.createMoney("5.56")));
    AccountPaymentEntity withdrawalPayment = savingsAccount.getAccountPayments().get(1);
    assertThat(withdrawalPayment.getAmount(), is(TestUtils.createMoney("105.56")));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 35 with AccountPaymentEntity

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

the class SavingsCloseTest method whenClosingAccountShouldCreateStatusChangeHistoryForClosure.

@Test
public void whenClosingAccountShouldCreateStatusChangeHistoryForClosure() {
    Money remainingBalance = TestUtils.createMoney("100");
    savingsAccount = new SavingsAccountBuilder().active().withSavingsProduct(savingsProduct).withCustomer(client).withBalanceOf(remainingBalance).build();
    AccountPaymentEntity payment = new AccountPaymentEntityBuilder().with(savingsAccount).with(remainingBalance).build();
    AccountNotesEntity notes = new AccountNotesEntityBuilder().build();
    CustomerBO customer = new ClientBuilder().buildForUnitTests();
    PersonnelBO loggedInUser = new PersonnelBuilder().build();
    // pre verification
    assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(1));
    // exercise test
    savingsAccount.closeAccount(payment, notes, customer, loggedInUser);
    // verification
    assertThat(savingsAccount.getAccountStatusChangeHistory().size(), is(2));
    AccountStatusChangeHistoryEntity closure = savingsAccount.getAccountStatusChangeHistory().get(1);
    assertThat(closure.getAccount(), is((AccountBO) savingsAccount));
    assertTrue(closure.getOldStatus().isInState(AccountState.SAVINGS_ACTIVE));
    assertTrue(closure.getNewStatus().isInState(AccountState.SAVINGS_CLOSED));
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) AccountNotesEntityBuilder(org.mifos.accounts.business.AccountNotesEntityBuilder) AccountPaymentEntityBuilder(org.mifos.accounts.business.AccountPaymentEntityBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) CustomerBO(org.mifos.customers.business.CustomerBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

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