Search in sources :

Example 46 with Company

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

the class AddressController method viewDirection.

public void viewDirection(ActionRequest request, ActionResponse response) {
    AddressRepository addressRepository = Beans.get(AddressRepository.class);
    try {
        MapService mapService = Beans.get(MapService.class);
        String key = null;
        if (Beans.get(AppBaseService.class).getAppBase().getMapApiSelect() == AppBaseRepository.MAP_API_GOOGLE) {
            key = mapService.getGoogleMapsApiKey();
        }
        Company company = Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
        if (company == null) {
            response.setFlash(I18n.get(IExceptionMessage.PRODUCT_NO_ACTIVE_COMPANY));
            return;
        }
        Address departureAddress = company.getAddress();
        if (departureAddress == null) {
            response.setFlash(I18n.get(IExceptionMessage.ADDRESS_7));
            return;
        }
        departureAddress = addressRepository.find(departureAddress.getId());
        Optional<Pair<BigDecimal, BigDecimal>> departureLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(departureAddress);
        if (!departureLatLong.isPresent()) {
            response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), departureAddress.getFullName()));
            return;
        }
        Address arrivalAddress = request.getContext().asType(Address.class);
        arrivalAddress = addressRepository.find(arrivalAddress.getId());
        Optional<Pair<BigDecimal, BigDecimal>> arrivalLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(arrivalAddress);
        if (!arrivalLatLong.isPresent()) {
            response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), arrivalAddress.getFullName()));
            return;
        }
        Map<String, Object> mapView = new HashMap<>();
        mapView.put("title", "Map");
        mapView.put("resource", mapService.getDirectionUrl(key, departureLatLong.get(), arrivalLatLong.get()));
        mapView.put("viewType", "html");
        response.setView(mapView);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) PartnerAddress(com.axelor.apps.base.db.PartnerAddress) Address(com.axelor.apps.base.db.Address) HashMap(java.util.HashMap) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) AddressService(com.axelor.apps.base.service.AddressService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) AddressRepository(com.axelor.apps.base.db.repo.AddressRepository) PartnerAddressRepository(com.axelor.apps.base.db.repo.PartnerAddressRepository) MapService(com.axelor.apps.base.service.MapService) Pair(org.apache.commons.lang3.tuple.Pair)

Example 47 with Company

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

the class MessageServiceBaseImpl method printMessage.

@SuppressWarnings("unchecked")
@Override
public String printMessage(Message message) throws AxelorException {
    Company company = message.getCompany();
    if (company == null) {
        return null;
    }
    PrintingSettings printSettings = company.getPrintingSettings();
    if (printSettings == null || printSettings.getDefaultMailBirtTemplate() == null) {
        return null;
    }
    BirtTemplate birtTemplate = printSettings.getDefaultMailBirtTemplate();
    logger.debug("Default BirtTemplate : {}", birtTemplate);
    Templates templates = new StringTemplates('$', '$');
    Map<String, Object> templatesContext = Maps.newHashMap();
    try {
        Class<? extends Model> className = (Class<? extends Model>) Class.forName(message.getClass().getName());
        templatesContext.put("Message", JPA.find(className, message.getId()));
    } catch (ClassNotFoundException e) {
        TraceBackService.trace(e);
    }
    String fileName = "Message " + message.getSubject() + "-" + appBaseService.getTodayDate(company).format(DateTimeFormatter.BASIC_ISO_DATE);
    return Beans.get(TemplateMessageServiceBaseImpl.class).generateBirtTemplateLink(templates, templatesContext, fileName, birtTemplate.getTemplateLink(), birtTemplate.getFormat(), birtTemplate.getBirtTemplateParameterList());
}
Also used : Company(com.axelor.apps.base.db.Company) BirtTemplate(com.axelor.apps.base.db.BirtTemplate) Templates(com.axelor.text.Templates) StringTemplates(com.axelor.text.StringTemplates) StringTemplates(com.axelor.text.StringTemplates) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) Model(com.axelor.db.Model)

Example 48 with Company

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

the class UserServiceImpl method getUserActiveCompanyLogoLink.

@Override
public String getUserActiveCompanyLogoLink() {
    final Company company = this.getUserActiveCompany();
    if (company == null) {
        return null;
    }
    MetaFile logo = company.getLogo();
    if (logo == null) {
        return null;
    }
    return metaFiles.getDownloadLink(logo, company);
}
Also used : Company(com.axelor.apps.base.db.Company) MetaFile(com.axelor.meta.db.MetaFile)

Example 49 with Company

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

the class CompanyBankDetailsController method fillCompanyBankDetailsDomain.

/**
 * Set the domain of company bank details field
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetailsDomain(ActionRequest request, ActionResponse response) throws AxelorException {
    Partner partner = (Partner) request.getContext().get("partner");
    Company company = (Company) request.getContext().get("company");
    PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
    Integer operationTypeSelect = null;
    if (request.getContext().get("_operationTypeSelect") != null) {
        operationTypeSelect = Integer.valueOf(request.getContext().get("_operationTypeSelect").toString());
    }
    response.setAttr("companyBankDetails", "domain", Beans.get(BankDetailsServiceImpl.class).createCompanyBankDetailsDomain(partner, company, paymentMode, operationTypeSelect));
}
Also used : Company(com.axelor.apps.base.db.Company) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 50 with Company

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

the class KilometricService method computeKilometricExpense.

public BigDecimal computeKilometricExpense(ExpenseLine expenseLine, Employee employee) throws AxelorException {
    BigDecimal distance = expenseLine.getDistance();
    EmploymentContract mainEmploymentContract = employee.getMainEmploymentContract();
    if (mainEmploymentContract == null || mainEmploymentContract.getPayCompany() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), employee.getName());
    }
    Company company = mainEmploymentContract.getPayCompany();
    KilometricLog log = getKilometricLog(employee, expenseLine.getExpenseDate());
    BigDecimal previousDistance = log == null ? BigDecimal.ZERO : log.getDistanceTravelled();
    KilometricAllowanceRate allowance = expenseLine.getKilometricAllowParam() != null ? Beans.get(KilometricAllowanceRateRepository.class).all().filter("self.kilometricAllowParam.id = :_kilometricAllowParamId " + "and self.hrConfig.id = :_hrConfigId").bind("_kilometricAllowParamId", expenseLine.getKilometricAllowParam().getId()).bind("_hrConfigId", Beans.get(HRConfigService.class).getHRConfig(company).getId()).fetchOne() : null;
    if (allowance == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.KILOMETRIC_ALLOWANCE_RATE_MISSING), expenseLine.getKilometricAllowParam() != null ? expenseLine.getKilometricAllowParam().getName() : "", company.getName());
    }
    List<KilometricAllowanceRule> ruleList = new ArrayList<>();
    List<KilometricAllowanceRule> allowanceRuleList = allowance.getKilometricAllowanceRuleList();
    if (ObjectUtils.notEmpty(allowanceRuleList)) {
        for (KilometricAllowanceRule rule : allowanceRuleList) {
            if (rule.getMinimumCondition().compareTo(previousDistance.add(distance)) <= 0 && rule.getMaximumCondition().compareTo(previousDistance) >= 0) {
                ruleList.add(rule);
            }
        }
    }
    if (ruleList.isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.KILOMETRIC_ALLOWANCE_NO_RULE), allowance.getKilometricAllowParam().getName());
    }
    BigDecimal price = BigDecimal.ZERO;
    if (ruleList.size() == 1) {
        price = distance.multiply(ruleList.get(0).getRate());
    } else {
        Collections.sort(ruleList, (object1, object2) -> object1.getMinimumCondition().compareTo(object2.getMinimumCondition()));
        for (KilometricAllowanceRule rule : ruleList) {
            BigDecimal min = rule.getMinimumCondition().max(previousDistance);
            BigDecimal max = rule.getMaximumCondition().min(previousDistance.add(distance));
            price = price.add(max.subtract(min).multiply(rule.getRate()));
        }
    }
    return price.setScale(2, RoundingMode.HALF_UP);
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) ArrayList(java.util.ArrayList) KilometricAllowanceRate(com.axelor.apps.hr.db.KilometricAllowanceRate) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) KilometricLog(com.axelor.apps.hr.db.KilometricLog) KilometricAllowanceRule(com.axelor.apps.hr.db.KilometricAllowanceRule) BigDecimal(java.math.BigDecimal)

Aggregations

Company (com.axelor.apps.base.db.Company)213 Transactional (com.google.inject.persist.Transactional)72 Partner (com.axelor.apps.base.db.Partner)68 AxelorException (com.axelor.exception.AxelorException)65 BigDecimal (java.math.BigDecimal)54 Move (com.axelor.apps.account.db.Move)35 MoveLine (com.axelor.apps.account.db.MoveLine)35 LocalDate (java.time.LocalDate)35 ArrayList (java.util.ArrayList)31 PaymentMode (com.axelor.apps.account.db.PaymentMode)28 AccountConfig (com.axelor.apps.account.db.AccountConfig)27 Journal (com.axelor.apps.account.db.Journal)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)25 BankDetails (com.axelor.apps.base.db.BankDetails)22 Currency (com.axelor.apps.base.db.Currency)19 Product (com.axelor.apps.base.db.Product)17 StockLocation (com.axelor.apps.stock.db.StockLocation)17 StockMove (com.axelor.apps.stock.db.StockMove)15 List (java.util.List)15