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\tSee Report editor help documentation for details
\n\n\t{{#each ayReportData}}\n\t