Search in sources :

Example 11 with AppBase

use of com.axelor.apps.base.db.AppBase in project axelor-open-suite by axelor.

the class PurchaseOrderPrintServiceImpl method prepareReportSettings.

public ReportSettings prepareReportSettings(PurchaseOrder purchaseOrder, String formatPdf) throws AxelorException {
    if (purchaseOrder.getPrintingSettings() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.PURCHASE_ORDER_MISSING_PRINTING_SETTINGS), purchaseOrder.getPurchaseOrderSeq()), purchaseOrder);
    }
    String locale = ReportSettings.getPrintingLocale(purchaseOrder.getSupplierPartner());
    String title = getFileName(purchaseOrder);
    AppBase appBase = appBaseService.getAppBase();
    ReportSettings reportSetting = ReportFactory.createReport(IReport.PURCHASE_ORDER, title + " - ${date}");
    return reportSetting.addParam("PurchaseOrderId", purchaseOrder.getId()).addParam("Timezone", purchaseOrder.getCompany() != null ? purchaseOrder.getCompany().getTimezone() : null).addParam("Locale", locale).addParam("GroupProducts", appBase.getIsRegroupProductsOnPrintings() && purchaseOrder.getGroupProductsOnPrintings()).addParam("GroupProductTypes", appBase.getRegroupProductsTypeSelect()).addParam("GroupProductLevel", appBase.getRegroupProductsLevelSelect()).addParam("GroupProductProductTitle", appBase.getRegroupProductsLabelProducts()).addParam("GroupProductServiceTitle", appBase.getRegroupProductsLabelServices()).addParam("HeaderHeight", purchaseOrder.getPrintingSettings().getPdfHeaderHeight()).addParam("FooterHeight", purchaseOrder.getPrintingSettings().getPdfFooterHeight()).addFormat(formatPdf);
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReportSettings(com.axelor.apps.report.engine.ReportSettings) AppBase(com.axelor.apps.base.db.AppBase)

Example 12 with AppBase

use of com.axelor.apps.base.db.AppBase in project axelor-open-suite by axelor.

the class UserServiceImpl method processChangedPassword.

@Override
@Transactional(rollbackOn = { Exception.class })
public void processChangedPassword(User user) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, AxelorException, JSONException {
    Preconditions.checkNotNull(user, I18n.get("User cannot be null."));
    try {
        if (!user.getSendEmailUponPasswordChange()) {
            return;
        }
        if (user.equals(AuthUtils.getUser())) {
            logger.debug("User {} changed own password.", user.getCode());
            return;
        }
        AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
        Template template = appBase.getPasswordChangedTemplate();
        if (template == null) {
            throw new AxelorException(appBase, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get("Template for changed password is missing."));
        }
        TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
        templateMessageService.generateAndSendMessage(user, template);
    } finally {
        user.setTransientPassword(null);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) AppBase(com.axelor.apps.base.db.AppBase) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 13 with AppBase

use of com.axelor.apps.base.db.AppBase in project axelor-open-suite by axelor.

the class UserHrServiceImpl method createEmployee.

@Transactional
public void createEmployee(User user) {
    if (user.getPartner() == null) {
        Beans.get(UserService.class).createPartner(user);
    }
    AppBase appBase = appHumanResourceService.getAppBase();
    AppLeave appLeave = appHumanResourceService.getAppLeave();
    Employee employee = new Employee();
    employee.setContactPartner(user.getPartner());
    employee.setTimeLoggingPreferenceSelect(appBase.getTimeLoggingPreferenceSelect());
    employee.setDailyWorkHours(appBase.getDailyWorkHours());
    employee.setNegativeValueLeave(appLeave.getAllowNegativeLeaveEmployees());
    EventsPlanning planning = null;
    Company company = user.getActiveCompany();
    if (company != null) {
        HRConfig hrConfig = company.getHrConfig();
        if (hrConfig != null) {
            planning = hrConfig.getPublicHolidayEventsPlanning();
        }
    }
    employee.setPublicHolidayEventsPlanning(planning);
    employee.setUser(user);
    Beans.get(EmployeeRepository.class).save(employee);
    user.setEmployee(employee);
    userRepo.save(user);
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Company(com.axelor.apps.base.db.Company) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) UserService(com.axelor.apps.base.service.user.UserService) AppLeave(com.axelor.apps.base.db.AppLeave) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) AppBase(com.axelor.apps.base.db.AppBase) Transactional(com.google.inject.persist.Transactional)

Example 14 with AppBase

use of com.axelor.apps.base.db.AppBase in project axelor-open-suite by axelor.

the class KilometricService method computeDistance.

/**
 * Compute the distance between two cities.
 *
 * @param fromCity
 * @param toCity
 * @return
 * @throws AxelorException
 */
protected BigDecimal computeDistance(String fromCity, String toCity) throws AxelorException {
    BigDecimal distance = BigDecimal.ZERO;
    if (StringUtils.isEmpty(fromCity) || StringUtils.isEmpty(toCity) || fromCity.equalsIgnoreCase(toCity))
        return distance;
    AppBase appBase = appBaseService.getAppBase();
    try {
        switch(appBase.getMapApiSelect()) {
            case AppBaseRepository.MAP_API_GOOGLE:
                distance = this.getDistanceUsingGoogle(fromCity, toCity);
                break;
            case AppBaseRepository.MAP_API_OPEN_STREET_MAP:
                distance = this.getDistanceUsingOSM(fromCity, toCity);
                break;
        }
        return distance;
    } catch (URISyntaxException | IOException | JSONException e) {
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) JSONException(wslite.json.JSONException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) AppBase(com.axelor.apps.base.db.AppBase)

Example 15 with AppBase

use of com.axelor.apps.base.db.AppBase in project axelor-open-suite by axelor.

the class CompanyServiceImpl method checkMultiBanks.

/**
 * {@inheritDoc}
 */
@Override
public void checkMultiBanks(Company company) {
    if (countActiveBankDetails(company) > 1) {
        AppBaseService appBaseService = Beans.get(AppBaseService.class);
        AppBase appBase = appBaseService.getAppBase();
        if (!appBase.getManageMultiBanks()) {
            appBaseService.setManageMultiBanks(true);
        }
    }
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) AppBase(com.axelor.apps.base.db.AppBase)

Aggregations

AppBase (com.axelor.apps.base.db.AppBase)18 AxelorException (com.axelor.exception.AxelorException)8 BigDecimal (java.math.BigDecimal)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)4 User (com.axelor.auth.db.User)3 JSONException (wslite.json.JSONException)3 Company (com.axelor.apps.base.db.Company)2 CurrencyConversionLine (com.axelor.apps.base.db.CurrencyConversionLine)2 Lead (com.axelor.apps.crm.db.Lead)2 ReportSettings (com.axelor.apps.report.engine.ReportSettings)2 Transactional (com.google.inject.persist.Transactional)2 MalformedURLException (java.net.MalformedURLException)2 LocalDate (java.time.LocalDate)2 AppLeave (com.axelor.apps.base.db.AppLeave)1 EventsPlanning (com.axelor.apps.base.db.EventsPlanning)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 MapService (com.axelor.apps.base.service.MapService)1 UserService (com.axelor.apps.base.service.user.UserService)1 Employee (com.axelor.apps.hr.db.Employee)1 HRConfig (com.axelor.apps.hr.db.HRConfig)1