Search in sources :

Example 91 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, OfficeBO transferToOffice) throws CustomerException {
    group.validateNewOffice(transferToOffice);
    group.validateNoActiveAccountsExist();
    customerDao.validateGroupNameIsNotTakenForOffice(group.getDisplayName(), transferToOffice.getOfficeId());
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(group);
        group.makeCustomerMovementEntries(transferToOffice);
        group.setPersonnel(null);
        if (group.isActive()) {
            group.setCustomerStatus(new CustomerStatusEntity(CustomerStatus.GROUP_HOLD));
        }
        CustomerBO oldParentOfGroup = group.getParentCustomer();
        if (oldParentOfGroup != null) {
            oldParentOfGroup.incrementChildCount();
            customerDao.save(oldParentOfGroup);
        }
        this.hibernateTransactionHelper.flushSession();
        group.generateSearchId();
        group.setUpdateDetails();
        customerDao.save(group);
        Set<CustomerBO> clients = group.getChildren();
        if (clients != null) {
            for (CustomerBO client : clients) {
                client.setUserContext(group.getUserContext());
                ((ClientBO) client).handleGroupTransfer();
                client.setUpdateDetails();
                customerDao.save(client);
            }
        }
        hibernateTransactionHelper.commitTransaction();
        return group.getGlobalCustNum();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) 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 92 with CustomerBO

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

the class CustomerServiceImpl method assembleCustomerPostionsFromDto.

private void assembleCustomerPostionsFromDto(List<CustomerPositionDto> customerPositions, CustomerBO customer) {
    for (CustomerPositionDto positionView : customerPositions) {
        boolean isPositionFound = false;
        for (CustomerPositionEntity positionEntity : customer.getCustomerPositions()) {
            if (positionView.getPositionId().equals(positionEntity.getPosition().getId())) {
                CustomerBO customerInPosition = null;
                if (positionView.getCustomerId() != null) {
                    customerInPosition = customerDao.findCustomerById(positionView.getCustomerId());
                }
                positionEntity.setCustomer(customerInPosition);
                isPositionFound = true;
                break;
            }
        }
        if (!isPositionFound) {
            CustomerBO customerInPosition = null;
            if (positionView.getCustomerId() != null) {
                customerInPosition = customerDao.findCustomerById(positionView.getCustomerId());
            }
            CustomerPositionEntity customerPosition = new CustomerPositionEntity(new PositionEntity(positionView.getPositionId()), customerInPosition, customer);
            customer.addCustomerPosition(customerPosition);
        }
    }
}
Also used : CustomerPositionEntity(org.mifos.customers.business.CustomerPositionEntity) CustomerPositionEntity(org.mifos.customers.business.CustomerPositionEntity) PositionEntity(org.mifos.customers.business.PositionEntity) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 93 with CustomerBO

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

the class GroupBO method updateSearchId.

/*
     * This methed is used to regenerate the searchId for a group
     * which has a bad searchId due to previous bugs (such as MIFOS-2737)
     */
public void updateSearchId() throws CustomerException {
    generateSearchId();
    update();
    if (getChildren() != null) {
        for (CustomerBO client : getChildren()) {
            client.setUserContext(getUserContext());
            ((ClientBO) client).handleGroupTransfer();
        }
    }
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO)

Example 94 with CustomerBO

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

the class GroupPerformanceHistoryEntity method getTotalSavingsAmount.

public Money getTotalSavingsAmount() throws CustomerException {
    Money amount = group.getSavingsBalance(getCurrency());
    List<CustomerBO> clients = getChildren();
    if (clients != null) {
        for (CustomerBO client : clients) {
            Money savingsBalance = client.getSavingsBalance(getCurrency());
            if (amount.getAmount().equals(BigDecimal.ZERO)) {
                amount = savingsBalance;
            } else {
                amount = amount.add(savingsBalance);
            }
        }
    }
    return amount;
}
Also used : Money(org.mifos.framework.util.helpers.Money) CustomerBO(org.mifos.customers.business.CustomerBO)

Example 95 with CustomerBO

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

the class GroupPerformanceHistoryEntity method generatePortfolioAtRisk.

// this method calculates the PAR using the method
// LoanBO.hasPortfolioAtRisk() to determine if a loan is in arrears
public void generatePortfolioAtRisk() throws CustomerException {
    Money amount = getBalanceForAccountsAtRisk(group);
    List<CustomerBO> clients = getChildren();
    if (clients != null) {
        for (CustomerBO client : clients) {
            Money balanceAtRisk = getBalanceForAccountsAtRisk(client);
            if (amount.getAmount().equals(BigDecimal.ZERO)) {
                amount = balanceAtRisk;
            } else {
                amount = amount.add(balanceAtRisk);
            }
        }
    }
    Money totalOutstandingLoanAmount = getTotalOutStandingLoanAmount();
    if (!totalOutstandingLoanAmount.getAmount().equals(BigDecimal.ZERO)) {
        setPortfolioAtRisk(new Money(amount.getCurrency(), amount.divide(totalOutstandingLoanAmount)));
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) CustomerBO(org.mifos.customers.business.CustomerBO)

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