Skip to content

Commit

Permalink
Add functionality to an invoice render:
Browse files Browse the repository at this point in the history
- Parse out invoice details
- Post invoice to firebase
  • Loading branch information
typotter committed Oct 11, 2018
1 parent 8844679 commit c6d2106
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
44 changes: 44 additions & 0 deletions ekos_parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,48 @@ var deployInventoryScan = function(domRoot) {
$(btn).appendTo('div.button_section_centered');
}

var buttonHtml = `
<style>
@media print { .printhide{ display:none; } }
</style>
<div class="printhide">
<button id="post">Post Invoice to K.N.O.T.S.</button>
</div>
`;
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
});

});
}
6 changes: 5 additions & 1 deletion ekos_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}];



Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c6d2106

Please sign in to comment.