From c6d2106e594ff7e6cd3d5cae43661b926c9e7f32 Mon Sep 17 00:00:00 2001 From: Ty Potter Date: Wed, 10 Oct 2018 21:05:22 -0600 Subject: [PATCH] Add functionality to an invoice render: - Parse out invoice details - Post invoice to firebase --- ekos_parsing.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ ekos_script.js | 6 +++++- manifest.json | 4 ++-- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/ekos_parsing.js b/ekos_parsing.js index 32acfae..13712ea 100644 --- a/ekos_parsing.js +++ b/ekos_parsing.js @@ -58,4 +58,48 @@ var deployInventoryScan = function(domRoot) { $(btn).appendTo('div.button_section_centered'); } +var buttonHtml = ` + +
+ +
+`; +var invoiceAddons = function(domRoot) { + console.log("parsing invoice"); + var invoicetext = $("div#right_side_top")[0].innerText; + var invtable = $("table:has(td:contains('SUBTOTAL')) td"); + var invoice = { + "id": invoicetext.match(/Invoice\: E-(.*)/)[1], + "date": invoicetext.match(/Order Date\: (.*)/)[1], + items: [], + subtotal: parseFloat(invtable[2].innerText.replace('$','')), + tax: parseFloat(invtable[5].innerText.replace('$','')), + total: parseFloat(invtable[8].innerText.replace('$','')) + }; + + var ordertable = $("table:has(th:contains('Item Number'))")[0]; + $("tr:has(td)", ordertable).each(function(i,o) { + var td = $("td", o); + invoice.items.push({ + sku: td[1].innerText, + quantity: parseInt(td[3].innerText), + unit_price: parseFloat(td[4].innerText.replace('$','')), + total: parseFloat(td[5].innerText.replace('$','')) + }); + }); + console.log("invoice", invoice); + + $("div#invoice_title").after(buttonHtml); + $("button#post").click(function() { + console.log("POSTING invoice to knotted systems."); + chrome.runtime.sendMessage({ + action: MSG_ACTIONS.WRITE, + section: "invoice/" + invoice.id, + map: invoice + }); + + }); +} diff --git a/ekos_script.js b/ekos_script.js index 6d8b001..7a9005b 100644 --- a/ekos_script.js +++ b/ekos_script.js @@ -18,7 +18,11 @@ var pageMatchers = [ {matcher: function(domRoot) { return $("h1.page_title:contains('Inventory')", domRoot).length > 0; }, - overlay: deployInventoryScan}]; + overlay: deployInventoryScan}, + {matcher: function(domRoot) { + return $("div#invoice_title", domRoot).length > 0; + }, + overlay: invoiceAddons}]; diff --git a/manifest.json b/manifest.json index 51b8a0e..aeaa3d4 100644 --- a/manifest.json +++ b/manifest.json @@ -19,8 +19,8 @@ { "matches": ["https://na2.goekos.com/*"], "js":[ - "jquery.min.js", "const.js", "ekos_parsing.js", - "overlays/batch.js", + "jquery.min.js", "const.js", "lib/knot.js", "ekos_parsing.js", + "overlays/batch.js", "lib/jspdf.debug.js", "ekos_script.js"], "run_at": "document_end", "all_frames": true,