Search in sources :

Example 81 with Transaction

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

the class OnvistaPDFExtractor method addDepositTransaction.

private void addDepositTransaction() {
    final DocumentType type = new DocumentType("Depotauszug", (context, lines) -> {
        Pattern pDate = Pattern.compile("Depotauszug per (\\d+.\\d+.\\d{4}+)?(.*)");
        Pattern pCurrency = Pattern.compile("(.*)Bewertung in[ ]+(\\w{3}+)");
        // read the current context here
        for (String line : lines) {
            Matcher m = pDate.matcher(line);
            if (m.matches()) {
                context.put("date", m.group(1));
            }
            m = pCurrency.matcher(line);
            if (m.matches()) {
                context.put("currency", m.group(2));
            }
        }
    });
    this.addDocumentTyp(type);
    Block block = new Block("(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?)(.*)");
    type.addBlock(block);
    Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        PortfolioTransaction entry = new PortfolioTransaction();
        entry.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
        return entry;
    });
    block.set(pdfTransaction);
    // Die WP-Bezeichnung muss hier leider über mehrere Zeilen hinweg
    // zusammengesucht werden, da im Depotauszug-PDF-Extrakt leider
    // (zumindest teilweise) Zeilenumbrüche innerhalb des Namens sind... (s.
    // Beispiel-Datei: OnvistaDepotauszug.txt)
    pdfTransaction.section("notation", "shares", "nameP1").optional().match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?) (?<nameP1>.*)").assign((t, v) -> {
        type.getCurrentContext().put("nameP1", v.get("nameP1"));
        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("nameP3").optional().find("(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (.*)").match("^(?<nameP3>^.*?)(\\s*)").assign((t, v) -> type.getCurrentContext().put("nameP3", v.get("nameP3"))).section("nameP2", "isin").optional().match("(?<nameP2>.* )(?<isin>\\w{12}+) (.*)").assign((t, v) -> {
        type.getCurrentContext().put("nameP2", v.get("nameP2"));
        type.getCurrentContext().put("isin", v.get("isin"));
    }).section("nameP4").optional().find("^(.*) (\\w{12}+) (.*)").match("^(?<nameP4>^.*\\.*)$").assign((t, v) -> type.getCurrentContext().put("nameP4", v.get("nameP4"))).section(// 
    "combine").match(// 
    "(?<combine>.*)").assign((t, v) -> {
        String name = type.getCurrentContext().get("nameP1") + type.getCurrentContext().get("nameP2") + type.getCurrentContext().get("nameP3") + type.getCurrentContext().get("nameP4");
        v.put("isin", type.getCurrentContext().get("isin"));
        if (name.indexOf(v.get("isin")) > -1) {
            name = name.substring(0, name.indexOf(v.get("isin")));
        }
        if (name.indexOf("STK ") > -1) {
            name = name.substring(0, name.indexOf("STK "));
        }
        // WP-Bezeichnung nachbearbeiten, kann doppelte
        // Leerzeichen enthalten...
        name = name.replaceAll("\\s+", " ");
        // oder auch überflüssige Nullen (00)...
        name = name.replaceAll("0+%", "%");
        // oder <Leerzeichen><Punkt> ( .)
        name = name.replaceAll("\\s+\\.", ".");
        v.put("name", name);
        t.setSecurity(getOrCreateSecurity(v));
        if (t.getDateTime() == null) {
            t.setDateTime(asDate(type.getCurrentContext().get("date")));
        }
        if (t.getCurrencyCode() == null) {
            t.setCurrencyCode(asCurrencyCode(type.getCurrentContext().get("currency")));
        }
    }).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) 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) Matcher(java.util.regex.Matcher) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)

Example 82 with Transaction

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

the class OnvistaPDFExtractor method addRemoveDididendRightsTransaction.

private void addRemoveDididendRightsTransaction() {
    DocumentType type = new DocumentType("Wertlose Ausbuchung");
    this.addDocumentTyp(type);
    Block block = new Block("Wertlose Ausbuchung(.*)");
    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(// 
    "Ausbuchung:(\\s*)").find(// 
    "Gattungsbezeichnung ISIN").match(// 
    "(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("notation", "shares", // 
    "date").find("Nominal Ex-Tag").match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?) (?<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.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
        t.setDateTime(asDate(v.get("date")));
    }).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) 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 83 with Transaction

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

the class OnvistaPDFExtractor method addBuyTransaction.

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<>();
    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", "time", "amount", // 
    "currency").match("Handelstag (?<date>\\d+.\\d+.\\d{4}+) (.*)").match("Handelszeit (?<time>\\d+:\\d+)(.*)").find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Lasten(\\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);
    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 84 with Transaction

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

the class SBrokerPDFExtractor method addSellTransaction.

@SuppressWarnings("nls")
private void addSellTransaction() {
    DocumentType type = new DocumentType("Verkauf");
    this.addDocumentTyp(type);
    Block block = new Block("Verkauf .*");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section("isin", // 
    "name").find(// 
    "Gattungsbezeichnung ISIN").match("(?<name>.*) Inhaber-Anteile (?<isin>.*)").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("date", "amount", // 
    "currency").find("Wert Konto-Nr. Betrag zu Ihren Gunsten").match(// 
    "(?<date>\\d+.\\d+.\\d{4}) \\d{2}/\\d{4}/\\d{3} (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
        t.setDate(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section(// 
    "shares").match(// 
    "^STK (?<shares>\\d+,\\d+?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("fee", "currency").optional().match(// 
    ".* Orderentgelt (?<currency>\\w{3}+) (?<fee>[\\d.]+,\\d+)-").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("fee", "currency").optional().match(// 
    ".* Börsengebühr (?<currency>\\w{3}+) (?<fee>[\\d.]+,\\d+)-").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).wrap(t -> new BuySellEntryItem(t)));
}
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) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Aggregations

Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)84 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)84 Transaction (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction)84 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)84 IOException (java.io.IOException)83 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)83 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)83 Client (name.abuchen.portfolio.model.Client)83 Unit (name.abuchen.portfolio.model.Transaction.Unit)82 Money (name.abuchen.portfolio.money.Money)81 Map (java.util.Map)60 Matcher (java.util.regex.Matcher)60 Pattern (java.util.regex.Pattern)60 BigDecimal (java.math.BigDecimal)43 Values (name.abuchen.portfolio.money.Values)16 BiConsumer (java.util.function.BiConsumer)11 RoundingMode (java.math.RoundingMode)7 MutableMoney (name.abuchen.portfolio.money.MutableMoney)7 Optional (java.util.Optional)6 Type (name.abuchen.portfolio.model.Transaction.Unit.Type)6