JasperReports is a powerful reporting engine that integrates seamlessly with iDempiere ERP, enabling you to create sophisticated and data-rich reports. This blog post delves into two essential aspects of JasperReports within iDempiere: utilizing subreports for detailed data presentation and dynamically incorporating images using parameters.

Dynamic Resource Location with Parameters

A key challenge in report development is managing resource paths (images, subreport files) across different environments. To address this, we leverage iDempiere’s parameter system, specifically “RESOURCE_DIR” and “SUBREPORT_DIR.” These parameters allow us to dynamically specify the locations of our report resources.

  • “RESOURCE_DIR”: This parameter points to the directory containing images and other resources used in the main report. (See Image 1)
  • “SUBREPORT_DIR”: This parameter specifies the directory where subreport .jasper files are located. (See Image 1)

During development in JasperReports Studio, setting these parameters to “./” (the current directory) simplifies editing and testing. In iDempiere, you can then configure these parameters within the “Report & Process” window to point to the appropriate locations.

Image 1

Embedding Images from iDempiere Attachments

This approach provides a robust way to include images in your reports. By utilizing “RESOURCE_DIR,” you can attach image files directly to the “Report & Process” record in iDempiere.

Here’s how it works:

  1. Attach Image: Upload your image file (e.g., the iDempiere logo) as an attachment to the relevant “Report & Process” record.
  2. Reference in Report: Within your JasperReport design, use an image element and set its “Image Expression” to reference the file using the “RESOURCE_DIR” parameter. For example: $P{RESOURCE_DIR} + "idempiere_logo.png" (See Image 2)

This method ensures that your images are managed within iDempiere and readily accessible during report generation.

Image 2

Implementing Subreports for Detailed Order Information

Subreports are invaluable for displaying related data within a report. In this example, we’ll demonstrate how to use a subreport to display order line details within a main report that lists orders.

  1. Main Report (Order List):
    • Create a main report that queries the C_Order table to retrieve a list of orders (e.g., from the Garden World example data).
  2. Subreport (Order Lines):
    • Create a subreport that queries the C_OrderLine table to retrieve the line items for a specific order.
    • Add a parameter to the subreport (e.g., C_ORDER_ID) to receive the C_Order_ID from the main report.
  3. Integrate Subreport:
    • In the main report’s detail band, add a subreport element.
    • Set the subreport Expression to the location of the subreport .jasper file, by using the SUBREPORT_DIR parameter. (See Image 3)
    • Please be aware that iDempiere subreports exclusively support jasper file names, and do not support jrxml file name. (See Image 3)
    • Pass the C_Order_ID from the main report to the subreport’s ORDER_ID parameter.
  4. Subreport query:
    • In the subreport query, use the parameter $P{C_ORDER_ID} in the where clause, to select the correct orderlines. (See Image 5, Image 6)

This design allows you to generate a main report listing orders, with each order’s details displayed neatly within the corresponding subreport.

Image 3
Image 4
Image 5
Image 6

Importing the Report Design (.jrxml or .jasper files)

  • First, design your report in JasperReports Studio. Once designed, compile it to generate a .jasper file.
  • Then, in iDempiere, navigate to the “Report & Process” window.
  • Click the “New” button to create a new report record.
  • Click Attachment in the Toolbar, and upload your jasper .jrxml , image file. (See Image 7)
  • Specify the attachment prefix and main report file name within JasperReports fields. (See Image 8)
  • Add the report to the menu.
Image 7
Image 8

The final report demonstration in iDempiere ERP.

Image 9

Benefits of This Approach

  • Modular Reporting: Subreports promote modularity, making report design and maintenance easier.
  • Data Organization: Subreports enable you to present complex, related data in a clear and structured manner.
  • Dynamic Resource Management: Using parameters for resource paths enhances flexibility and portability.
  • iDempiere Integration: Leveraging iDempiere attachments for images streamlines resource management.

By mastering subreports and dynamic image inclusion, you can unlock the full potential of JasperReports in iDempiere, creating reports that are both informative and visually appealing.

Reference


Feature: Jasper Report Deployment Refactoring and Improvement

https://wiki.idempiere.org/en/NF9_Jasper_Report_Deployment

By Ray Lee (System Analyst)

iDempeire ERP Contributor, 經濟部中小企業處財務管理顧問 李寶瑞

Leave a Reply

Your email address will not be published. Required fields are marked *