Commit e687ff38 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_printer: improve epson printer

1. update erp5_epson_canvas_printout.js&SaleOrder_viewEpsonPrintout.zpt with production
2. fix erp5_epson_canvas_printout.js doesn't work for discount
3  make it works in renderjs ui
parent 2e35011c
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_onlyjio_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_onlyjio_action</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>print_by_epson</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>Modify portal content</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>8.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Print By Epson</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/SaleOrder_viewPrintByEpsonDialog</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
.epson h2#invoice_title {
font-size: 1.5em;
margin-block-start: 0.83em;
margin-block-end: 0.83em;
margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
.epson table tr th {
font-weight: bold;
}
.epson table {
border-collapse: separate;
border-spacing: 2px;
}
.epson table tr th,
.epson table tr td {
padding: 1px;
}
.epson #print_button,
.epson .confirm_return{
padding: 6pt;
margin-top: 30pt;
margin-right: 12pt;
background-color: #FF6600;
color: #FFFFFF;
border-radius: 0.325em;
border-width: 1px;
border-style: solid;
border-color: #FF6600;
min-width: 8em;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.epson #print_button:hover,
.epson .confirm_return:hover,
.epson #print_button:focus,
.epson .confirm_return:focus{
background-color: #ff8533;
}
.epson .cancel_return{
background-color: #2FA2E4;
color: white;
padding: 6pt;
margin-top: 30pt;
margin-right: 12pt;
border-radius: 0.325em;
border-width: 1px;
border-style: solid;
border-color: #767676;
min-width: 8em;
box-shadow: 0 2px 4px rgb(47, 162, 228);
}
.epson .cancel_return:hover,
.epson .cancel_return:focus{
background-color: #46ade8;
}
.epson .footer_button button:not(:first-child) {
margin-left: 50px;
}
<html>
<head>
<!--
data-i18n=Receipt
data-i18n=Order Number
data-i18n=Document Date
data-i18n=Currency
data-i18n=Products details
data-i18n=PROD
data-i18n=QTY
data-i18n=PRICE
data-i18n=Total Including Tax
data-i18n=Discount
data-i18n=Total With Discount
data-i18n=Print by Epson
data-i18n=Confirm Order and Return
data-i18n=Cancel Order and Return
data-i18n=Products details
data-i18n=Order Information
data-i18n=Payment
data-i18n=Delivery Mode
-->
<meta charset="utf-8">
<script type="text/javascript" src="jquery.js" ></script>
<script type="text/javascript" src="epos-print-4.1.0.js"></script>
<script type="text/javascript" src= "erp5_epson_canvas_printout.js"></script>
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script type="text/javascript" src="gadget_global.js"></script>
<script type="text/javascript" src="handlebars.js"></script>
<link rel="stylesheet" type="text/css" href="erp5_epson_gadget.css">
<script id="epson-print-template" type="text/x-handlebars-template">
<header>
<h2 id="invoice_title">
<span>{{Receipt}}</span>
</h2>
<div>
<canvas id="canvas" width="512" style="display:none;" height="480"></canvas>
<img id="company_logo" alt="" src="{{source_section_image_absolute_url}}?quality=75.0&display=small&format=png" width="250" height="45">
</div>
<div id="company-info">
<div style="font-weight:bold">{{source_title}}</div>
<div>{{source_section_registeredcapital}}</div>
<div>{{source_address}}</div>
<div>{{source_telfax}}</div>
<div>{{source_email}}</div>
<div>{{source_section_corporateregcode}}</div>
<div>{{source_vatid}}</div>
<div>
</header>
<br>
<article>
<div id="detail">
<br>
<div id="invoice_information">
<div id="invoice_information_title">
<span style="font-weight:bold">{{Order_Information}}</span>
</div>
<div id="invoice_information_detail">
<div>
<span>{{Order_Number}}:</span>
<span>{{reference}}</span>
</div>
<div>
<span>{{Document_Date}}:</span>
<span>{{start_date}}</span>
</div>
<div>
<span>{{Currency}}:</span>
<span>{{currency}}</span>
</div>
{{#if payment_condition}}
<div>
<span>{{Payment}}:</span>
<span>{{payment_condition}}</span>
</div>
{{/if}}
{{#if delivery_mode}}
<div>
<span>{{Delivery_Mode}}:</span>
<span>{{delivery}}</span>
</div>
{{/if}}
</div>
</div>
</div>
<br>
<div id="product_detail_title">
<span style="font-weight:bold">{{Products_details}}</span>
</div>
<table id="invoice_line">
<thead>
<tr>
<th>
<span>{{PROD}}</span>
</th>
<th>
<span>{{QTY}}</span>
</th>
<th>
<span>{{PRICE}}</span>
</th>
</tr>
</thead>
<tbody>
{{#each line_not_tax}}
<tr>
<td><span>{{resource_title}}</span></td>
<td><span>{{total_quantity}}</span></td>
<td><span>{{total_price}}</span></td>
</tr>
{{/each}}
</tbody>
</table>
<br>
<table id="total_price">
<tr>
<th>
<span>{{Total_Including_Tax}}:</span>
</th>
<td>
<span>{{total_price}}</span>
</td>
</tr>
</table>
{{#if total_discount}}
<table id="total_discount">
<tr>
<th>
<span>{{Discount}}:</span>
</th>
<td>
<span>{{total_discount}}</span>
</td>
</tr>
</table>
<table id="total_price_with_discount">
<tr>
<th>
<span>{{Total_With_Discount}}:</span>
</th>
<td>
<span>{{total_price_with_discount}}</span>
</td>
</tr>
</table>
{{/if}}
<br />
<br />
<br />
<div id="loyalty_information_image" style="width:350px;text-align:center;">
<canvas id="ordernumbercanvas" width="512" style="display:none;" height="480"></canvas>
<img id="order_barcode" width="250" height="45" src="Base_generateBarcodeImage?barcode_type=code128&data={{reference}}">
<br />
<span id="order_number">{{reference}}</span>
</div>
<br />
<br>
<br>
</article>
<footer>Generated with ERP5 <br /> Open Source ERP suite (www.erp5.com)</footer>
<div class="footer_button">
<button id="print_button"><span>{{Print_by_Epson}}</span></button>
<button class="confirm_return" type="submit" value="SaleOrder_confirmAndReturn">
<span>{{Confirm_Order_and_Return}}</span>
</button>
<button class="cancel_return" type="submit" value="SaleOrder_cancelAndReturn">
<span>{{Cancel_Order_and_Return}}</span>
</button>
</div>
<hr>
<div id="js_error_log"> </div>
</script>
<script type="text/javascript" src="erp5_epson_gadget.js" ></script>
<link rel="license" href="http://www.opensource.org/licenses/mit-license/">
</head>
<body>
<form class='epson container' style="background:white; font-size: larger;">
</form>
</body>
</html>
\ No newline at end of file
/*global window, rJS, document*/
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, document, Handlebars, RSVP) {
"use strict";
var gadget_klass = rJS(window),
epson_print_source = gadget_klass.__template_element
.getElementById("epson-print-template")
.innerHTML,
epson_print_template = Handlebars.compile(epson_print_source);
gadget_klass
.declareAcquiredMethod("submitContent", "submitContent")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getTranslationList", "getTranslationList")
.declareMethod("render", function (options) {
var gadget = this,
data_dict = options.data_dict,
translation_list = [
'Receipt',
'Order Number',
'Document Date',
'Currency',
'Products details',
'PROD',
'QTY',
'PRICE',
'Total Including Tax',
'Discount',
'Total With Discount',
'Print by Epson',
'Confirm Order and Return',
'Cancel Order and Return',
'Products details',
'Order Information',
'Payment',
'Delivery Mode'
];
gadget.state.jio_key = options.jio_key;
gadget.state.printer_url = options.printer_url;
return new RSVP.Queue()
.push(function (hateoas_url) {
return RSVP.all([
gadget.getSetting('hateoas_url'),
gadget.getTranslationList(translation_list)
]);
})
.push(function (result_list) {
var index;
gadget.state.hateoas_url = result_list[0];
for (index = 0; index < translation_list.length; index += 1) {
data_dict[translation_list[index].replace(/ /g, '_')] = result_list[1][index];
}
// example: sale_order_module/359/1, total price is 2427.3, but Order_getODTDataDict return 2427.2999999999997
for (index = 0; index < data_dict.line_not_tax.length; index += 1) {
data_dict.line_not_tax[index].total_price = Math.round(data_dict.line_not_tax[index].total_price * 100) / 100;
}
//example: sale_order_module/356, total price is 30464.8, but return 30464.79999999999
data_dict.total_price_with_discount = Math.round(data_dict.total_price_with_discount * 100) / 100;
data_dict.total_price = Math.round(data_dict.total_price * 100) / 100;
gadget.element.querySelector('.container').innerHTML = epson_print_template(data_dict);
// enable monitoring
window.monitoring_enabled = 0;
gadget.listenToPrintButton();
});
})
.declareJob("listenToPrintButton", function () {
var gadget = this,
print_button = this.element.querySelector('#print_button');
return new RSVP.Queue()
.push(function () {
return RSVP.all([
promiseEventListener(gadget.element.querySelector('#company_logo'), 'load', false),
promiseEventListener(gadget.element.querySelector('#order_barcode'), 'load', false)
]);
})
.push(function () {
printInvoiceOnEpson(gadget.state.printer_url);
return loopEventListener(
print_button,
'click',
false,
function () {
printInvoiceOnEpson(gadget.state.printer_url);
});
});
})
.onEvent('submit', function submit(options) {
var method = document.activeElement.value,
gadget = this;
return gadget.submitContent(
gadget.state.jio_key,
gadget.state.hateoas_url + gadget.state.jio_key + "/" + method,
{})
.push(function (result) {
return gadget.redirect({
command: 'display',
options: {
"jio_key": result.jio_key,
"view": result.view
}
});
})
.push(undefined, function(error) {
if (! error instanceof RSVP.CancellationError) {
throw error;
}
});
});
}(window, rJS, document, Handlebars, RSVP));
<registered_skin_selection>
<skin_folder_selection>
<skin_folder>erp5_printer</skin_folder>
<skin_selection>View</skin_selection>
<skin_selection>Hal,HalRestricted,RJS,View</skin_selection>
</skin_folder_selection>
</registered_skin_selection>
\ No newline at end of file
<!doctype html>
<html tal:define="data_dict here/Order_getODTDataDict;
<html tal:define="dummy_variable python:context.REQUEST.response.setHeader('Access-Control-Allow-Origin', '*');
data_dict here/Order_getODTDataDict;
portal_url here/portal_url;
reservation python: request.get('reservation_only');
form_id python: request.get('form_id');
......@@ -8,7 +9,7 @@
price_renderer nocall:here/Base_viewTradeFieldLibrary_printer_custom/my_view_mode_total_price/render_pdf;
default_language python:test(request.get('international_form'), 'en', here.Localizer.get_selected_language());
printer_url python:context.SaleOrder_getPrinterUrl();
order_number python:data_dict['reference'];">
order_number python:data_dict['reference']; ">
<head>
<meta charset="utf-8">
<title>Receipt</title>
......@@ -28,7 +29,7 @@
</span>
</h2>
<div tal:define="logo_path python: '%s?display=default_image?pre_converted_only=True&quality=75.0&display=thumbnail&format=png' % data_dict['source_section_image_path'];">
<div tal:define="logo_path python: '%s?quality=75.0&display=small&format=png' % data_dict['source_section_image_absolute_url'];">
<canvas id="canvas" width="512" style="display:none;" height="480"></canvas>
<img id="company_logo" alt="" tal:attributes="src logo_path;" width="250" height="45">
</div>
......@@ -268,7 +269,7 @@
<br />
<br />
<div id="loyalty_information_header" style="width:350px;text-align:center;"
tal:condition="order_number">
tal:condition="python: False # order_number">
<span> Programme de fidélité </span> <br />
<span> www.weinparis.com/loyalty </span>
</div>
......@@ -283,7 +284,7 @@
</div>
<br />
<div id="loyalty_information_bottom" style="width:350px;text-align:center;"
tal:condition="order_number">
tal:condition="python: False # order_number">
<span>en vous inscrivant, bénéficiez de 12% de</span>
<br />
<span>réduction sur votre prochain achat</span>
......@@ -298,7 +299,7 @@
<br>
</article>
<footer>Generated with ERP5 <br /> Open Source ERP suite (www.erp5.com)</footer>
<button tal:condition="python: not request.get('preview_only', 0)"
<button i18n:translate="" i18n:domain="ui" tal:condition="python: not request.get('preview_only', 0)"
id="print_button"
tal:attributes="onclick python:'printInvoiceOnEpson(\'%s\')' % printer_url"
onclick='printInvoiceOnEpson()'>Print by Epson</button>
......@@ -310,18 +311,24 @@
})
</script>
<a tal:condition="python: not reservation" href="./SaleOrder_confirmAndReturn">
<span i18n:translate='' i18n:domain=''> Confirm Order and Return </span>
<span i18n:translate='' i18n:domain='ui'>Confirm Order and Return </span>
</a>
<a tal:condition="reservation" href="./SaleOrderModule_viewReservedItemFastInputDialog">
<span i18n:translate='' i18n:domain=''> Return </span>
</a>
<a style="float:right" tal:attributes="href python:'./SaleOrder_cancelAndReturn?reservation=%s' % reservation">
<span i18n:translate='' i18n:domain=''> Cancel Order and Return</span>
<span i18n:translate='' i18n:domain='ui'>Return</span>
</a>
<div style="float:right">
<a tal:attributes="href python:'./SaleOrder_cancelAndReturn?reservation=%s' % reservation">
<span i18n:translate='' i18n:domain='ui'>Cancel Order and Return</span>
</a>
<br/>
<a href="./" target="_blank" tal:condition="nothing">
<span i18n:translate='' i18n:domain='ui'>Edit Order</span>
</a>
</div>
</tal:block>
<tal:block tal:condition="python: form_id and not request.get('auto_print', 0)">
<a tal:attributes="href string:./${form_id}">
<span i18n:translate='' i18n:domain=''> Return </span>
<a tal:attributes="href string:./${form_id}">
<span i18n:translate='' i18n:domain='ui'>Return</span>
</a>
</tal:block>
<tal:block tal:condition="python: request.get('js_error_log', 1)">
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>action_title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>preview</string>
</list>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SaleOrder_viewPrintByEpsonDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>SaleOrder_viewEpsonPrintoutWrapper</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_view</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
url_list = [
"renderjs.js",
"rsvp.js",
"jiodev.js",
"jquery.js",
"epos-print-4.1.0.js",
"erp5_epson_canvas_printout.js",
"erp5_epson_gadget.js",
"erp5_epson_gadget.html",
"erp5_epson_gadget.css",
"gadget_global.js",
"handlebars.js",
"erp5_epson_printout.js"
]
return url_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSection_getEpsonPrecacheManifestList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -138,8 +138,9 @@ function draw(canvas) {
});
addFeed();
if ($("#total_discount").length > 0) {
builder.addText(context, $.trim($("#total_discount tr th").text()), {x:130});
addText(context, $.trim($("#total_discount tr th").text()), {x:130});
priceControl(context, $.trim($("#total_discount tr td").text()), {x:385});
addFeed();
......@@ -207,66 +208,78 @@ function enableEpsonMonitoring(printer_url){
msg = "ERROR: Unable to connect to the printer at the URL (Unreachable or Power off): " + monitoting_epos.address
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
}
monitoting_epos.onoffline = function () {
msg = "ERROR: Printer seems offline check if you can access printer at the URL (Unreachable or Power off): " + monitoting_epos.address
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
}
monitoting_epos.online = function () {
msg = "INFO: Printer is online at" + monitoting_epos.address
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close()
}
monitoting_epos.onpaperend = function () {
msg = "WARNNING: Printer report that paper is finished!"
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.onpapernearend = function () {
msg = "WARNNING: Printer report that paper is near finished from finish!"
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.onpaperok = function () {
msg = "INFO: Printer report that paper is OK."
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.ondrawerclosed = function () {
msg = "INFO: Printer report that drawer is closed."
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.ondraweropen = function () {
msg = "INFO: Printer report that drawer is open."
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.oncoveropen = function () {
msg = "WARNNING: Printer report that cover is open! Please close it!"
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.oncoverok = function () {
msg = "INFO: Printer cover is closed."
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.onstatuschange = function (status) {
msg = "INFO: Printer changed status to :" + status;
$("#js_error_log").append("<div>" + msg + "</div>");
console.log(msg);
monitoting_epos.close();
};
monitoting_epos.open();
......
erp5_jquery
erp5_trade
erp5_accounting
\ No newline at end of file
erp5_accounting
erp5_web
erp5_web_renderjs_ui
\ No newline at end of file
Sale Order | order_epson_print
\ No newline at end of file
Sale Order | order_epson_print
Sale Order | print_by_epson
\ No newline at end of file
web_page_module/gadget_epson_printer_html
web_page_module/gadget_epson_printer_js
web_page_module/gadget_epson_printer_css
\ No newline at end of file
web_page_module/gadget_epson_printer_css
web_page_module/gadget_epson_printer_html
web_page_module/gadget_epson_printer_js
\ No newline at end of file
erp5_printer | Hal
erp5_printer | HalRestricted
erp5_printer | RJS
erp5_printer | View
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment