-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecon.js
70 lines (63 loc) · 2.51 KB
/
recon.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
var fs = require('fs');
var parse = require('csv-parse');
var round10 = require('round10').round10;
var accounts = ['regchk', 'pmt', 'biz', 'regsav', 'house', 'vaca', 'instant'];
var results = {};
accounts.forEach(function (acct) {
var bank = fs.readFileSync('ExportedTransactions_' + acct + '.csv').toString();
var mint = fs.readFileSync('transactions_' + acct + '.csv').toString();
parse(bank, {}, function (err, bankParsed) {
parse(mint, {}, function(errMint, mintParsed) {
// Create a hash
var mintIdx = {};
for (var row = 1; row < mintParsed.length; row++) {
var hash = getHashCode(mintParsed[row][0], mintParsed[row][4], mintParsed[row][3]);
if (!mintIdx[hash.one]) {
mintIdx[hash.one] = {};
}
if (!mintIdx[hash.one][hash.two]) {
mintIdx[hash.one][hash.two] = {};
}
if (!mintIdx[hash.one][hash.two][hash.three]) {
mintIdx[hash.one][hash.two][hash.three] = [];
}
mintIdx[hash.one][hash.two][hash.three].push(mintParsed[row]);
//console.log(hash);
}
//console.log('**** MISSING TRANSACTION(S) FOR "' + acct + '": ***')
for (var row = 1; row < bankParsed.length; row++) {
//var amount = bankParsed[row][4];
var hash = getHashCode(bankParsed[row][1], bankParsed[row][3], bankParsed[row][4]);
//bankParsed[row][hash] = hash;
//console.log(hash);
if (!mintIdx[hash.one] || !mintIdx[hash.one][hash.two] || !mintIdx[hash.one][hash.two][hash.three]) {
if (!results[acct]) {
results[acct] = [];
}
results[acct].push(bankParsed[row]);
//console.log(mintParsed[row]);
}
else {
if (mintIdx[hash.one][hash.two][hash.three].length > 1) {
console.log('possible dupe? count: ' + mintIdx[hash.one][hash.two][hash.three].length + ' ' + acct + '_' + new Date(hash.one).toString() + '_' + hash.two + '_' + hash.three);
}
}
}
if (results[acct]) {
fs.writeFile('results_' + acct + '.txt', JSON.stringify(results[acct], null, 4));
}
});
});
});
function getHashCode(date, type, amount) {
//var amt = round10(Math.abs(parseFloat(amount)), -2);
//var t = type.toLowerCase() === 'check' ? 'debit' : type.toLowerCase();
//var hash = new Date(date).valueOf() + '_' + t + '_' + amt;
//if (!hash) {console.log('issue with HASH algorithm!')};
return {
one: new Date(date).valueOf(),
two: type.toLowerCase() === 'check' ? 'debit' : type.toLowerCase(),
three: round10(Math.abs(parseFloat(amount)), -2)
};
}
//console.log('program ended!');