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

Retail:Developers Guide/How-to/How to create jrxml templates

Contents

How to create jrxml templates

In this howto we explain how to create jrxml templates in order to print PDF reports in Openbravo Web POS.

The main difference between the jrxml templates used in Openbravo ERP and the ones used in Web POS is the datasource. In Openbravo ERP, most of them use a connection against the database and an sql query to extract data. However, in Web POS, all data comes from a json object created in the client side that is passed to the backend, and in this case to the jrxml file. There is no connection against the database.

The first step is to set up iReport tool that is going to be used to implement the templates.

Once iReport is ready to be used the next step is to learn how to pass needed data to iReport. This is done calling a service hosted in the hardware manager that populates the jrxml file.

This section is only needed if the Template Type to be created is new, not one that overwrittes one of the existing defaults.

Bulbgraph.png   To print a jrxml in a printer, the hardware manager properties file should be configured in mode printer (machine.printer). The mode usb is not supported

Call Hardware Manager to populate the jrxml file

This is the javascript request that needs to be implemented:

 
OB.POS.hwserver._printPDF({
      order: receipt.serializeToJSON(),
      mainReport: mainReport,
      subReports: subReports
    }, function (result) {
      var otherMe = me;
      var myreceipt = receipt;
      if (result && result.exception) {
        OB.UTIL.showConfirmation.display(OB.I18N.getLabel('OBPOS_MsgHardwareServerNotAvailable'), OB.I18N.getLabel('OBPOS_MsgPrintAgain'), [{
          label: OB.I18N.getLabel('OBMOBC_LblOk'),
          action: function () {
            var otherOtherMe = otherMe;
            otherOtherMe.print();
            return true;
          }
        }, {
          label: OB.I18N.getLabel('OBMOBC_LblCancel')
        }]);
      }
    });

There are three parameters that needs to be included in the request:

Once the request is implemented, the next step is to get this data in iReport.

Retrieve data in iReport

This is an example of a json object that could passed as a parameter:

{

 "order": {
   "id": "AACEA22C9200ED627D2F4AA5F499188F",
   "client": "39363B0921BB4293B48383844325E84C",
   "organization": "3B187EC130A549A7A9388F8060EF156D",
   "createdBy": "100",
   "updatedBy": "100",
   "documentType": "044E078A49CB4B1192B849462ACB4624",
   "posTerminal": "5F413EBD3A6042C28708821D43C91D0B",
   "posTerminal$_identifier": "CMS POS Terminal",
   "orderDate": "2014-02-19T15:38:05.080Z",
   "documentNo": "CMS1/0000120",
   "bp": {
     "id": "9C211C965971481CA91FC948CBC83076",
     "organization": "3B187EC130A549A7A9388F8060EF156D",
     "searchKey": "CMS/C0001",
     "_identifier": "CMS Customer",
     "name": "CMS Customer"
    },
    "lines": [
      {
       "product": {
         "id": "934E7D7587EC4C7A9E9FF58F0382D450",
         "searchkey": "WVG/M0019",
         "uPCEAN": null,
         "uOM": "100",
         "uOMsymbol": "Ud "
       },
       "qty": 1,
       "price": 0,
       "priceList": 150.5,
       "gross": 182.11
      }
    ],
    "payments": [
      {
       "amount": 182.11,
       "origAmount": 182.11,
       "paid": 182.11,
       "date": "2014-02-19T15:41:16.472Z",
       "kind": "OBPOS_payment.card",
       "name": "Card",
       "rate": "1",
       "mulrate": "1",
       "isocode": "EUR",
       "allowOpenDrawer": true,
       "isCash": false,
       "openDrawer": false
      }
    ]
 }

}

To have a better vision of the object use the following link to format it: http://www.jsoneditoronline.org/

Analyzing the order json object, is possible to identify three type of objects that they compose it:

The single properties and properties inside json objects are accessed in iReport as fields. Json Array objects are accessed as subreports parameters.

Look at an example of getting properties:

RDG HT Accessing Fields iReport.png

Look at an example of getting subreport parameter:

RDG HT Accessing Subreports iReport.png

At this point the next step is to create the subreports.

Create the subreport inside iReport

The following rules must be satisfied:

Once this is done, inside the subreport, the way to access the fields is the same as the main report.

Name of the subreport concatenated to name of the property, i.e. in "lines" report the "gross" property -> LINES.GROSS

Add a logo to the report

There is a parameter called REPORT_IMG_FOLDER that is passed to iReport that contains the absolute path of the folder where the images are stored. This folder belongs to the Hardware Manager and is configured in its properties file (openbravohw.properties, images.folder property)

Then, to add the logo, add Image object and set the following properties:

Add a barcode to the report

For barcodes there is a utility class in the Hardware Manager used to generate barcodes. The barcodes supported are: EAN13, CODE128 and CODE39. Here you can see an example to add a barcode for the document number:

<image scaleImage="Clip" isLazy="true" onErrorType="Icon">
  <reportElement x="409" y="10" width="131" height="33"/>
  <imageExpression><![CDATA[new com.openbravo.pos.printer.ticket.PrintItemBarcode("CODE128","none",$F{DOCUMENTNO},1.0).getImage()]]> 
  </imageExpression>
</image>

And this is the result:

BarcodeJRXML.png

The parameters of the constructor for the class 'PrintItemBarcode' are the following:

Retrieved from "http://wiki.openbravo.com/wiki/Retail:Developers_Guide/How-to/How_to_create_jrxml_templates"

This page has been accessed 6,504 times. This page was last modified on 29 January 2020, at 10:25. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.