Search in sources :

Example 61 with ClientBO

use of org.mifos.customers.client.business.ClientBO 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 62 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class CustomerServiceImpl method transferClientTo.

@Override
public ClientBO transferClientTo(UserContext userContext, Integer groupId, String clientGlobalCustNum, Integer previousClientVersionNo) throws CustomerException {
    ClientBO client = customerDao.findClientBySystemId(clientGlobalCustNum);
    client.validateVersion(previousClientVersionNo);
    client.validateIsSameGroup(groupId);
    client.updateDetails(userContext);
    GroupBO receivingGroup = (GroupBO) customerDao.findCustomerById(groupId);
    client.validateReceivingGroup(receivingGroup);
    client.validateForActiveAccounts();
    client.validateForPeriodicFees();
    if (client.getOfficeId() != receivingGroup.getOfficeId()) {
        customerDao.checkPermissionforEditingClientOfficeMembership(client.getUserContext(), client);
    }
    CustomerBO oldParent = client.getParentCustomer();
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(client);
        boolean regenerateSchedules = client.transferTo(receivingGroup);
        if (oldParent != null) {
            client.resetPositions(oldParent);
            oldParent.updateDetails(client.getUserContext());
            if (oldParent.getParentCustomer() != null) {
                CustomerBO center = oldParent.getParentCustomer();
                client.resetPositions(center);
                center.setUserContext(client.getUserContext());
            }
            customerDao.save(oldParent);
        }
        receivingGroup.updateDetails(client.getUserContext());
        customerDao.save(receivingGroup);
        client.updateDetails(userContext);
        customerDao.save(client);
        hibernateTransactionHelper.flushAndClearSession();
        if (regenerateSchedules) {
            client = customerDao.findClientBySystemId(clientGlobalCustNum);
            CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
            handleChangeInMeetingSchedule(client, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        }
        hibernateTransactionHelper.commitTransaction();
        return client;
    } 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) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerBO(org.mifos.customers.business.CustomerBO) 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 63 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class CustomerServiceImpl method updateClientPersonalInfo.

@Override
public final void updateClientPersonalInfo(UserContext userContext, ClientPersonalInfoUpdate personalInfo) throws CustomerException {
    ClientBO client = (ClientBO) this.customerDao.findCustomerById(personalInfo.getCustomerId());
    client.validateVersion(personalInfo.getOriginalClientVersionNumber());
    client.updateDetails(userContext);
    LocalDate currentDOB = new LocalDate(client.getDateOfBirth());
    LocalDate newDOB = currentDOB;
    try {
        // updating Date of birth
        // doesn''t sound normal but it can be required in certain cases
        // see http://mifosforge.jira.com/browse/MIFOS-4368
        newDOB = new LocalDate(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
    } catch (InvalidDateException e) {
        throw new MifosRuntimeException(e);
    }
    if (!currentDOB.isEqual(newDOB)) {
        customerDao.validateClientForDuplicateNameOrGovtId(personalInfo.getClientDisplayName(), newDOB.toDateMidnight().toDate(), null);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(client);
        client.updatePersonalInfo(personalInfo);
        clientPhotoService.update(personalInfo.getCustomerId().longValue(), personalInfo.getPicture());
        customerDao.save(client);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new CustomerException(e.getKey(), e);
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.commitTransaction();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientBO(org.mifos.customers.client.business.ClientBO) LocalDate(org.joda.time.LocalDate) 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 64 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class LoanAccountAction method findGovernmentId.

private String findGovernmentId(final Integer clientId) {
    ClientBO client = (ClientBO) this.customerDao.findCustomerById(clientId);
    String governmentId = client.getGovernmentId();
    return StringUtils.isBlank(governmentId) ? "-" : governmentId;
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO)

Example 65 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class LoanAccountAction method populateClientDetailsFromLoan.

List<LoanAccountDetailsDto> populateClientDetailsFromLoan(final List<ClientBO> activeClientsUnderGroup, final List<LoanBO> individualLoans, final List<ValueListElement> businessActivities) {
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    for (final ClientBO client : activeClientsUnderGroup) {
        LoanAccountDetailsDto clientDetail = new LoanAccountDetailsDto();
        clientDetail.setClientId(getStringValue(client.getCustomerId()));
        clientDetail.setClientName(client.getDisplayName());
        LoanBO loanAccount = (LoanBO) CollectionUtils.find(individualLoans, new Predicate() {

            @Override
            public boolean evaluate(final Object object) {
                return client.getCustomerId().equals(((LoanBO) object).getCustomer().getCustomerId());
            }
        });
        if (loanAccount != null) {
            final Integer businessActivityId = loanAccount.getBusinessActivityId();
            if (businessActivityId != null) {
                clientDetail.setBusinessActivity(Integer.toString(businessActivityId));
                ValueListElement businessActivityElement = (ValueListElement) CollectionUtils.find(businessActivities, new Predicate() {

                    @Override
                    public boolean evaluate(final Object object) {
                        return ((ValueListElement) object).getId().equals(businessActivityId);
                    }
                });
                if (businessActivityElement != null) {
                    clientDetail.setBusinessActivityName(businessActivityElement.getName());
                }
            }
            clientDetail.setLoanAmount(loanAccount.getLoanAmount() != null ? loanAccount.getLoanAmount().toString() : "0.0");
        }
        clientDetails.add(clientDetail);
    }
    return clientDetails;
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) ValueListElement(org.mifos.dto.domain.ValueListElement) Predicate(org.apache.commons.collections.Predicate)

Aggregations

ClientBO (org.mifos.customers.client.business.ClientBO)93 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 CustomerException (org.mifos.customers.exceptions.CustomerException)25 CustomerBO (org.mifos.customers.business.CustomerBO)23 GroupBO (org.mifos.customers.group.business.GroupBO)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 UserContext (org.mifos.security.util.UserContext)21 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 CenterBO (org.mifos.customers.center.business.CenterBO)19 BusinessRuleException (org.mifos.service.BusinessRuleException)17 ClientBuilder (org.mifos.domain.builders.ClientBuilder)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)14 GroupBuilder (org.mifos.domain.builders.GroupBuilder)14 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)14 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)14 Date (java.util.Date)13 DateTime (org.joda.time.DateTime)13 AccountException (org.mifos.accounts.exceptions.AccountException)13