Using Jasper Report Form in place of Standard Forms

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.

Jasper Report is adopted as more flexible and easy way to create reports. Without it, we need to create Forms or Reports using ADempiere's Print Format. In some case, it is ok, but many cases quite difficult to use.

--Kittiu 09:32, 17 August 2010 (UTC), ecosoft

Overview

There are many pages in this Wiki that talked in depth about Jasper Report, which are very informative to read.

In contrary, this page will highlight only on how to use Jasper Report as a Form, but with mores picture and easy steps to follow.

By default, clicking on Print Preview in document window menu give, Sales Order Form generated by standard Print Format technique. This page will address the need to use Jasper Report instead.

Sample Standard Order From

Understanding how ADempiere locate Forms for each document window

Wondering, how Print Preview button discover which Form to use? Here is the answer,

Before the integration with Jasper Report, Print Format is the only way to create Print Form in ADempiere. As such, in the window that do the Form & Document mapping is using the Print Format to tell what form to use for which document type. This give some confusion at first, but we will see how jasper report form will be used on top of it later.


  • For most Document Types, Print Form window will be used to store Print Format for each document forms by default (Some exception will be discussed later)
Print Form


  • To overwrite it to be more specific for different Document Type, use window Document Type, field Print Format
  • You can note that, by default, the Print Format field is blank. But you are likely to set it as needed.
Document Type


  • From there, you can right click on the Print Format field and Zoom to Print Format window to see them in detail.
  • You can also click on Format Item tab to see how this form is laid out.
  • Note that, by default, Jasper Report field is blank, which mean this Print Format (Form) is used directly as Printing Form
Print Format


  • Summary on how Print Preview button on document window find Print Format to use
    • Purchase Order and Sales Order: "Document Type" overwrite "Print Form"
    • Shipment (Customer) and Material Receipt: "Document Type" overwrite "Print Form"
    • Invoice (Customer) and Invoice (Vendor): "Business Partner / Customer tab (Invoice Print Format)" overwrite "Document Type" overwrite "Print Form"
    • Payment: This type of document is a bit special, as it will be looking the Print Format from "Bank / Bank Account Document tab (Check Print Format)". In Payment window, based on selected Bank Account, right Print Format will be used.
Note.gif Note:

In other windows, ADempiere will directly use Report specified in Process field located at "Tab" tab in "Window, Tab and Fields" window. And as such, only System level reports are available. See exactly how it works & org.compiere.print.RportCtl.java

Now we know, when Print Preview button is clicked, what Print Format Form will be called.

Although we can use Print Format to customize this form using its Format Item tab, but trust me, it is the most time consuming work to do with ADempiere. Let's make our life easier with Jasper Report!

Creating new Jasper Report Form and use it in place of the Print Format

Assuming that we already know how to use Jasper Report to create a form, the only trick is to ensure your Jasper Report will use $P{RECORD_ID} parameter to get ID from the calling window.

Jasper Sales Order

Note:

  • In most window, RECORD_ID is the real current record of the calling window. I.e., Sales Order = C_Order_ID, but not always.
  • Some window, such as Payment, is passing C_PaySelectionCheck_ID not C_Payment_ID.


Once the Jasper Report is tested fine, you then deploy report and have this new jrxml file registered within ADempiere.

1) As System, create new record and tell where this report is located
Register Jasper Report

Note:

  • It is important to select Report checkbox. Although, when Classname is not defined, it will be OK in some case. But for other case, i.e., we want to also run some process to validate something before Print and Java Classname is defined, AD will only execute the Java Class and ignore Jasper Report.
2) As Client, use this Jasper Report in the Print Format in question, i.e., following is for Sales Order Form
Use created Jasper Report on Sales Order Form


3) Now, test on Print Preview again, you should see the report in Jasper View as following.
Use created Jasper Report on Sales Order Form


Note: (as of 360LTS)

  • It is recommended to use jasper report to overwrite the default Print Format, rather than creating new print format just for it. Although you might notice that, the overwritten default print format configuration is not used at all.
  • The reason is, Jasper Report is just being used instead. Internally, the report engine still execute the overwritten Print Format although not used eventually. It can give non-fatal log message if, i.e., not found the Format Items records, or pass RECORD_ID that is unmatched with the Print Format's Table.
  • Or if it is necessary, make sure you create with the right table and click on "Copy/Create" button to create some Format Item records (just to avoid error).

Amount to Text in Jasper Form (Thai Language)

As Jasper Report can call java class that convert from number to text, so this problem is resolved easily using Scriptlet Java Class. Just following these steps to use Thai Text in Jasper Report.

  1. Compile this File:Scriptlet.java into your project [1]
  2. In Jasper Report --> Tools / Options / Classpath --> Add Jar file that compiled with Scriptlet.java
  3. In Jasper Report, create a Text Field where you want the Amount Text to display.
  4. In Jasper Report, create a Variable field (Integer) and set value to 2. This value hold decimal point we want to use.
  5. Put this string function --> "("+org.isec.report.utils.Scriptlet.getAmtInWords($F{payamt}.setScale($V{v_scale}).toString(),"THB")+")" on the Text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg

Resolving Export to PDF Problem

With jasper report that use Thai Charactors, from the print preview it will work just fine. But if you try to export it the character will be missing. As well as using report in WebUI, as internally it will convert to PDF first, its Thai character will also be missing.

Here is the steps to solve the problem.

For iReport

  • Copy font, i.e., Angsana from windows and store it some where.
  • Install Font: on iReport, click Tool | Options | iReport -> Fonts -> Install Fonts, then select the desired font. (for Window 7, ensure that you have disable the UAC)
  • Select fonts, [PDF Encoding ]= Identity-H (Unicode with horizontal writing) and [Embeded this font to PDF document] = True
  • On the report design, ensure that for all Thai words, use the installed font and mark PDF Embeded = True
  • Now, from the Preview report, you should be able to save them in PDF without problem with Thai charactor

Jasper font.jpg

  • We will still need to define PDF Font in the designer, in order to see Thai Font options, on Fonts Tab | PDF fonts path, select the folder that contain Thai fonts (make sure to add folder in classpath first).
  • Restart iReport and continue design, make sure PDF font name and PDF encoding is selected.

Thaifont setup.jpg

Tips – Using Style: It is inconvenient to set PDF attributes one by one for each object. Now you can create styles to handle it.

  • Create a new style.
  • Specify Pdf Font name and Pdf Encoding for the new style.
  • Assign the style to each objects on your report. Don’t forget to do it for your subreport.
  • If your later want to change the font or the path, you simply do it in the style. That is easy!

More trick about Jasper Report see this excellent article --> ADempiere/Compiere JasperReports Integration HowTo

Deploying Jasper Report for Production (in regards to Thai fonts)

Following are some conditions to meet
  1. Reports have sub-reports or image
  2. Reports have new fonts that was not originally exists
  3. Server is Linux (and Windows)
  4. Client is both Swing and Webui, on both Linux and Windows (as such, fonts must work for both)
  5. Easy to deploy new reports

Playing around with your development is one thing. Deploy for production is another thing. After many tries and wiki readings, there are many ways to deploy it, but most ways works for some condition and not others.

Following are what I think work best (at least for me) in most condition.

Deploying new fonts
  1. Jar all new fonts into, i..e, Fonts.jar.
  2. Deploy as new package in Adempiere. I..e, %ADEMPIERE_HOME%/packages/Fonts/lib/Fonts.jar
  3. Execute RUN_silentsetup.bat (.sh), this will make sure it will be availabe through both WebUI and also when deploy as WebStart (swing)
Deploying Jasper Files
  1. Create a folder in Server (a folder not a file!) %ADEMPIERE_HOME%/jboss/server/adempiere/deploy/reports.war
  2. Copy all jasper files, related images into this folder "reports.war". Without having to restart jboss, all these reports will be availabe in path http://<server>:8080/reports/<jasper files>.
  3. In Report & Process window of ADempiere, Jasper field, specify path to the report using the URL, i.e., http://<server>:8080/reports/MyReport.jasper. Make sure you use .jasper, not .jrxml.
  4. If you have new report, just copy the file into this folder and it should be available immediatelly.
Note when design jasper
  • Make sure that during design time, you can save to pdf and the font still display correctly. This is important, as it will make sure that new font will display correctly in boht WebUI and Swing client (when export to PDF). Read more about PDF here, http://www.adempiere.com/ADempiere/Compiere_JasperReports_Integration_HowTo#Problems_exporting_to_PDF
  • If the report has sub report or link to images, do use the URL to link the image, i.e., http://<server>:8080/reports/Logo.gif. Jasper will look up only for Logo.gif during design time. (if you don't specify as URL, Linux Server will not be able to find the correct image path).

Start the Application Server. Now report should be available in both WebUI and Swing, in any OS.


Some note on why other approach don't work
  • Deploy as attachment --> Case report with image link, Work in Windows, not work in Linux
  • Deploy at %ADEMPIERE_HOME%/reports --> Work in WebUI, but not deployed into client via WebStart.

Links about Jasper Reports