Search in sources :

Example 16 with ReportSettings

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();
}
Also used : ReportSettings(com.axelor.apps.report.engine.ReportSettings)

Example 17 with ReportSettings

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());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaFiles(com.axelor.meta.MetaFiles) ReportSettings(com.axelor.apps.report.engine.ReportSettings) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 18 with ReportSettings

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReportSettings(com.axelor.apps.report.engine.ReportSettings)

Example 19 with ReportSettings

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;
}
Also used : ReportSettings(com.axelor.apps.report.engine.ReportSettings) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 20 with ReportSettings

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) BirtException(org.eclipse.birt.core.exception.BirtException) ReportSettings(com.axelor.apps.report.engine.ReportSettings) BirtTemplateParameter(com.axelor.apps.base.db.BirtTemplateParameter)

Aggregations

ReportSettings (com.axelor.apps.report.engine.ReportSettings)20 AxelorException (com.axelor.exception.AxelorException)12 MetaFile (com.axelor.meta.db.MetaFile)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AppBase (com.axelor.apps.base.db.AppBase)2 MetaFiles (com.axelor.meta.MetaFiles)2 Invoice (com.axelor.apps.account.db.Invoice)1 EbicsUser (com.axelor.apps.bankpayment.db.EbicsUser)1 BirtTemplateParameter (com.axelor.apps.base.db.BirtTemplateParameter)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 StockMove (com.axelor.apps.stock.db.StockMove)1 User (com.axelor.auth.db.User)1 Transactional (com.google.inject.persist.Transactional)1 IOException (java.io.IOException)1 BirtException (org.eclipse.birt.core.exception.BirtException)1