Retail:Developers Guide/printingReceipts
Contents |
Printing receipts and sending data to customer displays
Introduction
Openbravo web POS have a client side infrastructure which allows to communicate with the hardware manager server. In this chapter we will analyze this infrastucture and how ii works.
HW resource
HW resource is an utility which allow to load a xml template. This template will be used to be printed. To load a resource just the path of xml file is needed.
this.templatereceipt = new OB.DS.HWResource(OB.OBPOSPointOfSale.Print.ReceiptTemplate);
In this piece of code, the path of the file is defined in OB.OBPOSPointOfSale.Print.ReceiptTemplate.
HW server
HW server is the javascript object that apply an object model to a template and sends it to the POS Hardware Server. This POS Hardware Server is located in the URL Hardware URL of the POS Terminal window. To invoke the function use:
OB.POS.hwserver.print(template, { order: receipt });
Where template is an OB.DS.HWResource instance and { order: receipt } is the object to apply to the template.
Model for print
Each window on Openbravo web POS is associated to a "print model". This model is a javascript object where is defined which template are used to print and which business logic is followed to decide what template print and which data is used.
As you can see in the code bellow, the constructor sets the templates to use, and the print function add some logic before print the ticket.
Last line of print function starts the print process. In the first step of this process the xml template and the data (receipt) are merged, then, the filled template is sent to the hardware manager.
var PrintReceipt = function(receipt) { this.receipt = receipt; this.receipt.on('print', this.print, this); this.templatereceipt = new OB.DS.HWResource(OB.OBPOSPointOfSale.Print.ReceiptTemplate); this.templateinvoice = new OB.DS.HWResource(OB.OBPOSPointOfSale.Print.ReceiptTemplateInvoice); this.templatereturn = new OB.DS.HWResource(OB.OBPOSPointOfSale.Print.ReceiptTemplateReturn); this.templatereturninvoice = new OB.DS.HWResource(OB.OBPOSPointOfSale.Print.ReceiptTemplateReturnInvoice); }; PrintReceipt.prototype.print = function () { // Clone the receipt var receipt = new OB.Model.Order(); receipt.clearWith(this.receipt); var template; if (receipt.get('generateInvoice')) { if (receipt.get('orderType') === 1) { template = this.templatereturninvoice; } else { template = this.templateinvoice; } } else { if (receipt.get('orderType') === 1) { template = this.templatereturn; } else { template = this.templatereceipt; } } OB.POS.hwserver.print(template, { order: receipt }); };
The default templates are defined as global, because of it, they can be overwritten. Check this how to to more details.
Connecting window model with print model
To print a receipt from a window model we need to create an instance of the print model that we are going to use and then execute the print method of this "print-model"
this.printLine = new OB.OBPOSPointOfSale.Print.ReceiptLine(receipt);
Back to Concepts