Created
January 5, 2021 04:56
-
-
Save seblavoie/bffddeb4be0a2872cc811a9e7bf4291d to your computer and use it in GitHub Desktop.
Export and clean up Harvest invoices data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [] | |
$("tbody.has-clickable-table-rows tr").each(function() { | |
var $t = $(this) | |
var line = { | |
date: $t.find(".col-issue-date").text().trim(), | |
name: "#" + _cleanText($t.find(".col-id")) + "-" + _cleanText($t.find(".col-client")), | |
amount: _cleanNumber($t.find(".col-amount")), | |
} | |
data.push(line) | |
}); | |
function _cleanText(el) { | |
return el.text().replace(/\s+/g, ' ').replace(",", "/").trim() | |
} | |
function _cleanNumber(el) { | |
return el.text().replace(/[A-Z$ ]+/g, "") | |
} | |
function convertToCSV(objArray) { | |
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; | |
var str = ''; | |
for (var i = 0; i < array.length; i++) { | |
var line = ''; | |
for (var index in array[i]) { | |
if (line != '') line += ',' | |
line += array[i][index]; | |
} | |
str += line + '\r\n'; | |
} | |
return str; | |
} | |
// copy(str) | |
console.log(convertToCSV(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment