forked from milenvoutchev/2ynab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
milen.voutchev
committed
Aug 8, 2019
1 parent
4e17749
commit 007b81e
Showing
10 changed files
with
131 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"Дата и час","Приход","Разход","Системен код","Кореспондент","Описание" | ||
"01.04.2019 09:14:08","0.00","1.96","1234567890123456","Кореспондент","Описание" | ||
"02.04.2019 09:14:08","0.00","1.68","1234567890123456","Кореспондент","Описание" | ||
"03.05.2019 11:22:51","0.00","33.67","1234567890123456","Кореспондент","Описание" | ||
"04.05.2019 11:22:51","0.00","3.64","1234567890123456","Кореспондент","Описание" | ||
"05.05.2019 11:22:52","0.00","3.60","1234567890123456","Кореспондент","Описание" | ||
"06.05.2019 11:22:52","0.00","1.45","1234567890123456","Кореспондент","Описание" | ||
"07.05.2019 11:22:52","0.00","5.48","1234567890123456","Кореспондент","Описание" | ||
"08.06.2019 12:07:32","0.00","1.80","1234567890123456","Кореспондент","Описание" | ||
"09.07.2019 13:27:16","0.00","5.18","1234567890123456","Кореспондент","Описание" | ||
"10.07.2019 13:27:17","0.00","3.64","1234567890123456","Кореспондент","Описание" | ||
"11.07.2019 13:27:17","0.00","1.80","1234567890123456","Кореспондент","Описание" | ||
"12.07.2019 13:27:17","0.00","6.40","1234567890123456","Кореспондент","Описание" | ||
"13.08.2019 19:00:47","0.00","3.64","1234567890123456","Кореспондент","Описание" | ||
"14.08.2019 19:00:48","0.00","1.57","1234567890123456","Кореспондент","Описание" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const parse = require('csv-parse/lib/sync'); | ||
const { getInput, writeOut } = require('../lib/file.js'); | ||
const BaseStrategy = require('./BaseStrategy'); | ||
|
||
const SETTINGS = { | ||
delimiter: ',', | ||
skip_empty_lines: true, | ||
skip_lines_with_empty_values: true, | ||
columns: [ | ||
'dateTime', | ||
'inBGN', | ||
'outBGN', | ||
'systemId', | ||
'recipient', | ||
'comment', | ||
], | ||
sliceBegin: 1, | ||
sliceEnd: Infinity, | ||
stringifier: { | ||
header: true, | ||
delimiter: ',', | ||
columns: [ | ||
'Date', | ||
'Payee', | ||
'Category', | ||
'Memo', | ||
'Outflow', | ||
'Inflow' | ||
], | ||
} | ||
}; | ||
|
||
const RATE_EUR_BGN = 1.95583; | ||
|
||
class EpayMicroaccountStrategy extends BaseStrategy { | ||
|
||
constructor() { | ||
super(); | ||
console.log('EpayMicroaccountStrategy:constructor'); | ||
} | ||
|
||
static toEUR(amount) { | ||
return amount * 1 / RATE_EUR_BGN; | ||
} | ||
|
||
static toDate(dateTime) { | ||
return String(dateTime).replace(/^(\d{2})\.(\d{2})\.(\d{4}).+/g,'$3-$2-$1'); | ||
} | ||
|
||
/** | ||
* | ||
* @param data | ||
* @returns {*[]} | ||
*/ | ||
static lineTransform(data) { | ||
const amountOut = EpayMicroaccountStrategy.toEUR(data.outBGN); | ||
const amountIn = EpayMicroaccountStrategy.toEUR(data.inBGN); | ||
const date = EpayMicroaccountStrategy.toDate(data.dateTime); | ||
const result = [ | ||
date, | ||
data.recipient, | ||
'', | ||
data.comment, | ||
Math.abs(amountOut), | ||
Math.abs(amountIn) | ||
]; | ||
return result; | ||
} | ||
|
||
/** | ||
* | ||
* @param inFile | ||
* @param outFile | ||
* @returns {Promise<void>} | ||
*/ | ||
async convert(inFile, outFile) { | ||
console.log(`In: ${inFile}`); | ||
|
||
const input = getInput(inFile, SETTINGS.sliceBegin, SETTINGS.sliceEnd); | ||
|
||
const data = parse(input, SETTINGS); | ||
|
||
console.log(`Transform: ${data.length}`); | ||
|
||
const result = await super.transformAsync(data, EpayMicroaccountStrategy.lineTransform); | ||
|
||
writeOut(outFile, result); | ||
console.log(`Written: ${outFile}`); | ||
} | ||
|
||
/** | ||
* E.g. epay_microaccount_2019-08-08_11-43-49.csv | ||
* @param inFile | ||
* @returns {boolean} | ||
*/ | ||
static isMatch(inFile) { | ||
return !!inFile.match(/epay_microaccount_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}.csv$/g); | ||
} | ||
} | ||
|
||
module.exports = EpayMicroaccountStrategy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const DbCreditCardStrategy = require(`./DbCreditCardStrategy.js`); | ||
const DbDebitCardStrategy = require(`./DbDebitCardStrategy.js`); | ||
const DkbCreditCardStrategy = require(`./DkbCreditCardStrategy.js`); | ||
const DkbGirokontoStrategy = require(`./DkbGirokontoStrategy.js`); | ||
const EpayMicroaccountStrategy = require(`./EpayMicroaccountStrategy.js`); | ||
|
||
module.exports = { | ||
DbCreditCardStrategy, | ||
DbDebitCardStrategy, | ||
DkbCreditCardStrategy, | ||
DkbGirokontoStrategy, | ||
EpayMicroaccountStrategy, | ||
}; |