-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.coffee
56 lines (42 loc) · 1.32 KB
/
run.coffee
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
csv = require 'csv'
json2csv = require 'json2csv'
moment = require 'moment'
fs = require 'fs'
filename = process.argv[2]
printUsage = ->
console.log """
ING Bank transaction report to Xero ISO 20022 bank statement converter
-------------------------------------------------------------------------
https://github.com/petrutoader/ingbrobu-xero
-------------------------------------------------------------------------
Usage: coffee run.coffee ~/Downloads/report.csv
"""
curate = (data) ->
moment.locale 'ro'
cleanupAmount = (amount) ->
return amount.replace('.', '').replace(',', '.')
curatedData = []
transaction = {}
data.forEach (item, index) ->
if item[0] != ""
curatedData.push transaction
transaction = {}
transaction.Date = moment(item[0], 'DD MMMM YYYY').format("DD/MM/YYYY")
transaction.Description = item[1]
if item[2] != ""
transaction.Amount = +cleanupAmount(item[2]) * -1
else
transaction.Amount = +cleanupAmount(item[3])
else
transaction.Description += " " + item[1]
return curatedData
cleanup = (data) ->
data.shift()
data.pop()
data.pop()
return data
return printUsage() if !filename?
data = fs.readFileSync filename
csv.parse data, (err, data) ->
cleanup data
console.log json2csv data: curate(data)