Search in sources :

Example 56 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class CollectionSheetServiceFacadeWebTier method saveCollectionSheet.

@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    final SaveCollectionSheetDto saveCollectionSheetDto = saveCollectionSheet;
    UserContext userContext = new UserContextFactory().create(user);
    int customerId = saveCollectionSheetDto.getSaveCollectionSheetCustomers().get(0).getCustomerId();
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    try {
        personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    CollectionSheetErrorsDto collectionSheetErrorsDto = null;
    try {
        collectionSheetErrorsDto = collectionSheetService.saveCollectionSheet(saveCollectionSheet);
    } catch (SaveCollectionSheetException e) {
        throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
    }
    return collectionSheetErrorsDto;
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 57 with CustomerBO

use of org.mifos.customers.business.CustomerBO 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 58 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class CustomerServiceImpl method handleChangeInMeetingSchedule.

private void handleChangeInMeetingSchedule(CustomerBO customer, final List<Days> workingDays, final List<Holiday> orderedUpcomingHolidays) throws AccountException {
    boolean lsimEnabled = this.configurationHelper.isLoanScheduleRepaymentIndependentOfCustomerMeetingEnabled();
    Set<AccountBO> accounts = customer.getAccounts();
    for (AccountBO account : accounts) {
        if (account instanceof LoanBO && lsimEnabled) {
        // do not change schedules when LSIm is on for loan accounts
        } else {
            account.handleChangeInMeetingSchedule(workingDays, orderedUpcomingHolidays, customer.isTopOfHierarchy());
            customerDao.save(account);
        }
    }
    for (CustomerBO child : customer.getChildren()) {
        handleChangeInMeetingSchedule(child, workingDays, orderedUpcomingHolidays);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerBO(org.mifos.customers.business.CustomerBO)

Example 59 with CustomerBO

use of org.mifos.customers.business.CustomerBO in project head by mifos.

the class CustomerServiceImpl method removeFromBlacklist.

public void removeFromBlacklist(UserContext userContext, Integer customerId) {
    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    customer.updateDetails(userContext);
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(customer);
        customer.unBlacklist();
        customerDao.save(customer);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : CustomerBO(org.mifos.customers.business.CustomerBO) 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 60 with CustomerBO

use of org.mifos.customers.business.CustomerBO 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

CustomerBO (org.mifos.customers.business.CustomerBO)138 ArrayList (java.util.ArrayList)39 Money (org.mifos.framework.util.helpers.Money)38 MifosUser (org.mifos.security.MifosUser)38 UserContext (org.mifos.security.util.UserContext)37 LocalDate (org.joda.time.LocalDate)35 MifosRuntimeException (org.mifos.core.MifosRuntimeException)31 AccountException (org.mifos.accounts.exceptions.AccountException)30 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)27 BusinessRuleException (org.mifos.service.BusinessRuleException)27 MeetingBO (org.mifos.application.meeting.business.MeetingBO)23 ClientBO (org.mifos.customers.client.business.ClientBO)23 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 DateTime (org.joda.time.DateTime)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)20 Date (java.util.Date)19 Test (org.junit.Test)19 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)17 HashMap (java.util.HashMap)15