From 659ea0e620fd9763e70c668355d19b5226c12228 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 14 Sep 2020 22:55:17 +0000 Subject: [PATCH] --- server/AyaNova/resource/rpt/ay-report.js | 38 ++++++++++++++----- .../EXAMPLE Bar code helper.ayrt | 1 + 2 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Bar code helper.ayrt diff --git a/server/AyaNova/resource/rpt/ay-report.js b/server/AyaNova/resource/rpt/ay-report.js index a953a23e..31784b2a 100644 --- a/server/AyaNova/resource/rpt/ay-report.js +++ b/server/AyaNova/resource/rpt/ay-report.js @@ -102,22 +102,33 @@ try { } */ Handlebars.registerHelper("ayBC", function (text, options) { - // options.text=text; let canvas = document.getElementById("aybarcode"); if (canvas == null) { canvas = document.createElement("canvas"); canvas.id = "aybarcode"; } - //let canvas = document.createElement("canvas"); + let opt = JSON.parse(options); + if (text == null) { + text = ""; + } else { + text = text.toString(); + } + opt.text = text; + opt.textxalign = "center"; - let opt = { - bcid: "code128", // Barcode type - text: "0123456789", // Text to encode - scale: 3, // 3x scaling factor - height: 10, // Bar height, in millimeters - includetext: true, // Show human-readable text - textxalign: "center" // Always good to set this - }; + if (opt.pad && opt.text) { + //pad out the code by inserting leading zeros to the specified length + opt.text = ayPad(opt.text, opt.pad, 0); + } + + // let opt = { + // bcid: "code128", // Barcode type + // text: "0123456789", // Text to encode + // scale: 3, // 3x scaling factor + // height: 10, // Bar height, in millimeters + // includetext: true, // Show human-readable text + // textxalign: "center" // Always good to set this + // }; bwipjs.toCanvas(canvas, opt); var url = canvas.toDataURL("image/png"); @@ -313,3 +324,10 @@ async function ayPostToAPI(route, data, token) { throw error; } } + +//Utils +function ayPad(n, width, z) { + z = z || "0"; + n = n + ""; + return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; +} diff --git a/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Bar code helper.ayrt b/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Bar code helper.ayrt new file mode 100644 index 00000000..fa51b45a --- /dev/null +++ b/server/AyaNova/resource/rpt/stock-report-templates/EXAMPLE Bar code helper.ayrt @@ -0,0 +1 @@ +{"Name":"EXAMPLE Bar code helper","Active":true,"Notes":"","Roles":124927,"ObjectType":2,"Template":"\n\n\n\t

Example: Bar code helper

\n\t

See Report editor help documentation for details

\n\n\t{{#each ayReportData}}\n\t

{{ Name }}

\n\t
\n\t\tSerial as \"CODE-128\" BarCode:
\n\t\t{{ ayBC Serial '{ \"bcid\": \"code128\",\"includetext\":true, \"scale\":1}' }}\n\t
\n\t
\n\t
\n\t\tSerial as \"QR\" Code:
\n\t\t{{ ayBC Serial '{ \"bcid\": \"qrcode\",\"includetext\":true, \"scale\":3}' }}\n\t
\n\t
\n\t
\n\t\tSample \"UPC-A\" Code (Serial wouldn't be a valid UPC code so hard coded here):
\n\t\t{{ ayBC \"712345678904\" '{ \"bcid\": \"upca\",\"includetext\":true, \"scale\":1}' }}\n\t
\n\t
\n\t
\n\t
\n\t{{/each}}\n\n\n","Style":".example {\n color: blue;\n}","JsPrerender":"async function ayPrepareData(reportData){ \n //this function (if present) is called with the report data \n //before the report is rendered\n //modify data as required here and return it to change the data before the report renders\n //see the help documentation for details\n return reportData;\n}","JsHelpers":"//Register custom Handlebars helpers here to use in your report script\n//https://handlebarsjs.com/guide/#custom-helpers\nHandlebars.registerHelper('loud', function (aString) {\n return aString.toUpperCase()\n})","RenderType":0} \ No newline at end of file