Sunteți pe pagina 1din 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

30/11/13

Report Example - OpenbravoWiki

Name: Business Partner Description: Anyone who takes part in daily business operations by acting as a customer, employee, etc. Help/Comment: A Business Partner is anyone with whom you transact. This can include a customer, vendor, employee or any combination of these. Sequence Number: 10 Defines the parameters order. More info at Sequence Number DB Column Name: C _BPartner_ID Defines the name of the parameter in the JRXML template. The DB C olumn Name must match exactly the parameter name defined in the template. It is case sensitive . Application Element: C _BPartner_ID - 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. In this case we choose Search, so it will be rendered as a 'selector'.

Reference Search Key: Business Partner Since we have choose Search reference, we choose the Business Partner selector. Length: 40 Defines the field length. Currency, Starting Date, Ending Date, Warehouse This parameters follow the same type of definition used on the Business Partner. The only change is the DB Column Name , and the Reference used by each one of them. Output Type This is a special parameter that should be present in all the Standard UI reports. Is used to specify which output you want to use: PDF, HTML, XLS Name: Output type Help/Comment: Defines the output format type from the available list. Sequence Number: 70 DB Column Name: outputType The name of the parameter must be outputType in order to use it as Application Element: outputType - 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, Html, PDF

Length: 20 Defines the length of the parameter Mandatory: Yes Defines that is a compulsory value, cannot be blank

Standard UI Pattern
The above parameters definition will be rendered as a pop-up window like this one:

1. Is the Help/Comment Report definition 2. The Element defined for each parameter 3. The Reference defined for each parameter

JasperReport Template
Openbravo 3 is shipped with JasperReports 4.0.1 version. You must use the same iReport version. You can read the iReport official Tutorials and Help documents in the iReport Documentation page. Open the JRXML template with iReport: Should be located under src/org/openbravo/erpC ommon/ad_reports/ReportPurchaseOrder.jxrml

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

2/5

30/11/13

Report Example - OpenbravoWiki

Parameters

The following parameter list, matches the DB Column Name parameter's definition in the Application Dictionary C_BPartner_ID: java.lang.String DateFrom: java.util.Date DateTo: java.util.Date M_Warehouse_ID: java.lang.String C_Project_ID: java.lang.String C_Currency_ID: java.lang.String
A uxiliary Parameters

This auxiliary parameters are used in the report SQL definition to set an extra restriction in the WHERE clause. The logic is simple, if the parameter is null or an empty String, we should not filter, otherwise we add an extra condition. aux_partner: $ P { C _ B P a r t n e r _ I D } . e q u a l s ( " " )?"":"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 }+ " ' " aux_warehouse:

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

3/5

30/11/13

Report Example - OpenbravoWiki

$ P { M _ W a r e h o u s e _ I D } . e q u a l s ( " " )?"":"A N DC _ O R D E R . 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 } . 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 } . e q u a l s ( " " ) )?" ":" A N DC _ O R D E R . D A T E O R D E R E D> = ' "+n e wj a v a . s q l . D a t e ( $ P { D a t e F r o m } . g e t T i 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 } . e q u a l s ( " " ) )?" ":" A N DC _ O R D E R . D A T E O R D E R E D< = ' "+n e wj a v a . s q l . D a t e ( $ P { D a t e T o } . g e t T i m e ( ) )+" ' "
Extra Parameters

There is some extra parameters USER_CLIENT: java.lang.String Parameter to be used in the SQL query and filter by by C lient USER_ORG: java.lang.String Parameter to be used in the SQL query and filter by Organization LANGUAGE: java.lang.String Parameter that holds the current language, e.g. en_US NUMBERFORMAT: java.text.DecimalFormat Parameter used in number text-fields formatting. e.g.

( $ 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 } . 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. This is the whole SQL query used to get the data.

S E L E C TD O C U M E N T N O ,D A T E O R D E R E D ,C L I E N T _ N A M E ,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 ,P 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 , S U M ( P R I C E L I S T )A SP R I C E L I S T ,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 ,P R O D U C T _ N A M E ,U O M N A M E , 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 ,' 0 ' ,' Y ' )A ST R A N S 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 } ,' 0 ' ,' 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 F R O M( S E L E C TC _ O R D E R . D O C U M E N T N OA SD O C U M E N T N O ,C _ O R D 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 _ B P A R T N E R . N A M EA SC L I E N T _ N A M E , S U M ( C _ O R D E R L I N E . Q T Y O R D E R E D )A SQ U A N T I T Y 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 LA SP R I C E A C T U A L , 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 . P R I C E A C T U A L ,C O A L E S C E ( C _ O R D E R L I N E . C _ C U R R E N C Y _ I D ,C _ O R D E R . C _ C U R R E N C Y _ I D ) ,$ P { C _ C u r r e n c y _ 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 . D A T E O R D E R E D ,C _ O R D E R . D A T E O R D E R E D ,N O W ( ) ) ) ,N U L L ,C _ O R D E R L I N E . A D _ C L I E N T _ I D ,C _ O R D E R L I N E . A D _ O R G _ I D )A SC O N V P R I C E A C T U A L , S U M ( C _ O R D E R L I N E . L I N E N E T A M T )A SP R I C E L I S T , 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 . L I N E N E T A M T ) ,C O A L E S C E ( C _ O R D E R L I N E . C _ C U R R E N C Y _ I D ,C _ O R D E R . C _ C U R R E N C Y _ I D ) ,$ P { C _ C u r r e n c y _ 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 . D A T E O R D E R E D ,C _ O R D E R . D A T E O R D E R E D ,N O W ( ) ) ) ,N U L L ,C _ O R D E R L I N E . A D _ C L I E N T _ I D ,C _ O R D E R L I N E . A D _ O R G _ I D )A SC O N V P R I C E L I S T , M _ P R O D U C T . N A M EA SP R O D U C T _ N A M E ,C _ U O M . N A M EA SU O M N A M E , C O A L E S C E ( C _ O R D E R L I N E . C _ C U R R E N C Y _ I D ,C _ O R D E R . 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 , T O _ D A T E ( 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 ,C _ O R D E R . D A T E O R D E R E D ,N O W ( ) ) )A ST R A N S D A T E , C _ O R D E R L I N E . A D _ C L I E N T _ I DA ST R A N S C L I E N T I D , 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 ,C _ O R D E R L I N E ,C _ B P A R T N E R ,M _ P R O D U C T ,C _ U O M W H E R EC _ O R D E R . C _ B P A R T N E R _ I D=C _ B P A R T N E R . C _ B P A R T N E R _ I D A N DC _ O R D E R . C _ O R D E R _ I D=C _ O R D E R L I N E . C _ O R D E R _ I D A N DC _ O R D E R L I N E . M _ P R O D U C T _ I D=M _ P R O D U C T . M _ P R O D U C T _ I D A N DC _ O R D E R L I N E . C _ U O M _ I D=C _ U O M . 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 . I S S O T R X=' N ' A N DC _ O R D E R . 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 } ) G R O U PB YC _ B P A R T N E R . N A M E ,C _ O R D E R L I N E . P R I C E A C T U A L ,M _ P R O D U C T . N A M E ,C _ U O M . N A M E ,C _ O R D E R . D O C U M E N T N O , C _ O R D E R . D A T E O R D E R E D ,C _ O R D E R L I N E . D A T E O R D E R E D , C _ O R D E R L I N E . C _ C U R R E N C Y _ I D ,C _ O R D E R . C _ C U R R E N C Y _ I D , C _ O R D E R L I N E . A D _ C L I E N T _ I D ,C _ O R D E R L I N E . 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 ,C O N V P R I C E A C T U A L ,P R O D U C T _ N A M E ,U O M N A M E ,D O C U M E N T N O ,D A T E O R D E R E D , T R A N S C U R R E N C Y I D ,T R A N S D A T E O R D E RB YC L I E N T _ N A M 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 } ,' 0 ' ,' 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 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 . C _ B P A R T N E R _ I D=C _ B P A R T N E R . C _ B P A R T N E R _ I D A N DC _ O R D E R . C _ O R D E R _ I D=C _ O R D E R L I N E . C _ O R D E R _ I D A N DC _ O R D E R L I N E . M _ P R O D U C T _ I D=M _ P R O D U C T . M _ P R O D U C T _ I D A N DC _ O R D E R L I N E . C _ U O M _ I D=C _ U O M . 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 . I S S O T R X=' N '

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

4/5

30/11/13
A N DC _ O R D E R . 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 - OpenbravoWiki

As you may see there aux_* parameters are used in the WHERE clause. e.g. Let's imagine that the user the users selects a Business Partner with ID 1000000, 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 . 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 _ 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 } ) 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, JasperReports will prepare a statement

A N DC _ O R D E R . 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 . 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 ,' 0 ' ,' Y ' )A ST R A N S 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 } ,' 0 ' ,' Y ' )A SC O N V S Y M ,-$ 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 ( ? ,' 0 ' ,' 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.openbravo.com/wiki/Report_Example" This page has been accessed 5,452 times. This page was last modified on 11 August 2011, at 12:52. C ontent is available under C reative C ommons Attribution-ShareAlike 2.5 Spain License. Category: Example

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

5/5

S-ar putea să vă placă și