@Override public Status process(BuySellEntry entry, Account account, Portfolio portfolio) { if (convertBuySellToDelivery) { PortfolioTransaction t = entry.getPortfolioTransaction(); PortfolioTransaction delivery = new PortfolioTransaction(); delivery.setType( t.getType() == PortfolioTransaction.Type.BUY ? PortfolioTransaction.Type.DELIVERY_INBOUND : PortfolioTransaction.Type.DELIVERY_OUTBOUND); delivery.setDate(t.getDate()); delivery.setSecurity(t.getSecurity()); delivery.setMonetaryAmount(t.getMonetaryAmount()); delivery.setNote(t.getNote()); delivery.setShares(t.getShares()); delivery.addUnits(t.getUnits()); return process(delivery, portfolio); } else { entry.setPortfolio(portfolio); entry.setAccount(account); entry.insert(); return Status.OK_STATUS; } }
private void addBuyTransaction() { DocumentType type = new DocumentType("Wir haben für Sie gekauft"); this.addDocumentTyp(type); Block block = new Block("Wir haben für Sie gekauft(.*)"); type.addBlock(block); Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>(); pdfTransaction.subject( () -> { BuySellEntry entry = new BuySellEntry(); entry.setType(PortfolioTransaction.Type.BUY); return entry; }); block.set(pdfTransaction); pdfTransaction .section("name", "isin") // .find("Gattungsbezeichnung ISIN") // .match("(?<name>.*) (?<isin>[^ ]\\S*)$") // .assign( (t, v) -> { t.setSecurity(getOrCreateSecurity(v)); }) .section("notation", "shares") // .find("Nominal Kurs") // .match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3})?)(.*)") // .assign( (t, v) -> { String notation = v.get("notation"); if (notation != null && !notation.equalsIgnoreCase("STK")) { // Prozent-Notierung, Workaround.. t.setShares((asShares(v.get("shares")) / 100)); } else { t.setShares(asShares(v.get("shares"))); } }) .section("date", "amount", "currency") // .find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Lasten(\\s*)$") // 14.01.2015 172305047 EUR 59,55 // Wert Konto-Nr. Betrag zu Ihren Lasten // 01.06.2011 172305047 EUR 6,40 .match( "(?<date>\\d+.\\d+.\\d{4}+) (\\d{6,12}) (?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)$") .assign( (t, v) -> { t.setDate(asDate(v.get("date"))); t.setAmount(asAmount(v.get("amount"))); t.setCurrencyCode(asCurrencyCode(v.get("currency"))); }) .wrap(t -> new BuySellEntryItem(t)); addFeesSections(pdfTransaction); }
private void addPayingTransaction() { DocumentType type = new DocumentType("Gutschriftsanzeige"); this.addDocumentTyp(type); Block block = new Block("Gutschriftsanzeige(.*)"); type.addBlock(block); Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>(); pdfTransaction.subject( () -> { BuySellEntry entry = new BuySellEntry(); entry.setType(PortfolioTransaction.Type.SELL); return entry; }); block.set(pdfTransaction); pdfTransaction .section("name", "isin") // .find("Gattungsbezeichnung (.*) ISIN") // .match("(?<name>.*) (.*) (?<isin>[^ ]\\S*)$") // .assign( (t, v) -> { t.setSecurity(getOrCreateSecurity(v)); }) .section("notation", "shares") // .find("Nominal Einlösung(.*)$") // .match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3})?)(.*)$") .assign( (t, v) -> { String notation = v.get("notation"); if (notation != null && !notation.equalsIgnoreCase("STK")) { // Prozent-Notierung, Workaround.. t.setShares((asShares(v.get("shares")) / 100)); } else { t.setShares(asShares(v.get("shares"))); } }) .section("date", "amount", "currency") // .find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Gunsten$") // 17.11.2014 172305047 EUR 51,85 .match( "(?<date>\\d+.\\d+.\\d{4}+) (\\d{6,12}) (?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)") .assign( (t, v) -> { t.setDate(asDate(v.get("date"))); t.setAmount(asAmount(v.get("amount"))); t.setCurrencyCode(asCurrencyCode(v.get("currency"))); }) .wrap(t -> new BuySellEntryItem(t)); addTaxesSectionsBuySell(pdfTransaction); }
private void addTransferInTransaction() { DocumentType type = new DocumentType("Wir erhielten zu Gunsten Ihres Depots"); this.addDocumentTyp(type); Block block = new Block("Wir erhielten zu Gunsten Ihres Depots(.*)"); type.addBlock(block); Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>(); pdfTransaction.subject( () -> { BuySellEntry entry = new BuySellEntry(); entry.setType(PortfolioTransaction.Type.TRANSFER_IN); return entry; }); block.set(pdfTransaction); pdfTransaction .section("name", "isin") // .find("Gattungsbezeichnung ISIN") // .match("(?<name>.*) (?<isin>[^ ]\\S*)$") // .assign( (t, v) -> { t.setSecurity(getOrCreateSecurity(v)); }) .section("notation", "shares", "date") // .find("Nominal Schlusstag Wert") // STK 28,000 02.12.2011 02.12.2011 .match( "(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (\\d+.\\d+.\\d{4}+) (?<date>\\d+.\\d+.\\d{4}+)(.*)") .assign( (t, v) -> { String notation = v.get("notation"); if (notation != null && !notation.equalsIgnoreCase("STK")) { // Prozent-Notierung, Workaround.. t.setShares((asShares(v.get("shares")) / 100)); } else { t.setShares(asShares(v.get("shares"))); } t.setDate(asDate(v.get("date"))); t.setCurrencyCode( asCurrencyCode(t.getPortfolioTransaction().getSecurity().getCurrencyCode())); }) .wrap(t -> new BuySellEntryItem(t)); addFeesSections(pdfTransaction); }
@Override public void execute() { BuySellEntry entry = new BuySellEntry(portfolio, account); entry.setDate(transaction.getDate()); entry.setType(PortfolioTransaction.Type.valueOf(transaction.getType().name())); entry.setSecurity(transaction.getSecurity()); entry.setShares(Values.Share.factor()); entry.setAmount(transaction.getAmount()); entry.setCurrencyCode(transaction.getCurrencyCode()); entry.insert(); account.getTransactions().remove(transaction); }
@Test public void testThatCorrectBuySellEntriesAreNotReported() { BuySellEntry entry = new BuySellEntry(portfolio, account); entry.setType(PortfolioTransaction.Type.BUY); entry.setDate(Dates.today()); entry.setSecurity(security); entry.setShares(1); entry.setAmount(100); entry.insert(); assertThat(new CrossEntryCheck().execute(client).size(), is(0)); }
@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 addDividendTransaction() { DocumentType type = new DocumentType("Erträgnisgutschrift"); this.addDocumentTyp(type); // Erträgnisgutschrift allein ist nicht gut hier, da es schon in der // Kopfzeile steht.. Block block = new Block( "Dividendengutschrift.*|Kupongutschrift.*|Erträgnisgutschrift.*(\\d+.\\d+.\\d{4})"); type.addBlock(block); Transaction<AccountTransaction> pdfTransaction = new Transaction<AccountTransaction>(); pdfTransaction.subject( () -> { AccountTransaction transaction = new AccountTransaction(); transaction.setType(AccountTransaction.Type.DIVIDENDS); return transaction; }); block.set(pdfTransaction); pdfTransaction .section("name", "isin") // .find("Gattungsbezeichnung(.*) ISIN") // Commerzbank AG Inhaber-Aktien o.N. DE000CBK1001 // 5,5% TUI AG Wandelanl.v.2009(2014) 17.11.2014 // 17.11.2010 DE000TUAG117 .match("(?<name>.*?) (\\d+.\\d+.\\d{4} ){0,2}(?<isin>[^ ]\\S*)$") // .assign( (t, v) -> { t.setSecurity(getOrCreateSecurity(v)); }) .section("notation", "shares", "date", "amount", "currency") // .find("Nominal (Ex-Tag )?Zahltag (.*etrag pro // .*)?(Zinssatz.*)?") // STK 25,000 17.05.2013 17.05.2013 EUR 0,700000 // Leistungen aus dem steuerlichen Einlagenkonto (§27 // KStG) EUR 17,50 .match( "(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (\\d+.\\d+.\\d{4}+) (?<date>\\d+.\\d+.\\d{4}+)?(.*)") .match( "(?<date>\\d+.\\d+.\\d{4}+)?(\\d{6,12})?(.{7,58} )?(?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)") .assign( (t, v) -> { String notation = v.get("notation"); if (notation != null && !notation.equalsIgnoreCase("STK")) { // Prozent-Notierung, Workaround.. t.setShares((asShares(v.get("shares")) / 100)); } else { t.setShares(asShares(v.get("shares"))); } t.setDate(asDate(v.get("date"))); t.setAmount(asAmount(v.get("amount"))); t.setCurrencyCode(asCurrencyCode(v.get("currency"))); }) .wrap(t -> new TransactionItem(t)); addTaxesSectionsAccount(pdfTransaction); // optional: Reinvestierung in: block = new Block("Reinvestierung.*"); type.addBlock(block); block.set( new Transaction<BuySellEntry>() .subject( () -> { BuySellEntry entry = new BuySellEntry(); entry.setType(PortfolioTransaction.Type.BUY); return entry; }) .section("date") .match( "(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (\\d+.\\d+.\\d{4}+) (?<date>\\d+.\\d+.\\d{4}+)?(.*)") .assign((t, v) -> t.setDate(asDate(v.get("date")))) .section("name", "isin") // .find("Die Dividende wurde wie folgt in neue Aktien reinvestiert:") .find("Gattungsbezeichnung ISIN") // .match("(?<name>.*) (?<isin>[^ ]\\S*)$") // .assign( (t, v) -> { t.setSecurity(getOrCreateSecurity(v)); }) .section("notation", "shares", "amount", "currency") // .find("Nominal Reinvestierungspreis") // STK 25,000 EUR 0,700000 .match( "(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(.*)") .assign( (t, v) -> { String notation = v.get("notation"); if (notation != null && !notation.equalsIgnoreCase("STK")) { // Prozent-Notierung, Workaround.. t.setShares((asShares(v.get("shares")) / 100)); } else { t.setShares(asShares(v.get("shares"))); } t.setCurrencyCode(asCurrencyCode(v.get("currency"))); }) .wrap(t -> new BuySellEntryItem(t))); }