Search in sources :

Example 66 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class DABPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("^Kauf .*$");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("isin", "name", // 
    "currency").find(// 
    "Gattungsbezeichnung ISIN").match("^(?<name>.*) (?<isin>[^ ]*)$").match("STK [\\d.]+(,\\d+)? (?<currency>\\w{3}+) ([\\d.]+,\\d+)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").find(// 
    "Nominal Kurs").match("^STK (?<shares>[\\d.]+(,\\d+)?) (\\w{3}+) ([\\d.]+,\\d+)$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", // 
    "currency").optional().find("Wert Konto-Nr. Betrag zu Ihren Lasten").match("^(\\d+.\\d+.\\d{4}+) ([0-9]*) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section("amount", "currency", "exchangeRate", "forex", "forexCurrency").optional().find(".* Ausmachender Betrag (?<forexCurrency>\\w{3}+) (?<forex>[\\d.]+,\\d+)-").find("Wert Konto-Nr. Devisenkurs Betrag zu Ihren Lasten").match("^(\\d+.\\d+.\\d{4}+) ([0-9]*) .../... (?<exchangeRate>[\\d.]+,\\d+) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
        Money amount = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("amount")));
        t.setMonetaryAmount(amount);
        BigDecimal exchangeRate = // 
        BigDecimal.ONE.divide(asExchangeRate(v.get("exchangeRate")), 10, BigDecimal.ROUND_HALF_DOWN);
        Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("forex")));
        Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, amount, forex, exchangeRate);
        t.getPortfolioTransaction().addUnit(grossValue);
    }).section(// 
    "date").match("^Handelstag (?<date>\\d+.\\d+.\\d{4}+) .*$").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("fees", // 
    "currency").optional().match("^.* Provision (?<currency>\\w{3}+) (?<fees>[\\d.]+,\\d+)-$").assign((t, v) -> {
        String currency = asCurrencyCode(v.get("currency"));
        // FIXME forex fees must update gross value
        if (currency.equals(t.getAccountTransaction().getCurrencyCode())) {
            t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(currency, asAmount(v.get("fees")))));
        }
    }).wrap(t -> {
        if (t.getPortfolioTransaction().getAmount() == 0L)
            throw new IllegalArgumentException("No amount found");
        return new BuySellEntryItem(t);
    }));
}
Also used : BigDecimal(java.math.BigDecimal) 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) Map(java.util.Map) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Money(name.abuchen.portfolio.money.Money) 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) BigDecimal(java.math.BigDecimal)

Example 67 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class DeutscheBankPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Kauf von Wertpapieren");
    this.addDocumentTyp(type);
    Block block = new Block("Abrechnung: Kauf von Wertpapieren");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("wkn", "isin", "name", "currency").find(// 
    "Filialnummer Depotnummer Wertpapierbezeichnung Seite").match(// 
    "^.{15}(?<name>.*)$").match(// 
    "^WKN (?<wkn>[^ ]*) (.*)$").match(// 
    "^ISIN (?<isin>[^ ]*) Kurs (?<currency>\\w{3}+) (.*)$").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
    }).section(// 
    "shares").match(// 
    "^WKN [^ ]* Nominal ST (?<shares>\\d+(,\\d+)?)").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", "currency").match("Buchung auf Kontonummer [\\d ]* mit Wertstellung (?<date>\\d+.\\d+.\\d{4}+) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
        t.setDate(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(v.get("currency"));
    }).section("provision", // 
    "currency").optional().match("Provision( \\([0-9,]* %\\))? (?<currency>\\w{3}+) (?<provision>[\\d.]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("provision")))))).section("additional", // 
    "currency").optional().match("Weitere Provision der Bank bei der börslichen Orderausführung (?<currency>\\w{3}+) (?<additional>[\\d.]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("additional")))))).section("xetra", // 
    "currency").optional().match("XETRA-Kosten (?<currency>\\w{3}+) (?<xetra>[\\d.]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new // 
    Unit(// 
    Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("xetra")))))).wrap(t -> new BuySellEntryItem(t)));
}
Also used : BigDecimal(java.math.BigDecimal) 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) MutableMoney(name.abuchen.portfolio.money.MutableMoney) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 68 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry in project portfolio by buchen.

the class DkbPDFExtractor method addBuyTransactionFund.

private void addBuyTransactionFund() {
    DocumentType type = new DocumentType("Wertpapier Abrechnung Ausgabe Investmentfonds");
    this.addDocumentTyp(type);
    Block block = new Block("Wertpapier Abrechnung Ausgabe Investmentfonds");
    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("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);
    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 69 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry 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 70 with BuySellEntry

use of name.abuchen.portfolio.model.BuySellEntry 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)

Aggregations

BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)169 Client (name.abuchen.portfolio.model.Client)150 IOException (java.io.IOException)141 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)125 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)125 Unit (name.abuchen.portfolio.model.Transaction.Unit)122 Money (name.abuchen.portfolio.money.Money)119 Security (name.abuchen.portfolio.model.Security)111 Test (org.junit.Test)108 ArrayList (java.util.ArrayList)107 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)105 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)105 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)104 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)104 Values (name.abuchen.portfolio.money.Values)83 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)79 LocalDateTime (java.time.LocalDateTime)78 List (java.util.List)78 Optional (java.util.Optional)78 PDFInputFile (name.abuchen.portfolio.datatransfer.pdf.PDFInputFile)75