Skip to content

Commit

Permalink
Improve skip dividend transaction from account statement
Browse files Browse the repository at this point in the history
Modify Deutsche Bank PDF-Importer #3548
  • Loading branch information
Nirus2000 committed Sep 14, 2023
1 parent 2c396ca commit 9e544a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,11 @@ public void testGiroKontoauszug06()
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "GiroKontoauszug06.txt"), errors);

assertThat(errors, empty());
assertThat(results.size(), is(3));
assertThat(countSecurities(results), is(0L));
assertThat(countBuySell(results), is(0L));
assertThat(countAccountTransactions(results), is(1L));
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check dividends transaction
assertThat(results, hasItem(removal( //
Expand All @@ -2319,18 +2323,6 @@ public void testGiroKontoauszug06()
hasAmount("EUR", 1000), hasGrossValue("EUR", 1000), //
hasTaxes("EUR", 0), hasFees("EUR", 0.00))));

assertThat(results, hasItem(deposit( //
hasDate("2023-08-16"), hasShares(0), //
hasSource("GiroKontoauszug06.txt"), hasNote(""), //
hasAmount("EUR", 33.23), hasGrossValue("EUR", 33.23), //
hasTaxes("EUR", 0), hasFees("EUR", 0.00))));

assertThat(results, hasItem(deposit( //
hasDate("2023-08-31"), hasShares(0), //
hasSource("GiroKontoauszug06.txt"), hasNote(""), //
hasAmount("EUR", 74.49), hasGrossValue("EUR", 74.49), //
hasTaxes("EUR", 0), hasFees("EUR", 0.00))));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -335,21 +335,14 @@ private void addDividendeTransaction()
private void addAccountStatementTransaction()
{
final DocumentType type = new DocumentType("Kontoauszug vom", (context, lines) -> {
Pattern pCurrency = Pattern.compile(".* (?<currency>[\\w]{3}) [\\-|\\+] [\\.,\\d]+$");
Pattern pYear = Pattern.compile(
"Kontoauszug vom [\\d]{2}\\.[\\d]{2}\\.(?<year>[\\d]{4}) bis [\\d]{2}\\.[\\d]{2}\\.[\\d]{4}");
Pattern pCurrency = Pattern.compile("^.* [\\d]{4} [\\d]{4} [\\d]{4} [\\d]{4} [\\d]{2} .*(?<currency>[\\w]{3}) [\\-|\\+] [\\.,\\d]+$");
Pattern pYear = Pattern.compile("^Kontoauszug vom [\\d]{2}\\.[\\d]{2}\\.(?<year>[\\d]{4}) bis [\\d]{2}\\.[\\d]{2}\\.[\\d]{4}$");

for (int lineNo = 0; lineNo < lines.length; lineNo++)
for (String line : lines)
{
String line = lines[lineNo];

// check for currency
if (line.startsWith("Auszug Seite") && lineNo + 1 < lines.length)
{
Matcher mCurrency = pCurrency.matcher(lines[lineNo + 1]);
if (mCurrency.matches())
context.put("currency", mCurrency.group("currency"));
}
Matcher mCurrency = pCurrency.matcher(line);
if (mCurrency.matches())
context.put("currency", mCurrency.group("currency"));

Matcher mYear = pYear.matcher(line);
if (mYear.matches())
Expand Down Expand Up @@ -424,22 +417,25 @@ private void addAccountStatementTransaction()
t.setAmount(asAmount(v.get("amount")));
t.setNote(v.get("note"));

// @formatter:off
// If we have fees, then we skip the transaction
//
// 31.12. 31.12. Verwendungszweck/ Kundenreferenz - 13,47
// Saldo der Abschlussposten
// @formatter:on
if ("Saldo der Abschlussposten".equals(v.get("note1")))
type.getCurrentContext().putBoolean("skipTransaction", true);

// @formatter:off
// If we have security transaction, then we skip the transaction
//
// 01.06. 02.06. Verwendungszweck/ Kundenreferenz - 1.073,65
// 2023 2023 WERTPAPIER-KAUF STK/NOM: 35
// @formatter:on
if (v.get("note1").contains("WERTPAPIER"))
// @formatter:off
// If we have fees, then we skip the transaction
//
// 31.12. 31.12. Verwendungszweck/ Kundenreferenz - 13,47
// Saldo der Abschlussposten
// @formatter:on
if ("Saldo der Abschlussposten".equals(v.get("note1")))
type.getCurrentContext().putBoolean("skipTransaction", true);

// @formatter:off
// If we have security transaction, then we skip the transaction
//
// 01.06. 02.06. Verwendungszweck/ Kundenreferenz - 1.073,65
// 2023 2023 WERTPAPIER-KAUF STK/NOM: 35
//
// 16.08. 16.08. Verwendungszweck/ Kundenreferenz + 33,23
// 2023 2023 ZINSEN/DIVIDENDEN/ERTRAEGE FIL/DEPOT-NR:
// @formatter:on
if (v.get("note1").contains("WERTPAPIER") || v.get("note1").contains("DEPOT-NR:"))
type.getCurrentContext().putBoolean("skipTransaction", true);
})

Expand All @@ -449,15 +445,14 @@ private void addAccountStatementTransaction()
if (t.getCurrencyCode() != null && t.getAmount() == 0)
item.setFailureMessage(Messages.MsgErrorTransactionTypeNotSupported);

if (Boolean.valueOf(type.getCurrentContext().getBoolean("skipTransaction")))
return null;

// If we have multiple entries in the document,
// then the "skipTransaction" flag must be removed.
boolean skipTransaction = type.getCurrentContext().getBoolean("skipTransaction");
type.getCurrentContext().remove("skipTransaction");

if (!skipTransaction)
return item;

return null;
return item;
}));

// @formatter:off
Expand Down

0 comments on commit 9e544a7

Please sign in to comment.