How to create a Report with iReport
Contents
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.
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
Defining a Database Connection
- Click the Report Datasources icon
- 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
Creating the Template
- File > New
- Pick Report
- Click Launch Report Wizzard
- 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.
- 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 the fields based on your query
- Pick all the fields
- Click Next
- 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
- 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
- Click the Preview button to get a report preview
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.
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)
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.
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
From 3.0PR15Q2 it is possible to create a report using a process definition. For more info see here.