Search in sources :

Example 6 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class SavingsAccountBuilder method build.

// build individual savings account
public SavingsBO build() {
    CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
    LocalDate activationDate = new LocalDate(createdDate);
    SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, activationDate);
    return buildAccount(derivedActivationDetails);
}
Also used : SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) CalendarEvent(org.mifos.calendar.CalendarEvent) LocalDate(org.joda.time.LocalDate)

Example 7 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class CustomerServiceImpl method transferGroupTo.

@Override
public final String transferGroupTo(GroupBO group, CenterBO receivingCenter) throws CustomerException {
    group.validateReceivingCenter(receivingCenter);
    group.validateNoActiveAccountsExist();
    if (group.isDifferentBranch(receivingCenter.getOffice())) {
        customerDao.validateGroupNameIsNotTakenForOffice(group.getDisplayName(), receivingCenter.getOfficeId());
    }
    CustomerBO oldParent = group.getParentCustomer();
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(group);
        boolean regenerateSchedules = group.transferTo(receivingCenter);
        if (oldParent != null) {
            oldParent.updateDetails(group.getUserContext());
            customerDao.save(oldParent);
        }
        receivingCenter.updateDetails(group.getUserContext());
        customerDao.save(receivingCenter);
        group.updateDetails(group.getUserContext());
        customerDao.save(group);
        Set<CustomerBO> clients = group.getChildren();
        for (CustomerBO client : clients) {
            client.setUserContext(group.getUserContext());
            ((ClientBO) client).handleGroupTransfer();
            client.setUpdateDetails();
            customerDao.save(client);
        }
        hibernateTransactionHelper.flushSession();
        GroupBO groupInitialised = group;
        if (regenerateSchedules) {
            CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(group.getOfficeId());
            groupInitialised = customerDao.findGroupBySystemId(group.getGlobalCustNum());
            handleChangeInMeetingSchedule(groupInitialised, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        }
        hibernateTransactionHelper.commitTransaction();
        return groupInitialised.getGlobalCustNum();
    } catch (ApplicationException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) CalendarEvent(org.mifos.calendar.CalendarEvent) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class CustomerServiceImpl method createCustomer.

private void createCustomer(CustomerBO customer, MeetingBO meeting, List<AccountFeesEntity> accountFees) {
    try {
        this.hibernateTransactionHelper.startTransaction();
        this.customerDao.save(customer);
        this.hibernateTransactionHelper.flushSession();
        // must first be saved via the customer save.
        for (AccountBO account : customer.getAccounts()) {
            if (account.isSavingsAccount()) {
                SavingsBO savingsAccount = (SavingsBO) account;
                savingsAccount.setUserContext(customer.getUserContext());
                savingsAccount.generateSystemId(customer.getOffice().getGlobalOfficeNum());
            }
        }
        this.customerDao.save(customer);
        this.hibernateTransactionHelper.flushSession();
        CalendarEvent applicableCalendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
        CustomerAccountBO customerAccount = this.customerAccountFactory.create(customer, accountFees, meeting, applicableCalendarEvents);
        customer.addAccount(customerAccount);
        this.customerDao.save(customer);
        this.hibernateTransactionHelper.flushSession();
        if (customer.getParentCustomer() != null) {
            this.customerDao.save(customer.getParentCustomer());
        }
        customer.generateGlobalCustomerNumber();
        customer.generateSearchId();
        this.customerDao.save(customer);
        if (customer.getParentCustomer() != null) {
            this.customerDao.save(customer.getParentCustomer());
        }
        this.hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CalendarEvent(org.mifos.calendar.CalendarEvent) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 9 with CalendarEvent

use of org.mifos.calendar.CalendarEvent 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 10 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class CustomerServiceImpl method updateGroupStatus.

@Override
public final void updateGroupStatus(GroupBO group, CustomerStatus oldStatus, CustomerStatus newStatus, CustomerStatusFlag customerStatusFlag, CustomerNoteEntity customerNote) throws CustomerException {
    validateChangeOfStatusForGroup(group, oldStatus, newStatus);
    CustomerStatusFlagEntity customerStatusFlagEntity = populateCustomerStatusFlag(customerStatusFlag);
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(group);
        if (group.isActiveForFirstTime(oldStatus.getValue(), newStatus.getValue())) {
            group.setCustomerActivationDate(new DateTime().toDate());
            group.updateCustomerHierarchy();
            CalendarEvent applicableCalendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(group.getOfficeId());
            group.regenerateCustomerFeeSchedule(applicableCalendarEvents);
        }
        Set<CustomerBO> groupChildren = group.getChildren();
        if (oldStatus.isGroupPending() && newStatus.isGroupCancelled() && groupChildren != null) {
            for (CustomerBO child : groupChildren) {
                ClientBO client = (ClientBO) child;
                if (client.isPending()) {
                    client.setUserContext(group.getUserContext());
                    hibernateTransactionHelper.beginAuditLoggingFor(client);
                    client.updateCustomerStatus(CustomerStatus.CLIENT_PARTIAL);
                    customerDao.save(client);
                }
            }
        }
        group.updateCustomerStatus(newStatus, customerNote, customerStatusFlagEntity);
        customerDao.save(group);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) CustomerStatusFlagEntity(org.mifos.customers.business.CustomerStatusFlagEntity) CalendarEvent(org.mifos.calendar.CalendarEvent) CustomerBO(org.mifos.customers.business.CustomerBO) DateTime(org.joda.time.DateTime) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

CalendarEvent (org.mifos.calendar.CalendarEvent)18 AccountException (org.mifos.accounts.exceptions.AccountException)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 CustomerException (org.mifos.customers.exceptions.CustomerException)8 ArrayList (java.util.ArrayList)7 CustomerBO (org.mifos.customers.business.CustomerBO)7 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 BusinessRuleException (org.mifos.service.BusinessRuleException)7 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)6 DateTime (org.joda.time.DateTime)5 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)5 ClientBO (org.mifos.customers.client.business.ClientBO)5 LocalDate (org.joda.time.LocalDate)4 Test (org.junit.Test)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)4 CenterBO (org.mifos.customers.center.business.CenterBO)4 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)4 CenterBuilder (org.mifos.domain.builders.CenterBuilder)4