Search in sources :

Example 16 with AccountTrxnEntity

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

the class StandardAccountServiceIntegrationTest method testMakePaymentForSavingsAccountOnDeposit.

@Test
public void testMakePaymentForSavingsAccountOnDeposit() throws Exception {
    savingsBO = createClientSavingsAccount();
    String deposit = "400";
    CustomerDto clientDto = new CustomerDto();
    clientDto.setCustomerId(client.getCustomerId());
    //FIXME why one day in future payment is allowed
    LocalDate paymentDate = new LocalDate().plusDays(1);
    LocalDate receiptDate = new LocalDate().minusDays(3);
    String receiptNumber = "AA/03/UX-9Q";
    Assert.assertEquals(0, savingsBO.getAccountPayments().size());
    AccountPaymentParametersDto depositPayment = new AccountPaymentParametersDto(new UserReferenceDto(savingsBO.getPersonnel().getPersonnelId()), new AccountReferenceDto(savingsBO.getAccountId()), new BigDecimal(deposit), paymentDate, defaultPaymentType, "comment", receiptDate, receiptNumber, clientDto);
    standardAccountService.makePayment(depositPayment);
    TestObjectFactory.updateObject(savingsBO);
    Assert.assertEquals("The amount returned for the payment should have been " + deposit, Double.parseDouble(deposit), savingsBO.getLastPmntAmnt());
    Assert.assertEquals(1, savingsBO.getAccountPayments().size());
    for (AccountPaymentEntity payment : savingsBO.getAccountPayments()) {
        Assert.assertEquals(TestUtils.createMoney(deposit), payment.getAmount());
        Assert.assertEquals(1, payment.getAccountTrxns().size());
        Assert.assertEquals(paymentDate.toDateMidnight().toDate(), payment.getPaymentDate());
        Assert.assertEquals(defaultPaymentType.getName(), payment.getPaymentType().getName());
        Assert.assertEquals("comment", payment.getComment());
        Assert.assertEquals(savingsBO, payment.getAccount());
        Assert.assertEquals(savingsBO.getPersonnel(), payment.getCreatedByUser());
        Assert.assertEquals(receiptDate.toDateMidnight().toDate(), payment.getReceiptDate());
        Assert.assertEquals(receiptNumber, payment.getReceiptNumber());
        Assert.assertNull(payment.getCheckNumber());
        Assert.assertNull(payment.getBankName());
        Assert.assertNull(payment.getVoucherNumber());
        Assert.assertTrue(payment.isSavingsDeposit());
        Assert.assertFalse(payment.isSavingsWithdrawal());
        Assert.assertTrue(payment.isSavingsDepositOrWithdrawal());
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            Assert.assertEquals(client.getCustomerId(), accountTrxn.getCustomer().getCustomerId());
        }
    }
}
Also used : UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountReferenceDto(org.mifos.dto.domain.AccountReferenceDto) CustomerDto(org.mifos.dto.domain.CustomerDto) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountPaymentParametersDto(org.mifos.dto.domain.AccountPaymentParametersDto) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 17 with AccountTrxnEntity

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

the class CustomerTrxnDetailEntityIntegrationTest method testGenerateReverseTrxn.

@Test
public void testGenerateReverseTrxn() throws Exception {
    accountBO = client.getCustomerAccount();
    Date currentDate = new Date(System.currentTimeMillis());
    CustomerAccountBO customerAccountBO = (CustomerAccountBO) accountBO;
    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(accountBO, TestUtils.createMoney(100), "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(200), "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);
    PersonnelBO loggedInUser = legacyPersonnelDao.getPersonnel(userContext.getId());
    for (AccountTrxnEntity accntTrxn : customerAccountBO.findMostRecentPaymentByPaymentDate().getAccountTrxns()) {
        AccountTrxnEntity reverseAccntTrxn = ((CustomerTrxnDetailEntity) accntTrxn).generateReverseTrxn(loggedInUser, "adjustment");
        Assert.assertEquals(reverseAccntTrxn.getAmount(), accntTrxn.getAmount().negate());
        Assert.assertEquals(loggedInUser.getPersonnelId(), reverseAccntTrxn.getPersonnel().getPersonnelId());
    }
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity) Test(org.junit.Test)

Example 18 with AccountTrxnEntity

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

the class CustomerAccountBOIntegrationTest method testUpdateInstallmentAfterAdjustment.

@Test
public void testUpdateInstallmentAfterAdjustment() throws Exception {
    userContext = TestUtils.makeUser();
    createInitialObjects();
    applyPayment();
    customerAccountBO = TestObjectFactory.getObject(CustomerAccountBO.class, customerAccountBO.getAccountId());
    client = customerAccountBO.getCustomer();
    customerAccountBO.setUserContext(userContext);
    List<AccountTrxnEntity> reversedTrxns = AccountTestUtils.reversalAdjustment("payment adjustment done", customerAccountBO.findMostRecentPaymentByPaymentDate());
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    customerAccountBO.updateInstallmentAfterAdjustment(reversedTrxns, loggedInUser);
    for (AccountTrxnEntity accntTrxn : reversedTrxns) {
        CustomerTrxnDetailEntity custTrxn = (CustomerTrxnDetailEntity) accntTrxn;
        CustomerScheduleEntity accntActionDate = (CustomerScheduleEntity) customerAccountBO.getAccountActionDate(custTrxn.getInstallmentId());
        Assert.assertEquals("Misc Fee Adjusted", accntActionDate.getMiscFeePaid(), TestUtils.createMoney());
        Assert.assertEquals("Misc Penalty Adjusted", accntActionDate.getMiscPenaltyPaid(), TestUtils.createMoney());
    }
    for (CustomerActivityEntity customerActivityEntity : customerAccountBO.getCustomerActivitDetails()) {
        Assert.assertEquals("Amnt Adjusted", customerActivityEntity.getDescription());
    }
}
Also used : AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) Test(org.junit.Test)

Example 19 with AccountTrxnEntity

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

the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenBothCustomerAccountChargesAndFeesAreDue.

@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenBothCustomerAccountChargesAndFeesAreDue() throws Exception {
    createCenter();
    FeeBO extraFee = TestObjectFactory.createPeriodicAmountFee("extra fee", FeeCategory.ALLCUSTOMERS, "5.5", RecurrenceType.WEEKLY, Short.valueOf("1"));
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    AccountFeesEntity extraAccountFeesEntity = new AccountFeesEntity(customerAccount, extraFee, 11.66);
    // FIXME: a fee is being added by exposing an internal data structure and adding it directly to it
    customerAccount.getAccountFeesIncludingInactiveFees().add(extraAccountFeesEntity);
    final Money eightAmount = new Money(getCurrency(), "8.0");
    final Money fiftyAmount = new Money(getCurrency(), "50.0");
    final Money seventyAmount = new Money(getCurrency(), "70.0");
    final Money oneHundredTwentyAmount = new Money(getCurrency(), "120.0");
    for (AccountActionDateEntity accountActionDateEntity : customerAccount.getAccountActionDates()) {
        CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerSchedule.getInstallmentId() == 2) {
            customerSchedule.setMiscFee(fiftyAmount);
            customerSchedule.setMiscPenalty(seventyAmount);
        }
        if (customerSchedule.getInstallmentId() == 3) {
            CustomerAccountBOTestUtils.applyPeriodicFees(customerSchedule, extraAccountFeesEntity.getFees().getFeeId(), new Money(getCurrency(), "8"));
        }
    }
    Date transactionDate = incrementCurrentDate(14);
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "428"), center.getPersonnel(), Short.valueOf("1"), transactionDate);
    paymentData.setCustomer(center);
    IntegrationTestObjectMother.applyAccountPayment(customerAccount, paymentData);
    if (customerAccount.getAccountPayments() != null && customerAccount.getAccountPayments().size() == 1) {
        for (AccountPaymentEntity accountPaymentEntity : customerAccount.getAccountPayments()) {
            final Money zeroAmount = new Money(accountPaymentEntity.getAmount().getCurrency(), "0.0");
            final Money OneHundredAmount = new Money(accountPaymentEntity.getAmount().getCurrency(), "100.0");
            if (accountPaymentEntity.getAccountTrxns() != null && accountPaymentEntity.getAccountTrxns().size() == 3) {
                for (AccountTrxnEntity accountTrxnEntity : accountPaymentEntity.getAccountTrxns()) {
                    CustomerTrxnDetailEntity customerTrxnDetailEntity = (CustomerTrxnDetailEntity) accountTrxnEntity;
                    if (customerTrxnDetailEntity.getInstallmentId() == 2) {
                        Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getAmount());
                        Assert.assertEquals(oneHundredTwentyAmount, customerTrxnDetailEntity.getTotalAmount());
                        Assert.assertEquals(fiftyAmount, customerTrxnDetailEntity.getMiscFeeAmount());
                        Assert.assertEquals(seventyAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
                    } else {
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getAmount());
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getTotalAmount());
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscFeeAmount());
                        Assert.assertEquals(zeroAmount, customerTrxnDetailEntity.getMiscPenaltyAmount());
                    }
                    if (customerTrxnDetailEntity.getFeesTrxnDetails() != null && customerTrxnDetailEntity.getFeesTrxnDetails().size() < 3) {
                        for (FeesTrxnDetailEntity feesTrxnDetailEntity : customerTrxnDetailEntity.getFeesTrxnDetails()) {
                            if (feesTrxnDetailEntity.getAccountFees().getAccountFeeId() == extraAccountFeesEntity.getAccountFeeId()) {
                                Assert.assertEquals(eightAmount, feesTrxnDetailEntity.getFeeAmount());
                            } else {
                                Assert.assertEquals(OneHundredAmount, feesTrxnDetailEntity.getFeeAmount());
                            }
                        }
                    } else {
                        throw new Exception("Expected one FeesTrxnDetailEntity, found none or more than two");
                    }
                }
            } else {
                throw new Exception("Expected three CustomerTrxnDetailEntity, found none or not three");
            }
        }
    } else {
        throw new Exception("Expected one AccountPaymentEntity, found none or more than one");
    }
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Date(java.sql.Date) SystemException(org.mifos.framework.exceptions.SystemException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) FeesTrxnDetailEntity(org.mifos.accounts.business.FeesTrxnDetailEntity) Test(org.junit.Test)

Example 20 with AccountTrxnEntity

use of org.mifos.accounts.business.AccountTrxnEntity 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)

Aggregations

AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)36 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 Test (org.junit.Test)15 Money (org.mifos.framework.util.helpers.Money)14 LocalDate (org.joda.time.LocalDate)8 Date (java.sql.Date)7 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 AccountException (org.mifos.accounts.exceptions.AccountException)6 PaymentData (org.mifos.accounts.util.helpers.PaymentData)6 CustomerBO (org.mifos.customers.business.CustomerBO)6 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)6 FeesTrxnDetailEntity (org.mifos.accounts.business.FeesTrxnDetailEntity)5 DateTimeService (org.mifos.framework.util.DateTimeService)5 LinkedHashSet (java.util.LinkedHashSet)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)3 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)3 FinancialTransactionBO (org.mifos.accounts.financial.business.FinancialTransactionBO)3