Search in sources :

Example 31 with Block

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

the class INGDiBaExtractor method addDividendengutschrift.

@SuppressWarnings("nls")
private void addDividendengutschrift() {
    final DocumentType type = new DocumentType("Dividendengutschrift", isJointAccount);
    this.addDocumentTyp(type);
    Block block = new Block("Dividendengutschrift");
    type.addBlock(block);
    Transaction<AccountTransaction> transaction = new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction entry = new AccountTransaction();
        entry.setType(AccountTransaction.Type.DIVIDENDS);
        return entry;
    }).section("wkn", "isin", // 
    "name").match("^ISIN \\(WKN\\) (?<isin>[^ ]*) \\((?<wkn>.*)\\)$").match("Wertpapierbezeichnung (?<name>.*)").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").match("^Nominale (?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section(// 
    "date").match(// 
    "Ex-Tag (?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("amount", // 
    "currency").match(// 
    "Gesamtbetrag zu Ihren Gunsten (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).wrap(TransactionItem::new);
    addTaxSectionToAccountTransaction(type, transaction);
    block.set(transaction);
}
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) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 32 with Block

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

the class OnvistaPDFExtractor method addExchangeTransaction.

private void addExchangeTransaction() {
    DocumentType type = new DocumentType("Umtausch");
    this.addDocumentTyp(type);
    Block block = new Block("(Aus|Ein)buchung:(.*)");
    type.addBlock(block);
    Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        PortfolioTransaction entry = new PortfolioTransaction();
        entry.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
        return entry;
    });
    block.set(pdfTransaction);
    // 
    pdfTransaction.section("name", "isin").find(// 
    "Gattungsbezeichnung ISIN").match(// 
    "(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
        // Merken für evtl. Steuerrückerstattung:
        type.getCurrentContext().put("isin", v.get("isin"));
    }).section(// 
    "transactiontype").match(// 
    "^(?<transactiontype>.*buchung:)(.*)").assign((t, v) -> {
        String transactiontype = v.get("transactiontype");
        if ("Einbuchung:".equalsIgnoreCase(transactiontype)) {
            t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
        } else if ("Ausbuchung:".equalsIgnoreCase(transactiontype)) {
            t.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
        } else {
        // TODO: evtl. Warnung/Hinweis ausgeben?
        }
    }).section(// 
    "date").find("(.*)(Schlusstag|Ex-Tag|Wert Konto-Nr.*)").match(// 
    "(.*)(^|\\s+)(?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("currency", "amount").optional().find("(.*)(Schlusstag|Ex-Tag|Wert Konto-Nr.*|Wert Betrag zu Ihren.*)").match("(^|\\s+)(\\d+\\.\\d+\\.\\d{4}+)?(\\s)?(\\d+)?(\\s)?(?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)").assign((t, v) -> t.setAmount(asAmount(v.get("amount")))).section("notation", // 
    "shares").find("Nominal(.*)").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")));
        }
        t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
    }).wrap(TransactionItem::new);
    addTaxesSectionsTransaction(pdfTransaction);
    addTaxBlock(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) 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) 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 33 with Block

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

the class OnvistaPDFExtractor method addTaxBlock.

private void addTaxBlock(DocumentType type) {
    // optional: Steuer dem Konto buchen
    Block block = new Block("(Kapitalertragsteuer)(.*)-$");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction entry = new AccountTransaction();
        entry.setType(AccountTransaction.Type.TAXES);
        return entry;
    }).section("tax").optional().match("^Kapitalertragsteuer (?<currency>\\w{3}+) (?<tax>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(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.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(t.getAmount() + asAmount(v.get("soli")));
    }).section("kirchenst").optional().match("^Kirchensteuer (?<currency>\\w{3}+) (?<kirchenst>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(t.getAmount() + asAmount(v.get("kirchenst")));
    }).section("date", "currency").optional().find("Wert(\\s+)Konto-Nr.(\\s+)Betrag zu Ihren Lasten(\\s*)$").match("(^|\\s+)(?<date>\\d+\\.\\d+\\.\\d{4}+)(\\s)(\\d+)(\\s)(?<currency>\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{2})?)").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        v.put("isin", type.getCurrentContext().get("isin"));
        t.setSecurity(getOrCreateSecurity(v));
    }).wrap(TransactionItem::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) 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) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 34 with Block

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

the class OnvistaPDFExtractor method addSellTransaction.

private void addSellTransaction() {
    DocumentType type = new DocumentType("Wir haben für Sie verkauft");
    this.addDocumentTyp(type);
    Block block = new Block("Wir haben für Sie verkauft(.*)");
    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("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", "time", "amount", // 
    "currency").match("Handelstag (?<date>\\d+.\\d+.\\d{4}+) (.*)").match("Handelszeit (?<time>\\d+:\\d+)(.*)").find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Gunsten(\\s*)$").match("(\\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"), v.get("time")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).wrap(BuySellEntryItem::new);
    addTaxesSectionsTransaction(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) 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 35 with Block

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

the class OnvistaPDFExtractor method addAccountStatementTransaction2017.

private void addAccountStatementTransaction2017() {
    // this seems to be the new format of account statements from the year 2017
    final DocumentType type = new DocumentType("Kontoauszug Nr.", (context, lines) -> {
        Pattern pYear = Pattern.compile("^Kontoauszug Nr. (\\d{4}) / .*\\.(\\d{4})$");
        Pattern pCurrency = Pattern.compile("^(\\w{3}+) - Verrechnungskonto: .*$");
        // read the current context here
        for (String line : lines) {
            Matcher m = pYear.matcher(line);
            if (m.matches()) {
                context.put("year", m.group(1));
            }
            m = pCurrency.matcher(line);
            if (m.matches()) {
                context.put("currency", m.group(1));
            }
        }
    });
    this.addDocumentTyp(type);
    // 31.10. 31.10. REF: 000017304356 37,66
    Block block = new Block("^\\d+\\.\\d+\\.\\s+\\d+\\.\\d+\\.\\s+REF:\\s+\\d+\\s+[\\d.-]+,\\d+[+-]?(.*)");
    type.addBlock(block);
    Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        AccountTransaction entry = new AccountTransaction();
        entry.setType(AccountTransaction.Type.DEPOSIT);
        return entry;
    });
    block.set(pdfTransaction);
    // 
    pdfTransaction.section("valuta", "amount", "sign").match("^\\d+\\.\\d+\\.\\s+(?<valuta>\\d+\\.\\d+\\.)\\s+REF:\\s+\\d+\\s+(?<amount>[\\d.-]+,\\d+)(?<sign>[+-]?)(.*)").assign((t, v) -> {
        Map<String, String> context = type.getCurrentContext();
        String date = v.get("valuta");
        if (date != null) {
            // create a long date from the year in the
            // context
            t.setDateTime(asDate(date + context.get("year")));
        }
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(context.get("currency")));
        // check for withdrawals
        String sign = v.get("sign");
        if ("-".equals(sign)) {
            // change type for withdrawals
            t.setType(AccountTransaction.Type.REMOVAL);
        }
    }).section(// 
    "postingtype").find(// 
    "\\d+\\.\\d+\\.\\s+\\d+\\.\\d+\\. REF:(.*)").match("(?<postingtype>.*?)").assign((t, v) -> {
        String postingtype = v.get("postingtype");
        if (postingtype != null) {
            switch(postingtype) {
                case "Wertpapierkauf":
                case "Umtausch/Bezug":
                case "Sollbuchung HSBC":
                    t.setType(AccountTransaction.Type.BUY);
                    break;
                case "Wertpapierverkauf":
                case "Spitze Verkauf":
                case "Habenbuchung HSBC":
                case "Tilgung":
                    t.setType(AccountTransaction.Type.SELL);
                    break;
                case "Zinsen/Dividenden":
                    t.setType(AccountTransaction.Type.DIVIDENDS);
                    break;
                case "AbgSt. Optimierung":
                    t.setType(AccountTransaction.Type.TAX_REFUND);
                    break;
                default:
                    break;
            }
        }
    }).wrap(t -> {
        // Konto:
        if (t.getType() != AccountTransaction.Type.DIVIDENDS && t.getType() != AccountTransaction.Type.BUY && t.getType() != AccountTransaction.Type.SELL && t.getType() != AccountTransaction.Type.TAX_REFUND)
            return new TransactionItem(t);
        return null;
    });
}
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) 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) Map(java.util.Map)

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