@Test public void testErtragsgutschrift() throws IOException { DeutscheBankPDFExctractor extractor = new DeutscheBankPDFExctractor(new Client()) { @Override String strip(File file) throws IOException { return from("DeutscheBankErtragsgutschrift.txt"); } }; List<Exception> errors = new ArrayList<Exception>(); List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors); assertThat(errors, empty()); assertThat(results.size(), is(2)); new AssertImportActions().check(results, CurrencyUnit.EUR); // check security Security security = assertSecurity(results); // check transaction Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst(); assertThat(item.isPresent(), is(true)); assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class)); AccountTransaction transaction = (AccountTransaction) item.get().getSubject(); assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS)); assertThat(transaction.getSecurity(), is(security)); assertThat(transaction.getDate(), is(LocalDate.parse("2014-12-15"))); assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 1495L))); assertThat(transaction.getShares(), is(Values.Share.factorize(123))); }
@Test public void testErtragsgutschrift2() throws IOException { DeutscheBankPDFExctractor extractor = new DeutscheBankPDFExctractor(new Client()) { @Override String strip(File file) throws IOException { return from(file.getName()); } }; List<Exception> errors = new ArrayList<Exception>(); List<Item> results = extractor.extract(Arrays.asList(new File("DeutscheBankErtragsgutschrift2.txt")), errors); assertThat(errors, empty()); assertThat(results.size(), is(2)); new AssertImportActions().check(results, CurrencyUnit.EUR); // check security Security security = results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity(); assertThat(security.getName(), is("ISHS-MSCI N. AMERIC.UCITS ETF BE.SH.(DT.ZT.)")); assertThat(security.getIsin(), is("DE000A0J2060")); assertThat(security.getWkn(), is("A0J206")); assertThat(security.getCurrencyCode(), is("USD")); // check transaction Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst(); assertThat(item.isPresent(), is(true)); assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class)); AccountTransaction transaction = (AccountTransaction) item.get().getSubject(); assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS)); assertThat(transaction.getSecurity(), is(security)); assertThat(transaction.getDate(), is(LocalDate.parse("2015-03-24"))); assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 16_17L))); assertThat(transaction.getShares(), is(Values.Share.factorize(123))); Optional<Unit> grossValue = transaction.getUnit(Unit.Type.GROSS_VALUE); assertThat(grossValue.isPresent(), is(true)); assertThat(grossValue.get().getAmount(), is(Money.of("EUR", 16_17L))); assertThat(grossValue.get().getForex(), is(Money.of("USD", 17_38L))); assertThat( grossValue.get().getExchangeRate().doubleValue(), IsCloseTo.closeTo(0.930578, 0.000001)); }
@Test public void testErtragsgutschrift7_USD_Freibetrag_nicht_ausgeschoepft() throws IOException { ConsorsbankPDFExctractor extractor = new ConsorsbankPDFExctractor(new Client()); List<Exception> errors = new ArrayList<Exception>(); URL url = FileLocator.resolve( getClass() .getResource( "ConsorsbankErtragsgutschrift7_USD_Freibetrag_nicht_ausgeschoepft.pdf")); List<Item> results = extractor.extract(Arrays.asList(new File(url.getPath())), errors); assertThat(errors, empty()); assertThat(results.size(), is(2)); // check security Security security = results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity(); assertThat(security.getWkn(), is("200417")); assertThat(security.getName(), is("ALTRIA GROUP INC.")); // check dividend transaction AccountTransaction t = (AccountTransaction) results .stream() .filter(i -> i instanceof TransactionItem) .filter( i -> ((AccountTransaction) i.getSubject()).getType() == AccountTransaction.Type.DIVIDENDS) .findFirst() .get() .getSubject(); assertThat(t.getDate(), is(LocalDate.parse("2016-01-11"))); assertThat(t.getShares(), is(Values.Share.factorize(650))); assertThat(t.getMonetaryAmount(), is(Money.of("EUR", 285_60))); assertThat(t.getUnit(Unit.Type.GROSS_VALUE).get().getForex(), is(Money.of("USD", 367_25))); // check tax assertThat(t.getUnitSum(Type.TAX), is(Money.of("EUR", 50_40))); // QUEST }
private void addTaxesSectionsBuySell(Transaction<BuySellEntry> pdfTransaction) { pdfTransaction .section("tax") .optional() // Kapitalertragsteuer EUR 4,22- .match( "^Kapitalertragsteuer (?<currency>\\w{3}+) (?<tax>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)") .assign( (t, v) -> { t.getPortfolioTransaction() .addUnit( new Unit( Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax"))))); }) .section("soli") .optional() .match( "^Solidaritätszuschlag (?<currency>\\w{3}+) (?<soli>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)") .assign( (t, v) -> { t.getPortfolioTransaction() .addUnit( new Unit( Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("soli"))))); }) .section("kirchenst") .optional() .match( "^Kirchensteuer (?<currency>\\w{3}+) (?<kirchenst>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)") .assign( (t, v) -> { t.getPortfolioTransaction() .addUnit( new Unit( Unit.Type.TAX, Money.of( asCurrencyCode(v.get("currency")), asAmount(v.get("kirchenst"))))); }); }
@Test public void testWertpapierVerkauf2() throws IOException { DeutscheBankPDFExctractor extractor = new DeutscheBankPDFExctractor(new Client()) { @Override String strip(File file) throws IOException { return from("DeutscheBankVerkauf2.txt"); } }; List<Exception> errors = new ArrayList<Exception>(); List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors); assertThat(errors, empty()); assertThat(results.size(), is(2)); new AssertImportActions().check(results, CurrencyUnit.EUR); assertSecurity(results); // check buy sell transaction Optional<Item> item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst(); assertThat(item.isPresent(), is(true)); assertThat(item.get().getSubject(), instanceOf(BuySellEntry.class)); BuySellEntry entry = (BuySellEntry) item.get().getSubject(); assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL)); assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL)); assertThat( entry.getPortfolioTransaction().getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(453.66)))); assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2015-01-30"))); assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(8))); assertThat( entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0)))); assertThat( entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(7.90 + 0.60 + 2)))); }
private void addFeesSections(Transaction<BuySellEntry> pdfTransaction) { pdfTransaction .section("brokerage") .optional() .match("(^.*)(Orderprovision) (\\w{3}+) (?<brokerage>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)") .assign( (t, v) -> t.getPortfolioTransaction() .addUnit( new Unit( Unit.Type.FEE, Money.of( asCurrencyCode(v.get("currency")), asAmount(v.get("brokerage")))))) .section("stockfees") .optional() .match("(^.*) (B\\Drsengeb\\Dhr) (\\w{3}+) (?<stockfees>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)") .assign( (t, v) -> t.getPortfolioTransaction() .addUnit( new Unit( Unit.Type.FEE, Money.of( asCurrencyCode(v.get("currency")), asAmount(v.get("stockfees")))))) .section("agent") .optional() .match("(^.*)(Maklercourtage)(\\s+)(\\w{3}+) (?<agent>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)") .assign( (t, v) -> t.getPortfolioTransaction() .addUnit( new Unit( Unit.Type.FEE, Money.of( asCurrencyCode(v.get("currency")), asAmount(v.get("agent")))))); }