From e29650f47617247235c7cc42fcced74c0a988f62 Mon Sep 17 00:00:00 2001 From: Alex Mous <48971842+polarpiberry@users.noreply.github.com> Date: Sun, 17 Jan 2021 23:42:33 -0800 Subject: [PATCH] v7.1.1: Fix bug with tax calculations --- PrinterPiExtension/CHANGELOG.md | 9 ++++++++ PrinterPiExtension/js/background.js | 33 +++++++++++++++++++++++------ PrinterPiExtension/js/main.js | 2 +- PrinterPiExtension/manifest.json | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 PrinterPiExtension/CHANGELOG.md diff --git a/PrinterPiExtension/CHANGELOG.md b/PrinterPiExtension/CHANGELOG.md new file mode 100644 index 0000000..7821787 --- /dev/null +++ b/PrinterPiExtension/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog +All notable changes to the PrinterPiExtension code will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [7.1.1] - 2021-01-17 +### Changed +- Fixed rounding error with tax field when on eBay Regular page (causing incorrect values to be present in resulting receipt) diff --git a/PrinterPiExtension/js/background.js b/PrinterPiExtension/js/background.js index 2538ef3..2f9c6ff 100644 --- a/PrinterPiExtension/js/background.js +++ b/PrinterPiExtension/js/background.js @@ -45,7 +45,7 @@ to: address, shipping: shipping, subtotal: itemTotal, - tax: grandTotal-(shipping+itemTotal), + tax: Math.round((grandTotal-(shipping+itemTotal) + Number.EPSILON) * 100) / 100, //Ensure tax is valid (to ensure not 1e-14 or similar) items: item_arr } } @@ -95,12 +95,28 @@ let itemsArr = []; items.forEach((item) => { let itemRow = item.querySelectorAll("span"); - itemsArr.push({ - desc: itemRow[0].innerText, + let desc, priceNode, qty; + if (itemRow.length == 2) { //Single item + desc = itemRow[0].innerText; + qty = "1"; + priceNode = itemRow[1]; + } else if (itemRow.length == 3) { //Multiple items + let tmpNode = itemRow[0].firstChild; + while (tmpNode.nodeType != document.TEXT_NODE) { + tmpNode = tmpNode.nextSibling; + } + desc = tmpNode.data; + qty = parseInt(itemRow[1].innerText.match(/\d+/)?.[0]); + priceNode = itemRow[2]; + } + let itm = { + desc: desc, sku: "I", //No SKU field currently - qty: "1", //No QTY field currently - price: parseFloat(itemRow[1].innerText.replace("$", "")) - }); + qty: qty, //No QTY field currently + price: parseFloat(priceNode.innerText.replace("$", "")) + }; + console.log("[PrinterPi] Found Item: ", itm); + itemsArr.push(itm); }); let tax = 0; //No tax currently @@ -134,7 +150,7 @@ subtotal -= shipping; //Get the address - let addr = order.querySelector("#td_sellerWasShipped + *").innerText + "\n" + order.querySelector("#td_sellerWasShipped + * + * > div").innerText; //Combine the name and address + let addr = order.querySelector("#td_sellerWasShipped + *, #td_sellerShipAddress + *").innerText + "\n" + order.querySelector("#td_sellerWasShipped + * + * > div, #td_sellerShipAddress + * + * > div").innerText; //Combine the name and address ordersRes.push({ to: addr, @@ -149,18 +165,21 @@ console.log("[PrinterPi] Parsing data..."); try { //Try eBay Regular let data = parseEbayRegular(); + console.log("Data:", data); chrome.runtime.sendMessage({ orders: [data] }); } catch (errA) { try { //Otherwise, try eBay Bulk let orders = parseEbayBulk(); + console.log("Data:", orders); chrome.runtime.sendMessage({ orders: orders }); } catch (errB) { //Finally, try PayPal try { let orders = parsePayPalRegular(); + console.log("Data:", orders); chrome.runtime.sendMessage({ orders: orders }); diff --git a/PrinterPiExtension/js/main.js b/PrinterPiExtension/js/main.js index ebf29a0..4c915c6 100644 --- a/PrinterPiExtension/js/main.js +++ b/PrinterPiExtension/js/main.js @@ -282,7 +282,7 @@ let printEnvelope = (pkt) => { pdf.setLineWidth(0.5); let fromLogo = pkt.settings.fromLogo; - if (fromLogo) { //Image to add + if (fromLogo && fromLogo.height && fromLogo.width) { //Image to add if (fromLogo.height*2 > fromLogo.width) { //Height is larger than half of the width - show next to address as opposed to on top wImg = hBox * pkt.settings.fromLogo.width / pkt.settings.fromLogo.height; pdf.line(fromXY.x+wImg, fromXY.y, fromXY.x+wImg, fromXY.y+hBox); //Add line under box diff --git a/PrinterPiExtension/manifest.json b/PrinterPiExtension/manifest.json index c1b5715..59abf9e 100644 --- a/PrinterPiExtension/manifest.json +++ b/PrinterPiExtension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "PrinterPi", - "version": "7.1", + "version": "7.1.1", "description": "Parse eBay Print Shipping Label or PayPal Activity pages and send the data to an application that controls a receipt printer", "options_page": "options.html",