<<

C@ELOLJ

9lj`e\jj`ek\cc`^\eZ\n`k_Fg\eF]]`Z\%fi^9Xj\ 98J<9L@C;

Learn how to analyze your business data with the help of OpenOffice. org Base and the Sun Report Builder extension. BY DMITRI POPOV

f you own a business or work as a fered by Sun Report Builder. Take, for ex- nector/J from MySQL’s website, unpack freelancer, analyzing your business ample, BambooInvoice [3], an easy-to- the file and move the resulting @data can be as useful as it is for cor- use invoicing application based on mysql-connector--x.x.x-bin.jar file porations. Investing thousands of dollars MySQL/PHP [4]. Although it does a into the desired location (e.g., your in high-end business intelligence (BI) good job managing invoices, BambooIn- home directory). tools isn’t required; in many cases, the voice is rather limited when it comes to In OpenOffice.org, choose Tools | Op- OpenOffice.org Base application com- analyzing the invoicing data. OpenOf- tions | Java, then make sure that the ap- bined with the Sun Report Builder exten- fice.org enters the picture here. Using the propriate Java Runtime Environment is sion can do the job just fine. Base/ Sun Report Builder combo, you selected and click the Class Path button. Sun Report Builder [1] uses the same can create a solution that allows you to Next, click the Add Archive button and reporting engine as the BI suite view the invoicing data from different select mysql-connector-java-x.x.x-bin.jar. [2], and its pedigree makes it a perfect angles and turn numbers into easy-to- To save the settings, click OK, then close tool for analyzing your business data. digest graphs. the window and restart OpenOffice.org. OpenOffice.org Base, in turn, can con- Before you start, make sure that you Now you are ready to connect Ope- nect to a variety of database systems, so have the Sun Java Runtime Environment nOffice.org to the MySQL database. In you can use it to pull data from virtually and the latest version of the Sun Report OpenOffice.org, choose New | Database. any business application that uses a da- Builder extension installed on your sys- In the Database Wizard, select the Con- tabase and analyze it with the tools of- tem. Connecting OpenOffice.org Base to nect to an existing database option, se- BambooInvoices’s database back end is lect MySQL from the drop-down list, and Dmitri Popov holds the first order of business. To do this, click Next. Then select the Connect using a degree in Russian you need a small piece of software, JDBC (Java Database Connectivity) op- language and com- called a connector, that acts as a bridge tion and click Next. In the appropriate puter linguistics. He between the MySQL-based back end of fields, enter the name of the database has been writing exclusively about BambooInvoice and an OpenOffice.org (by default, BambooInvoice uses a data- and open Base database. base called bambooinvoice) and the source software for MySQL provides two connectors: Con- server address (Figure 1). several years, and his articles have nector/ODBC and Connector/ J [5]. In To make sure that the MySQL JDBC THE AUTHOR THE appeared in Danish, British, North the example here, I’ll use the latter be- driver works properly, click the Test class American, German, and Russian cause it’s significantly easier to install button. When the driver has been loaded magazines and websites. and configure. After you download Con- successfully, click Next, then enter the

88 ISSUE 98 JANUARY 2009

088-090_workspace.indd 88 13.11.2008 15:55:35 Uhr Workspace: Business Data C@ELOLJ

=`^li\(1:fe]`^li`e^:fee\Zkfi&A%

database username in the User name to create a new =`^li\)1Hl\ip]fik_\]`ijki\gfik% field and tick the Password required query. In the checkbox. To see whether everything Query window, add three database ta- of the amount field to Sum. This way, works as it’s supposed to, click the Test bles: bamboo_invoices, bamboo_invoice_ the amount field will contain the total Connection button, then click the Next items, and bamboo_clients. Next, you sum of all invoice payments with the button, select the Yes, register the data- have to create relations between these same invoice number. base for me option, and click Finish. three tables, which is done by dragging To better understand what exactly the After you name the database (e.g., the mouse from a field in one table to Group and Sum functions do, try to run “BambooInvoice”), save it, open the da- the target field in another table. This the query without them. Listing 1 shows tabase, and click on the Tables button. adds a connector between the two fields. results similar to those you should re- After entering the database’s password, In this sample case, you need to create ceive. As you can see, a single invoice you should see a list of all tables in the two relations: bamboo_invoices.id to has a separate record for each invoice bambooinvoice database. bamboo_invoice_items.invoice_id and item. Now apply the Group and Sum bamboo_clients.id to bamboo_invoices. functions as described and run the query :i\Xk`e^Hl\i`\jXe[ client_id (Figure 2). Then add the in- again. The result should be a single re- I\gfikj voice_number, dateIssued, name, and cord, which is exactly what you need Now I’ll explain how to create a simple amount fields to the query by dragging (Listing 2). report that prints a list of all invoices them from the tables onto the Field col- Next, save the query and give it a stored in BambooInvoice. Each item in umns in the lower pane of the Query name – for example, “Query1.” Then the list will contain the invoice number, window. you can start working on a new report. customer name, invoice creation date, After you’ve added the fields, you For a new report, switch to the Reports and the total payment due. All the data have to group the invoice_number field section and click on the Create Report in is stored in the different BambooInvoice so that all records with the same invoice Design View link. This opens a blank re- tables, so you must create a query that number appear as one item in the report. port in Sun Report Builder. In the Data pulls the desired records from them. To do this, select Group in the Function section of the Properties pane, specify a Switch to the Queries section and click row of the invoice_number column. data source by selecting Query from the on the Create Query in Design View link Also, you have to set the Function option Content Type drop-down list and the cre-

=`^li\*1:i\Xk`e^Xj`dgc\i\gfik% =`^li\+1Hl\ip]fik_\j\Zfe[i\gfik%

JANUARY 2009 ISSUE 98 89

088-090_workspace.indd 89 13.11.2008 15:55:39 Uhr C@ELOLJ

=`^li\,18[[`e^XZ_Xik% =`^li\-1

ated Query1 from the Content list. Then 4). After you save the query, create a on the chart to put it into editing mode, drag the fields from the Add field win- new report that uses it as a data source right-click on the chart, and select the dow onto the Detail section of the report (Figure 5). Because you might want the Chart Type item. This opens the Chart and arrange and format them the way chart to appear in the report only once, Type wizard, which helps you choose you want (Figure 3). That’s it – your re- you must place it in either the Report and configure the chart type you want port is ready. To test it, press the Execute Header or Report Footer section. To add (Figure 6). Report button on the Report Builder’s these sections to the report, choose Edit main toolbar. | Insert Report Header/ Footer, then press =`eXcNfi[ the Chart button on the Report Builder’s Using Sun Report Builder, you can turn 8[[`e^:_Xikj main toolbar and draw a chart in the re- OpenOffice.org Base into a powerful BI Because Sun Report Builder supports port section you want. After making sure tool. If you don’t feel like creating the charts, you can explore your data visu- that the chart is selected (i.e., it has described solution from scratch, you can ally through graphs instead of as plain green handles around it), choose the ap- download the sample BambooInvoice. rows of text and numbers. For example, propriate query as its data source. odb database [6] containing the de- you can create a report with a chart rep- Note that instead of creating the query scribed queries and reports. resenting the invoiced amount for each in the Queries section, you can specify it The database requires a working Bam- customer. Similar to a regular report, a as the chart’s data source directly in the booInvoice installation, and you must report with a chart pulls data either di- report. To do this, select SQL command replace the default connection settings. rectly from a table or from a query. Be- from the Content type drop-down list, To do this, open the BambooInvoice.odb cause you have to obtain records from then click on the button next to the Con- database, choose Edit | Database | Prop- different tables, you need the latter. In tent list to open the Query window. Then erties, and replace the default username this case, you need to get data from the- use it to construct the query. When you and password. p name field of the bamboo_clients table save the created query, the system con- and the amount field of the bamboo_in- verts it into a SQL statement and inserts INFO voice_items table. it in the Content field. [1] Sun Report Builder: extensions. By default, Sun Report Builder inserts As in the previous query, you must set services. openoffice. org/ project/ the Function option of the name and a bar chart, but you can change it to an- reportdesign amount fields to Group and Sum (Figure other chart type. To do this, click twice [2] Pentaho: www. pentaho. com Listing 1: Query without Group and Sum [3] BambooInvoice: www. bambooinvoice. org 01 invoice_number dateIssued name amount [4] “BambooInvoice Web-Based Invoic- 02 3 11/27/08 Nuts and Bolts Inc 375 ing Solution” by Dmitri Popov, Linux 03 3 11/27/08 Nuts and Bolts Inc 2157 Magazine, December 2008, http:// 04 3 11/27/08 Nuts and Bolts Inc 211 www. linux-magazine. com/ issues/ 2008/ 97/ smooth_solution [5] MySQL connectors: www.mysql. Listing 2: Query with Group and Sum com/ products/ connector/ 01 invoice_number dateIssued name amount [6] Sample BambooInvoice database: 02 3 11/27/08 Nuts and Bolts Inc 2743 www. mediafire. com/ ? gi44bdx1z4m

90 ISSUE 98 JANUARY 2009

088-090_workspace.indd 90 13.11.2008 15:55:42 Uhr