Skip to content

Commit

Permalink
fix(velobank): use new csv format
Browse files Browse the repository at this point in the history
The PDF to CSV formatter is changed now so the coverter is udapted
  • Loading branch information
Valdermeyder committed Dec 10, 2023
1 parent 2e865e3 commit d5f5b32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions converters/velobankConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ const { transform } = require('stream-transform')
const categoryResolver = require('../categoryResolver')
const { sanitize } = require('../utils')

const columns = ['date', 'realDate', 'description', 'payer', 'amount', 'balance']
const columns = ['date', 'realDate', 'description', 'amount', 'balance']

const parseAmount = amount => parseFloat(amount.replace(' ', '').replace(/w/, '').replace(',', '.'))
const parseAmount = amount => parseFloat(amount.replace(' ', '').replace(',', '.'))

const parsePayer = payer => {
const payerWithoutLocation = payer.split(',')[0]
return payerWithoutLocation.replace('w ', '').trim()
const parseDescription = description => {
const descriptionParts = description.split(',')
if (descriptionParts.length === 1) {
return descriptionParts[0]
}
const payerPart = descriptionParts[1]
return payerPart.replace('w ', '').replace(/\d+ PLN/, '').trim()
}

const getExpenseManagerRecord = recordCategoryResolver => record => {
const payer = parsePayer(record[columns[3]]);
const amount = parseAmount(record[columns[4]])
const payer = parseDescription(record[columns[2]]);
const amount = parseAmount(record[columns[3]])
const { category, subCategory } = recordCategoryResolver(payer, amount);
return record[columns[0]] + ','
+ amount + ',' + category + ',' + subCategory
Expand Down
4 changes: 2 additions & 2 deletions converters/velobankConverter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const categoriesMapping = {
};

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 input = `30.10.2019,24.11.2023,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
`
Expand Down

0 comments on commit d5f5b32

Please sign in to comment.