View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Add page
Show collection (0 pages)
Collections help

Search

Reports obsolete

Contents

Introduction

Reports are defined in Application Dictionary in the same window as processes: Application Dictionary || Report and Process.

Openbravo ERP support two types of reports: JasperReports with automatically generated interface and servlet reports which are just a servlet that generates all the page contents.

Bulbgraph.png   This page contains obsolete information. Please visit the following link to learn how to create reports since 3.0PR15Q3 version.

iReport Configuration

iReport is a graphical tool you can use to create/edit templates (jrxml files) that will be later processed by JasperReports engine.

Bulbgraph.png   You must use iReport 4.0.1

Fonts

JasperReports introduced a change in version 3.6.1 that it should fail (throw an exception) when you're trying to use a font that is not available.

JasperReports 3.6.1 (2009-10-26, SVN 3170)
---------------------------------------------
- net.sf.jasperreports.awt.ignore.missing.font configuration property added
to control font availability verifications during report filling and report
AWT rendering;

If you open a JasperReports template and is using a font not available in your system, you won't see the text of label. To avoid this problem you need to configure your iReport to skip this check.

Ireport-conf-1.png

Scriplet Class

Openbravo 3 doesn't support out of the box any Scriplet class. Make sure your template doesn't contain any class in the template properties.

Ireport-conf-2.png

Language

The default language for expressions in Openbravo 3 is Java. Make sure that your template uses Java as language expression.

Ireport-conf-3.png

Openbravo Runtime Environment

The standard reports in Openbravo (src/org/openbravo/erpReports) make use of several methods that reside inside the Openbravo Runtime Environment, which cannot be executed at design time. For this reason, we provide the following .jar file that encapsulates the following adapted methods of the org.openbravo.erpCommon.utility.Utility Class:

For this, to be able to preview the standard Openbravo reports from iReport, it suffices just to import this file into iReport . The import of a .jar file within iReport is done via Tools > Options > Classpath > Add JAR.

Jasper Reports (Standard UI)

Openbravo 3 can automatically generate the user interface for requesting the parameters for a jasper report. The UI is similar to the one generated for processes.

Ob-3-Ref-ui-jasper-report.png

The first step is to create the report template. This is explained in the How_to_create_a_Report.

These reports are defined by:

Parameters

Parameters can be defined for this kind of reports, it is done in the same way as parameters for processes. These parameters must be managed by the template.

Adding images and logos to a report using the ShowImage API

You can use the new Image BLOB reference to display an image for a specific report, or one of the Company logos in the application. First you need to add an image object to your report, set the expression class to "java.awt.Image" and the expression image to a call to the ShowImage function of the Utility class (if you want it to display a standard ImageBLOB image reference, that corresponds to a field added to a tab), or to the ShowImageLogo function if you want to display the logo of an Organization or Client.

Images loaded with this method must not have alpha channel. A transparency layer is not supported by the function that loads images in Jasper Reports.

IMAGEID needs to be the UUID of the image you want to show. You could set this value using a Jasper parameter.

ORGANIZATIONID needs to be the UUID of the Organization whose log you want to show. You could set this value using a Jasper argument. An example could be org.openbravo.erpCommon.utility.Utility.showImageLogo("yourcompanydoc", "4387D62C6486481AB3D148442A6AD34E") being 4387D62C6486481AB3D148442A6AD34E the organization ID.

Java servlet reports (UI Manual)

The second type of reports are the ones implemented as regular Java servlets. Here Openbravo does not manage the parameter window and does also not manage the actual report rendering automatically. Instead the report definition just defines how to call the servlet which then has to manage all of this tasks on its own.

When to use this kind of reports

This kind of report is used when either the automatic UI generation of Openbravo is not sufficient or when the report should be produced by a different reporting system than Jasper reports. An example for the first case is shown further down.

How to use this kind of reports

These reports are defined by:

Example of this type of report

As an example for this the report Discount Invoice Report (Sales Management || Analysis Tools || Discount Invoice Report || Discount Invoice Report) will be used.

This report does not use the generated UI as its parameter window uses the Business Partner Multiple Selector. Using this selector more than one Business Partner can be selected to be used in a report. However the Standard UI does not support this type of selector, so that the parameter window has to be coded manually.

This report consists of a number of individual files in the org/openbravo/erpCommon/ad_reports folder:

This example focuses on the first four files, as the jrxml file has not special changes compared to a report with a Standard UI.

The controlling part of our report is the Java servlet. It serves two purposes in the report:

  1. Displaying the parameter window with the various widgets and a button to start the report execution.
  2. The report execution itself.

When looking at the source code of the servlet the main entry point is the doGet method. In this method the distinction between the different actions is made and the execution flow splits according to the requested action.

When the report is called from the menu then the servlet is called with the command DEFAULT. In the doGet method this is checked and after reading some necessary parameters the execution continues in the mod printPageDataSheet. This method is responsible of displaying the parameter window with its various widgets and the HTML button which starts the report rendering.

Display of the parameter window (method: printPageDataSheet)

This method needs to generate and output the HTML code needed to display the parameter window. In Openbravo a template engine named XmlEngine is used to produce the HTML output based on templates and data inserted at runtime.

Find more information regarding XmlEngine in the XmlEngine article.

The following stripped down version of the printPageDataSheet method shows the general use of XmlEngine:

// load the HTML template and xml control file
XmlDocument xmlDocument = xmlEngine.readXmlTemplate(
        "org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountJR").createXmlDocument();
 
// set parameter and data for the template
xmlDocument.setParameter("ccurrencyid", strCurrencyId);
xmlDocument.setData("reportC_Currency_ID", "liststructure", comboTableData.select(false));
...
 
// produce html output and write the servlet response
response.setContentType("text/html; charset=UTF-8");
 
PrintWriter out = response.getWriter();
out.println(xmlDocument.print());
out.close();

What is now missing to be able to render the widgets is how the HTML code does look like for each and which parameter need to be specified for the widget by the Java servlet. The description of the widgets used in Openbravo can be found in the skins article.

The first four common elements used in any page which is shown inside the main Openbravo window are:

  1. NavigationBar
  2. LeftTabsBar
  3. ToolBar
  4. WindowTabs

The NavigationBar is the widget which displays the Go back and reload button and the Breadcrumb (Location of the current window in the menu structure). The following Java snippet prepares the HTML for this widget and passes it to the XmlEngine via the parameter toolbar.

ToolBar toolbar = new ToolBar(this, vars.getLanguage(),
    "ReportInvoiceDiscountReportInvoiceDiscountJR", false, "", "", "", false, "ad_reports",
    strReplaceWith, false, true);
toolbar.prepareSimpleToolBarTemplate();
xmlDocument.setParameter("toolbar", toolbar.toString());

This parameter for the template is defined in the xml control file of the report:

<PARAMETER id="paramToolBar" name="toolbar" default=""/>

This tag defines a parameter for XmlEngine with the name toolbar and a default value "". The value of the parameter will then be placed at the position of an element in the HTML template with id="paramToolBar".

<div class="Main_ContentPane_ToolBar" id="paramToolBar"></div>

In a similar fashion the HTML for the LeftTabsBar is prepared. This widget is shown in the vertical space between the menu and the content area. Example for it are the buttons for switching between Form View and Grid View in the normal generated windows.

The ToolBar widget is responsible for showing the different button just below the NavigationBar. In our example this part has no visible buttons.

Finally the WindowTabs widget renders the area where in generated windows the different tabs of the windows are shown. In our example report it just shows the report name at the right side of the window.

The next common widget in most of the windows is the MessageBox part which displays feedback information like infos, warnings and error message to the user.

As a user visible interaction can last several individual server requests the info if a message should be shown and the message details are stored in the server side session. The key for this data needs to be unique per window and is the report (filename) in this example. The following Java snippets retrieves this message (if one is available) and sets it as XmlEngine parameters to be displayed in the HTML page.

OBError myMessage = vars.getMessage("ReportInvoiceDiscountJR");
vars.removeMessage("ReportInvoiceDiscountJR");
if (myMessage != null) {
  xmlDocument.setParameter("messageType", myMessage.getType());
  xmlDocument.setParameter("messageTitle", myMessage.getTitle());
  xmlDocument.setParameter("messageMessage", myMessage.getMessage());
}

As an example of how an individual widget can be used the combo box for displaying and selecting a currency will be explained.

Our HTML template needs two different inputs to render this widget. First one is the list of entries which includes both the internal value for each element and the user visible text for each. The user visible text should be translated according to the currently selected UI language.

The second needed input is which entry should be selected when rendering the page. In our example report this default value is the base currency of the currently selected client. The following snippet shows the needed Java code which creates the data for both inputs.

xmlDocument.setParameter("ccurrencyid", strCurrencyId);
try {
  ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Currency_ID",
      "", "", Utility.getContext(this, vars, "#AccessibleOrgTree", "ReportInvoiceDiscountJR"), Utility
          .getContext(this, vars, "#User_Client", "ReportInvoiceDiscountJR"), 0);
  Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceDiscountJR",
          strCurrencyId);
  xmlDocument.setData("reportC_Currency_ID", "liststructure", comboTableData.select(false));
  comboTableData = null;
} catch (Exception ex) {
  throw new ServletException(ex);
}

This snippets uses the ComboTableData class to get the list of currency values including translation to be by the combobox widget. The result list is passed to the template with the setData method. The default value is passed as usual with a setParameter call.

Finally the HTML template in the example report contains a button which is used to start the rendering of the Jasper report. This report has the following Javascript method call assigned to onClick.

openServletNewWindow('FIND', true, 'ReportInvoiceDiscountJR.html', 'ReportInvoiceDiscountJR', null, false, '700', '1000', true);

This will first call the validate method defined in the HTML template. It is used to check if all needed inputs have been provided by the user. In our example report it checks if the mandatory fields have been filled.

Then the relative URL ReportInvoiceDiscountJR.html will the called with the FIND command value. The output of this request will be shown in a new pop-up window as the Javascript method name indicates. This will again call into the same servlet, but now the doPost method will dispatch the call to the printPageDataHtml Java method which start the report rendering.

Rendering of the jasper report

The printPageDataHtml has the responsibility of finally rendering the Jasper report. The following snippet gives a short overview about the needed task on the Java side:

// relative report filename, same as in automatic UI case
String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountJR.jrxml";
 
// output format: html,pdf,xls
String strOutput = "html";
 
// get needed data from database
ReportInvoiceDiscountData[] data = null;
data = ReportInvoiceDiscountData.select(this, strCurrencyId, Utility.getContext(this, vars,
    "#User_Client", "ReportInvoiceDiscountJR"), Utility.getContext(this, vars, "#AccessibleOrgTree",
    "ReportInvoiceDiscountJR"), strDateFrom, strDateTo, strcBpartnerId, (strDiscount
    .equals("N")) ? "" : "discount");
 
// pass extra parameters to jasper report template
HashMap<String, Object> parameters = new HashMap<String, Object>();
String strSubTitle = Utility.messageBD(this, "From", vars.getLanguage()) + " " + strDateFrom
     + " " + Utility.messageBD(this, "To", vars.getLanguage()) + " " + strDateTo;
parameters.put("REPORT_SUBTITLE", strSubTitle);
 
// start jasper report rendering
renderJR(vars, response, strReportName, strOutput, parameters, data, null);

The real rendering is started by the last method call: renderJR.

This method reads the report template (a jrxml file) and runs it through the Openbravo translation engine. Then the Jasper template is compiled and the provided data (here read from the database) and other parameters are sent to the Jasper engine. Finally the finished report will be exported to the specified format (html, xls or pdf) and sent to the browser.

Retrieved from "http://wiki.openbravo.com/wiki/Reports_obsolete"

This page has been accessed 503 times. This page was last modified on 11 March 2016, at 07:35. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.