Skip to content

Commit

Permalink
Modify Deutsche Bank PDF-Importer to support new transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Nirus2000 authored and buchen committed Dec 19, 2023
1 parent ed6f5d2 commit db6d2b8
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package name.abuchen.portfolio.datatransfer.pdf.deutschebank;

import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countAccountTransactions;
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countBuySell;
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countSecurities;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.check;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.deposit;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.dividend;
Expand All @@ -32,6 +21,16 @@
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.removal;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.sale;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.security;
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countAccountTransactions;
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countBuySell;
import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countSecurities;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.text.MessageFormat;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -91,7 +90,8 @@ public void testDividende01()
// check dividends transaction
assertThat(results, hasItem(dividend( //
hasDate("2014-12-15"), hasShares(380), //
hasSource("Dividende01.txt"), hasNote(null), //
hasSource("Dividende01.txt"), //
hasNote(null), //
hasAmount("EUR", 64.88), hasGrossValue("EUR", 87.13), hasForexGrossValue("USD", 98.80), //
hasTaxes("EUR", 8.71 + 0.47 + 13.07), hasFees("EUR", 0.00))));
}
Expand All @@ -118,7 +118,8 @@ public void testDividende01WithSecurityInEUR()
// check dividends transaction
assertThat(results, hasItem(dividend( //
hasDate("2014-12-15"), hasShares(380), //
hasSource("Dividende01.txt"), hasNote(null), //
hasSource("Dividende01.txt"), //
hasNote(null), //
hasAmount("EUR", 64.88), hasGrossValue("EUR", 87.13), //
hasTaxes("EUR", 8.71 + 0.47 + 13.07), hasFees("EUR", 0.00), //
check(tx -> {
Expand Down Expand Up @@ -155,7 +156,8 @@ public void testDividende02()
// check dividends transaction
assertThat(results, hasItem(dividend( //
hasDate("2014-12-15"), hasShares(123), //
hasSource("Dividende02.txt"), hasNote(null), //
hasSource("Dividende02.txt"), //
hasNote(null), //
hasAmount("EUR", 14.95), hasGrossValue("EUR", 20.22), //
hasTaxes("EUR", 4.28 + 0.23 + 0.76), hasFees("EUR", 0.00))));
}
Expand Down Expand Up @@ -406,7 +408,7 @@ public void testDividende07()
hasName("6% MAGNUM AG GENUßSCHEINE 99/UNBEGR."), //
hasCurrencyCode("EUR"))));

// check dividende transaction
// check dividends transaction
assertThat(results, hasItem(dividend( //
hasDate("2023-09-05T00:00"), hasShares(60.00), //
hasSource("Dividende07.txt"), //
Expand All @@ -415,6 +417,37 @@ public void testDividende07()
hasTaxes("EUR", 88.02 + 4.84 + 7.92), hasFees("EUR", 0.00))));
}

@Test
public void testDividende08()
{
DeutscheBankPDFExtractor extractor = new DeutscheBankPDFExtractor(new Client());

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

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

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

// check security
assertThat(results, hasItem(security( //
hasIsin("US1912161007"), hasWkn("850663"), hasTicker(null), //
hasName("COCA-COLA CO., THE REGISTERED SHARES DL -,25"), //
hasCurrencyCode("USD"))));

// check dividends transaction
assertThat(results, hasItem(dividend( //
hasDate("2023-12-15T00:00"), hasShares(170.00), //
hasSource("Dividende08.txt"), //
hasNote(null), //
hasAmount("USD", 58.22), hasGrossValue("USD", 78.21), //
hasTaxes("USD", 11.74 + 7.82 + 0.43), hasFees("USD", 0.00))));
}

@Test
public void testWertpapierKauf01()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PDFBox Version: 1.8.17
Portfolio Performance Version: 0.66.2
-----------------------------------------
Deutsche Bank AG
24/7-Kundenservice (069) 910-10000
JyehWInT TFKsxmtiY und
EWLZW Dr. hwapgd KngFGdxcT
lmQjgRJRgsER Str. 3
13210 Usbzsvqhh
18. Dezember 2023
Ihr Depot Nr. 668 8419216 35
Dividendengutschrift
Stück WKN ISIN
170,000000 850663 US1912161007
COCA-COLA CO., THE REGISTERED SHARES DL -,25
Dividende pro Stück 0,4600000000 USD Zahlbar 15.12.2023
Ursprungsland USA Ex-Tag 30.11.2023
Geschäftsjahr 2023
Bruttoertrag 78,20 USD
15,0000000 % Ausländische Quellensteuer - 11,73 USD
Kapitalertragsteuer (KESt) - 7,82 USD
Solidaritätszuschlag auf KESt - 0,43 USD
Umrechnungskurs USD zu EUR 1,1019000000
Gutschrift mit Wert 15.12.2023 58,22 USD
Steuerliche Bemessungsgrundlagen zur Dividendengutschrift - keine Steuerbescheinigung
KESt-pflichtiger Kapitalertrag 70,97 EUR
Anrechenbare ausländische Quellensteuer 10,65 EUR
Auf die KESt angerechnete ausländische
10,65 EUR
Quellensteuer
Vorsitzender des Aufsichtsrats: Alexander R. Wynaendts
Vorstand: Christian Sewing (Vorsitzender), James von Moltke, Fabrizio Campelli, Bernd Leukert, Alexander von zur Mühlen, Claudio de Sanctis, Rebecca Short,
Stefan Simon, Olivier Vigneron
Deutsche Bank Aktiengesellschaft mit Sitz in Frankfurt am Main; Amtsgericht Frankfurt am Main, HRB Nr. 30 000; Umsatzsteuer-Id.-Nr. DE114103379;
www.db.com/de, www.deutsche-bank.de 1/2
TRINCM0001 DIVI 20231216 28176989
Wir überweisen den Betrag von 58,22 USD auf Ihr Konto 1701689 02.
Kapitalerträge sind einkommensteuerpflichtig!
Diese Mitteilung wurde maschinell erstellt und wird nicht unterschrieben.
2/2
Original file line number Diff line number Diff line change
Expand Up @@ -304,22 +304,44 @@ private void addDividendeTransaction()
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
})

// @formatter:off
// Bruttoertrag 98,80 USD 87,13 EUR
// Umrechnungskurs USD zu EUR 1,1339000000
// @formatter:on
.section("fxGross", "gross", "baseCurrency", "termCurrency", "exchangeRate").optional() //
.match("^Bruttoertrag (?<fxGross>[\\.,\\d]+) [\\w]{3} (?<gross>[\\.,\\d]+) [\\w]{3}$") //
.match("^Umrechnungskurs (?<termCurrency>[\\w]{3}) zu (?<baseCurrency>[\\w]{3}) (?<exchangeRate>[\\.,\\d]+)$") //
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);
.optionalOneOf( //
// @formatter:off
// Bruttoertrag 98,80 USD 87,13 EUR
// Umrechnungskurs USD zu EUR 1,1339000000
// @formatter:on
section -> section //
.attributes("fxGross", "gross", "termCurrency", "baseCurrency", "exchangeRate") //
.match("^Bruttoertrag (?<fxGross>[\\.,\\d]+) [\\w]{3} (?<gross>[\\.,\\d]+) [\\w]{3}$") //
.match("^Umrechnungskurs (?<termCurrency>[\\w]{3}) zu (?<baseCurrency>[\\w]{3}) (?<exchangeRate>[\\.,\\d]+)$") //
.assign((t, v) -> {
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);

Money gross = Money.of(rate.getBaseCurrency(), asAmount(v.get("gross")));
Money fxGross = Money.of(rate.getTermCurrency(), asAmount(v.get("fxGross")));
Money gross = Money.of(rate.getBaseCurrency(), asAmount(v.get("gross")));
Money fxGross = Money.of(rate.getTermCurrency(), asAmount(v.get("fxGross")));

checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
})
checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
}),
// @formatter:off
// Bruttoertrag 78,20 USD
// Umrechnungskurs USD zu EUR 1,1019000000
// @formatter:on
section -> section //
.attributes("gross", "baseCurrency", "termCurrency", "exchangeRate") //
.match("^Bruttoertrag (?<gross>[\\.,\\d]+) [\\w]{3}$") //
.match("^Umrechnungskurs (?<termCurrency>[\\w]{3}) zu (?<baseCurrency>[\\w]{3}) (?<exchangeRate>[\\.,\\d]+)$") //
.assign((t, v) -> {
if (!type.getCurrentContext().getBoolean("negative"))
{
ExtrExchangeRate rate = asExchangeRate(v);
type.getCurrentContext().putType(rate);

Money gross = Money.of(rate.getBaseCurrency(), asAmount(v.get("gross")));
Money fxGross = rate.convert(rate.getTermCurrency(), gross);

checkAndSetGrossUnit(gross, fxGross, t, type.getCurrentContext());
}
}))

.conclude(ExtractorUtils.fixGrossValueA())

Expand Down Expand Up @@ -417,7 +439,7 @@ private void addAccountStatementTransaction()
// @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
//
Expand Down

0 comments on commit db6d2b8

Please sign in to comment.