From fe09f7ddaf2c9c57b399f192c8f73015be873c67 Mon Sep 17 00:00:00 2001 From: Alex Mous <48971842+polarpiberry@users.noreply.github.com> Date: Sun, 1 Nov 2020 11:41:24 -0800 Subject: [PATCH] V6.0: Add support for tax --- PrinterPiExtension/js/background.js | 17 +++++++++++---- PrinterPiExtension/js/main.js | 34 ++++++++++++++++++++++------- PrinterPiExtension/main.html | 4 +++- PrinterPiExtension/manifest.json | 2 +- PrinterPiExtension/options.html | 2 ++ PrinterPiServer/CHANGELOG.md | 16 ++++++++++++++ PrinterPiServer/Packet.java | 1 + PrinterPiServer/Printer.java | 6 +++++ PrinterPiServer/PrinterServer.java | 5 ++++- 9 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 PrinterPiServer/CHANGELOG.md diff --git a/PrinterPiExtension/js/background.js b/PrinterPiExtension/js/background.js index 7ae93ec..53c9f0c 100644 --- a/PrinterPiExtension/js/background.js +++ b/PrinterPiExtension/js/background.js @@ -19,23 +19,29 @@ try { //Try eBay let address = document.querySelector("#shipToAddress").innerText; - let shipping = document.querySelectorAll(".BuyerPurchaseDetails--1nhS6")[3].children[1].innerText; - let total = document.querySelectorAll(".BuyerPurchaseDetails--1nhS6")[2].children[1].innerText; + let shipping = document.querySelectorAll(".BuyerPurchaseDetails--1nhS6")[3].children[1].innerText; + shipping = parseFloat(shipping.substring(shipping.indexOf("$")+1)); //Shipping as a float + let grandTotal = document.querySelectorAll(".BuyerPurchaseDetails--1nhS6")[2].children[1].innerText; //Shipping+items+tax + grandTotal = parseFloat(grandTotal.substring(grandTotal.indexOf("$")+1)); + let itemTotal = 0; //Total cost of items let items = document.querySelectorAll(".PurchasedItem---CkHb"); let item_arr = []; for (let i=0; i} items Items purchased * @property {Settings} settings User settings as defined above @@ -63,7 +64,7 @@ * @param {string} resError Response error (if any) */ - +const VERSION_NO = 6.0; //Current version /* Data format to send to PrinterPi (NOTE: item descs and skus MUST NOT CONTAIN ~ and NO EXTRA SPACES ARE ALLOWED before/after parameters): @@ -71,6 +72,7 @@ To: Line1/n/Line2/n/Line3 From: Line1/n/Line2/n/Line3 Subtotal: $5.00 + Tax: $0.00 Shipping: $3.00 SaveFile: 1 Item: Item_1~I123~1~$1.00 @@ -144,8 +146,9 @@ let convertToMessage = (pkt) => { To: Line1/n/Line2/n/Line3 From: Line1/n/Line2/n/Line3 - Subtotal: $5.00 - Shipping: $3.00 + Subtotal: $2.00 + Tax: $1.00 + Shipping: $1.00 Item: Item_1~I123~1~$1.00 Item: Item 2, And 3~I32-+A5~44~$1.00 Message: Contact me at eikyutsuho@gmail.com if you have any questions/concerns/n/Thank you for your business! @@ -155,6 +158,7 @@ let convertToMessage = (pkt) => { msg += "To: " + pkt.to.split("\n").join("/n/") + "\r\n"; msg += "From: " + pkt.settings.from.split("\n").join("/n/") + "\r\n"; msg += "Subtotal: " + pkt.subtotal + "\r\n"; + msg += "Tax: " + pkt.tax + "\r\n"; msg += "Shipping: " + pkt.shipping + "\r\n"; pkt.items.forEach((item) => msg += "Item: " + item.desc.replace("~", " ") + "~" + item.sku.replace("~", " ") + "~" + item.qty + "~" + item.price + "\r\n"); msg += "Message: " + pkt.settings.messages.split("\n").join("~") + "\r\n"; @@ -174,6 +178,7 @@ let sendData = (pkt) => { done_msg.innerHTML = "Sending data..."; done_msg.classList = "text-warning"; let msg = convertToMessage(pkt); + console.log(msg); fetch("http://" + pkt.settings.ipAddress, { method: "POST", headers: { @@ -207,7 +212,7 @@ let sendData = (pkt) => { /** - * Download the data Packet onto the user's OS (only select options [to, shipping, subtotal and items] are used) + * Download the data Packet onto the user's OS (only select options [to, shipping, tax, subtotal, items and version] are used) * * @function downloadFile * @param {Packet} pkt @@ -216,8 +221,10 @@ let downloadFile = (pkt, filepath) => { let blob = new Blob([JSON.stringify({ to: pkt.to, shipping: pkt.shipping, + tax: pkt.tax, subtotal: pkt.subtotal, - items: pkt.items + items: pkt.items, + version: VERSION_NO })], {type: "application/json"}); let url = URL.createObjectURL(blob); let item_skus = pkt.items.filter((item) => item.sku.length > 1); @@ -315,6 +322,7 @@ let getData = () => { //Read the data from the HTML page let data = { to: document.getElementById("Address").value, subtotal: document.getElementById("Subtotal").value, + tax: document.getElementById("Tax").value, shipping: document.getElementById("Shipping").value, items: items } @@ -346,6 +354,7 @@ let getPacket = (settings) => { let setData = (pkt) => { document.getElementById("Address").value = pkt.to; document.getElementById('Shipping').value = pkt.shipping; + document.getElementById('Tax').value = pkt.tax; document.getElementById('Subtotal').value = pkt.subtotal; document.getElementById('items').innerHTML = ""; //Remove existing items pkt.items.forEach((item) => addItem(item)); @@ -406,8 +415,8 @@ let validateNumberInput = (ele, name) => { let validateInputs = () => { let err_msg = ""; //Hold the error to be returned to the user - //Validate the shipping and total - var values = ["Subtotal", "Shipping"]; + //Validate the shipping, tax and total + var values = ["Subtotal", "Tax", "Shipping"]; values.forEach((id) => { let res = validateNumberInput(document.getElementById(id), id) if (res) @@ -539,9 +548,14 @@ let parseFile = (ev) => { const reader = new FileReader(); reader.onload = (event) => { const data = JSON.parse(event.target.result); + let tax = 0; + if (data.version >= 6.0) { //Tax support added in version 6.0 + tax = data.tax + } setData({ //Set the data packet to: data.to, shipping: data.shipping, + tax: tax, subtotal: data.subtotal, items: data.items, }); @@ -582,9 +596,12 @@ window.onload = () => { //Add event listeners, etc. document.getElementById('file-dialog').addEventListener('change', parseFile) document.getElementById("items-row-btn").addEventListener("click", addRowItems); document.getElementById("options-btn").addEventListener("click", showOptions); - document.getElementById('Shipping').addEventListener("change", validateInputs); + document.getElementById('Shipping').addEventListener("change", validateInputs); + document.getElementById('Tax').addEventListener("change", validateInputs); document.getElementById('Subtotal').addEventListener("change", validateInputs); document.getElementById('Address').addEventListener("change", validateInputs); + + $('[data-toggle="tooltip"]').tooltip(); //Setup up tooltips } chrome.runtime.onMessage.addListener((msg) => { //Listen for messages and set the data accordingly @@ -598,6 +615,7 @@ chrome.runtime.onMessage.addListener((msg) => { //Listen for messages and set th setData({ //Set the data packet to: msg.to, shipping: msg.shipping, + tax: msg.tax, subtotal: msg.subtotal, items: msg.items, }); diff --git a/PrinterPiExtension/main.html b/PrinterPiExtension/main.html index 54481bb..d070a36 100644 --- a/PrinterPiExtension/main.html +++ b/PrinterPiExtension/main.html @@ -36,7 +36,9 @@
Address
Shipping
-
Subtotal

(not including shipping)

+
Tax
+ +
Subtotal

Items Purchased
diff --git a/PrinterPiExtension/manifest.json b/PrinterPiExtension/manifest.json index 269a6f5..47f37e4 100644 --- a/PrinterPiExtension/manifest.json +++ b/PrinterPiExtension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "PrinterPi", - "version": "5.3", + "version": "6.0", "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", diff --git a/PrinterPiExtension/options.html b/PrinterPiExtension/options.html index 54419bc..80de4ba 100644 --- a/PrinterPiExtension/options.html +++ b/PrinterPiExtension/options.html @@ -8,6 +8,8 @@

PrinterPi Settings


+
Version: 6.0
+
Loading...

Return Address
diff --git a/PrinterPiServer/CHANGELOG.md b/PrinterPiServer/CHANGELOG.md new file mode 100644 index 0000000..f4e10cc --- /dev/null +++ b/PrinterPiServer/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog +All notable changes to the PrinterPiServer 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). + +## [1.1.0] - 2020-11-01 +### Added +- Support for Tax field in transmitted data packets + +## [1.0.0] - 2020-09-15 +### Added +- Add support for transmitting to and from addresses, as well as custom message +### Changed +- Implemented direct HTTP connections via custom port +- Update way receipts are printed diff --git a/PrinterPiServer/Packet.java b/PrinterPiServer/Packet.java index f73fc48..7c0b075 100644 --- a/PrinterPiServer/Packet.java +++ b/PrinterPiServer/Packet.java @@ -26,6 +26,7 @@ public class Packet { public String[] from; public double subtotal; public double shipping; + public double tax; public double total; public Set items; public String[] messages; diff --git a/PrinterPiServer/Printer.java b/PrinterPiServer/Printer.java index 0d0c251..e718921 100644 --- a/PrinterPiServer/Printer.java +++ b/PrinterPiServer/Printer.java @@ -142,6 +142,12 @@ public static void print(Packet packet) throws IOException { //String address, S write(" $" + String.format("%.2f",packet.shipping)); cr(); style(0x88); //Bold, underline + write("Tax:"); + style(0x00); //Clear + cr(); + write(" $" + String.format("%.2f",packet.tax)); + cr(); + style(0x88); //Bold, underline write("Total:"); style(0x00); //Clear cr(); diff --git a/PrinterPiServer/PrinterServer.java b/PrinterPiServer/PrinterServer.java index c3e46fb..5207b8a 100644 --- a/PrinterPiServer/PrinterServer.java +++ b/PrinterPiServer/PrinterServer.java @@ -112,6 +112,9 @@ Data format (NOTE: item descs and skus MUST NOT CONTAIN ~ or ` and NO EXTRA SPAC case "shipping": pkt.shipping = Double.parseDouble(value.substring(1)); break; + case "tax": + pkt.tax = Double.parseDouble(value.substring(1)); + break; case "item": String desc = value.substring(0, value.indexOf("~")); value = value.substring(value.indexOf("~")+1); @@ -129,7 +132,7 @@ Data format (NOTE: item descs and skus MUST NOT CONTAIN ~ or ` and NO EXTRA SPAC default: System.out.println("Unrecognized parameter: " + key); } - pkt.total = pkt.shipping + pkt.subtotal; + pkt.total = pkt.shipping + pkt.subtotal + pkt.tax; } if (pkt.isComplete()) { response = "HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n{\"success\":true}\r\n";