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

How to create a receipt report



Web POS is capable to print receipts using the Receipt and Customer display document schema. But this schema is oriented to receipt printers and has limited layout capabilities. In the case it is required to print documents with a richer layout, the Jasper Reports engine can be used to print documents through the Hardware Manager. This capability is available only for printers using the Printer mode. See Hardware and Peripherals Installation.

This document will explain step by step how to create a new module that includes a Jasper Reports document to print invoices from Web POS. This module has been published in mode Test and can be installed from the Module Management window. If you want to inspect the source code or modify it for your own project, the source code is available from the Retail Sales Receipt Report project page.

Is it also possible to define a receipt template that depending for example on a receipt property to print a receipt report or a regular receipt template. This functionality is explained in the Javascript template engine for receipt printers and customer displays document.

Create a new module

Before creating the report definition you need to create a new module. This module will contain the report declaration and the report files. It is required that you know about the Openbravo modularity concepts. You can learn about Openbravo Modularity in the document How_To_Create_and_Package_a_Module.

As System Administrator go to the window Module and create a new record. Fill in all the required fields and save. Go to the the tab Dependency and add dependencies to the module Web POS and Web POS Hardware Manager. This the definition of the module example.

Retail Sales Receipt Report Module

Declare the invoice template

The next step is to declare the invoice template. In this example we are going to create a new report for invoices created from the Web POS.

As System Administrator go to the window POS Print Templates and create a new record. The fields to fill in are the following:

If the report has subreports, that in general it will, you have to go to the tab Subreports and create as many records as subreports has. The fields to fill in are:

View larger

Design the invoice

The tool used to design the reports is iReport Designer. To know how to use this tool you can go to the Jaspersoft documentation

The parameters received by the report are:

Fields of the report depends on the type of the report and are translated directly from the JSON that contains the document data. In this example the following fields of the invoice are used:

Invoice lines data is received as a report parameter:

And the fields used in each line are:

Tax lines data is received as a report parameter too:

And the fields used in each tax line are:

View larger

Place the report file in the correct location in the module

The report file should be placed inside the module in the web directory of the module and within it again in a directory which has the same name as the module. The OB convention is to use then a subfolder called res.

See here how this is placed within the org.openbravo.retail.posterminal module:

View larger

Install and configure the printer

The only requirement to print reports is to configure the printer in the Hardware Manager in printer mode. This mode is printers installed as a printer in the operating system using the system driver provided by the manufacturer of the printer. In the document Hardware and Peripherals Installation it is explained how to configure a printer.

If instead of printing the report you want to generate a PDF file you can configure a Virtual PDF printer. There are several options depending on the operating system you use.

The following example configures in the Hardware Manager the printer named My_Printer" as printer number 1:

## Receipt printers  ## 
machine.printer = printer\:My_Printer,standard

Configure the store

To configure your store to use the report created, as Client Administrator go to the Organization window, and in the Web POS section select the template to use. The following fields can select a template: Print Ticket Template, Cash Up Report Template, Closed Receipt Template, Invoice Template, Return Template, Return Invoice Template, Layaway Template, Sales Report Template and Print Ticket Template for Training Mode. In our case Invoice Template.

View larger

Print the invoice

Now all the work is done. To test everything works open a Web POS terminal as create a new invoice. Invoices are created selecting in the menu Invoice this receipt. Also you can only create a receipt for customers that have a valid Tax ID.

View larger

And this is how the invoice created looks like in a virtual PDF printer.

View larger

Javac and Groovy Class Not Found Exception

Bulbgraph.png   Note: to have Web POS use jasper reports through the hardware manager you need to make sure the hardware manager can run the 'javac' program. Javac is delivered as part of the java JDK distributions.

If you get this exception when printing a ticket:

[java] java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException
     [java] 	at$
     [java] 	at$
     [java] 	at Method)
     [java] 	at
     [java] 	at java.lang.ClassLoader.loadClass(
     [java] 	at sun.misc.Launcher$AppClassLoader.loadClass(
     [java] 	at java.lang.ClassLoader.loadClass(
     [java] 	at java.lang.Class.forName0(Native Method)
     [java] 	at java.lang.Class.forName(
     [java] 	at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(
     [java] 	at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(
     [java] 	at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(
     [java] 	at net.sf.jasperreports.engine.JasperCompileManager.compileReport(
     [java] 	at net.sf.jasperreports.engine.JasperCompileManager.compileReport(
     [java] 	at com.openbravo.poshw.TicketPdfServlet.doProcess(
     [java] 	at com.openbravo.poshw.TicketPdfServlet.doPost(

Then you need to set the correct language in the jasper template. Open the template and right click on the root node in the report tree and then set Java as the language.

View larger

Retrieved from ""

This page has been accessed 20,142 times. This page was last modified on 16 August 2016, at 13:19. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.