From d5f5b32011f4c5e2ede23d80fe91f6bf7e150c35 Mon Sep 17 00:00:00 2001 From: Volodymyr Huzar Date: Sun, 10 Dec 2023 18:41:09 +0100 Subject: [PATCH] fix(velobank): use new csv format The PDF to CSV formatter is changed now so the coverter is udapted --- converters/velobankConverter.js | 18 +++++++++++------- converters/velobankConverter.spec.js | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/converters/velobankConverter.js b/converters/velobankConverter.js index e7a3d81..921e40a 100644 --- a/converters/velobankConverter.js +++ b/converters/velobankConverter.js @@ -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 diff --git a/converters/velobankConverter.spec.js b/converters/velobankConverter.spec.js index 717da57..913814e 100644 --- a/converters/velobankConverter.spec.js +++ b/converters/velobankConverter.spec.js @@ -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 `