use of com.axelor.apps.report.engine.ReportSettings in project axelor-open-suite by axelor.
the class RawMaterialRequirementServiceImpl method print.
@Override
public String print(RawMaterialRequirement rawMaterialRequirement) throws AxelorException {
String name = String.format("%s - ${date}", I18n.get(RAW_MATERIAL_REPORT_TITLE));
ReportSettings reportSetting = ReportFactory.createReport(IReport.RAW_MATERIAL_REQUIREMENT, name);
String locale = ReportSettings.getPrintingLocale(null);
return reportSetting.addParam("RawMaterialRequirementId", rawMaterialRequirement.getId()).addParam("Timezone", rawMaterialRequirement.getCompany() != null ? rawMaterialRequirement.getCompany().getTimezone() : null).addParam("Locale", locale).generate().getFileLink();
}
use of com.axelor.apps.report.engine.ReportSettings in project axelor-open-suite by axelor.
the class InvoicePrintServiceImpl method printAndSave.
public File printAndSave(Invoice invoice, Integer reportType, String format, String locale) throws AxelorException {
ReportSettings reportSettings = prepareReportSettings(invoice, reportType, format, locale);
MetaFile metaFile;
reportSettings.toAttach(invoice);
File file = reportSettings.generate().getFile();
try {
MetaFiles metaFiles = Beans.get(MetaFiles.class);
metaFile = metaFiles.upload(file);
metaFile.setFileName(String.format("%s.%s", reportSettings.getOutputName(), format));
invoice.setPrintedPDF(metaFile);
return MetaFiles.getPath(metaFile).toFile();
} catch (IOException e) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICE_PRINTING_IO_ERROR) + " " + e.getLocalizedMessage());
}
}
use of com.axelor.apps.report.engine.ReportSettings in project axelor-open-suite by axelor.
the class InvoicePrintServiceImpl method prepareReportSettings.
@Override
public ReportSettings prepareReportSettings(Invoice invoice, Integer reportType, String format, String locale) throws AxelorException {
if (invoice.getPrintingSettings() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.INVOICE_MISSING_PRINTING_SETTINGS), invoice.getInvoiceId()), invoice);
}
String title = I18n.get(InvoiceToolService.isRefund(invoice) ? "Refund" : "Invoice");
if (invoice.getInvoiceId() != null) {
title += " " + invoice.getInvoiceId();
}
ReportSettings reportSetting = ReportFactory.createReport(IReport.INVOICE, title + " - ${date}");
if (Strings.isNullOrEmpty(locale)) {
String userLanguageCode = Optional.ofNullable(AuthUtils.getUser()).map(User::getLanguage).orElse(null);
String companyLanguageCode = invoice.getCompany().getLanguage() != null ? invoice.getCompany().getLanguage().getCode() : userLanguageCode;
String partnerLanguageCode = invoice.getPartner().getLanguage() != null ? invoice.getPartner().getLanguage().getCode() : userLanguageCode;
locale = accountConfigRepo.findByCompany(invoice.getCompany()).getIsPrintInvoicesInCompanyLanguage() ? companyLanguageCode : partnerLanguageCode;
}
String watermark = null;
if (accountConfigRepo.findByCompany(invoice.getCompany()).getInvoiceWatermark() != null) {
watermark = MetaFiles.getPath(accountConfigRepo.findByCompany(invoice.getCompany()).getInvoiceWatermark()).toString();
}
return reportSetting.addParam("InvoiceId", invoice.getId()).addParam("Locale", locale).addParam("Timezone", invoice.getCompany() != null ? invoice.getCompany().getTimezone() : null).addParam("ReportType", reportType == null ? 0 : reportType).addParam("HeaderHeight", invoice.getPrintingSettings().getPdfHeaderHeight()).addParam("Watermark", watermark).addParam("FooterHeight", invoice.getPrintingSettings().getPdfFooterHeight()).addFormat(format);
}
use of com.axelor.apps.report.engine.ReportSettings in project axelor-open-suite by axelor.
the class TemplateMessageServiceBaseImpl method generateBirtTemplate.
public File generateBirtTemplate(TemplateMaker maker, Templates templates, Map<String, Object> templatesContext, String fileName, String modelPath, String format, List<BirtTemplateParameter> birtTemplateParameterList) throws AxelorException {
File birtTemplate = null;
ReportSettings reportSettings = generateTemplate(maker, templates, templatesContext, fileName, modelPath, format, birtTemplateParameterList);
if (reportSettings != null) {
birtTemplate = reportSettings.getFile();
}
return birtTemplate;
}
use of com.axelor.apps.report.engine.ReportSettings in project axelor-open-suite by axelor.
the class TemplateMessageServiceBaseImpl method generateTemplate.
private ReportSettings generateTemplate(TemplateMaker maker, Templates templates, Map<String, Object> templatesContext, String fileName, String modelPath, String format, List<BirtTemplateParameter> birtTemplateParameterList) throws AxelorException {
if (modelPath == null || modelPath.isEmpty()) {
return null;
}
ReportSettings reportSettings = ReportFactory.createReport(modelPath, fileName).addFormat(format);
for (BirtTemplateParameter birtTemplateParameter : birtTemplateParameterList) {
try {
String parseValue = null;
if (maker != null) {
maker.setTemplate(birtTemplateParameter.getValue());
parseValue = maker.make();
} else {
parseValue = templates.fromText(birtTemplateParameter.getValue()).make(templatesContext).render();
}
reportSettings.addParam(birtTemplateParameter.getName(), convertValue(birtTemplateParameter.getType(), parseValue));
} catch (BirtException e) {
throw new AxelorException(e.getCause(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TEMPLATE_MESSAGE_BASE_2));
}
}
reportSettings.generate();
return reportSettings;
}
Aggregations