How to create a Report with iReport

From InfiniteERP Wiki
Revision as of 10:11, 16 December 2021 by Wikiadmin (talk | contribs) (Created page with "== Objetive == The goal of this how to is to describe the steps required to create a new report in Openbravo 3. The example explained is a simple report with a list of product...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Objetive

The goal of this how to is to describe the steps required to create a new report in Openbravo 3. The example explained is a simple report with a list of products.

Bulbgraph.png   Note: iReport was the recommended design client before PR15Q3. Since PR15Q3 Jaspersoft Studio is the recommended report designer. Go here to know how to create a Report using Jaspersoft Studio.

Acknowledgments

Before starting make sure that you have read the prerequisite knowledge article. And you are confident with Openbravo modularity concepts

Setting up iReport

You need to download iReport, a graphical tool that allows you create and modify JasperReports templates (.jrxml files).

  • Download iReport 4.0.1
  • On Linux: just download the .tar.gz or .zip file and uncompress it, execute the binary
    bin/ireport
  • On Windows: Download and execute the .exe file

Configuring iReport

Some properties of iReport need to be modified in order to work properly. This configuration settings is explained in iReport configuration In short, you need to make sure:

  • You modified the JasperReport property net.sf.jasperreports.awt.ignore.missing.font and set it to true
  • Not use any Scriplet class
  • Use Java as default expression language

Setting up Classpath

  • Open from the menu options: Tools > Options
  • Move to Classpath tab
  • Click Add Jar button
  • Go to your Openbravo sources folder. Under lib/runtime folder, search for postgresql*jdbc*.jar and pick it.
  • Click OK
Ireport-classpath.png

Defining a Database Connection

  • Click the Report Datasources icon Ireport-report-datasources-button.png
  • Click New
  • Pick Database JDBC Connection and click Next
  • Fill all the fields
    • Name: openbravo (or any name you like, e.g. pi)
    • JDBC Driver: PostgreSQL (org.postgresql.Driver)
    • Server Address: your database server address, e.g. localhost
    • Database: pi (or the name of your database)
    • Username: tad (you can check your username/password in Openbravo.properties configuration file)
    • Password: tad
  • Click Wizzard button to generate the JDBC URL
  • Test your connection
  • Save
Ireport-database-connection.png

Creating the Template

  • File > New
  • Pick Report
  • Click Launch Report Wizzard
Ireport-new-file.png
  • Define a Report Name
  • Define the file Location. Notice that your .jrxml template must be placed under the src folder of your module. More information on the project folder structure. A common convention is to place your reports in a ad_reports folder, e.g. modules/org.your.java.package/src/org/your/java/package/ad_reports. This is a convention, not a requirement, but you need to remember where you placed your template.
Ireport-new-file-location.png
  • Define the query to extract the data
  • Pick the report datasource previously defined
  • The products are stored in the M_Product table <source lang="sql">SELECT m_product_id, value, name FROM m_product</source>
  • Click Next
Ireport-define-query.png
  • iReport define the fields based on your query
  • Pick all the fields
  • Click Next
Ireport-define-fields.png
  • Rember to clear the Scriptlet class and modify the Language for expressions
  • Window > Report Inspector
  • In the report properties in the right, scroll down to More section
    • Clear the Scriptlet class
    • Choose Java as Language
  • Save your changes
Ireport-report-property-language.png
  • Put a static text as report title: Product List
  • Place the fields in the Detail band and a title in the Column Header band
  • Save your changes
Ireport-detail-band.png


  • Click the Preview button to get a report preview
Ireport-sample-output.png
Bulbgraph.png   Note: It is recommended to use Dejavu fonts in jasper reports because this fonts support most of the characters in almost all languages​​. Besides, Dejavu typography is the family of fonts that Openbravo included in jasperreports-fonts library.

Registering the Report in Application Dictionary

Creating the Report

  • Using the System Administrator role
  • Using the quick-launch, open: Report and Process window
    • You can find it in the menu: Application Dictionary > Report and Process
  • Create a new record
  • Fill all required fields
    • Module: Pick your module
    • Search Key: SMPLRProductList (Is a best practice to start with your module's DB_Prefix)
    • Name: Product List
    • Data Access Level: Client/Organization
    • UI Pattern: Standard
    • Jasper Report: Check
    • JR Template name:
      @basedesign@/org/openbravo/examples/report/ad_reports/ProductList.jrxml
      • @basedesign@ is a constant that you must use always, after that, starting with a slash you need to write the path to your jrxml template.
Bulbgraph.png   Note: Report checkbox must be unchecked
Add-report.png

Creating the Menu record

  • Using the System Administrator role
  • Open the Menu window
  • Create a new record
  • Fill all required fields:
    • Module: Your module
    • Name: Name of the menu entry (Product List)
    • Description: You must enter a description. Although is not mark as required, it is for this type of reports
    • Action: Pick Process
    • Process: Pick your process (Product List)
Add-menu-entry.png

Compiling

After you have registered the report and menu entry in the Application Dictionary, you need to compile to generated the the necessary code. <source lang="bash">ant smartbuild</source>

Once the compilation has completed, refresh your Eclipse project, and restart your tomcat server.

Testing the Report

If you have completed all the steps, you should be able to open your Product List report form the quick-lauch, or menu entry.

Final-product-list.png


Further Details

Layout

For information on how JasperReports handles the layout check Making HTML, XLS or CSV friendly reports

Creating a Report Using a Process Definition

Bulbgraph.png   This feature is available from 3.0PR15Q2

From 3.0PR15Q2 it is possible to create a report using a process definition. For more info see here.