Skip to content

Commit

Permalink
v7.1.1: Fix bug with tax calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-mous committed Jan 18, 2021
1 parent 3fcdafd commit e29650f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions PrinterPiExtension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 26 additions & 7 deletions PrinterPiExtension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
});
Expand Down
2 changes: 1 addition & 1 deletion PrinterPiExtension/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PrinterPiExtension/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit e29650f

Please sign in to comment.