Search in sources :

Example 96 with AccountBO

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

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForGroupForMultipleCurrencies.

/*
     * When trying to sum amounts across loans with different currencies, we should get an exception
     */
@Test
public void testGetTotalAmountForGroupForMultipleCurrencies() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES, TestUtils.EURO.getCurrencyCode());
    GroupBO group1;
    AccountBO account1;
    AccountBO account2;
    try {
        CustomerPersistence customerPersistence = new CustomerPersistence();
        meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
        center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
        group1 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center);
        account1 = getLoanAccount(group1, meeting, "adsfdsfsd", "3saf", TestUtils.RUPEE);
        account2 = getLoanAccount(group1, meeting, "adspp", "kkaf", TestUtils.EURO);
        try {
            customerPersistence.getTotalAmountForGroup(group1.getCustomerId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
            Assert.fail("didn't get the expected CurrencyMismatchException");
        } catch (CurrencyMismatchException e) {
            // if we got here then we got the exception we were expecting
            Assert.assertNotNull(e);
        } catch (Exception e) {
            Assert.fail("didn't get the expected CurrencyMismatchException");
        }
    } finally {
        configMgr.clearProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) GroupBO(org.mifos.customers.group.business.GroupBO) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 97 with AccountBO

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

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForAllClientsOfGroup.

@Test
public void testGetTotalAmountForAllClientsOfGroup() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = createCenter("new_center");
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client = TestObjectFactory.createClient("client1", CustomerStatus.CLIENT_ACTIVE, group);
    AccountBO clientAccount1 = getLoanAccount(client, meeting, "fdbdhgsgh", "54hg");
    AccountBO clientAccount2 = getLoanAccount(client, meeting, "fasdfdsfasdf", "1qwe");
    Money amount = customerPersistence.getTotalAmountForAllClientsOfGroup(group.getOffice().getOfficeId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, group.getSearchId() + ".%");
    Assert.assertEquals(new Money(getCurrency(), "600"), amount);
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    clientAccount1.changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "none", loggedInUser);
    clientAccount2.changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "none", loggedInUser);
    TestObjectFactory.updateObject(clientAccount1);
    TestObjectFactory.updateObject(clientAccount2);
    StaticHibernateUtil.flushSession();
    Money amount2 = customerPersistence.getTotalAmountForAllClientsOfGroup(group.getOffice().getOfficeId(), AccountState.LOAN_ACTIVE_IN_BAD_STANDING, group.getSearchId() + ".%");
    Assert.assertEquals(new Money(getCurrency(), "600"), amount2);
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) Test(org.junit.Test)

Example 98 with AccountBO

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

the class CustomerPersistenceIntegrationTest method testRetrieveAllLoanAccountUnderCustomer.

@Test
public void testRetrieveAllLoanAccountUnderCustomer() throws PersistenceException {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = createCenter("center");
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    CenterBO center1 = createCenter("center1");
    GroupBO group1 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center1);
    client = TestObjectFactory.createClient("client1", CustomerStatus.CLIENT_ACTIVE, group);
    ClientBO client2 = TestObjectFactory.createClient("client2", CustomerStatus.CLIENT_ACTIVE, group);
    ClientBO client3 = TestObjectFactory.createClient("client3", CustomerStatus.CLIENT_ACTIVE, group1);
    account = getLoanAccount(group, meeting, "cdfggdfs", "1qdd");
    AccountBO account1 = getLoanAccount(client, meeting, "fdbdhgsgh", "54hg");
    AccountBO account2 = getLoanAccount(client2, meeting, "fasdfdsfasdf", "1qwe");
    AccountBO account3 = getLoanAccount(client3, meeting, "fdsgdfgfd", "543g");
    AccountBO account4 = getLoanAccount(group1, meeting, "fasdf23", "3fds");
    CustomerBOTestUtils.setCustomerStatus(client2, new CustomerStatusEntity(CustomerStatus.CLIENT_CLOSED));
    TestObjectFactory.updateObject(client2);
    client2 = TestObjectFactory.getClient(client2.getCustomerId());
    CustomerBOTestUtils.setCustomerStatus(client3, new CustomerStatusEntity(CustomerStatus.CLIENT_CANCELLED));
    TestObjectFactory.updateObject(client3);
    client3 = TestObjectFactory.getClient(client3.getCustomerId());
    List<AccountBO> loansForCenter = customerPersistence.retrieveAccountsUnderCustomer(center.getSearchId(), Short.valueOf("3"), Short.valueOf("1"));
    Assert.assertEquals(3, loansForCenter.size());
    List<AccountBO> loansForGroup = customerPersistence.retrieveAccountsUnderCustomer(group.getSearchId(), Short.valueOf("3"), Short.valueOf("1"));
    Assert.assertEquals(3, loansForGroup.size());
    List<AccountBO> loansForClient = customerPersistence.retrieveAccountsUnderCustomer(client.getSearchId(), Short.valueOf("3"), Short.valueOf("1"));
    Assert.assertEquals(1, loansForClient.size());
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) Test(org.junit.Test)

Example 99 with AccountBO

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

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForGroup.

@Ignore
@Test
public void testGetTotalAmountForGroup() throws Exception {
    CustomerPersistence customerPersistence = new CustomerPersistence();
    meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    GroupBO group1 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center);
    AccountBO account1 = getLoanAccount(group1, meeting, "adsfdsfsd", "3saf");
    AccountBO account2 = getLoanAccount(group1, meeting, "adspp", "kkaf");
    Money amount = customerPersistence.getTotalAmountForGroup(group1.getCustomerId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
    Assert.assertEquals(new Money(getCurrency(), "600"), amount);
    AccountBO account3 = getLoanAccountInActiveBadStanding(group1, meeting, "adsfdsfsd1", "4sa");
    AccountBO account4 = getLoanAccountInActiveBadStanding(group1, meeting, "adspp2", "kaf5");
    Money amount2 = customerPersistence.getTotalAmountForGroup(group1.getCustomerId(), AccountState.LOAN_ACTIVE_IN_BAD_STANDING);
    Assert.assertEquals(new Money(getCurrency(), "600"), amount2);
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Money(org.mifos.framework.util.helpers.Money) GroupBO(org.mifos.customers.group.business.GroupBO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 100 with AccountBO

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

the class SavingsPostInterestTest method whenPostingInterestASavingsAcitvityIsAddedWithCorrectDetails.

@Test
public void whenPostingInterestASavingsAcitvityIsAddedWithCorrectDetails() {
    // setup
    InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
    DateTime activationDate = new DateTime().withDate(2010, 7, 20);
    DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
    savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
    // pre verification
    assertThat(new LocalDate(savingsAccount.getNextIntPostDate()), is(nextInterestPostingDate.toLocalDate()));
    InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
    InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
    PersonnelBO createdBy = new PersonnelBuilder().build();
    // exercise
    savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
    // verification
    List<SavingsActivityEntity> savingsActivityityDetails = new ArrayList<SavingsActivityEntity>(savingsAccount.getSavingsActivityDetails());
    SavingsActivityEntity interestPostingActivity = savingsActivityityDetails.get(0);
    assertThat(interestPostingActivity.getAccount(), is((AccountBO) savingsAccount));
    assertThat(interestPostingActivity.getActivity().getId(), is(AccountActionTypes.SAVINGS_INTEREST_POSTING.getValue()));
    assertThat(interestPostingActivity.getAmount(), is(TestUtils.createMoney("100")));
    assertThat(datePartOf(interestPostingActivity.getTrxnCreatedDate()), is(nextInterestPostingDate.toLocalDate()));
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) InterestPostingPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) AccountBO(org.mifos.accounts.business.AccountBO) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) InterestCalculationPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder) SavingsActivityEntity(org.mifos.accounts.savings.business.SavingsActivityEntity) Test(org.junit.Test)

Aggregations

AccountBO (org.mifos.accounts.business.AccountBO)106 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)39 LoanBO (org.mifos.accounts.loan.business.LoanBO)35 ArrayList (java.util.ArrayList)30 Money (org.mifos.framework.util.helpers.Money)30 UserContext (org.mifos.security.util.UserContext)29 Test (org.junit.Test)27 MifosRuntimeException (org.mifos.core.MifosRuntimeException)26 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)20 ServiceException (org.mifos.framework.exceptions.ServiceException)19 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)18 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)16 AccountException (org.mifos.accounts.exceptions.AccountException)15 MifosUser (org.mifos.security.MifosUser)14 Date (java.util.Date)13 LocalDate (org.joda.time.LocalDate)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)11 PersistenceException (org.mifos.framework.exceptions.PersistenceException)10 FeeBO (org.mifos.accounts.fees.business.FeeBO)9