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);
}
}
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());
}
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);
}
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));
}
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);
}
Aggregations