Search in sources :

Example 6 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class CustomerServiceImpl method changeStatus.

private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
    Short oldStatusId = oldStatus.getValue();
    Short newStatusId = newStatus.getValue();
    if (customer.isClient()) {
        ClientBO client = (ClientBO) customer;
        if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
            if (client.getParentCustomer() != null) {
                CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
                client.addCustomerHierarchy(hierarchy);
            }
            CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
            List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
            client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
            client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
            if (client.getOfferingsAssociatedInCreate() != null) {
                for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
                    try {
                        SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
                        if (savingsOffering.isActive()) {
                            List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
                            client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
                        }
                    } catch (AccountException pe) {
                        throw new CustomerException(pe);
                    }
                }
            }
            new SavingsPersistence().persistSavingAccounts(client);
            try {
                if (client.getParentCustomer() != null) {
                    List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
                    if (client.getParentCustomer().getParentCustomer() != null) {
                        savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
                    }
                    for (SavingsBO savings : savingsList) {
                        savings.setUserContext(client.getUserContext());
                        if (client.getCustomerMeeting().getMeeting() != null) {
                            if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
                                DateTime today = new DateTime().toDateMidnight().toDateTime();
                                savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
                                savings.update();
                            }
                        }
                    }
                }
            } catch (PersistenceException pe) {
                throw new CustomerException(pe);
            } catch (AccountException ae) {
                throw new CustomerException(ae);
            }
        }
    }
}
Also used : CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CalendarEvent(org.mifos.calendar.CalendarEvent) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) DateTime(org.joda.time.DateTime) AccountException(org.mifos.accounts.exceptions.AccountException) DateMidnight(org.joda.time.DateMidnight) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 7 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class GroupBO method regenerateCustomerFeeSchedule.

public void regenerateCustomerFeeSchedule(CalendarEvent applicableCalendarEvents) {
    CustomerAccountBO customerAccount = this.getCustomerAccount();
    if (customerAccount != null) {
        List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customerAccount.getAccountFees());
        customerAccount.createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(this, accountFees, this.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
    }
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) DateMidnight(org.joda.time.DateMidnight) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

Example 8 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class DepositAccountingEntryTest method setupForAllTests.

@Before
public void setupForAllTests() {
    currency = TestUtils.RUPEE;
    transactionActionDate = new DateMidnight(2009, 9, 9);
    transactionPostedDate = new DateMidnight(2009, 1, 1);
    depositAmount = "30";
    // trans on asset acccount sorts first in returned
    bankGLCode = "1";
    // list of transactions
    // trans on savings account sorts second in
    savingsDepositGLCode = "2";
    // returned list of transactions
    comments = "test comment";
    mockedFinancialActivity = mock(SavingsDepositFinancialActivity.class);
    mockedIncomingTransaction = mock(SavingsTrxnDetailEntity.class);
    mockedSavingsBO = mock(SavingsBO.class);
    mockedSavingsOffering = mock(SavingsOfferingBO.class);
    mockedSavingsType = mock(SavingsTypeEntity.class);
    mockedBankGLCode = mock(GLCodeEntity.class);
    mockedSavingsDepositGLCode = mock(GLCodeEntity.class);
    mockedFinancialBusinessService = mock(FinancialBusinessService.class);
    mockedSavingsGLCategory = mock(COABO.class);
    mockedBankGLCategory = mock(COABO.class);
    mockedBankGLAccount = mock(COABO.class);
    mockedSavingsGLAccount = mock(COABO.class);
    mockedFinancialAction = mock(FinancialActionTypeEntity.class);
}
Also used : FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) DateMidnight(org.joda.time.DateMidnight) COABO(org.mifos.accounts.financial.business.COABO) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) SavingsDepositFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsDepositFinancialActivity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) FinancialBusinessService(org.mifos.accounts.financial.business.service.FinancialBusinessService) Before(org.junit.Before)

Example 9 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class SavingsAdjustmentAccountingEntryTest method setupForAllTests.

@Before
public void setupForAllTests() {
    // Refresh mocks before each test
    mockedFinancialActivity = mock(SavingsAdjustmentFinancialActivity.class);
    mockedIncomingTransaction = mock(SavingsTrxnDetailEntity.class);
    mockedSavingsBO = mock(SavingsBO.class);
    mockedSavingsOffering = mock(SavingsOfferingBO.class);
    mockedSavingsType = mock(SavingsTypeEntity.class);
    //        mockedAccountPayment = mock(AccountPaymentEntity.class);
    //        mockedLastTransaction = mock(AccountTrxnEntity.class);
    //        mockedAccountAction = mock(AccountActionEntity.class);
    mockedBankGLCode = mock(GLCodeEntity.class);
    mockedSavingsDepositGLCode = mock(GLCodeEntity.class);
    mockedFinancialBusinessService = mock(FinancialBusinessService.class);
    //        mockedSavingsGLCategory = mock(COABO.class);
    //        mockedBankGLCategory = mock(COABO.class);
    mockedBankGLAccount = mock(COABO.class);
    mockedSavingsGLAccount = mock(COABO.class);
    mockedFinancialAction = mock(FinancialActionTypeEntity.class);
    mockedSavingsHelper = mock(SavingsHelper.class);
    // Hard-coded values that are just passed through and thus not relevant to what's being tested
    currency = TestUtils.RUPEE;
    withdrawalAmount = new Money(currency, "20");
    depositAmount = new Money(currency, "30");
    transactionActionDate = new DateMidnight(2009, 9, 9);
    transactionPostedDate = new DateMidnight(2009, 1, 1);
    commentString = "test comment";
    // Always set to 1
    expectedAccountingUpdatedFlag = (short) 1;
    /*
         * The method under test creates a set with two transactions, a transaction on the savings account and a
         * transaction on the bank's account, each of which is verified differently. In order to know which is which,
         * the set is converted to a list that is sorted on GL code.
         */
    // trans on asset acccount sorts first
    bankGLCodeString = "1";
    // trans on savings account sorts second
    savingsDepositGLCodeString = "2";
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialActionTypeEntity(org.mifos.accounts.financial.business.FinancialActionTypeEntity) SavingsTypeEntity(org.mifos.accounts.productdefinition.business.SavingsTypeEntity) DateMidnight(org.joda.time.DateMidnight) COABO(org.mifos.accounts.financial.business.COABO) SavingsHelper(org.mifos.accounts.savings.util.helpers.SavingsHelper) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) SavingsAdjustmentFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsAdjustmentFinancialActivity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsTrxnDetailEntity(org.mifos.accounts.savings.business.SavingsTrxnDetailEntity) FinancialBusinessService(org.mifos.accounts.financial.business.service.FinancialBusinessService) Before(org.junit.Before)

Example 10 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class SavingsBOTest method generateNextSetOfMeetingDatesMoratoriumOn12thInstallment.

@Ignore
@Test
public void generateNextSetOfMeetingDatesMoratoriumOn12thInstallment() throws Exception {
    // setup
    Holiday moratorium = new HolidayBuilder().from(new DateMidnight().toDateTime().plusWeeks(11)).to(new DateMidnight().toDateTime().plusWeeks(11)).withRepaymentMoratoriumRule().build();
    List<Holiday> withMoratorium = new ArrayList<Holiday>();
    withMoratorium.add(moratorium);
    when(savingsAccountCustomer.getCustomerMeeting()).thenReturn(customerMeetingEntity);
    when(customerMeetingEntity.getMeeting()).thenReturn(defaultWeeklyCustomerMeeting);
    when(savingsAccountCustomer.getCustomerLevel()).thenReturn(customerLevelEntity);
    when(customerLevelEntity.getId()).thenReturn(CustomerLevel.CLIENT.getValue());
    // exercise test
    savingsAccount = savingsAccountBuilder.with(moratorium).buildForUnitTests();
    savingsAccount.generateNextSetOfMeetingDates(allWorkingDays, withMoratorium);
    // verify
    List<SavingsScheduleEntity> sortedSavingsSchedules = getSortedSavingsScheduleEntities();
    assertThat(sortedSavingsSchedules.size(), is(20));
    DateTime installmentDate = new DateMidnight().toDateTime();
    int installmentId = 1;
    for (SavingsScheduleEntity savingsScheduleEntity : getSortedSavingsScheduleEntities()) {
        if (installmentId < 12) {
            assertThat("Installment " + installmentId, savingsScheduleEntity.getActionDate(), is(installmentDate.toDate()));
        } else {
            // Second and later deposits are pushed out one week by the moratorium
            assertThat("Installment " + installmentId, savingsScheduleEntity.getActionDate(), is(installmentDate.plusWeeks(1).toDate()));
        }
        assertThat(savingsScheduleEntity.getDeposit(), is(new Money(TestUtils.RUPEE, "13.0")));
        assertThat(savingsScheduleEntity.getDepositPaid(), is(new Money(TestUtils.RUPEE, "0.0")));
        installmentDate = installmentDate.plusWeeks(1);
        installmentId++;
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) Holiday(org.mifos.application.holiday.business.Holiday) DateMidnight(org.joda.time.DateMidnight) ArrayList(java.util.ArrayList) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DateMidnight (org.joda.time.DateMidnight)70 DateTime (org.joda.time.DateTime)33 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)10 Money (org.mifos.framework.util.helpers.Money)10 Ignore (org.junit.Ignore)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 LocalDate (org.joda.time.LocalDate)6 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)6 Holiday (org.mifos.application.holiday.business.Holiday)6 Date (java.util.Date)5 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)5 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)4 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)4 UserContext (org.mifos.security.util.UserContext)4 DateTimeZone (org.joda.time.DateTimeZone)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Before (org.junit.Before)3