-
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.
feat(velobank): add support for velobank CSV
Velobank CSV is manually created from pdf
- Loading branch information
1 parent
d13e880
commit 2e865e3
Showing
6 changed files
with
85 additions
and
2 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,29 @@ | ||
const { parse } = require('csv-parse/sync') | ||
const { transform } = require('stream-transform') | ||
const categoryResolver = require('../categoryResolver') | ||
const { sanitize } = require('../utils') | ||
|
||
const columns = ['date', 'realDate', 'description', 'payer', 'amount', 'balance'] | ||
|
||
const parseAmount = amount => parseFloat(amount.replace(' ', '').replace(/w/, '').replace(',', '.')) | ||
|
||
const parsePayer = payer => { | ||
const payerWithoutLocation = payer.split(',')[0] | ||
return payerWithoutLocation.replace('w ', '').trim() | ||
} | ||
|
||
const getExpenseManagerRecord = recordCategoryResolver => record => { | ||
const payer = parsePayer(record[columns[3]]); | ||
const amount = parseAmount(record[columns[4]]) | ||
const { category, subCategory } = recordCategoryResolver(payer, amount); | ||
return record[columns[0]] + ',' | ||
+ amount + ',' + category + ',' + subCategory | ||
+ ',Credit Card,,,' + sanitize(payer) | ||
+ ',,,GetIn\n' | ||
} | ||
|
||
exports.convertCvsFileData = (input, categoriesMapping) => { | ||
const getExpenseManagerWithMapping = getExpenseManagerRecord(categoryResolver.resolveCategory(categoriesMapping)) | ||
return transform(parse(input, { delimiter: ',', columns, relax: true, relax_column_count: true, bom: true }), | ||
record => getExpenseManagerWithMapping(record)) | ||
} |
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,31 @@ | ||
const citiConverter = require('./velobankConverter') | ||
|
||
const categoriesMapping = { | ||
'Play': { category: 'Utilities', subCategory: 'Telephone' }, | ||
'Employer': { category: 'Income', subCategory: 'Salary' }, | ||
'Deposit': { category: 'Income', subCategory: 'Deposit' } | ||
}; | ||
|
||
test('should be able to convert Velobank manually created CSV files format', (done) => { | ||
const input = `30.10.2019,24.11.2023,"Przelew z rachunku: xxxxx,",Employer,"9 839,29 PLN","1 574,59 PLN" | ||
28.10.2019,24.11.2023,"Operacja kartą na kwotę 17,99 PLN","w Play, GDANSK, PL","-10,00 PLN","2 374,59 PLN"` | ||
const expected = `30.10.2019,9839.29,Income,Salary,Credit Card,,,Employer,,,GetIn | ||
28.10.2019,-10,Utilities,Telephone,Credit Card,,,Play,,,GetIn | ||
` | ||
let transformedData = ''; | ||
|
||
const converter = citiConverter.convertCvsFileData(input, categoriesMapping) | ||
.on('readable', () => { | ||
let row = converter.read() | ||
while (row) { | ||
transformedData += row | ||
row = converter.read() | ||
} | ||
}) | ||
.on('finish', () => { | ||
setTimeout(() => { | ||
expect(transformedData).toEqual(expected) | ||
done() | ||
}) | ||
}) | ||
}) |
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,2 @@ | ||
30.10.2019,24.11.2023,"Przelew z rachunku: xxxxx,",Employer,"9 839,29 PLN","1 574,59 PLN" | ||
28.10.2019,24.11.2023,"Operacja kartą na kwotę 17,99 PLN","w Play, GDANSK, PL","-10,00 PLN","2 374,59 PLN" |
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