Search in sources :

Example 11 with CustomerLevel

use of org.mifos.customers.api.CustomerLevel in project head by mifos.

the class WebTierAccountServiceFacade method isPaymentPermitted.

@Override
public boolean isPaymentPermitted(Integer accountId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        AccountBO account = new AccountBusinessService().getAccount(accountId);
        CustomerLevel customerLevel = null;
        if (account.getType().equals(AccountTypes.CUSTOMER_ACCOUNT)) {
            customerLevel = account.getCustomer().getLevel();
        }
        Short personnelId = userContext.getId();
        if (account.getPersonnel() != null) {
            personnelId = account.getPersonnel().getPersonnelId();
        }
        return ActivityMapper.getInstance().isPaymentPermittedForAccounts(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), personnelId);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerLevel(org.mifos.customers.api.CustomerLevel) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with CustomerLevel

use of org.mifos.customers.api.CustomerLevel in project head by mifos.

the class CustomerPersistence method setSearchFilters.

private void setSearchFilters(final List<Param> paramList, final SearchFiltersDto filters) throws PersistenceException {
    Map<String, Boolean> customerLevelIds = filters.getCustomerLevels();
    Map<String, Integer> customerStates = filters.getCustomerStates();
    for (CustomerLevel customerLevel : CustomerLevel.values()) {
        if (customerLevelIds != null) {
            paramList.add(typeNameValue("Boolean", customerLevel.toString() + "_SEARCH", customerLevelIds.get(customerLevel.toString())));
        } else {
            paramList.add(typeNameValue("Boolean", customerLevel.toString() + "_SEARCH", true));
        }
        if (customerStates != null) {
            paramList.add(typeNameValue("Short", customerLevel.toString() + "_STATUS", customerStates.get(customerLevel.toString())));
        } else {
            paramList.add(typeNameValue("Short", customerLevel.toString() + "_STATUS", "all"));
        }
    }
    try {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
        if (filters.getCreationDateRangeStart() != null && !filters.getCreationDateRangeStart().equals("")) {
            paramList.add(typeNameValue("Boolean", "CREATED_DATE_RANGE_START_SEARCH", true));
            paramList.add(typeNameValue("Date", "CREATED_DATE_RANGE_START", simpleDateFormat.parse(filters.getCreationDateRangeStart())));
        } else {
            paramList.add(typeNameValue("Boolean", "CREATED_DATE_RANGE_START_SEARCH", false));
            paramList.add(typeNameValue("Date", "CREATED_DATE_RANGE_START", null));
        }
        if (filters.getCreationDateRangeEnd() != null && !filters.getCreationDateRangeEnd().equals("")) {
            paramList.add(typeNameValue("Boolean", "CREATED_DATE_RANGE_END_SEARCH", true));
            paramList.add(typeNameValue("Date", "CREATED_DATE_RANGE_END", simpleDateFormat.parse(filters.getCreationDateRangeEnd())));
        } else {
            paramList.add(typeNameValue("Boolean", "CREATED_DATE_RANGE_END_SEARCH", false));
            paramList.add(typeNameValue("Date", "CREATED_DATE_RANGE_END", null));
        }
    } catch (ParseException e) {
        throw new MifosRuntimeException(e);
    }
    if (filters.getGender() != null && filters.getGender() != 0) {
        paramList.add(typeNameValue("Boolean", "GENDER_SEARCH", true));
        paramList.add(typeNameValue("Short", "GENDER_ID", filters.getGender().shortValue()));
    } else {
        paramList.add(typeNameValue("Boolean", "GENDER_SEARCH", false));
        paramList.add(typeNameValue("Short", "GENDER_ID", null));
    }
    if (filters.getEthnicity() != null && !filters.getEthnicity().equals("")) {
        List<Integer> ethnicityIds = getLookupIdsByValue(filters.getEthnicity(), LookUpEntity.ETHNICITY);
        if (ethnicityIds.size() == 0) {
            ethnicityIds.add(-1);
        }
        paramList.add(typeNameValue("Boolean", "ETHNICITY_SEARCH", true));
        paramList.add(typeNameValue("List", "ETHNICITY_IDS", ethnicityIds));
    } else {
        paramList.add(typeNameValue("Boolean", "ETHNICITY_SEARCH", false));
        paramList.add(typeNameValue("List", "ETHNICITY_IDS", null));
    }
    if (filters.getBusinessActivity() != null && !filters.getBusinessActivity().equals("")) {
        List<Integer> businessActivityIds = getLookupIdsByValue(filters.getBusinessActivity(), LookUpEntity.BUSINESS_ACTIVITY);
        if (businessActivityIds.size() == 0) {
            businessActivityIds.add(-1);
        }
        paramList.add(typeNameValue("Boolean", "BUSINESS_ACTIVITY_SEARCH", true));
        paramList.add(typeNameValue("List", "BUSINESS_ACTIVITY_IDS", businessActivityIds));
    } else {
        paramList.add(typeNameValue("Boolean", "BUSINESS_ACTIVITY_SEARCH", false));
        paramList.add(typeNameValue("List", "BUSINESS_ACTIVITY_IDS", null));
    }
    if (filters.getCitizenship() != null && !filters.getCitizenship().equals("")) {
        List<Integer> citizenshipIds = getLookupIdsByValue(filters.getCitizenship(), LookUpEntity.CITIZENSHIP);
        if (citizenshipIds.size() == 0) {
            citizenshipIds.add(-1);
        }
        paramList.add(typeNameValue("Boolean", "CITIZENSHIP_SEARCH", true));
        paramList.add(typeNameValue("List", "CITIZENSHIP_IDS", citizenshipIds));
    } else {
        paramList.add(typeNameValue("Boolean", "CITIZENSHIP_SEARCH", false));
        paramList.add(typeNameValue("List", "CITIZENSHIP_IDS", null));
    }
}
Also used : CustomerLevel(org.mifos.customers.api.CustomerLevel) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

CustomerLevel (org.mifos.customers.api.CustomerLevel)12 ServiceException (org.mifos.framework.exceptions.ServiceException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)7 AccountTypes (org.mifos.accounts.util.helpers.AccountTypes)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 MifosUser (org.mifos.security.MifosUser)4 UserContext (org.mifos.security.util.UserContext)4 AccountBO (org.mifos.accounts.business.AccountBO)3 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)3 BusinessRuleException (org.mifos.service.BusinessRuleException)3 HashMap (java.util.HashMap)2 AccountPenaltiesEntity (org.mifos.accounts.business.AccountPenaltiesEntity)2 FeeBO (org.mifos.accounts.fees.business.FeeBO)2 RateFeeBO (org.mifos.accounts.fees.business.RateFeeBO)2 LoanBO (org.mifos.accounts.loan.business.LoanBO)2 PenaltyBO (org.mifos.accounts.penalties.business.PenaltyBO)2 RatePenaltyBO (org.mifos.accounts.penalties.business.RatePenaltyBO)2 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)2