Search in sources :

Example 96 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class SavingsBOIntegrationTest method testSuccessfulApplyPayment.

@Test
public void testSuccessfulApplyPayment() throws AccountException, Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client1 = TestObjectFactory.createClient("Client", CustomerStatus.CLIENT_ACTIVE, group);
    savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1");
    savings = TestObjectFactory.createSavingsAccount("43245434", client1, AccountStates.SAVINGS_ACC_INACTIVE, new Date(System.currentTimeMillis()), savingsOffering);
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    savings.setSavingsBalance(new Money(getCurrency()));
    Money enteredAmount = new Money(currency, "100.0");
    PaymentData paymentData = PaymentData.createPaymentData(enteredAmount, savings.getPersonnel(), Short.valueOf("1"), new Date(System.currentTimeMillis()));
    paymentData.setCustomer(client1);
    paymentData.setReceiptDate(new Date(System.currentTimeMillis()));
    paymentData.setReceiptNum("34244");
    AccountActionDateEntity accountActionDate = savings.getAccountActionDate(Short.valueOf("1"));
    SavingsPaymentData savingsPaymentData = new SavingsPaymentData(accountActionDate);
    paymentData.addAccountPaymentData(savingsPaymentData);
    IntegrationTestObjectMother.applyAccountPayment(savings, paymentData);
    Assert.assertEquals(AccountStates.SAVINGS_ACC_APPROVED, savings.getAccountState().getId().shortValue());
    Assert.assertEquals(TestUtils.createMoney(100.0), savings.getSavingsBalance());
    Assert.assertEquals(1, savings.getSavingsActivityDetails().size());
    savings.getAccountPayments().clear();
    client1 = IntegrationTestObjectMother.findCustomerById(client1.getCustomerId());
}
Also used : SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Date(java.util.Date) Test(org.junit.Test)

Example 97 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class SavingsBOIntegrationTest method testSuccessfulDepositForCenterAccount.

@Test
public void testSuccessfulDepositForCenterAccount() throws AccountException, Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client1 = TestObjectFactory.createClient("Client", CustomerStatus.CLIENT_ACTIVE, group);
    savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1");
    savings = TestObjectFactory.createSavingsAccount("43245434", center, AccountStates.SAVINGS_ACC_APPROVED, new Date(System.currentTimeMillis()), savingsOffering);
    savings.setSavingsBalance(new Money(getCurrency()));
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    Money enteredAmount = new Money(currency, "100.0");
    PaymentData paymentData = PaymentData.createPaymentData(enteredAmount, savings.getPersonnel(), Short.valueOf("1"), new Date(System.currentTimeMillis()));
    paymentData.setCustomer(client1);
    paymentData.setReceiptDate(new Date(System.currentTimeMillis()));
    paymentData.setReceiptNum("34244");
    AccountActionDateEntity accountActionDate = savings.getAccountActionDate(Short.valueOf("1"));
    SavingsPaymentData savingsPaymentData = new SavingsPaymentData(accountActionDate);
    paymentData.addAccountPaymentData(savingsPaymentData);
    IntegrationTestObjectMother.applyAccountPayment(savings, paymentData);
    savings = (SavingsBO) legacyAccountDao.getAccount(savings.getAccountId());
    Assert.assertEquals(AccountStates.SAVINGS_ACC_APPROVED, savings.getAccountState().getId().shortValue());
    Assert.assertEquals(TestUtils.createMoney(100.0), savings.getSavingsBalance());
    Assert.assertEquals(1, savings.getSavingsActivityDetails().size());
    List<AccountPaymentEntity> payments = savings.getAccountPayments();
    Assert.assertEquals(1, payments.size());
    for (AccountPaymentEntity payment : payments) {
        Assert.assertEquals(1, payment.getAccountTrxns().size());
        for (AccountTrxnEntity accountTrxn : payment.getAccountTrxns()) {
            SavingsTrxnDetailEntity trxn = (SavingsTrxnDetailEntity) accountTrxn;
            Assert.assertEquals(enteredAmount, trxn.getBalance());
            Assert.assertEquals(client1.getCustomerId(), trxn.getCustomer().getCustomerId());
        }
    }
    client1 = IntegrationTestObjectMother.findCustomerById(client1.getCustomerId());
}
Also used : SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) Money(org.mifos.framework.util.helpers.Money) PaymentData(org.mifos.accounts.util.helpers.PaymentData) SavingsPaymentData(org.mifos.accounts.util.helpers.SavingsPaymentData) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) Date(java.util.Date) Test(org.junit.Test)

Example 98 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class SavingsPaymentStrategyForMandatorySavingsAccountsTest method whenDepositAmountIsInExcessOfTotalDepositDueTheExcessAmountIsReturnedInRemainingAmount.

@Test
public void whenDepositAmountIsInExcessOfTotalDepositDueTheExcessAmountIsReturnedInRemainingAmount() {
    // setup
    final Money balanceBeforeDeposit = new Money(TestUtils.RUPEE, "0.0");
    final Money fullDepositAmount = new Money(TestUtils.RUPEE, "80.0");
    final Date dateOfDeposit = new DateTime().toDate();
    final SavingsScheduleEntity unpaidSaving1 = new SavingsScheduleBuilder().withInstallmentNumber(1).withAccount(savingsAccount).withCustomer(payingCustomer).withDepositDue(new Money(TestUtils.RUPEE, "10.0")).build();
    final SavingsScheduleEntity unpaidSaving2 = new SavingsScheduleBuilder().withInstallmentNumber(2).withAccount(savingsAccount).withCustomer(payingCustomer).withDepositDue(new Money(TestUtils.RUPEE, "50.0")).build();
    final List<SavingsScheduleEntity> unpaidDepositsForPayingCustomer = Arrays.asList(unpaidSaving1, unpaidSaving2);
    // stubbing
    when(accountPayment.getAmount()).thenReturn(fullDepositAmount);
    when(accountPayment.getPaymentDate()).thenReturn(dateOfDeposit);
    // exercise test
    final Money remainingAmount = paymentStrategy.makeScheduledPayments(accountPayment, unpaidDepositsForPayingCustomer, payingCustomer, SavingsType.MANDATORY, balanceBeforeDeposit);
    // verification
    assertThat(remainingAmount, is(new Money(TestUtils.RUPEE, "20.0")));
}
Also used : SavingsScheduleBuilder(org.mifos.domain.builders.SavingsScheduleBuilder) Money(org.mifos.framework.util.helpers.Money) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 99 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class SavingsPaymentStrategyForVoluntarySavingsAccountsTest method whenNoUnpaidScheduledInstallmentsExistTheFullAmountOfTheDepositIsReturned.

@Test
public void whenNoUnpaidScheduledInstallmentsExistTheFullAmountOfTheDepositIsReturned() {
    // setup
    final Money balanceBeforeDeposit = new Money(TestUtils.RUPEE, "0.0");
    final Money fullDepositAmount = new Money(TestUtils.RUPEE, "100.0");
    final Date dateOfDeposit = new DateTime().toDate();
    final List<SavingsScheduleEntity> unpaidDepositsForPayingCustomer = Arrays.asList();
    // stubbing
    when(accountPayment.getAmount()).thenReturn(fullDepositAmount);
    when(accountPayment.getPaymentDate()).thenReturn(dateOfDeposit);
    // exercise test
    final Money remainingAmount = paymentStrategy.makeScheduledPayments(accountPayment, unpaidDepositsForPayingCustomer, payingCustomer, SavingsType.VOLUNTARY, balanceBeforeDeposit);
    // verification
    assertThat(remainingAmount, is(fullDepositAmount));
}
Also used : Money(org.mifos.framework.util.helpers.Money) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 100 with Money

use of org.mifos.framework.util.helpers.Money in project head by mifos.

the class SavingsPaymentStrategyForVoluntarySavingsAccountsTest method whenUnpaidScheduledInstallmentsExistAllAreMarkedAsPaid.

@Test
public void whenUnpaidScheduledInstallmentsExistAllAreMarkedAsPaid() {
    // setup
    final Money balanceBeforeDeposit = new Money(TestUtils.RUPEE, "0.0");
    final Money fullDepositAmount = new Money(TestUtils.RUPEE, "100.0");
    final Date dateOfDeposit = new DateTime().toDate();
    final SavingsScheduleEntity unpaidSaving1 = new SavingsScheduleBuilder().withInstallmentNumber(1).withAccount(savingsAccount).withCustomer(payingCustomer).build();
    final SavingsScheduleEntity unpaidSaving2 = new SavingsScheduleBuilder().withInstallmentNumber(2).withAccount(savingsAccount).withCustomer(payingCustomer).build();
    final List<SavingsScheduleEntity> unpaidDepositsForPayingCustomer = Arrays.asList(unpaidSaving1, unpaidSaving2);
    // stubbing
    when(accountPayment.getAmount()).thenReturn(fullDepositAmount);
    when(accountPayment.getPaymentDate()).thenReturn(dateOfDeposit);
    // exercise test
    paymentStrategy.makeScheduledPayments(accountPayment, unpaidDepositsForPayingCustomer, payingCustomer, SavingsType.VOLUNTARY, balanceBeforeDeposit);
    // verification
    assertThat(unpaidSaving1.isPaid(), is(true));
    assertThat(unpaidSaving2.isPaid(), is(true));
}
Also used : SavingsScheduleBuilder(org.mifos.domain.builders.SavingsScheduleBuilder) Money(org.mifos.framework.util.helpers.Money) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Money (org.mifos.framework.util.helpers.Money)688 Test (org.junit.Test)326 Date (java.util.Date)110 ArrayList (java.util.ArrayList)93 LocalDate (org.joda.time.LocalDate)90 Date (java.sql.Date)85 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)80 DateTime (org.joda.time.DateTime)67 LoanBO (org.mifos.accounts.loan.business.LoanBO)64 MeetingBO (org.mifos.application.meeting.business.MeetingBO)57 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)56 BigDecimal (java.math.BigDecimal)53 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)49 AccountException (org.mifos.accounts.exceptions.AccountException)48 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)46 UserContext (org.mifos.security.util.UserContext)46 CustomerBO (org.mifos.customers.business.CustomerBO)39 MifosUser (org.mifos.security.MifosUser)35 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)34 PaymentData (org.mifos.accounts.util.helpers.PaymentData)34