-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-checks.js
41 lines (37 loc) · 1.36 KB
/
process-checks.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
const fs = require('fs');
const tabula = require('tabula-js');
const moment = require('moment');
const csv = require('csv');
const file = process.argv[2];
const fileDate = moment(file.replace(/[^0-9]+/g,''), 'MMDDYY');
const t = tabula(file, {pages: 'all'});
var futureCSV = [['date', 'to', 'description', 'amount']];
t.extractCsv((err, data) => {
if (err) console.log(err);
data.forEach(function (datum, idx) {
csv.parse(datum, function (err, parsed) {
if (err) console.log(err);
var lineItem = parsed[0];
if (parsed[0] &&
lineItem[0] &&
lineItem[0].split(' ')[0] &&
moment(lineItem[0].split(' ')[0], 'M/DD/YYYY').isValid()) {
var date = moment(lineItem[0].split(' ')[0], 'M/DD/YYYY');
var to = lineItem[1].trim();
var description = lineItem[2].trim();
if (!isNaN(Number(description.replace(',','')))) {
description = '';
}
var currency = lineItem[lineItem.length-1].trim();
var amount = Number(currency.replace(/[^0-9\.]+/g,""));
futureCSV.push([date.format(), to, description, amount]);
}
if (idx === data.length-1) {
csv.stringify(futureCSV, function (err, output) {
if (err) console.log(err);
fs.writeFileSync('./check-runs/' + fileDate.format('MM-DD-YY') + '.csv', output);
});
}
});
});
});