-
Notifications
You must be signed in to change notification settings - Fork 2
/
postings.js
68 lines (50 loc) · 1.69 KB
/
postings.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
/**
* maintains postings table
*/
function updatePostings(postings, formatter, postingsTable, paging) {
const rows = []
for (i = 0; i < postings.length; i = i + 1) {
p1 = postings[i]
let p2;
if (i + 1 < postings.length) {
p2 = postings[i + 1]
}
if (p2 && p1.date.getTime() === p2.date.getTime() && p1.amount === -p2.amount && p1.merchant === p2.merchant && p1.type === p2.type) {
i++
rows.push([
p1.date.getFullYear() + '/' + (1 + p1.date.getMonth()) + '/' + p1.date.getDate() + "<br> ",
escapeHtml(p1.accounts.join(':')) + "<br>" + escapeHtml(p2.accounts.join(':')),
escapeHtml(p1.merchant) + "<br> ",
formatter(p1.amount) + "<br> ",
p1.type
])
} else {
rows.push([
p1.date.getFullYear() + '/' + (1 + p1.date.getMonth()) + '/' + p1.date.getDate(),
escapeHtml(p1.accounts.join(':')),
escapeHtml(p1.merchant),
formatter(p1.amount),
p1.type
])
}
}
const tableElement = postingsTable.get(0);
if (tableElement._table) {
tableElement._table.destroy();
}
tableElement._table = postingsTable.DataTable({
data: rows,
deferRender: true,
lengthMenu: [ [15, 50, 500, -1], [15, 50, 500, "All"] ],
paging: paging,
searching: paging,
order: [[0, "desc"]],
'columnDefs': [
{
"targets": 3,
"className": "text-right",
}
],
});
}
module.exports = { updatePostings }