Search in sources :

Example 16 with Block

use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.

the class DkbPDFExtractor method addSellTransaction.

private void addSellTransaction() {
    DocumentType type = new DocumentType("Wertpapier Abrechnung Verkauf");
    this.addDocumentTyp(type);
    Block block = new Block("Wertpapier Abrechnung Verkauf");
    type.addBlock(block);
    Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    });
    block.set(pdfTransaction);
    pdfTransaction.section("notation", "shares", "name", "isin", "wkn").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(?<notation>^St\\Dck|^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{2,})?) (?<name>.*) (?<isin>[^ ]*) (\\((?<wkn>.*)\\).*)$").assign((t, v) -> {
        String notation = v.get("notation");
        if (notation != null && !(notation.startsWith("St") && notation.endsWith("ck"))) {
            // Prozent-Notierung, Workaround..
            t.setShares(asShares(v.get("shares")) / 100);
        } else {
            t.setShares(asShares(v.get("shares")));
        }
        t.setSecurity(getOrCreateSecurity(v));
    }).section("date", "amount").match("(^Schlusstag)(/-Zeit)? (?<date>\\d+.\\d+.\\d{4}+) (.*)").match("(^Ausmachender Betrag) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?) (?<currency>\\w{3}+)(.*)").assign((t, v) -> {
        t.setDate(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).wrap(BuySellEntryItem::new);
    addTaxesSectionsTransaction(type, pdfTransaction);
    addFeesSectionsTransaction(pdfTransaction);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)

Example 17 with Block

use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.

the class DkbPDFExtractor method addRemoveTransaction.

private void addRemoveTransaction() {
    DocumentType type = new DocumentType("ung");
    this.addDocumentTyp(type);
    Block block = new Block("Gesamtkündigung|Teilrückzahlung mit Nennwertänderung" + "|Teilliquidation mit Nennwertreduzierung|Einlösung bei Gesamtfälligkeit");
    type.addBlock(block);
    Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.getPortfolioTransaction().setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
        entry.getAccountTransaction().setType(AccountTransaction.Type.TRANSFER_IN);
        return entry;
    });
    block.set(pdfTransaction);
    pdfTransaction.section("notation", "shares", "name", "isin", "wkn").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(?<notation>^St\\Dck|^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{2,})?) (?<name>.*) (?<isin>[^ ]*) (\\((?<wkn>.*)\\).*)$").assign((t, v) -> {
        String notation = v.get("notation");
        if (notation != null && !(notation.startsWith("St") && notation.endsWith("ck"))) {
            // Prozent-Notierung, Workaround..
            t.setShares(asShares(v.get("shares")) / 100);
        } else {
            t.setShares(asShares(v.get("shares")));
        }
        t.setSecurity(getOrCreateSecurity(v));
        // Merken für evtl. Steuerrückerstattung:
        type.getCurrentContext().put("isin", v.get("isin"));
    }).section("date", "amount", "sign").match("(^Ausmachender Betrag) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?[+-]) (?<currency>\\w{3}+)(.*)").match("(^Den Betrag buchen wir mit Valuta) (?<date>\\d+.\\d+.\\d{4}+) zu (?<sign>Gunsten|Lasten) des Kontos (.*)").assign((t, v) -> {
        String sign = v.get("sign");
        if ("Lasten".equalsIgnoreCase(sign)) {
            t.getPortfolioTransaction().setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
            t.getAccountTransaction().setType(AccountTransaction.Type.TRANSFER_OUT);
        }
        t.setDate(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).wrap(BuySellEntryItem::new);
    addTaxesSectionsTransaction(type, pdfTransaction);
    addFeesSectionsTransaction(pdfTransaction);
    addTaxReturnBlock(type);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)

Example 18 with Block

use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.

the class DkbPDFExtractor method addInterestTransaction.

private void addInterestTransaction() {
    DocumentType type = new DocumentType("Zinsgutschrift");
    this.addDocumentTyp(type);
    Block block = new Block("Zinsgutschrift");
    type.addBlock(block);
    Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        AccountTransaction transaction = new AccountTransaction();
        transaction.setType(AccountTransaction.Type.DIVIDENDS);
        return transaction;
    });
    block.set(pdfTransaction);
    pdfTransaction.section("notation", "shares", "name", "isin", "wkn").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(?<notation>^St\\Dck|^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{2,})?) (?<name>.*) (?<isin>[^ ]*) (\\((?<wkn>.*)\\).*)$").assign((t, v) -> {
        String notation = v.get("notation");
        if (notation != null && !(notation.startsWith("St") && notation.endsWith("ck"))) {
            // Prozent-Notierung, Workaround..
            t.setShares(asShares(v.get("shares")) / 100);
        } else {
            t.setShares(asShares(v.get("shares")));
        }
        t.setSecurity(getOrCreateSecurity(v));
    }).section("date", "amount").match("(^Ausmachender Betrag) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(.*) (?<currency>\\w{3}+)").match("(^Den Betrag buchen wir mit Wertstellung) (?<date>\\d+.\\d+.\\d{4}+) zu Gunsten des Kontos (.*)").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).wrap(TransactionItem::new);
    addTaxesSectionsTransaction(type, pdfTransaction);
    addFeesSectionsTransaction(pdfTransaction);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 19 with Block

use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.

the class DkbPDFExtractor method addTransferOutTransaction.

private void addTransferOutTransaction() {
    DocumentType type = new DocumentType("Depotbuchung - Belastung");
    this.addDocumentTyp(type);
    Block block = new Block("Depotbuchung - Belastung");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.TRANSFER_OUT);
        return entry;
    }).section("notation", "shares", "name", "isin", "wkn").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(?<notation>^St\\Dck|^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{2,})?) (?<name>.*) (?<isin>[^ ]*) (\\((?<wkn>.*)\\).*)$").assign((t, v) -> {
        String notation = v.get("notation");
        if (notation != null && !(notation.startsWith("St") && notation.endsWith("ck"))) {
            // Prozent-Notierung, Workaround..
            t.setShares(asShares(v.get("shares")) / 100);
        } else {
            t.setShares(asShares(v.get("shares")));
        }
        t.setSecurity(getOrCreateSecurity(v));
    }).section("date").match("(^Valuta) (?<date>\\d+.\\d+.\\d{4}+) (.*)").assign((t, v) -> {
        t.setDate(asDate(v.get("date")));
        t.setCurrencyCode(asCurrencyCode(t.getPortfolioTransaction().getSecurity().getCurrencyCode()));
    }).wrap(BuySellEntryItem::new));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)

Example 20 with Block

use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.

the class DkbPDFExtractor method addInvestmentEarningTransaction.

private void addInvestmentEarningTransaction() {
    DocumentType type = new DocumentType("Investmenterträge", (context, lines) -> {
        Pattern pattern = Pattern.compile("Devisenkurs (?<term>\\w{3}+) / (?<base>\\w{3}+) (?<exchangeRate>[\\d,.]*)");
        for (String line : lines) {
            Matcher m = pattern.matcher(line);
            if (m.matches())
                context.put(EXCHANGE_RATE, m.group("exchangeRate"));
        }
    });
    this.addDocumentTyp(type);
    Block block = new Block("Gutschrift von Investmenterträgen");
    type.addBlock(block);
    Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        AccountTransaction transaction = new AccountTransaction();
        transaction.setType(AccountTransaction.Type.DIVIDENDS);
        return transaction;
    });
    block.set(pdfTransaction);
    pdfTransaction.section("shares", "name", "isin", "wkn", "currency").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(^St\\Dck) (?<shares>[\\d,.]*) (?<name>.*)$").match(// 
    ".*").match(// 
    "(?<isin>[^ ]*) \\((?<wkn>.*)\\)$").match("^Ertrag pro St. [\\d,.]* (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setShares(asShares(v.get("shares")));
        t.setSecurity(getOrCreateSecurity(v));
    }).section("date", "amount").match("(^Ausmachender Betrag) (?<amount>[\\d,.]*)(.*) (?<currency>\\w{3}+)").match("(^Lagerstelle) (.*)").match("(^Den Betrag buchen wir mit Wertstellung) (?<date>\\d+.\\d+.\\d{4}+) zu Gunsten des Kontos (.*)").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).wrap(TransactionItem::new);
    addTaxesSectionsTransaction(type, pdfTransaction);
    addFeesSectionsTransaction(pdfTransaction);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Matcher(java.util.regex.Matcher) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Aggregations

Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)83 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)83 Transaction (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction)81 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)81 IOException (java.io.IOException)80 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)80 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)80 Client (name.abuchen.portfolio.model.Client)80 Unit (name.abuchen.portfolio.model.Transaction.Unit)79 Money (name.abuchen.portfolio.money.Money)78 Map (java.util.Map)58 Matcher (java.util.regex.Matcher)58 Pattern (java.util.regex.Pattern)58 BigDecimal (java.math.BigDecimal)42 Values (name.abuchen.portfolio.money.Values)16 BiConsumer (java.util.function.BiConsumer)9 MutableMoney (name.abuchen.portfolio.money.MutableMoney)7 RoundingMode (java.math.RoundingMode)6 Optional (java.util.Optional)5 Type (name.abuchen.portfolio.model.Transaction.Unit.Type)5