Skip to content

Commit

Permalink
Fix barclaycard format (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
sercxanto authored Sep 10, 2024
1 parent 899ae6e commit b4308aa
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20240910-195727.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: 'Update dependencies: go-yaml, adrg/xdg, x/text'
time: 2024-09-10T19:57:27.129084907+02:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20240910-195846.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Adapt to new barclaycard format (additional payee field)
time: 2024-09-10T19:58:46.902626699+02:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20240910-195916.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Skip barclaycard entries with empty date ("vorgemerkt")
time: 2024-09-10T19:59:16.638026314+02:00
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
date;payment;info;payee;memo;amount;category;tags
2020-09-28;1;PAYPAL *DEALER 98765432 DE;;;-64.140000;;
2020-09-19;1;XYZ ROTTERDAM NL;;;-15.000000;;
2020-09-12;1;Abc *Abc def 12345 DE;;;-3.980000;;
2020-09-12;1;DB FERNVERKEHR AG FRANKFURT DE;;;-4.970000;;
2020-09-11;1;BANK ORT 1 PORT 2 > DE;;;-250.000000;;
2020-09-09;1;DB BAHN A-BC 123ZOO INTERNET DE;;;-13.100000;;
2020-09-28;1;PAYPAL *DEALER 98765432 DE;Händler1;;-64.140000;;
2020-09-19;1;XYZ ROTTERDAM NL;Händler2;;-15.000000;;
2020-09-12;1;Abc *Abc def 12345 DE;Händler3;;-3.980000;;
2020-09-12;1;DB FERNVERKEHR AG FRANKFURT DE;Händler4;;-4.970000;;
2020-09-11;1;BANK ORT 1 PORT 2 > DE;Händler5;;-250.000000;;
2020-09-09;1;DB BAHN A-BC 123ZOO INTERNET DE;Händler6;;-13.100000;;
Binary file modified internal/pkg/batchconvert/testfiles/input/mixed/Umsaetze.xlsx
Binary file not shown.
12 changes: 11 additions & 1 deletion pkg/parser/barclaycard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type barclaycardRecord struct {
bookingDate time.Time
value float64
description string
payee string
}

type barclaycardParser struct {
Expand Down Expand Up @@ -45,6 +46,7 @@ func isValidBarclaycardHeader(record []string) bool {
"Name des Karteninhabers",
"Kartennetzwerk",
"Kontaktlose Bezahlung",
"Händlerdetails",
}
return reflect.DeepEqual(record, expected)
}
Expand Down Expand Up @@ -76,6 +78,13 @@ func (b *barclaycardParser) ParseFile(filepath string) error {
Field: "Buchungsdatum(1)/Transaktionsdatum",
}
}

// Entries with an empty "Buchungsdatum" are "vorgemerkt", not "Berechnet"
// and need to be skipped
if len(row[2]) == 0 {
continue
}

bDate, err := time.Parse("02.01.2006", row[2])
if err != nil {
return &ParserError{
Expand Down Expand Up @@ -103,6 +112,7 @@ func (b *barclaycardParser) ParseFile(filepath string) error {
bookingDate: bDate,
value: value,
description: row[4],
payee: row[14],
}
b.entries = append(b.entries, bRecord)
} else {
Expand All @@ -125,7 +135,7 @@ func (b *barclaycardRecord) convertRecord() homebankRecord {
date: b.transactionDate.Format("2006-01-02"),
payment: 1, // Credit card
info: b.description,
payee: "",
payee: b.payee,
memo: "",
amount: b.value,
category: "",
Expand Down
12 changes: 6 additions & 6 deletions pkg/parser/testfiles/barclaycard/Umsaetze.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
date;payment;info;payee;memo;amount;category;tags
2020-09-28;1;PAYPAL *DEALER 98765432 DE;;;-64.140000;;
2020-09-19;1;XYZ ROTTERDAM NL;;;-15.000000;;
2020-09-12;1;Abc *Abc def 12345 DE;;;-3.980000;;
2020-09-12;1;DB FERNVERKEHR AG FRANKFURT DE;;;-4.970000;;
2020-09-11;1;BANK ORT 1 PORT 2 > DE;;;-250.000000;;
2020-09-09;1;DB BAHN A-BC 123ZOO INTERNET DE;;;-13.100000;;
2020-09-28;1;PAYPAL *DEALER 98765432 DE;Händler1;;-64.140000;;
2020-09-19;1;XYZ ROTTERDAM NL;Händler2;;-15.000000;;
2020-09-12;1;Abc *Abc def 12345 DE;Händler3;;-3.980000;;
2020-09-12;1;DB FERNVERKEHR AG FRANKFURT DE;Händler4;;-4.970000;;
2020-09-11;1;BANK ORT 1 PORT 2 > DE;Händler5;;-250.000000;;
2020-09-09;1;DB BAHN A-BC 123ZOO INTERNET DE;Händler6;;-13.100000;;
Binary file modified pkg/parser/testfiles/barclaycard/Umsaetze.xlsx
Binary file not shown.
Binary file modified pkg/parser/testfiles/barclaycard/Umsaetze_nok_wrongamount.xlsx
Binary file not shown.
Binary file modified pkg/parser/testfiles/barclaycard/Umsaetze_nok_wrongdate1.xlsx
Binary file not shown.
Binary file modified pkg/parser/testfiles/barclaycard/Umsaetze_nok_wrongdate2.xlsx
Binary file not shown.

0 comments on commit b4308aa

Please sign in to comment.