Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify DKB PDF-Importer to support new transaction #3053

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3424,6 +3424,35 @@ public void testGiroKontoauszug18()
assertThat(transaction.getNote(), is("Storno Gutschrift"));
}

@Test
public void testGiroKontoauszug19()
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client());

List<Exception> errors = new ArrayList<Exception>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "GiroKontoauszug19.txt"), errors);

assertThat(errors, empty());
assertThat(results.size(), is(1));

// check transaction
// get transactions
Iterator<Extractor.Item> iter = results.stream().filter(TransactionItem.class::isInstance).iterator();
assertThat(results.stream().filter(TransactionItem.class::isInstance).count(), is(1L));

Item item = iter.next();

// assert transaction
AccountTransaction transaction = (AccountTransaction) item.getSubject();
assertThat(transaction.getType(), is(AccountTransaction.Type.FEES));
assertThat(transaction.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2018-06-12T00:00")));
assertThat(transaction.getAmount(), is(Values.Amount.factorize(0.01)));
assertThat(transaction.getSource(), is("GiroKontoauszug19.txt"));
assertThat(transaction.getNote(), is("Buchung Identifikationscode"));
}

@Test
public void testKreditKontoauszug01()
{
Expand Down
@@ -0,0 +1,19 @@
PDFBox Version: 1.8.16
Portfolio Performance Version: 0.59.3
-----------------------------------------
Deutsche Kreditbank, Taubenstr. 7-9, 10117 Berlin
Max Mustermann
Musterstr. 1 IHR DISPOKREDIT EUR 0,00
12345 Musterstadt
DKB-Cash
Kontoauszug Nummer 007 / 2018 vom 02.06.2018 bis 04.07.2018
Kontonummer 1234567890 / IBAN DE21 1203 0000 1234 5678 90
Bu.Tag Wert Wir haben für Sie gebucht Belastung in EUR Gutschrift in EUR
12.06. 12.06. BUCHUNG 0,01
KREDITKARTENABRECHNUNG
IDENTIFIKATIONSCODE 123456 - KARTENENDNUMMER
1234. SCH LIEßEN SIE DIE REGISTRIERUN G AB UNTER
WWW.DKB.DE/SECUR E-VISA
ALTER KONTOSTAND 0,00 H EUR
NEUER KONTOSTAND 0,01 H EUR
[...]
Expand Up @@ -538,7 +538,9 @@ private void addAccountStatementTransaction()
m = pYear.matcher(line);
if (m.matches())
{
context.put("nr", m.group("nr"));
// Remove all leading zeros
context.put("nr", m.group("nr").replaceFirst("^0+(?!$)", ""));

context.put("year", m.group("year"));
}

Expand Down Expand Up @@ -673,7 +675,7 @@ private void addAccountStatementTransaction()
Map<String, String> context = type.getCurrentContext();
// since year is not within the date correction
// necessary in first receipt of year
if (context.get("nr").compareTo("001") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
if (context.get("nr").compareTo("1") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
{
Integer year = Integer.parseInt(context.get("year")) - 1;
t.setDateTime(asDate(v.get("day") + "." + v.get("month2") + "." + year.toString()));
Expand Down Expand Up @@ -737,7 +739,7 @@ private void addAccountStatementTransaction()
Map<String, String> context = type.getCurrentContext();
// since year is not within the date correction
// necessary in first receipt of year
if (context.get("nr").compareTo("001") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
if (context.get("nr").compareTo("1") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
{
Integer year = Integer.parseInt(context.get("year")) - 1;
t.setDateTime(asDate(v.get("day") + "." + v.get("month2") + "." + year.toString()));
Expand Down Expand Up @@ -780,7 +782,7 @@ private void addAccountStatementTransaction()
Map<String, String> context = type.getCurrentContext();
// since year is not within the date correction
// necessary in first receipt of year
if (context.get("nr").compareTo("001") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
if (context.get("nr").compareTo("1") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
{
Integer year = Integer.parseInt(context.get("year")) - 1;
t.setDateTime(asDate(v.get("day") + "." + v.get("month2") + "." + year.toString()));
Expand All @@ -797,7 +799,7 @@ private void addAccountStatementTransaction()

.wrap(TransactionItem::new));

Block feesBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\. [\\d]{2}\\.[\\d]{2}\\. Rechnung [\\.,\\d]+$");
Block feesBlock = new Block("^[\\d]{2}\\.[\\d]{2}\\. [\\d]{2}\\.[\\d]{2}\\. (?i)(Rechnung|Buchung) [\\.,\\d]+$");
type.addBlock(feesBlock);
feesBlock.set(new Transaction<AccountTransaction>()

Expand All @@ -809,14 +811,14 @@ private void addAccountStatementTransaction()

.section("month1", "day", "month2", "note1", "amount", "note2")
.match("^[\\d]{2}\\.(?<month1>[\\d]{2})\\. (?<day>[\\d]{2})\\.(?<month2>[\\d]{2})\\. "
+ "(?<note1>Rechnung) "
+ "(?i)(?<note1>Rechnung|Buchung) "
+ "(?<amount>[\\.,\\d]+)$")
.match("^.*(?<note2>(Bargeldeinzahlung|R.ckruf\\/Nachforschung)).*$")
.match("^(.*)?(?i)(?<note2>(Bargeldeinzahlung|R.ckruf\\/Nachforschung|Identifikationscode)).*$")
.assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
// since year is not within the date correction
// necessary in first receipt of year
if (context.get("nr").compareTo("001") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
if (context.get("nr").compareTo("1") == 0 && Integer.parseInt(v.get("month1")) != Integer.parseInt(v.get("month2")))
{
Integer year = Integer.parseInt(context.get("year")) - 1;
t.setDateTime(asDate(v.get("day") + "." + v.get("month2") + "." + year.toString()));
Expand All @@ -829,6 +831,10 @@ private void addAccountStatementTransaction()
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
t.setNote(v.get("note1") + " " + v.get("note2"));

// Formatting some notes
if (t.getNote().equals("BUCHUNG IDENTIFIKATIONSCODE"))
t.setNote("Buchung Identifikationscode");
})

.wrap(TransactionItem::new));
Expand Down