Search in sources :

Example 21 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method testFailureMakePayment.

@Test
public void testFailureMakePayment() 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("The size of the payments done is", customerAccount.getAccountPayments().size(), 1);
    try {
        // one more for the next meeting
        customerAccount.applyPayment(accountPaymentDataView);
        // and the error one
        customerAccount.applyPayment(accountPaymentDataView);
        Assert.fail("Payment is done even though they are no dues");
    } catch (AccountException ae) {
        Assert.assertTrue("Payment is not allowed when there are no dues", true);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) Date(java.sql.Date) Test(org.junit.Test)

Example 22 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method testPayPartOfMiscChargePlusWeeklyFeePreviousDay.

@Test
public void testPayPartOfMiscChargePlusWeeklyFeePreviousDay() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center_Active_test", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group_Active_test", CustomerStatus.GROUP_ACTIVE, center);
    StaticHibernateUtil.flushSession();
    center = TestObjectFactory.getCustomer(center.getCustomerId());
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    customerAccountBO = group.getCustomerAccount();
    UserContext uc = TestUtils.makeUser();
    customerAccountBO.setUserContext(uc);
    customerAccountBO.applyCharge(Short.valueOf("-1"), new Double("33"));
    CustomerScheduleEntity firstInstallment = null;
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            firstInstallment = customerScheduleEntity;
            Assert.assertEquals(new Money(getCurrency(), "33.0"), customerScheduleEntity.getMiscFee());
        }
    }
    DateMidnight pDate = new DateMidnight(firstInstallment.getActionDate());
    PaymentData paymentData = PaymentData.createPaymentData(new Money(getCurrency(), "120.0"), center.getPersonnel(), (short) 1, pDate.minusDays(1).toDate());
    customerAccountBO.applyPayment(paymentData);
    for (AccountActionDateEntity accountActionDateEntity : customerAccountBO.getAccountActionDates()) {
        CustomerScheduleEntity customerScheduleEntity = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(new Money(getCurrency(), "33"), customerScheduleEntity.getMiscFee());
            Assert.assertEquals(new Money(getCurrency(), "20"), customerScheduleEntity.getMiscFeePaid());
            Assert.assertEquals(new Money(getCurrency(), "100"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmount());
            Assert.assertEquals(new Money(getCurrency(), "100"), customerScheduleEntity.getAccountFeesActionDetailsSortedByFeeId().get(0).getFeeAmountPaid());
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 23 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData 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 24 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData 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 25 with PaymentData

use of org.mifos.accounts.util.helpers.PaymentData in project head by mifos.

the class CustomerAccountBOIntegrationTest method verifyExpectedDetailMessageThrown.

private void verifyExpectedDetailMessageThrown(final CustomerBO customer, final Money paymentAmount, final Integer numberOfDaysForward, final String expectedErrorMessage) throws Exception {
    CustomerAccountBO customerAccount = customer.getCustomerAccount();
    Date transactionDate = incrementCurrentDate(numberOfDaysForward);
    PaymentData paymentData = PaymentData.createPaymentData(paymentAmount, customer.getPersonnel(), Short.valueOf("1"), transactionDate);
    paymentData.setCustomer(customer);
    String actualErrorMessage = "No Error Message";
    try {
        customerAccount.makePayment(paymentData);
    } catch (AccountException e) {
        actualErrorMessage = e.getMessage();
    }
    Assert.assertEquals(expectedErrorMessage, actualErrorMessage);
}
Also used : PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountException(org.mifos.accounts.exceptions.AccountException) Date(java.sql.Date)

Aggregations

PaymentData (org.mifos.accounts.util.helpers.PaymentData)59 Money (org.mifos.framework.util.helpers.Money)34 Test (org.junit.Test)32 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)24 Date (java.util.Date)22 AccountException (org.mifos.accounts.exceptions.AccountException)22 LoanBO (org.mifos.accounts.loan.business.LoanBO)22 ArrayList (java.util.ArrayList)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 Date (java.sql.Date)17 MeetingBO (org.mifos.application.meeting.business.MeetingBO)15 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)15 LocalDate (org.joda.time.LocalDate)11 UserContext (org.mifos.security.util.UserContext)11 BigDecimal (java.math.BigDecimal)10 SavingsPaymentData (org.mifos.accounts.util.helpers.SavingsPaymentData)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 MifosUser (org.mifos.security.MifosUser)7 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)6 DateTimeService (org.mifos.framework.util.DateTimeService)6