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);
}
}
}
}
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());
}
}
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);
}
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";
}
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++;
}
}
Aggregations