View source | Discuss this page | Page history | Printable version   
Toolbox
Main Page
Upload file
What links here
Recent changes
Help

PDF Books
Show collection (0 pages)
Collections help

Search

Retail:Developers Guide/How-to/How to create and modify new receipt documents from other module

Contents

How to create and modify new receipt documents from other module

The first step in this HowTo is create the new module. Because this module will extend Openbravo web POS it must depends on it. Here you can find information related to the creation of new modules.

See images bellow to see the main parts of the module which will be used in this How-to:

RDG HT createModule dependency.png
RDG HT createModule datapackage.png
RDG HT createModule dbprefix.png


The module has been created! Let's add files to the module file structure.


RDG HT createFolders allFiles.png

printreceipt.xml: New Template to be printed

changeDefaultTemplates.js: This js file will be used to overwrite the default template used by Openbravo web POS to print receipts.

OBEXPOSComponentProvider.java: This java class will include our javascript file into the resources of Openbravo web POS. It allow us to extend the default properties.

Here is our component provider. As you can see in getGlobalComponentResources() method, the js file which we have created in the previous step, will be added to Openbravo web POS resources.

 
package org.openbravo.retail.extendposterminal;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.enterprise.context.ApplicationScoped;
 
import org.openbravo.client.kernel.BaseComponentProvider;
import org.openbravo.client.kernel.BaseComponentProvider.ComponentResource.ComponentResourceType;
import org.openbravo.client.kernel.Component;
import org.openbravo.client.kernel.ComponentProvider;
import org.openbravo.retail.posterminal.POSUtils;
 
/**
 * @author guilleaer
 * 
 */
@ApplicationScoped
@ComponentProvider.Qualifier(OBEXPOSComponentProvider.QUALIFIER)
public class OBEXPOSComponentProvider extends BaseComponentProvider {
  public static final String QUALIFIER = "OBEXPOS_Main";
  public static final String MODULE_JAVA_PACKAGE = "org.openbravo.retail.extendposterminal";
 
  @Override
  public Component getComponent(String componentId, Map<String, Object> parameters) {
    throw new IllegalArgumentException("Component id " + componentId + " not supported.");
  }
 
  @Override
  public List<ComponentResource> getGlobalComponentResources() {
    final List<ComponentResource> globalResources = new ArrayList<ComponentResource>();
    final String prefix = "web/" + MODULE_JAVA_PACKAGE + "/js/";
 
    String[] resourceList = { "changeDefaultTemplates" };
 
    for (String resource : resourceList) {
      globalResources.add(createComponentResource(ComponentResourceType.Static, prefix + resource
          + ".js", POSUtils.APP_NAME));
    }
 
    return globalResources;
  }
}

Here is the source code of changeDefaultTemplates.js. With this code, the default template for print receipts is overwritten.

 
OB.OBPOSPointOfSale.Print.ReceiptTemplate = '../org.openbravo.retail.extendposterminal/receipts/printreceipt.xml';

Finally, the template can be customized editing the XML file. In this example, the ticket will be changed for a simple one.

 
<?xml version="1.0" encoding="UTF-8"?>
<output>
  <ticket>
    <line>
      <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('This is')%></text>
    </line>
    <line>
      <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent('a customized ticket')%></text>
    </line>
  </ticket>
 
  <display>
      <line>
        <text align="left" length="10"><%= OB.UTIL.encodeXMLComponent('This is a customized display')%></text>
      </line>
  </display>
 
  <opendrawer/>
</output>

Before test it, ant smartbuild should be executed.

And this is the final result. The receipt has been changed!

RDG customizedticket.png

Web POS Templates

Here is a list of all the templates that Web POS uses.

Property Default Resource Type Description
OB.OBPOSPointOfSale.Print.ReceiptTemplate res/printreceipt.xml Print Ticket Used to print the ticket once it is paid.
OB.OBPOSPointOfSale.Print.ReceiptClosedTemplate res/printclosedreceipt.xml Closed Receipt Prints already paid tickets.
OB.OBPOSPointOfSale.Print.ReceiptTemplateInvoice res/printinvoice.xml Invoice Prints invoices.
OB.OBPOSPointOfSale.Print.ReceiptTemplateReturn res/printreturn.xml Return Prints returns.
OB.OBPOSPointOfSale.Print.ReceiptTemplateReturnInvoice res/printreturninvoice.xml Return Invoice Prints returned invoices.
OB.OBPOSPointOfSale.Print.ReceiptLineTemplate res/printline.xml N/A Prints information about added lines to the ticket.
OB.OBPOSPointOfSale.Print.ReceiptTemplateLayaway res/printlayaway.xml Layway Prints layaways
OB.OBPOSPointOfSale.Print.DisplayTotal res/displaytotal.xml N/A Prints total before paying
OB.OBPOSPointOfSale.Print.CashUpTemplate res/printcashup.xml Cash Up Report Prints Cash Up Report

To overwrite in a module any of this templates is enough with overwriting the property to point to the correct template resource. Doing in this way, the module will change the default template for any Store that doesn't explicitly set any other.

Bulbgraph.png   Topics covered in this section below this line are available starting from RMP31

It is possible to define at Store level a different templates than the ones defined as defaults. To make a template available to be used in this way, it is necessary to register it (as System Administrator) in POS Print Templates window.

POSPrintTemplates.png

Adding new Templates

External modules can provide new templates to print different reports than the ones in core. They need to provide the template resource as well as the code to invoke the report with that template in the proper place.

Bulbgraph.png   Topics covered in this section below this line are available starting from RMP31

If the default templates provided by external modules are desired to be overwritten at Store level, it will be required to Make the Template Available from POS Print Templates window and Include it as Part of Terminal Information.

Make the Template Available from POS Print Templates and Organization windows

The module providing this new template type needs to add a new entry in Reference window for OBPOS_PrintTemplates reference. In List Reference subtab.

Once this is done it will be possible to define in modules implementations for this template type.

Next step is to extend AD_Org database table to add a new column that allows to select our template at Organization/Store level.

Include it as Part of Terminal Information

Having the information in database model, the next step is to make use of it in Web POS.

This is done by providing in the module a class extending org.openbravo.retail.posterminal.term with @Qualifier(Terminal.terminalPropertyExtension). This class should add to the of terminal properties the required one:

 
@Qualifier(Terminal.terminalPropertyExtension)
public class MyTerminalProperties extends org.openbravo.retail.posterminal.term.TerminalProperties {
 
  @Override
  public List<HQLProperty> getHQLProperties(Object params) {
 
    ArrayList<HQLProperty> list = new ArrayList<HQLProperty>();
 
    addTemplateProperty(Organization.PROPERTY_MYTEMPLATEPROPERTY, "printMyPropertyTemplate",
        list);
 
    // add any other property you might need
 
    return list;
  }
}

In this case the property will be available in Web POS javascript at OB.POS.modelterminal.get('terminal').printMyPropertyTemplate

Configure PDF templates

This section explains how to configure a PDF Template to be used in Web POS. In order to be able to use this functionality to generate PDF templates the javac command needs to be properly configured. In Linux machines this is done automatically while installing java, but in window machines the folder path of javac command needs to be added to PATH environment variable. Having this configured, a JRXML template needs to be created in order to use in Web POS.

Bulbgraph.png   Topics covered in this section below this line are available starting from RMP32

Once the JRXML template has been created, to configure a PDF template navigate to POS Print Templates window (as a System Administrator).

To overwrite an existing template defined at Store level create a new record and set as Template Type the desired one.

To implement a new Template Type create a new record as explained in Make the Template Available from POS Print Templates window and Include it as Part of Terminal Information sections.

Then,

Configure PDF Template Web POS.png

If the report has any subreport, define them on a tab called Subreport defined under POS Print Templates, onnly displayed if PDF checkbox is selected. Define a Name and Template Path.


RDG HT Pos Print Templates Subreport.png

The subreports will be available in Web POS javascript at OB.POS.modelterminal.get('terminal').printMyPropertyTemplate + index starting from 0. In this case:


Back to How-to

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

This page has been accessed 21,113 times. This page was last modified on 26 August 2014, at 11:47. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.