Search in sources :

Example 21 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class CustSearchAction method search.

/**
     * FIXME: KEITHW - When replacing search functionality for customers with spring/ftl implementation,
     * find cleaner way of implementing search that returns a non domain related class (data only object)
     */
@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (request.getParameter("perspective") != null) {
        request.setAttribute("perspective", request.getParameter("perspective"));
    }
    ActionForward actionForward = super.search(mapping, form, request, response);
    CustSearchActionForm actionForm = (CustSearchActionForm) form;
    UserContext userContext = getUserContext(request);
    String searchString = actionForm.getSearchString();
    if (searchString == null) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String officeName = this.centerServiceFacade.retrieveOfficeName(userContext.getBranchId());
    addSeachValues(searchString, userContext.getBranchId().toString(), officeName, request);
    searchString = SearchUtils.normalizeSearchString(searchString);
    if (StringUtils.isBlank(searchString)) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    if (actionForm.getInput() != null && actionForm.getInput().equals("loan")) {
        QueryResult groupClients = new CustomerPersistence().searchGroupClient(searchString, userContext.getId(), false);
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, groupClients, request);
    } else if (actionForm.getInput() != null && actionForm.getInput().equals("savings")) {
        QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(searchString, userContext.getId());
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerForSavings, request);
    }
    return actionForward;
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) CustSearchActionForm(org.mifos.customers.struts.actionforms.CustSearchActionForm) UserContext(org.mifos.security.util.UserContext) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) ActionForward(org.apache.struts.action.ActionForward) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 22 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class EditCustomerStatusAction method updateStatus.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updateStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    EditCustomerStatusActionForm editStatusActionForm = (EditCustomerStatusActionForm) form;
    CustomerBO customerBOInSession = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    if (customerBOInSession.isBlackListed() && customerBOInSession.getStatus().getValue() == CustomerConstants.CLIENT_CLOSED) {
        try {
            this.clientServiceFacade.removeFromBlacklist(customerBOInSession.getCustomerId());
            customerBOInSession.setVersionNo(customerBOInSession.getVersionNo() + 1);
        } catch (AccessDeniedException e) {
            throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
        }
    }
    try {
        this.centerServiceFacade.updateCustomerStatus(customerBOInSession.getCustomerId(), customerBOInSession.getVersionNo(), editStatusActionForm.getFlagId(), editStatusActionForm.getNewStatusId(), editStatusActionForm.getNotes());
        createClientQuestionnaire.saveResponses(request, editStatusActionForm, customerBOInSession.getCustomerId());
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e);
    }
    return mapping.findForward(getDetailAccountPage(form));
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) EditCustomerStatusActionForm(org.mifos.customers.struts.actionforms.EditCustomerStatusActionForm) CustomerBO(org.mifos.customers.business.CustomerBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 23 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class SavingsBO method generateNextSetOfMeetingDates.

public void generateNextSetOfMeetingDates(final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
    CustomerBO customerBO = getCustomer();
    if (customerBO.getCustomerMeeting() != null && customerBO.getCustomerMeeting().getMeeting() != null) {
        MeetingBO depositSchedule = customerBO.getCustomerMeeting().getMeeting();
        Date oldMeetingDate = depositSchedule.getStartDate();
        Short lastInstallmentId = getLastInstallmentId();
        AccountActionDateEntity lastInstallment = getAccountActionDate(lastInstallmentId);
        if (lastInstallment == null) {
            // a special workaround for MIFOS-5107
            lastInstallment = new SavingsScheduleEntity(this, this.getCustomer(), (short) 0, new java.sql.Date(new LocalDate().minusDays(1).toDateMidnight().getMillis()), PaymentStatus.UNPAID, new Money(Money.getDefaultCurrency(), 0.0));
        }
        depositSchedule.setMeetingStartDate(lastInstallment.getActionDate());
        if (customerBO.getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || customerBO.getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
            generateDepositAccountActions(customerBO, depositSchedule, lastInstallment, workingDays, holidays);
        } else {
            List<CustomerBO> children;
            try {
                children = getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.OTHER_THAN_CLOSED);
            } catch (CustomerException ce) {
                throw new AccountException(ce);
            }
            for (CustomerBO customer : children) {
                generateDepositAccountActions(customer, depositSchedule, lastInstallment, workingDays, holidays);
            }
        }
        depositSchedule.setStartDate(oldMeetingDate);
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) Money(org.mifos.framework.util.helpers.Money) CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 24 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class SavingsBO method regenerateFutureInstallments.

@Override
protected void regenerateFutureInstallments(final AccountActionDateEntity nextInstallment, final List<Days> workingDays, final List<Holiday> holidays) throws AccountException {
    MeetingBO customerMeeting = getCustomer().getCustomerMeetingValue();
    ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(customerMeeting);
    LocalDate currentDate = new LocalDate();
    LocalDate thisIntervalStartDate = customerMeeting.startDateForMeetingInterval(currentDate);
    LocalDate nextMatchingDate = new LocalDate(scheduledEvent.nextEventDateAfter(thisIntervalStartDate.toDateTimeAtStartOfDay()));
    DateTime futureIntervalStartDate = customerMeeting.startDateForMeetingInterval(nextMatchingDate).toDateTimeAtStartOfDay();
    ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, holidays);
    int numberOfInstallmentsToGenerate = getLastInstallmentId();
    List<DateTime> meetingDates = dateGeneration.generateScheduledDates(numberOfInstallmentsToGenerate, futureIntervalStartDate, scheduledEvent, false);
    if (getCustomer().getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || getCustomer().getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
        updateSchedule(nextInstallment.getInstallmentId(), meetingDates);
    } else {
        List<CustomerBO> children;
        try {
            children = getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.OTHER_THAN_CLOSED);
        } catch (CustomerException ce) {
            throw new AccountException(ce);
        }
        updateSavingsSchedule(nextInstallment.getInstallmentId(), meetingDates, children);
    }
}
Also used : InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) ScheduledEvent(org.mifos.schedule.ScheduledEvent) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) CustomerException(org.mifos.customers.exceptions.CustomerException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomerBO(org.mifos.customers.business.CustomerBO) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Example 25 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class SavingsBO method goActiveForFristTimeAndGenerateSavingsSchedule.

/**
     * use minimal constructor which generates scheduled savings payments correctly and does not
     * do through this method.
     */
@Deprecated
private void goActiveForFristTimeAndGenerateSavingsSchedule(final CustomerBO customer) throws AccountException {
    HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class);
    CalendarEvent futureCalendarEventsApplicableToOffice = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
    this.activationDate = new DateTime(new DateTimeService().getCurrentJavaDateTime()).toDate();
    List<Days> workingDays = futureCalendarEventsApplicableToOffice.getWorkingDays();
    List<Holiday> holidays = futureCalendarEventsApplicableToOffice.getHolidays();
    logger.debug("In SavingsBO::generateDepositAccountActions()");
    // center/group with individual deposits, insert row for every client
    if (this.getCustomer().getCustomerMeeting() != null && this.getCustomer().getCustomerMeeting().getMeeting() != null) {
        MeetingBO depositSchedule = this.getCustomer().getCustomerMeeting().getMeeting();
        if (this.getCustomer().getCustomerLevel().getId().equals(CustomerLevel.CLIENT.getValue()) || this.getCustomer().getCustomerLevel().getId().equals(CustomerLevel.GROUP.getValue()) && this.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue())) {
            this.generateDepositAccountActions(this.getCustomer(), depositSchedule, workingDays, holidays, new DateTime(this.activationDate));
        } else {
            List<CustomerBO> children;
            try {
                children = this.getCustomer().getChildren(CustomerLevel.CLIENT, ChildrenStateType.ACTIVE_AND_ONHOLD);
            } catch (CustomerException ce) {
                throw new AccountException(ce);
            }
            for (CustomerBO customer1 : children) {
                this.generateDepositAccountActions(customer1, depositSchedule, workingDays, holidays, new DateTime(this.activationDate));
            }
        }
    }
    InterestScheduledEvent interestPostingEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(this.savingsOffering.getFreqOfPostIntcalc().getMeeting());
    this.nextIntPostDate = interestPostingEvent.nextMatchingDateAfter(new LocalDate(startOfFiscalYear()), new LocalDate(this.activationDate)).toDateMidnight().toDate();
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) CustomerException(org.mifos.customers.exceptions.CustomerException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CalendarEvent(org.mifos.calendar.CalendarEvent) LocalDate(org.joda.time.LocalDate) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) DateTime(org.joda.time.DateTime) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) AccountException(org.mifos.accounts.exceptions.AccountException) Holiday(org.mifos.application.holiday.business.Holiday) Days(org.joda.time.Days) CustomerBO(org.mifos.customers.business.CustomerBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Aggregations

CustomerException (org.mifos.customers.exceptions.CustomerException)103 Test (org.junit.Test)52 UserContext (org.mifos.security.util.UserContext)29 ClientBO (org.mifos.customers.client.business.ClientBO)23 GroupBuilder (org.mifos.domain.builders.GroupBuilder)21 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 BusinessRuleException (org.mifos.service.BusinessRuleException)21 CenterBO (org.mifos.customers.center.business.CenterBO)20 GroupBO (org.mifos.customers.group.business.GroupBO)20 AccountException (org.mifos.accounts.exceptions.AccountException)18 CenterBuilder (org.mifos.domain.builders.CenterBuilder)18 ArrayList (java.util.ArrayList)17 MifosRuntimeException (org.mifos.core.MifosRuntimeException)14 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)13 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 MifosUser (org.mifos.security.MifosUser)11 DateTime (org.joda.time.DateTime)10