You are on page 1of 5

30/11/13

Log in / create account

Report Example - OpenbravoWiki
Openbravo.com Partner Portal Issues Blogs Forge Exchange University Downloads

View source | Discuss this page | Page history | Printable version

Report Example
Contents 1 Introduction 2 Objective 3 Implementation 3.1 Application Dictionary 3.2 Parameters 3.2.1 Business Partner 3.2.2 C urrency, Starting Date, Ending Date, Warehouse 3.2.3 Output Type 3.3 Standard UI Pattern 3.4 JasperReport Template 3.4.1 Parameters 3.4.1.1 Auxiliary Parameters 3.4.1.2 Extra Parameters 3.4.2 SQL Query 3.4.2.1 Use of parameter in a Function call 3.4.2.2 Use of Auxiliary Parameters 3.4.2.3 C lient and Organization 3.4.3 P{} vs P!{} 3.5 Final Result

Introduction
This example explains the 'Purchase Order Report' already present in Openbravo. Before going into details, you can test the report in the following path: Procurement Management > Analysis Tools > Purchase Order Report

Objective
The main objective of this document is to give, in a pragmatic way, a detailed explanation on how to integrate a JasperReports template into Openbravo ERP.

Implementation
Application Dictionary
Following these steps you'll be able to find the report in the Application Dictionary: As System Administrator go to: Application Dictionary > Report and Process Use the filter and search for: Purchase Order Report Select the found record You should be able to see the report definition: Search Key: JR_ReportPurchaseOrder Name: Purchase Order Report Description: Purchase Order Report Help/Comment: Purchase Order Report JR Active: Yes Data Access Level: C lient/Organization Data Access Level defines who has access to this report. UI Pattern: Standard Standard or Manual. A Standard process is used to generate automatically the pop-up which will ask for the report parameters. A Manual pop-up should be created by the developer. No pop-up will be automaticaly generated the report parameters. Report: No Jasper Report: Yes Notice that when you register a JasperReport based report, you don't select the Report check-box, but the Jasper Report one. These reports are handled as processes JR Template name: @basedesign@/org/openbravo/erpC ommon/ad_reports/ReportPurchaseOrder.jrxml Defines where is located the JRXML template. @basedesign@ is a constant evaluated at run-time, and translated to something like: your_tomcat_context/src-loc/design

Parameters
Business Partner Now we go to the Parameters tab. Report and Processes > Parameters. Select the Business Partner parameter

wiki.openbravo.com/wiki/Report_Example#Currency.2C_Starting_Date.2C_Ending_Date.2C_Warehouse

1/5

Sequence Number: 70 DB Column Name: outputType The name of the parameter must be outputType in order to use it as Application Element: outputType . More info at Sequence Number DB Column Name: C _BPartner_ID Defines the name of the parameter in the JRXML template. etc. The DB C olumn Name must match exactly the parameter name defined in the template.Output type Defines the Element associated with this parameter Reference: List Defines that we want to use a List of defined values Reference Search Key: Output format This is the list of possible values on the combo: Excel. You can read the iReport official Tutorials and Help documents in the iReport Documentation page.com/wiki/Report_Example#Currency. we choose the Business Partner selector. and the Reference used by each one of them. In this case we choose Search. Sequence Number: 10 Defines the parameters order. so it will be rendered as a 'selector'. vendor.jxrml wiki. The Reference defined for each parameter JasperReport Template Openbravo 3 is shipped with JasperReports 4. Ending Date. Length: 40 Defines the field length.2C_Warehouse 2/5 . This can include a customer. employee or any combination of these. employee. PDF Length: 20 Defines the length of the parameter Mandatory: Yes Defines that is a compulsory value.2C_Starting_Date.OpenbravoWiki Name: Business Partner Description: Anyone who takes part in daily business operations by acting as a customer.Business Partner Defines the Element used by when rendering this parameter Reference: Search Defines which type of Reference you want to use when prompting for parameter values.1 version. Open the JRXML template with iReport: Should be located under src/org/openbravo/erpC ommon/ad_reports/ReportPurchaseOrder.0.openbravo. cannot be blank Standard UI Pattern The above parameters definition will be rendered as a pop-up window like this one: 1. You must use the same iReport version. Html. Application Element: C _BPartner_ID . Reference Search Key: Business Partner Since we have choose Search reference. Starting Date.30/11/13 Report Example .2C_Ending_Date. Warehouse This parameters follow the same type of definition used on the Business Partner. Is used to specify which output you want to use: PDF. XLS Name: Output type Help/Comment: Defines the output format type from the available list. HTML. Is the Help/Comment Report definition 2. It is case sensitive . The only change is the DB Column Name . Help/Comment: A Business Partner is anyone with whom you transact. Currency. Output Type This is a special parameter that should be present in all the Standard UI reports. The Element defined for each parameter 3.

lang.com/wiki/Report_Example#Currency.Date M_Warehouse_ID: java.2C_Ending_Date. otherwise we add an extra condition.2C_Starting_Date.String C_Currency_ID: java. e q u a l s ( " " )?"":"A N DC _ O R D E R .String C_Project_ID: java.util. C _ B P A R T N E R _ I D=' "+$ P { C _ B P a r t n e r _ I D }+ " ' " aux_warehouse: wiki.2C_Warehouse 3/5 .String DateFrom: java. The logic is simple.30/11/13 Report Example .Date DateTo: java. if the parameter is null or an empty String.openbravo. aux_partner: $ P { C _ B P a r t n e r _ I D } .util. we should not filter.String A uxiliary Parameters This auxiliary parameters are used in the report SQL definition to set an extra restriction in the WHERE clause.lang.lang.OpenbravoWiki Parameters The following parameter list.lang. matches the DB Column Name parameter's definition in the Application Dictionary C_BPartner_ID: java.

N A M E . A D _ O R G _ I D )A SC O N V P R I C E A C T U A L . C _ C U R R E N C Y _ S Y M B O L ( T R A N S C U R R E N C Y I D .C _ U O M W H E R EC _ O R D E R . D A T E O R D E R E D< = ' "+n e wj a v a .C _ O R D E R L I N E .C L I E N T _ N A M E . A D _ C L I E N T _ I DA ST R A N S C L I E N T I D .' Y ' )A SC O N V S Y M . M _ P R O D U C T _ I D=M _ P R O D U C T . P R I C E A C T U A LA SP R I C E A C T U A L .C O N V P R I C E A C T U A L .T R A N S D A T E O R D E RB YC L I E N T _ N A M E .$ P { C _ C u r r e n c y _ I D } . ( $ F { P R I C E L I S T } ! = n u l l ) ? $ P { N U M B E R F O R M A T } .C _ O R D E R . C _ B P A R T N E R _ I D A N DC _ O R D E R .S U M ( C O N V P R I C E L I S T )A SC O N V P R I C E L I S T .lang.C _ O R D E R . s q l .C _ O R D E R L I N E . e q u a l s ( " " )?"":"A N DC _ O R D E R . C _ O R D E R .S U M ( Q U A N T I T Y O R D E R )A SQ U A N T I T Y O R D E R . C _ U O M _ I D A N D1 = 1 $ P ! { a u x _ p a r t n e r } $ P ! { a u x _ w a r e h o u s e } $ P ! { a u x _ p r o j e c t } $ P ! { a u x _ D a t e F r o m } $ P ! { a u x _ D a t e T o } A N DC _ O R D E R . D A T E O R D E R E D . D A T E O R D E R E D .C _ U O M . C _ O R D E R L I N E . A D _ C L I E N T _ I DI N( $ P ! { U S E R _ C L I E N T } ) A N DC _ O R D E R . C _ O R D E R L I N E . P R I C E A C T U A L . L I N E N E T A M T )A SP R I C E L I S T .String Parameter that holds the current language. P R I C E A C T U A L .' Y ' )A ST R A N S S Y M . C _ B P A R T N E R _ I D=C _ B P A R T N E R .N O W ( ) ) ) . C _ C U R R E N C Y _ I D )A ST R A N S C U R R E N C Y I D .C _ O R D E R L I N E .P R O D U C T _ N A M E . C _ O R D E R _ I D A N DC _ O R D E R L I N E . C _ C U R R E N C Y _ I D ) . A D _ C L I E N T _ I D . S E L E C TD O C U M E N T N O . C _ C U R R E N C Y _ S Y M B O L ( $ P { C _ C u r r e n c y _ I D } . A D _ O R G _ I DI N( $ P ! { U S E R _ O R G } ) G R O U PB YC _ B P A R T N E R . T O _ D A T E ( C O A L E S C E ( C _ O R D E R L I N E .C _ O R D E R . en_US NUMBERFORMAT: java. D A T E O R D E R E D . C _ C U R R E N C Y _ I S O S Y M ( $ P { C _ C u r r e n c y _ I D } )A SC O N V I S O S Y M We use the parameter C_Currency_ID to get the currency symbol Use of A uxiliary Parameters W H E R EC _ O R D E R .D O C U M E N T N O . C _ O R D E R _ I D=C _ O R D E R L I N E . N A M EA SU O M N A M E .$ P { C _ C u r r e n c y _ I D } . C _ C U R R E N C Y _ I S O S Y M ( $ P { C _ C u r r e n c y _ I D } )A SC O N V I S O S Y M F R O M( S E L E C TC _ O R D E R . L I N E N E T A M T ) . e q u a l s ( " " ) )?" ":" A N DC _ O R D E R .C _ O R D E R L I N E .String Parameter to be used in the SQL query and filter by Organization LANGUAGE: java.lang. This is the whole SQL query used to get the data.openbravo.lang.C _ O R D E R .C _ O R D E R L I N E .C O A L E S C E ( C _ O R D E R L I N E . e.' 0 ' . S U M ( C _ O R D E R L I N E .N O W ( ) ) )A ST R A N S D A T E . M _ P R O D U C T _ I D=M _ P R O D U C T . A D _ C L I E N T _ I D .DecimalFormat Parameter used in number text-fields formatting. M _ W A R E H O U S E _ I D=' "+$ P { M _ W a r e h o u s e _ I D }+" ' " aux_project: $ P { C _ P r o j e c t _ I D } . D A T E O R D E R E D . e q u a l s ( " " )?"":"A N DC _ O R D E R . C _ P R O J E C T _ I D=' "+$ P { C _ P r o j e c t _ I D }+" ' " aux_DateFrom: ( $ P { D a t e F r o m }= =n u l l| |$ P { D a t e F r o m } .C _ B P A R T N E R . D A T E O R D E R E DA SD A T E O R D E R E D . C O A L E S C E ( C _ O R D E R L I N E . C _ O R D E R L I N E .2C_Ending_Date. T O _ D A T E ( C O A L E S C E ( C _ O R D E R L I N E . e q u a l s ( " " ) )?" ":" A N DC _ O R D E R . f o r m a t ( $ F { P R I C E L I S T } ) : n e wS t r i n g ( "" ) SQL Query The report SQL query can be edited in the property Query Text of the report.C _ O R D E R . A D _ C L I E N T _ I D .U O M N A M E . t o S t r i n g ( )+" ' " aux_DateTo: ( $ P { D a t e T o }= =n u l l| |$ P { D a t e T o } .2C_Warehouse 4/5 . D O C U M E N T N OA SD O C U M E N T N O .P R I C E A C T U A L . S U M ( C _ O R D E R L I N E .com/wiki/Report_Example#Currency. D A T E O R D E R E D> = ' "+n e wj a v a .C _ O R D E R .M _ P R O D U C T .C _ O R D E R L I N E . A D _ O R G _ I DA ST R A N S O R G I D F R O MC _ O R D E R .N O W ( ) ) ) . N A M E .N U L L .D A T E O R D E R E D . M _ P R O D U C T _ I D A N DC _ O R D E R L I N E . M _ P R O D U C T _ I D A N DC _ O R D E R L I N E . C _ C U R R E N C Y _ C O N V E R T ( C _ O R D E R L I N E .D A T E O R D E R E D .2C_Starting_Date. A D _ O R G _ I D )Z Z G R O U PB YC L I E N T _ N A M E .P R I C E A C T U A L . I S S O T R X=' N ' A N DC _ O R D E R .C O N V P R I C E A C T U A L .' Y ' )A SC O N V S Y M .text. N A M E . g e t T i m e ( ) )+" ' " Extra Parameters There is some extra parameters USER_CLIENT: java. C _ O R D E R _ I D=C _ O R D E R L I N E . C _ C U R R E N C Y _ I D . D A T E O R D E R E D . C _ O R D E R _ I D A N DC _ O R D E R L I N E . T R A N S C U R R E N C Y I D . A D _ O R G _ I D )A SC O N V P R I C E L I S T . S U M ( P R I C E L I S T )A SP R I C E L I S T .OpenbravoWiki $ P { M _ W a r e h o u s e _ I D } . T O _ D A T E ( C O A L E S C E ( C _ O R D E R L I N E . C _ B P A R T N E R _ I D=C _ B P A R T N E R . D A T E O R D E R E D . C _ C U R R E N C Y _ I D . C _ O R D E R L I N E . C _ U O M _ I D A N D1 = 1 $ P ! { a u x _ p a r t n e r } $ P ! { a u x _ w a r e h o u s e } $ P ! { a u x _ p r o j e c t } $ P ! { a u x _ D a t e F r o m } $ P ! { a u x _ D a t e T o } A N DC _ O R D E R . s q l . C _ C U R R E N C Y _ I D . Q T Y O R D E R E D )A SQ U A N T I T Y O R D E R .String Parameter to be used in the SQL query and filter by by C lient USER_ORG: java.C _ O R D E R . C _ C U R R E N C Y _ I D .P R O D U C T _ N A M E .C _ O R D E R L I N E .30/11/13 Report Example .C _ O R D E R . C _ B P A R T N E R _ I D A N DC _ O R D E R . D A T E O R D E R E D . D A T E O R D E R E D . N A M EA SC L I E N T _ N A M E .C _ O R D E R .C _ O R D E R L I N E . D a t e ( $ P { D a t e T o } .C _ O R D E R L I N E . e. C _ C U R R E N C Y _ I D ) .N U L L .g. D a t e ( $ P { D a t e F r o m } . C _ U O M _ I D=C _ U O M . C _ C U R R E N C Y _ C O N V E R T ( S U M ( C _ O R D E R L I N E . N A M EA SP R O D U C T _ N A M E .C _ U O M . M _ P R O D U C T .g.M _ P R O D U C T . C _ C U R R E N C Y _ I D .' 0 ' . D O C U M E N T N O . C _ U O M _ I D=C _ U O M .U O M N A M E .' 0 ' .C O A L E S C E ( C _ O R D E R L I N E .D A T E O R D E R E D Use of parameter in a Function call C _ C U R R E N C Y _ S Y M B O L ( $ P { C _ C u r r e n c y _ I D } . g e t T i m e ( ) ) .C _ B P A R T N E R . I S S O T R X=' N ' wiki.

openbravo. A D _ C L I E N T _ I DI N( $ P ! { U S E R _ C L I E N T } ) A N DC _ O R D E R . A D _ O R G _ I DI N( $ P ! { U S E R _ O R G } ) Report Example .-$ P { C _ C u r r e n c y _ I D }w i l lb eaS Q Lp a r a m e t e rC _ C U R R E N C Y _ S Y M B O L ( ? . A D _ C L I E N T _ I DI N( $ P ! { U S E R _ C L I E N T } )-$ P ! { U S E R _ C L I E N T }w i l lb er e p l a c e db yas t r i n gl i k e' 1 0 0 0 0 ' A N DC _ O R D E R .' Y ' )A SC O N V S Y M . C _ C U R R E N C Y _ S Y M B O L ( $ P { C _ C u r r e n c y _ I D } .' Y ' )A SC O N V S Y M C _ C U R R E N C Y _ I S O S Y M ( $ P { C _ C u r r e n c y _ I D } )A SC O N V I S O S Y M Final Result C hoosing PDF as Output type you should be able to get a report like this: Retrieved from "http://wiki.OpenbravoWiki As you may see there aux_* parameters are used in the WHERE clause.com/wiki/Report_Example" This page has been accessed 5. C _ B P A R T N E R _ I D=' 1 0 0 0 0 0 0 ' " So the report will be filtered by that Business Partner Client and Organization The report is also filtered by C lient and Organization A N DC _ O R D E R . A D _ O R G _ I DI N( $ P ! { U S E R _ O R G } ) C _ C U R R E N C Y _ S Y M B O L ( T R A N S C U R R E N C Y I D .452 times.2C_Warehouse 5/5 .com/wiki/Report_Example#Currency. at 12:52. Category: Example wiki. A D _ C L I E N T _ I DI N( $ P ! { U S E R _ C L I E N T } ) A N DC _ O R D E R .5 Spain License. JasperReports will prepare a statement A N DC _ O R D E R .' Y ' )A ST R A N S S Y M .openbravo. This page was last modified on 11 August 2011.' 0 ' . A D _ O R G _ I DI N( $ P ! { U S E R _ O R G } ) P{} vs P!{} $P!{} this syntax is used to replace the parameter placeholder with its value as raw chunk of query $P{} this syntax is used to treat the parameter as SQL parameter. e.g.30/11/13 A N DC _ O R D E R .2C_Ending_Date.' 0 ' . that value will be passed to the template and the line: $ P ! { a u x _ p a r t n e r } Will be changed to: "A N DC _ O R D E R . C _ B P A R T N E R _ I D=' "+$ P { C _ B P a r t n e r _ I D }+ " ' " And after evaluating the value of the parameter will be: "A N DC _ O R D E R .' 0 ' . Let's imagine that the user the users selects a Business Partner with ID 1000000.2C_Starting_Date. C ontent is available under C reative C ommons Attribution-ShareAlike 2.