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 DADAT PDF-Importer to support dividends with exchangeRate #2378

Merged
merged 1 commit into from
Aug 15, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,61 @@ public void testWertpapierDividende02()
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
}

@Test
public void testWertpapierDividende03()
{
DADATBankenhausPDFExtractor extractor = new DADATBankenhausPDFExtractor(new Client());

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

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

assertThat(errors, empty());
assertThat(results.size(), is(4));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
Security security = results.stream().filter(i -> i instanceof SecurityItem).findFirst()
.orElseThrow(IllegalArgumentException::new).getSecurity();
assertThat(security.getIsin(), is("US00206R1023"));
assertThat(security.getName(), is("AT + T INC. DL 1"));
assertThat(security.getCurrencyCode(), is(CurrencyUnit.USD));

// check 1st dividends transaction
AccountTransaction transaction = (AccountTransaction) results.stream().filter(i -> i instanceof TransactionItem).findFirst()
.orElseThrow(IllegalArgumentException::new).getSubject();

assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2021-08-03T00:00")));
assertThat(transaction.getShares(), is(Values.Share.factorize(200)));

assertThat(transaction.getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(63.05))));
assertThat(transaction.getGrossValue(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(86.96))));
assertThat(transaction.getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(23.91))));
assertThat(transaction.getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));

// check 2nd dividends transaction
transaction = (AccountTransaction) results.stream().filter(i -> i instanceof TransactionItem).collect(Collectors.toList())
.get(1).getSubject();

assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2021-08-03T00:00")));
assertThat(transaction.getShares(), is(Values.Share.factorize(40)));

assertThat(transaction.getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(15.22))));
assertThat(transaction.getGrossValue(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(20.99))));
assertThat(transaction.getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize((3.77 / 1.1959) + (3.13 / 1.1959)))));
assertThat(transaction.getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
}

@Test
public void testSteuernAusschuettungsgleicheErtraege01()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
PDF author: ''
PDFBox Version: 1.8.16
-----------------------------------------
DADAT-Bank KONTOAUSZUG
BH Schelhammer & Schattera AG vom 03.08.2021
68273
Kundennummer
Alter Saldo per 05.07.2021 527,91
Summe der Gutschriften 78,27
Summe der Lastschriften 0,00
BH Schelhammer, PF 1000, 5021 Salzburg
Neuer Saldo zu Ihren Gunsten
Max Moritz EUR 606,18
Mühlengasse 08/15
1010 Wien
Konto-Nr.: 012345123450 Bankleitzahl: 19190
Empfängerhinweis:
Datum Buchungstext Wert Betrag
03.08 Ertrag Depot 0123456700/20210802-1234567 02.08 63,05
ISIN US00206R1023 AT + T INC. DL 1 200,00000 STK
Kurs 0,520000 ZINSERTRAG 104,00 USD
QUELLENSTEUER -15,60 USD Auslands-KESt -13,00 USD
DevKurs 1,195900/30.7.2021
03.08 Ertrag Depot 0123456700/20210802-1234568 02.08 15,22
ISIN US92343V1044 VERIZON COMM. INC. DL-,10 40,00000 STK
Kurs 0,627500 ZINSERTRAG 25,10 USD
QUELLENSTEUER -3,77 USD Auslands-KESt -3,13 USD
DevKurs 1,195900/30.7.2021
Neuer Saldo zu Ihren Gunsten 606,18
AT21 1919 0000 1234 5678 BSSWATWW 01 0037 1/1
IBAN BIC Filiale Auszug Blatt/Gesamt
R0092 12342 Doknr.: EK00-045-1000000008
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void addDividendeAccountStatementTransaction()
Matcher m = pCurrency.matcher(line);
if (m.matches())
{
context.put("currency", m.group("currency"));
context.put("localCurrency", m.group("currency"));
}
}
});
Expand All @@ -344,16 +344,46 @@ private void addDividendeAccountStatementTransaction()
// 31.07 Ertrag Depot 7800000000/20200730-45756156 30.07 8,16
// ISIN AT0000969985 AT+S AUST. TECH.SYS.O.N. 45,00000 STK
// Kurs 0,250000 ZINSERTRAG 11,25 EUR
.section("date", "year", "amount", "isin", "name", "shares", "currency")
.section("date", "year", "amount", "isin", "name", "shares", "currency").optional()
.match("^(?<date>\\d+.\\d+) Ertrag [\\s]+Depot [\\s]+[\\d]+\\/(?<year>[\\d]{4})[\\d]+\\-[\\d]+ [\\d]+.[\\d]+ (?<amount>[.,\\d]+)([-])?$")
.match("^ISIN (?<isin>[\\w]{12}) (?<name>.*) [\\s]+(?<shares>[.,\\d]+) STK$")
.match("^.* ZINSERTRAG [\\s]+([-])?[.,\\d]+ (?<currency>[\\w]{3})$")
.assign((t, v) -> {
t.setDateTime(asDate(v.get("date") + "." + v.get("year")));
t.setShares(asShares(v.get("shares")));
t.setSecurity(getOrCreateSecurity(v));
t.setCurrencyCode(asCurrencyCode(type.getCurrentContext().get("currency")));
t.setCurrencyCode(asCurrencyCode(type.getCurrentContext().get("localCurrency")));
t.setAmount(asAmount(v.get("amount")));
})

// 03.08 Ertrag Depot 0123456700/20210802-1234567 02.08 63,05
// ISIN US00206R1023 AT + T INC. DL 1 200,00000 STK
// Kurs 0,520000 ZINSERTRAG 104,00 USD
// QUELLENSTEUER -15,60 USD Auslands-KESt -13,00 USD
// DevKurs 1,195900/30.7.2021
.section("date", "year", "amount", "isin", "name", "shares", "forexCurrency", "exchangeRate").optional()
.match("^(?<date>\\d+.\\d+) Ertrag [\\s]+Depot [\\s]+[\\d]+\\/(?<year>[\\d]{4})[\\d]+\\-[\\d]+ [\\d]+.[\\d]+ (?<amount>[.,\\d]+)([-])?$")
.match("^ISIN (?<isin>[\\w]{12}) (?<name>.*) [\\s]+(?<shares>[.,\\d]+) STK$")
.match("^.* ZINSERTRAG [\\s]+([-])?[.,\\d]+ (?<forexCurrency>[\\w]{3})$")
.match("^DevKurs [\\s]+(?<exchangeRate>[.,\\d]+)\\/.*$")
.assign((t, v) -> {
t.setDateTime(asDate(v.get("date") + "." + v.get("year")));
t.setShares(asShares(v.get("shares")));
t.setSecurity(getOrCreateSecurity(v));
t.setCurrencyCode(asCurrencyCode(type.getCurrentContext().get("localCurrency")));
t.setAmount(asAmount(v.get("amount")));

BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate")).setScale(10,
RoundingMode.HALF_DOWN);
BigDecimal inverseRate = BigDecimal.ONE.divide(exchangeRate, 10, RoundingMode.HALF_DOWN);

type.getCurrentContext().put("exchangeRate", exchangeRate.toPlainString());

Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")),
Math.round(t.getAmount() / inverseRate.doubleValue()));
Unit unit = new Unit(Unit.Type.GROSS_VALUE, t.getMonetaryAmount(), forex, inverseRate);
if (unit.getForex().getCurrencyCode().equals(t.getSecurity().getCurrencyCode()))
t.addUnit(unit);
})

.wrap(TransactionItem::new);
Expand Down Expand Up @@ -448,13 +478,27 @@ private <T extends Transaction<?>> void addTaxesSectionsTransaction(T transactio
processTaxEntries(t, v, type);
})

// QUELLENSTEUER -15,60 USD Auslands-KESt -13,00 USD
.section("tax", "currency").optional()
.match("^QUELLENSTEUER [\\s]+-(?<tax>[.,\\d]+) (?<currency>[\\w]{3}) .*$")
.assign((t, v) -> {
processTaxEntries(t, v, type);
})

// Auslands-KESt: -1,54 USD
.section("tax", "currency").optional()
.match("^Auslands-KESt: -(?<tax>[.,\\d]+) (?<currency>[\\w]{3}).*$")
.assign((t, v) -> {
processTaxEntries(t, v, type);
})

// QUELLENSTEUER -3,77 USD Auslands-KESt -3,13 USD
.section("tax", "currency").optional()
.match("^.* Auslands-KESt [\\s]+-(?<tax>[.,\\d]+) (?<currency>[\\w]{3})$")
.assign((t, v) -> {
processTaxEntries(t, v, type);
})

// KEST -140,27 USD Handelsspesen -5,07 USD
.section("tax", "currency").optional()
.match("^KEST [\\s]+-(?<tax>[.,\\d]+) (?<currency>[\\w]{3}).*$")
Expand Down