Search in sources :

Example 1 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class CenterServiceFacadeWebTier method waiveChargesDue.

@Override
public void waiveChargesDue(Integer accountId, Integer waiveType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        account.updateDetails(userContext);
        PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
        WaiveEnum waiveEnum = WaiveEnum.fromInt(waiveType);
        if (account.getPersonnel() != null) {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
        } else {
            new AccountBusinessService().checkPermissionForWaiveDue(waiveEnum, account.getType(), account.getCustomer().getLevel(), userContext, account.getOffice().getOfficeId(), userContext.getId());
        }
        try {
            this.transactionHelper.startTransaction();
            if (account instanceof LoanBO) {
                ((LoanBO) account).waiveAmountDue(waiveEnum);
            } else if (account instanceof SavingsBO) {
                ((SavingsBO) account).waiveNextDepositAmountDue(loggedInUser);
            } else {
                ((CustomerAccountBO) account).waiveAmountDue();
            }
            this.customerDao.save(account);
            this.transactionHelper.commitTransaction();
        } catch (Exception e) {
            this.transactionHelper.rollbackTransaction();
            throw new BusinessRuleException(account.getAccountId().toString(), e);
        } finally {
            this.transactionHelper.closeSession();
        }
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : WaiveEnum(org.mifos.accounts.util.helpers.WaiveEnum) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class ClientBO method createDepositSchedule.

/**
     * delete when usage in constructor is removed...
     */
@Deprecated
public void createDepositSchedule(final List<Days> workingDays, final List<Holiday> holidays) throws CustomerException {
    try {
        if (getParentCustomer() != null) {
            List<SavingsBO> savingsList = getCustomerPersistence().retrieveSavingsAccountForCustomer(getParentCustomer().getCustomerId());
            if (getParentCustomer().getParentCustomer() != null) {
                savingsList.addAll(getCustomerPersistence().retrieveSavingsAccountForCustomer(getParentCustomer().getParentCustomer().getCustomerId()));
            }
            for (SavingsBO savings : savingsList) {
                savings.setUserContext(getUserContext());
                savings.generateAndUpdateDepositActionsForClient(this, workingDays, holidays);
            }
        }
    } catch (PersistenceException pe) {
        throw new CustomerException(pe);
    } catch (AccountException ae) {
        throw new CustomerException(ae);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Example 3 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO 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 4 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO 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 5 with SavingsBO

use of org.mifos.accounts.savings.business.SavingsBO in project head by mifos.

the class CustomerBO method getSavingsBalance.

public Money getSavingsBalance(MifosCurrency currency) {
    Money amount = new Money(currency);
    for (AccountBO account : getAccounts()) {
        if (account.getType() == AccountTypes.SAVINGS_ACCOUNT) {
            SavingsBO savingsBO = (SavingsBO) account;
            amount = amount.add(savingsBO.getSavingsBalance());
        }
    }
    return amount;
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) SavingsBO(org.mifos.accounts.savings.business.SavingsBO)

Aggregations

SavingsBO (org.mifos.accounts.savings.business.SavingsBO)111 UserContext (org.mifos.security.util.UserContext)43 MifosRuntimeException (org.mifos.core.MifosRuntimeException)30 AccountException (org.mifos.accounts.exceptions.AccountException)28 LocalDate (org.joda.time.LocalDate)27 MifosUser (org.mifos.security.MifosUser)26 Test (org.junit.Test)25 Money (org.mifos.framework.util.helpers.Money)24 ArrayList (java.util.ArrayList)22 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 Date (java.util.Date)20 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)19 BusinessRuleException (org.mifos.service.BusinessRuleException)18 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)17 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)17 CustomerBO (org.mifos.customers.business.CustomerBO)15 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)14 ServiceException (org.mifos.framework.exceptions.ServiceException)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12