-
Notifications
You must be signed in to change notification settings - Fork 2
/
Register.js
51 lines (36 loc) · 1.64 KB
/
Register.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
const Register = (array_transactions, typeSort) => {
var sprintf=require("sprintf-js").sprintf;
// const parser = require("./parser");
// array_transactions = parser(file);
const sortBy = require("./SortBy");
sortBy(array_transactions, typeSort);
// console.log(sprintf("%5j",array_transactions));
var registerContent = [];
var sumas = {};
var valoresTotales = [];
for (transaction in array_transactions) {
var movements = (array_transactions[transaction]["movements"].length);
var date = (array_transactions[transaction]["date"])
date = date.replace(/\//g,'-');
var description = (array_transactions[transaction]["description"])
console.log(`${date} ${description}`)
for (var i=0; i<movements; i++) {
var amount = array_transactions[transaction]["movements"][i]["amount"];
var curr = array_transactions[transaction]["movements"][i]["currency"];
var desc = array_transactions[transaction]["movements"][i]["description"];
if (sumas.hasOwnProperty(curr)){
sumas[curr] += amount;
} else {
sumas[curr] = amount;
}
valoresTotales.push(sumas[curr]);
var movement = [desc,amount,curr]
registerContent.push(movement);
console.log(sprintf("%50s %10s %1.2f %20s %1.2f",desc, curr, amount, curr, sumas[curr]));
}
for (i in sumas) {
console.log(sprintf("%88s %1.2f", i, sumas[i]));
}
}
}
module.exports = Register