Attached Files | printingJASPERorXML.diff [^] (22,105 bytes) 2015-12-21 12:51 [Show Content] [Hide Content]diff --git a/src-db/database/sourcedata/OBPOS_PRINT_TEMPLATE.xml b/src-db/database/sourcedata/OBPOS_PRINT_TEMPLATE.xml
--- a/src-db/database/sourcedata/OBPOS_PRINT_TEMPLATE.xml
+++ b/src-db/database/sourcedata/OBPOS_PRINT_TEMPLATE.xml
@@ -36,6 +36,19 @@
<!--259C995F9D91404088F6404627BD3423--> <ISPDF><![CDATA[N]]></ISPDF>
<!--259C995F9D91404088F6404627BD3423--></OBPOS_PRINT_TEMPLATE>
+<!--4BB3AC0D408B42238490844C1344BA1A--><OBPOS_PRINT_TEMPLATE>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <OBPOS_PRINT_TEMPLATE_ID><![CDATA[4BB3AC0D408B42238490844C1344BA1A]]></OBPOS_PRINT_TEMPLATE_ID>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <NAME><![CDATA[Proof of Concept Receipt JRXML]]></NAME>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <TEMPLATE_TYPE><![CDATA[PrintTicket]]></TEMPLATE_TYPE>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <TEMPLATE_PATH><![CDATA[res/proofofconcepterror.jrxml]]></TEMPLATE_PATH>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <ISPDF><![CDATA[Y]]></ISPDF>
+<!--4BB3AC0D408B42238490844C1344BA1A--> <PRINTER><![CDATA[2]]></PRINTER>
+<!--4BB3AC0D408B42238490844C1344BA1A--></OBPOS_PRINT_TEMPLATE>
+
<!--56A8FF38A1AC40A5A56AE35A373617C0--><OBPOS_PRINT_TEMPLATE>
<!--56A8FF38A1AC40A5A56AE35A373617C0--> <OBPOS_PRINT_TEMPLATE_ID><![CDATA[56A8FF38A1AC40A5A56AE35A373617C0]]></OBPOS_PRINT_TEMPLATE_ID>
<!--56A8FF38A1AC40A5A56AE35A373617C0--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -108,6 +121,18 @@
<!--C3B2C9C362904B05A67B0D20E25BD4EF--> <ISPDF><![CDATA[N]]></ISPDF>
<!--C3B2C9C362904B05A67B0D20E25BD4EF--></OBPOS_PRINT_TEMPLATE>
+<!--D3339C6F5D10481FB434955AA22A2CDD--><OBPOS_PRINT_TEMPLATE>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <OBPOS_PRINT_TEMPLATE_ID><![CDATA[D3339C6F5D10481FB434955AA22A2CDD]]></OBPOS_PRINT_TEMPLATE_ID>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <AD_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_MODULE_ID>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <NAME><![CDATA[Proof of Concept Receipt XML]]></NAME>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <TEMPLATE_TYPE><![CDATA[PrintTicket]]></TEMPLATE_TYPE>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <TEMPLATE_PATH><![CDATA[res/proofofconceptreceipt.xml]]></TEMPLATE_PATH>
+<!--D3339C6F5D10481FB434955AA22A2CDD--> <ISPDF><![CDATA[N]]></ISPDF>
+<!--D3339C6F5D10481FB434955AA22A2CDD--></OBPOS_PRINT_TEMPLATE>
+
<!--F15ADD456F554672B7CAB356F42FEC2E--><OBPOS_PRINT_TEMPLATE>
<!--F15ADD456F554672B7CAB356F42FEC2E--> <OBPOS_PRINT_TEMPLATE_ID><![CDATA[F15ADD456F554672B7CAB356F42FEC2E]]></OBPOS_PRINT_TEMPLATE_ID>
<!--F15ADD456F554672B7CAB356F42FEC2E--> <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff --git a/web/org.openbravo.retail.posterminal/js/datasource.js b/web/org.openbravo.retail.posterminal/js/datasource.js
--- a/web/org.openbravo.retail.posterminal/js/datasource.js
+++ b/web/org.openbravo.retail.posterminal/js/datasource.js
@@ -7,7 +7,7 @@
************************************************************************************
*/
-/*global OB, $, Backbone, _, enyo, Audio, setTimeout, setInterval, clearTimeout, clearInterval */
+/*global OB, $, Backbone, _, enyo, Audio, setTimeout, setInterval, clearTimeout, clearInterval, Promise */
// HWServer: TODO: this should be implemented in HW Manager module
OB.DS.HWResource = function (res) {
@@ -217,10 +217,49 @@
};
OB.DS.HWServer.prototype._print = function (templatedata, params, callback) {
+
+ var promisedata = function (template) {
+ return new Promise(function (resolve, reject) {
+ template.getData(function () {
+ resolve();
+ });
+ });
+
+ };
var computeddata;
try {
- computeddata = this._template(templatedata, params);
- this._send(computeddata, callback);
+ computeddata = this._template(templatedata, params).trim();
+
+ if (computeddata.substr(0, 6) === 'jrxml:') {
+ // Print a jasper PDF report. We need to rebuild the parameters to adjust the _printPDF() call...
+ var returnedparams = JSON.parse(computeddata.substr(6));
+ var getdatas = [];
+ var i = 0;
+ var me = this;
+
+ var newtemplate = new OB.DS.HWResource(returnedparams.report);
+ newtemplate.ispdf = true;
+ newtemplate.printer = returnedparams.printer || 1;
+ newtemplate.dateFormat = OB.Format.date;
+ getdatas.push(promisedata(newtemplate));
+ newtemplate.subreports = [];
+
+ for (i = 0; i < returnedparams.subreports.length; i++) {
+ newtemplate.subreports[i] = new OB.DS.HWResource(returnedparams.subreports[i]);
+ getdatas.push(promisedata(newtemplate.subreports[i]));
+ }
+
+ Promise.all(getdatas).then(function () {
+ me._printPDF({
+ param: params.order.serializeToJSON(),
+ mainReport: newtemplate,
+ subReports: newtemplate.subreports
+ }, callback);
+ });
+ } else {
+ // Print the computed receipt as usual
+ this._send(computeddata, callback);
+ }
} catch (ex) {
OB.error('Error computing the template to print.', ex);
callback({
diff --git a/web/org.openbravo.retail.posterminal/res/proofofconceptreceipt.xml b/web/org.openbravo.retail.posterminal/res/proofofconceptreceipt.xml
new file mode 100644
--- /dev/null
+++ b/web/org.openbravo.retail.posterminal/res/proofofconceptreceipt.xml
@@ -0,0 +1,250 @@
+<% if (true) { // here goes the check to print the receipt or a report %>
+ jrxml:{
+ "printer": 2,
+ "report": "res/proofofconceptreport.jrxml",
+ "subreports": [
+ "res/proofofconceptreport_subreport1.jrxml",
+ "res/proofofconceptreport_subreport2.jrxml"
+ ]
+ }
+<% } else { %>
+
+
+
+
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ************************************************************************************
+ * Copyright (C) 2012 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+-->
+
+<output>
+ <ticket>
+ <line></line>
+ <line></line>
+ <line>
+ <text align="center" length="42">PROOF OF CONCEPT</text>
+ </line>
+ <line></line>
+ <line>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tckheader_line1'))%></text>
+ </line>
+ <line>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tckheader_line2'))%></text>
+ </line>
+ <line></line>
+ <line>
+ <text align="left" length="22"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_ticket')) %></text>
+ <text><%= OB.UTIL.encodeXMLComponent(order.get('documentNo')) %></text>
+ </line>
+ <line>
+ <text align="left" length="22"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_datetime')) %></text>
+ <text><%= OB.I18N.formatDate(order.get('orderDate')) %></text>
+ <text> </text>
+ <% var time;
+ if(!OB.UTIL.isNullOrUndefined(order.get('created'))){
+ time = new Date(order.get('created'));
+ } else {
+ time = new Date();
+ }
+ %>
+ <text><%= OB.I18N.formatHour(time) %></text>
+ </line>
+ <line>
+ <text align="left" length="22"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_cashierPOS')) %></text>
+ <text><%= OB.UTIL.encodeXMLComponent(order.get('salesRepresentative'+OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER)) %></text>
+ <text>, </text>
+ <text><%= OB.UTIL.encodeXMLComponent(order.get('posTerminal'+OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER)) %></text>
+ </line>
+ <line></line>
+ <line>
+ <text align ="left" length="21"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_LineItem'))%></text>
+ <text align ="right" length="5">#</text>
+ <text align ="right" length="8"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_LinePrice'))%></text>
+ <text align ="right" length="8"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_LineTotal'))%></text>
+ </line>
+ <line>
+ <text>------------------------------------------</text>
+ </line>
+ <%
+ var lines = order.get('lines'), line, promotions;
+ for (var i = 0; i < lines.length; i++) {
+ line = lines.at(i);
+ %>
+ <line>
+ <text align ="left" length="21"><%= OB.UTIL.encodeXMLComponent(line.get('product').get('_identifier')) %></text>
+ <text align ="right" length="5"><%= line.printQty() %></text>
+ <text align ="right" length="8"><%= line.printPrice() %></text>
+ <%if(order.get('priceIncludesTax')){%>
+ <text align ="right" length="8"><%= line.printGross() %></text>
+ <%}else{%>
+ <text align ="right" length="8"><%= line.printNet() %></text>
+ <%}%>
+ </line>
+ <%
+ promotions = line.get('promotions');
+ if (promotions){
+ promotions.forEach(function(p) {
+ if (!p.hidden) {
+ %>
+ <line>
+ <text align="left" length="2">--</text>
+ <text align="left" length="32"><%= p.name %></text>
+ <text align="right" length="8"><%= OB.I18N.formatCurrency(-p.amt) %></text>
+ </line>
+ <%
+ }
+ });
+ }
+ }
+ %>
+ <%if(!order.get('priceIncludesTax')){%>
+ <line>
+ <text align ="left" length="21"><%= OB.I18N.getLabel('OBPOS_LblTotalTax') %></text>
+ <text align ="right" length="5"></text>
+ <text align ="right" length="8"></text>
+ <text align ="right" length="8"><%= OB.I18N.formatCurrency(OB.DEC.sub(order.getGross() , order.getNet())) %></text>
+ </line>
+ <%}%>
+ <line></line>
+ <line size="1">
+ <text align ="left" length="25"><%=OB.I18N.getLabel('OBPOS_ReceiptTotal') + ' ' + order.get('currency' + OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER) %></text>
+ <text align ="right" length="14"><%= order.printGross() %></text>
+ </line>
+ <%
+ var payments = order.get('payments');
+ for (var i = 0; i < payments.length; i++) {
+ if(payments.at(i).get('rate') && payments.at(i).get('rate')!=='1'){
+ %>
+ <line>
+ <text align="left" length="15"><%= payments.at(i).get('name') %></text>
+ <text align="right" length="12"><%= '('+OB.I18N.formatCurrency(payments.at(i).get('amount'))+' '+payments.at(i).get('isocode')+')' %></text>
+ <text align="right" length="13"><%= OB.I18N.formatCurrency(payments.at(i).get('origAmount')) %></text>
+ </line>
+ <%
+ }else {
+ %>
+ <line>
+ <text align="left" length="20"><%= payments.at(i).get('name') %></text>
+ <text align="right" length="20"><%= OB.I18N.formatCurrency(payments.at(i).get('amount')) %></text>
+ </line>
+ <%
+ }
+ if (payments.at(i).get('gatewayData')) {
+ var pinfo = payments.at(i).get('gatewayData');
+ %>
+ <line>
+ <text align="left" length="2"></text>
+ <text align="left" length="20"><%= OB.I18N.getLabel('OBPOS_PaymentTran') %></text>
+ <text align="left" length="20"><%= pinfo.transaction %></text>
+ </line>
+ <line>
+ <text align="left" length="2"></text>
+ <text align="left" length="20"><%= OB.I18N.getLabel('OBPOS_PaymentApproval') %></text>
+ <text align="left" length="20"><%= pinfo.authorization %></text>
+ </line>
+ <% if (pinfo.cardmasked) { %>
+ <line>
+ <text align="left" length="2"></text>
+ <text align="left" length="20"><%= OB.I18N.getLabel('OBPOS_PaymentAct') %></text>
+ <text align="left" length="20"><%= pinfo.cardmasked %></text>
+ </line>
+ <% } %>
+ <% if (pinfo.cardlogo) { %>
+ <line>
+ <text align="left" length="2"></text>
+ <text align="left" length="20"><%= OB.I18N.getLabel('OBPOS_PaymentLogo') %></text>
+ <text align="left" length="20"><%= pinfo.cardlogo %></text>
+ </line>
+ <% } %>
+
+ <%
+ }
+ }
+ %>
+ <line>
+ <text align="left" length="20"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_ticketChange')) %></text>
+ <text align="right" length="20"><%= OB.I18N.formatCurrency(order.get('change'))%></text>
+ </line>
+ <line></line>
+ <line size="1">
+ <% if (order.get('hasbeenpaid') === 'Y') { %>
+ <% if (order.get('paidOnCredit')){ %>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_paidOnCredit')) %></text>
+ <% } else if (order.getGross() < 0){ %>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_paidReturn')) %></text>
+ <% } else { %>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tckfooter_line1')) %></text>
+ <% } %>
+ <% } else { %>
+ <% if (order.getGross() < 0){ %>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_ReturnDraft')) %></text>
+ <% } else { %>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tckfooter_draft')) %></text>
+ <% } %>
+ <% } %>
+ </line>
+ <line>
+ <text align="center" length="42"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tckfooter_line2'))%></text>
+ </line>
+ <line></line>
+ <line>
+ <text align ="left" length="12"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tck_breakdown'))%></text>
+ <text align ="left" length="12"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tck_base'))%></text>
+ <text align ="left" length="12"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_tck_TAX'))%></text>
+ </line>
+ <line>
+ <text>------------------------------------------</text>
+ </line>
+ <%
+ var totAmount = 0;
+ var taxes = order.get('taxes');
+ taxes = _.sortBy(taxes, function(tax){
+ return tax.name;
+ });
+ for (var t in taxes) {
+ totAmount += taxes[t].amount;
+ %>
+ <line>
+ <text align ="left" length="12"><%= OB.I18N.formatRate(taxes[t].rate) %></text>
+ <text align ="left" length="12"><%= OB.I18N.formatCurrency(taxes[t].net) %></text>
+ <text align ="left" length="12"><%= OB.I18N.formatCurrency(taxes[t].amount) %></text>
+ </line>
+ <%
+ }
+ %>
+ <line>
+ <text>------------------------------------------</text>
+ </line>
+ <line>
+ <text align ="left" length="24"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_display_total'))%></text>
+ <text align ="left" length="12"><%= OB.I18N.formatCurrency(totAmount) %></text>
+ </line>
+
+ <line>
+ <barcode type="CODE128" position="left"><%= OB.UTIL.encodeXMLComponent(order.get('documentNo')) %></barcode>
+ </line>
+
+ </ticket>
+
+ <display>
+ <line>
+ <text align="left" length="10"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_display_total'))%></text>
+ <text align="right" length="10"><%= order.printGross() %></text>
+ </line>
+ <line>
+ <text align="center" length="20"><%= OB.UTIL.encodeXMLComponent(OB.I18N.getLabel('OBPOS_thankyou'))%></text>
+ </line>
+ </display>
+
+</output>
+
+
+
+
+<% } %>
\ No newline at end of file
diff --git a/web/org.openbravo.retail.posterminal/res/proofofconceptreport.jrxml b/web/org.openbravo.retail.posterminal/res/proofofconceptreport.jrxml
new file mode 100644
--- /dev/null
+++ b/web/org.openbravo.retail.posterminal/res/proofofconceptreport.jrxml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="proofofconceptreport" language="java" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
+ <property name="ireport.zoom" value="1.0"/>
+ <property name="ireport.x" value="0"/>
+ <property name="ireport.y" value="0"/>
+ <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
+ <defaultValueExpression><![CDATA["/home/adrian/workspace/pipg/pi-retail/modules/org.openbravo.retail.posterminal/web/org.openbravo.retail.posterminal/res/"]]></defaultValueExpression>
+ </parameter>
+ <background>
+ <band splitType="Stretch"/>
+ </background>
+ <title>
+ <band height="79" splitType="Stretch">
+ <staticText>
+ <reportElement x="230" y="50" width="100" height="20"/>
+ <textElement/>
+ <text><![CDATA[Main report]]></text>
+ </staticText>
+ </band>
+ </title>
+ <pageHeader>
+ <band height="35" splitType="Stretch"/>
+ </pageHeader>
+ <columnHeader>
+ <band height="61" splitType="Stretch"/>
+ </columnHeader>
+ <detail>
+ <band height="125" splitType="Stretch">
+ <subreport>
+ <reportElement x="40" y="0" width="200" height="100"/>
+ <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
+ <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "proofofconceptreport_subreport1.jasper"]]></subreportExpression>
+ </subreport>
+ <subreport>
+ <reportElement x="267" y="0" width="200" height="100"/>
+ <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
+ <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "proofofconceptreport_subreport2.jasper"]]></subreportExpression>
+ </subreport>
+ </band>
+ </detail>
+ <columnFooter>
+ <band height="45" splitType="Stretch"/>
+ </columnFooter>
+ <pageFooter>
+ <band height="54" splitType="Stretch"/>
+ </pageFooter>
+ <summary>
+ <band height="42" splitType="Stretch"/>
+ </summary>
+</jasperReport>
diff --git a/web/org.openbravo.retail.posterminal/res/proofofconceptreport_subreport1.jrxml b/web/org.openbravo.retail.posterminal/res/proofofconceptreport_subreport1.jrxml
new file mode 100644
--- /dev/null
+++ b/web/org.openbravo.retail.posterminal/res/proofofconceptreport_subreport1.jrxml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="proofofconceptreport_subreport1" language="java" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
+ <property name="ireport.zoom" value="1.0"/>
+ <property name="ireport.x" value="0"/>
+ <property name="ireport.y" value="0"/>
+ <background>
+ <band splitType="Stretch"/>
+ </background>
+ <title>
+ <band height="79" splitType="Stretch">
+ <staticText>
+ <reportElement x="334" y="35" width="100" height="20"/>
+ <textElement/>
+ <text><![CDATA[Subreport1]]></text>
+ </staticText>
+ </band>
+ </title>
+ <pageHeader>
+ <band height="35" splitType="Stretch"/>
+ </pageHeader>
+ <columnHeader>
+ <band height="61" splitType="Stretch"/>
+ </columnHeader>
+ <detail>
+ <band height="125" splitType="Stretch"/>
+ </detail>
+ <columnFooter>
+ <band height="45" splitType="Stretch"/>
+ </columnFooter>
+ <pageFooter>
+ <band height="54" splitType="Stretch"/>
+ </pageFooter>
+ <summary>
+ <band height="42" splitType="Stretch"/>
+ </summary>
+</jasperReport>
diff --git a/web/org.openbravo.retail.posterminal/res/proofofconceptreport_subreport2.jrxml b/web/org.openbravo.retail.posterminal/res/proofofconceptreport_subreport2.jrxml
new file mode 100644
--- /dev/null
+++ b/web/org.openbravo.retail.posterminal/res/proofofconceptreport_subreport2.jrxml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="proofofconceptreport_subreport2" language="java" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
+ <property name="ireport.zoom" value="1.0"/>
+ <property name="ireport.x" value="0"/>
+ <property name="ireport.y" value="0"/>
+ <background>
+ <band splitType="Stretch"/>
+ </background>
+ <title>
+ <band height="79" splitType="Stretch">
+ <staticText>
+ <reportElement x="324" y="25" width="100" height="20"/>
+ <textElement/>
+ <text><![CDATA[Subreport2]]></text>
+ </staticText>
+ </band>
+ </title>
+ <pageHeader>
+ <band height="35" splitType="Stretch"/>
+ </pageHeader>
+ <columnHeader>
+ <band height="61" splitType="Stretch"/>
+ </columnHeader>
+ <detail>
+ <band height="125" splitType="Stretch"/>
+ </detail>
+ <columnFooter>
+ <band height="45" splitType="Stretch"/>
+ </columnFooter>
+ <pageFooter>
+ <band height="54" splitType="Stretch"/>
+ </pageFooter>
+ <summary>
+ <band height="42" splitType="Stretch"/>
+ </summary>
+</jasperReport>
unittests-issue-31395.diff [^] (8,132 bytes) 2016-01-22 11:55 [Show Content] [Hide Content]diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/AllPrintingTests.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/AllPrintingTests.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/AllPrintingTests.java
@@ -0,0 +1,64 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2016 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.printing;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.junit.runner.RunWith;
+import org.openbravo.test.mobile.common.selenium.toolbox.SuiteClassesToolbox;
+import org.openbravo.test.mobile.common.selenium.toolbox.WildcardPatternSuite;
+
+@RunWith(WildcardPatternSuite.class)
+@SuiteClassesToolbox()
+public class AllPrintingTests {
+
+ public static String readFile(Reader reader) throws IOException {
+
+ BufferedReader r = null;
+ try {
+ r = new BufferedReader(reader);
+ int nRead;
+ char[] data = new char[16384];
+ StringBuilder s = new StringBuilder();
+
+ while ((nRead = r.read(data, 0, data.length)) != -1) {
+ s.append(data, 0, nRead);
+ }
+
+ return s.toString();
+ } finally {
+ if (r != null) {
+ r.close();
+ }
+ }
+ }
+
+ public static String readFile(String file) throws IOException {
+ return readFile(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+ }
+
+ public static String readResource(String res) throws IOException {
+ return readFile(new InputStreamReader(AllPrintingTests.class.getResourceAsStream(res), "UTF-8"));
+ }
+}
diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/Feature31395_UnitTestsPrinting.java b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/Feature31395_UnitTestsPrinting.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/Feature31395_UnitTestsPrinting.java
@@ -0,0 +1,35 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2016 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.printing;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+
+public class Feature31395_UnitTestsPrinting extends WebPOSTerminalHelper {
+
+ @Test
+ // @TestAnnotations(from = "RR16Q2", waitFixOf = 31395)
+ public void testJRXMLHardwareManager() throws IOException {
+ SeleniumHelper.executeScript(AllPrintingTests.readResource("testJRXMLHardwareManager.js"));
+ }
+}
diff --git a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/testJRXMLHardwareManager.js b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/testJRXMLHardwareManager.js
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/printing/testJRXMLHardwareManager.js
@@ -0,0 +1,99 @@
+/**
+ *
+ */
+
+// alert('esto es una segunda mierda');
+
+
+(function () {
+
+ // Classic inherit
+ function inherit(proto) {
+ function F() {}
+ F.prototype = proto;
+ return new F;
+ }
+
+ //
+ // MOCKHWServer inherits OB.DS.HWServer
+ //
+ function MOCKHWServer () {}
+
+ MOCKHWServer.prototype = inherit(OB.DS.HWServer.prototype);
+
+ MOCKHWServer.prototype._send = function (data, callback) {
+ this.assert('XML', this.func);
+ this.assert(this.expects, data);
+ };
+
+ MOCKHWServer.prototype._sendPDF = function (data, callback) {
+ this.assert('PDF', this.func);
+ this.assert(this.expects, data);
+ };
+
+ MOCKHWServer.prototype.printExpects = function (func, expects) {
+ this.func = func;
+ this.expects = expects;
+ };
+
+ MOCKHWServer.prototype.assert = function (expectedvalue, datavalue) {
+ if (expectedvalue === datavalue) {
+ console.log('Data value was the expected value: ' + datavalue);
+ } else {
+ var asserterror = 'Error: Expected: ' + expectedvalue + '\n'
+ + 'But was: ' + datavalue;
+ console.error(asserterror);
+ throw new Error(assertError);
+ }
+ };
+
+ //
+ // Test 1 go to xml
+ //
+ (function testPrintXML () {
+
+ var xmltemplate = 'xmltemplate *<%= order.documentNo %>*';
+ var parameter = {
+ order: {
+ documentNo: '12345',
+ serializeToJSON: function () {
+ return '12345';
+ }
+ }
+ };
+ var xmltemplateexpects = 'xmltemplate *12345*';
+
+ var mymockedhwserver = new MOCKHWServer();
+ mymockedhwserver.printExpects('XML', xmltemplateexpects);
+ mymockedhwserver.print(new OB.DS.HWResource('data:text/plain,' + xmltemplate), parameter, function () {});
+ }());
+
+ //
+ // Test 2 select JRXML
+ //
+ (function testPrintJRXML () {
+
+ var jrxmltemplate = 'jrxml:{ \
+ "printer": 2, \
+ "report": "data:text/plain,reportdata", \
+ "subreports": [ \
+ "data:text/plain,subreport1data", \
+ "data:text/plain,subreport2data" \
+ ] \
+ }';
+ var parameter = {
+ order: {
+ documentNo: '12345',
+ serializeToJSON: function () {
+ return '12345';
+ }
+ }
+ };
+ var jrxmltemplateexpected ='{"param":"12345","mainReport":{"resource":"data:text/plain,reportdata","resourcedata":"reportdata","ispdf":true,"printer":2,"dateFormat":"dd-MM-yyyy","subreports":[{"resource":"data:text/plain,subreport1data","resourcedata":"subreport1data"},{"resource":"data:text/plain,subreport2data","resourcedata":"subreport2data"}]},"subReports":[{"resource":"data:text/plain,subreport1data","resourcedata":"subreport1data"},{"resource":"data:text/plain,subreport2data","resourcedata":"subreport2data"}]}';
+
+ var mymockedhwserver = new MOCKHWServer();
+ mymockedhwserver.printExpects('PDF', jrxmltemplateexpected);
+ mymockedhwserver.print(new OB.DS.HWResource('data:text/plain,' + jrxmltemplate), parameter, function () {});
+ }());
+
+}());
\ No newline at end of file
|