-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_nubank.js
99 lines (89 loc) · 2.55 KB
/
content_nubank.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
getData();
sendResponse();
}
);
function getData() {
var date, description, amount, charges_array, charges;
charges_array = [
["Tipo", "Nº de Parcelas", "Quantia (R$)", "Descrição", "Data", "Categoria", "Nº do Documento", "Centro de Custo / Receita", "Cliente/Fornecedor", "Observação", "Produto", "Região"]
];
charges = $(".md-tab-content:not(.ng-hide)").find(".charge");
vencimento = $("md-tab.active md-tab-label h3").get(0).textContent.trim();
vencimento = normalizeExpiryMonth(vencimento) + normalizeExpiryYear(vencimento);
for (var i = 0; i < charges.length; i++) {
date = normalizeDate($(charges).find(".date").get(i).textContent.trim());
description = $(charges).find(".description").get(i).textContent.trim();
amount = amountFormat($(charges).find(".amount").get(i).textContent.trim());
if (description == 'Pagamento recebido')
continue;
charges_array.push(["Normal", "", amount, description, date, "", "", "", "", "", "", ""]);
}
var wb = XLSX.utils.book_new(),
ws = XLSX.utils.aoa_to_sheet(charges_array);
XLSX.utils.book_append_sheet(wb, ws, "Fatura " + vencimento);
XLSX.writeFile(wb, "Fatura-Nubank-" + vencimento + ".xls");
}
function amountFormat(amount) {
var value = amount.replace(/[^0-9-,]/g, '').replace(",", ".");
return value * -1;
}
function normalizeDate(date) {
return normalizeDay(date) + "/" + normalizeMonth(date) + "/" + normalizeYear(date);
}
function normalizeDay(date) {
return date.split(' ')[0]
}
function normalizeMonth(date) {
var month = date.split(' ')[1]
var months = {
'Jan': '01',
'Fev': '02',
'Mar': '03',
'Abr': '04',
'Mai': '05',
'Jun': '06',
'Jul': '07',
'Ago': '08',
'Set': '09',
'Out': '10',
'Nov': '11',
'Dez': '12'
}
return months[month];
}
function normalizeYear(date) {
var dateArray = date.split(' ');
if (dateArray.length > 2) {
return '20' + dateArray[2];
} else {
return new Date().getFullYear();
};
}
function normalizeExpiryMonth(date) {
var month = date.split(' ')[0]
var months = {
'Jan': '01',
'Fev': '02',
'Mar': '03',
'Abr': '04',
'Mai': '05',
'Jun': '06',
'Jul': '07',
'Ago': '08',
'Set': '09',
'Out': '10',
'Nov': '11',
'Dez': '12'
}
return months[month];
}
function normalizeExpiryYear(date) {
var dateArray = date.split(' ');
if (dateArray.length == 2) {
return '20' + dateArray[1];
} else {
return new Date().getFullYear();
};
}