Search in sources :

Example 76 with MeetingBuilder

use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.

the class UpdateCustomerMeetingScheduleTest method givenLsimIsEnabledShouldNotRegenerateSchedulesForLoanAccountsButShouldRegenerateSchedulesForCustomerAndSavingsAccounts.

@Test
public void givenLsimIsEnabledShouldNotRegenerateSchedulesForLoanAccountsButShouldRegenerateSchedulesForCustomerAndSavingsAccounts() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    DateTime mondayTwoWeeksAgo = new DateTime().withDayOfWeek(DayOfWeek.monday()).minusWeeks(2);
    MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).withStartDate(mondayTwoWeeksAgo).build();
    weeklyMeeting.updateDetails(userContext);
    CustomerAccountBuilder accountBuilder = new CustomerAccountBuilder();
    CenterBO center = new CenterBuilder().active().with(weeklyMeeting).withAccount(accountBuilder).withAccount(this.loanAccount).build();
    MeetingBO weeklyWednesdayMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).occuringOnA(WeekDay.WEDNESDAY).build();
    weeklyWednesdayMeeting.updateDetails(userContext);
    // stubbing
    CalendarEvent calendarEvent = new CalendarEventBuilder().build();
    when(holidayDao.findCalendarEventsForThisYearAndNext(anyShort())).thenReturn(calendarEvent);
    when(configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled()).thenReturn(true);
    // pre - verification
    assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(center, WeekDay.MONDAY);
    // exercise test
    customerService.updateCustomerMeetingSchedule(weeklyWednesdayMeeting, center);
    // verification
    assertThatAllCustomerSchedulesOccuringBeforeOrOnCurrentInstallmentPeriodRemainUnchanged(center, WeekDay.MONDAY);
    assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(center, WeekDay.WEDNESDAY);
}
Also used : UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerAccountBuilder(org.mifos.domain.builders.CustomerAccountBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CalendarEvent(org.mifos.calendar.CalendarEvent) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) CalendarEventBuilder(org.mifos.domain.builders.CalendarEventBuilder) Test(org.junit.Test)

Example 77 with MeetingBuilder

use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.

the class CustomerAccountGenerateNextSetOfMeetingDatesTest method canGenerateNextSetOfMeetingScheduleOnTopOfPreviousMeetingScheduleWithRecurringFees.

@Test
public void canGenerateNextSetOfMeetingScheduleOnTopOfPreviousMeetingScheduleWithRecurringFees() {
    // use default setup
    MeetingBuilder weeklyMeetingBuilder = new MeetingBuilder().customerMeeting().weekly().every(1);
    MeetingBO customerMeeting = weeklyMeetingBuilder.build();
    customer = new CenterBuilder().active().with(customerMeeting).build();
    AmountFeeBO recurringFee = new FeeBuilder().appliesToAllCustomers().periodic().with(weeklyMeetingBuilder).withFeeAmount("3.0").build();
    AccountFeesEntity recurringFeeEntity = new AccountFeesEntity(null, recurringFee, recurringFee.getFeeAmount().getAmountDoubleValue());
    recurringFeeEntity = spy(recurringFeeEntity);
    when(recurringFeeEntity.getAccountFeeId()).thenReturn(1);
    accountFees = new ArrayList<AccountFeesEntity>();
    accountFees.add(recurringFeeEntity);
    customerAccount = CustomerAccountBO.createNew(customer, accountFees, customerMeeting, calendarEvent);
    // setup
    AccountFeesEntity sameButDifferentRecurringFeeEntity = new AccountFeesEntity(customerAccount, recurringFee, recurringFee.getFeeAmount().getAmountDoubleValue());
    sameButDifferentRecurringFeeEntity = spy(sameButDifferentRecurringFeeEntity);
    customerAccount.getAccountFees().clear();
    customerAccount.addAccountFees(sameButDifferentRecurringFeeEntity);
    when(sameButDifferentRecurringFeeEntity.getAccountFeeId()).thenReturn(1);
    List<AccountActionDateEntity> schedules = new ArrayList<AccountActionDateEntity>(customerAccount.getAccountActionDates());
    DateTime lastScheduledDate = new DateTime(schedules.get(9).getActionDate());
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
    // stubbing
    List<DateTime> generatedDates = elevenDatesStartingFromAndIncluding(lastScheduledDate, scheduledEvent);
    when(scheduledDateGeneration.generateScheduledDates(anyInt(), (DateTime) anyObject(), (ScheduledEvent) anyObject(), anyBoolean())).thenReturn(generatedDates);
    // exercise test
    customerAccount.generateNextSetOfMeetingDates(scheduledDateGeneration);
    assertThat(customerAccount.getAccountActionDates().size(), is(20));
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) CenterBuilder(org.mifos.domain.builders.CenterBuilder) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) DateTime(org.joda.time.DateTime) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) FeeBuilder(org.mifos.domain.builders.FeeBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 78 with MeetingBuilder

use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.

the class CustomerAccountGenerateNextSetOfMeetingDatesTest method canGenerateNextSetOfMeetingDatesWithFreshlyGeneratedSchedule.

@Test
public void canGenerateNextSetOfMeetingDatesWithFreshlyGeneratedSchedule() {
    // use default setup
    MeetingBO customerMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).build();
    customer = new CenterBuilder().active().with(customerMeeting).build();
    customerAccount = CustomerAccountBO.createNew(customer, accountFees, customerMeeting, calendarEvent);
    // pre verification
    assertThat(customerAccount.getAccountActionDates().size(), is(10));
    // setup
    List<AccountActionDateEntity> schedules = new ArrayList<AccountActionDateEntity>(customerAccount.getAccountActionDates());
    DateTime lastScheduledDate = new DateTime(schedules.get(9).getActionDate());
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customer.getCustomerMeetingValue());
    // stubbing
    List<DateTime> generatedDates = elevenDatesStartingFromAndIncluding(lastScheduledDate, scheduledEvent);
    when(scheduledDateGeneration.generateScheduledDates(anyInt(), (DateTime) anyObject(), (ScheduledEvent) anyObject(), anyBoolean())).thenReturn(generatedDates);
    // exercise test
    customerAccount.generateNextSetOfMeetingDates(scheduledDateGeneration);
    //verification
    assertThat(customerAccount.getAccountActionDates().size(), is(20));
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) ScheduledEvent(org.mifos.schedule.ScheduledEvent) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 79 with MeetingBuilder

use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.

the class CustomerAccountBOIntegrationTest method testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue.

@Test
public void testTrxnDetailEntityObjectsForMultipleInstallmentsWhenOnlyCustomerAccountChargesAreDue() throws Exception {
    MeetingBO weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).startingToday().build();
    center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
    IntegrationTestObjectMother.createCenter((CenterBO) center, weeklyMeeting);
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    final Money fiftyAmount = new Money(getCurrency(), "50.0");
    final Money seventyAmount = new Money(getCurrency(), "70.0");
    final Money oneHundredTwentyAmount = new Money(getCurrency(), "120.0");
    final Money twoHundredFortyAmount = new Money(getCurrency(), "240.0");
    for (AccountActionDateEntity accountActionDateEntity : customerAccount.getAccountActionDates()) {
        CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
        if (customerSchedule.getInstallmentId() != 2) {
            customerSchedule.setMiscFee(fiftyAmount);
            customerSchedule.setMiscPenalty(seventyAmount);
        }
    }
    Date transactionDate = incrementCurrentDate(14);
    PaymentData paymentData = PaymentData.createPaymentData(twoHundredFortyAmount, 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");
            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());
                    }
                    Assert.assertEquals(0, customerTrxnDetailEntity.getFeesTrxnDetails().size());
                }
            } 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) MeetingBO(org.mifos.application.meeting.business.MeetingBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) CenterBuilder(org.mifos.domain.builders.CenterBuilder) 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) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 80 with MeetingBuilder

use of org.mifos.domain.builders.MeetingBuilder in project head by mifos.

the class CenterValidationTest method cannotCreateCenterWithMultipleInstancesOfSamePeriodFee.

@Test
public void cannotCreateCenterWithMultipleInstancesOfSamePeriodFee() {
    // setup
    DateTime today = new DateTime();
    MeetingBuilder aWeeklyMeeting = new MeetingBuilder().customerMeeting().weekly();
    CenterBO center = new CenterBuilder().withName("center1").withLoanOfficer(anyLoanOfficer()).with(aWeeklyMeeting).withMfiJoiningDate(today).build();
    MeetingBuilder aWeeklyFeeMeeting = new MeetingBuilder().periodicFeeMeeting().weekly();
    AmountFeeBO montlyPeriodicFee = new FeeBuilder().appliesToCenterOnly().with(aWeeklyFeeMeeting).build();
    AccountFeesEntity accountFee = new AccountFeesEntity(null, montlyPeriodicFee, montlyPeriodicFee.getFeeAmount().getAmountDoubleValue());
    List<AccountFeesEntity> centerAccountFees = new ArrayList<AccountFeesEntity>();
    centerAccountFees.add(accountFee);
    centerAccountFees.add(accountFee);
    // exercise test
    try {
        center.validateMeetingAndFees(centerAccountFees);
        fail("cannotCreateCenterWithFeeThatHasDifferentPeriod");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(CustomerConstants.ERRORS_DUPLICATE_PERIODIC_FEE));
    }
}
Also used : FeeBuilder(org.mifos.domain.builders.FeeBuilder) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTime(org.joda.time.DateTime) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) Test(org.junit.Test)

Aggregations

MeetingBuilder (org.mifos.domain.builders.MeetingBuilder)106 Test (org.junit.Test)74 MeetingBO (org.mifos.application.meeting.business.MeetingBO)74 CenterBuilder (org.mifos.domain.builders.CenterBuilder)73 DateTime (org.joda.time.DateTime)58 ArrayList (java.util.ArrayList)47 CenterBO (org.mifos.customers.center.business.CenterBO)43 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)38 LocalDate (org.joda.time.LocalDate)27 GroupBuilder (org.mifos.domain.builders.GroupBuilder)24 Before (org.junit.Before)21 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)20 FeeBuilder (org.mifos.domain.builders.FeeBuilder)20 OfficeBO (org.mifos.customers.office.business.OfficeBO)19 ClientBuilder (org.mifos.domain.builders.ClientBuilder)15 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)14 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)14 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)13 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)11 Ignore (org.junit.Ignore)10