Search in sources :

Example 56 with DocumentType

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

the class DeutscheBankPDFExtractor method addDividendTransaction.

@SuppressWarnings("nls")
private void addDividendTransaction(String nameOfTransaction) {
    DocumentType type = new DocumentType(nameOfTransaction);
    this.addDocumentTyp(type);
    Block block = new Block(nameOfTransaction);
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction transaction = new AccountTransaction();
        transaction.setType(AccountTransaction.Type.DIVIDENDS);
        return transaction;
    }).section("wkn", "isin", "name", // 
    "currency").find(// 
    "Stück WKN ISIN").match(// 
    "(\\d+,\\d*) (?<wkn>\\S*) (?<isin>\\S*)").match(// 
    "^(?<name>.*)$").match(// 
    "Bruttoertrag ([\\d.]+,\\d+) (?<currency>\\w{3}+).*").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").match("(?<shares>\\d+,\\d*) (\\S*) (\\S*)").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", "currency").match("Gutschrift mit Wert (?<date>\\d+.\\d+.\\d{4}+) (?<amount>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section("grossValue", // 
    "currency").optional().match("Bruttoertrag (?<grossValue>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
        Money grossValue = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("grossValue")));
        // calculating taxes as the difference between gross
        // value and transaction amount
        Money taxes = MutableMoney.of(t.getCurrencyCode()).add(grossValue).subtract(t.getMonetaryAmount()).toMoney();
        if (!taxes.isZero())
            t.addUnit(new Unit(Unit.Type.TAX, taxes));
    }).section("forexSum", "forexCurrency", "grossValue", "currency", // 
    "exchangeRate").optional().match("Bruttoertrag (?<forexSum>[\\d.]+,\\d+) (?<forexCurrency>\\w{3}+) (?<grossValue>[\\d.]+,\\d+) (?<currency>\\w{3}+)").match(// 
    "Umrechnungskurs (\\w{3}+) zu (\\w{3}+) (?<exchangeRate>[\\d.]+,\\d+)").assign((t, v) -> {
        Money grossValue = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("grossValue")));
        Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("forexSum")));
        BigDecimal exchangeRate = // 
        BigDecimal.ONE.divide(asExchangeRate(v.get("exchangeRate")), 10, BigDecimal.ROUND_HALF_DOWN);
        Unit unit = new Unit(Unit.Type.GROSS_VALUE, grossValue, forex, exchangeRate);
        // security actually matches
        if (unit.getForex().getCurrencyCode().equals(t.getSecurity().getCurrencyCode()))
            t.addUnit(unit);
        // calculating taxes as the difference between gross
        // value and transaction amount
        Money taxes = MutableMoney.of(t.getCurrencyCode()).add(grossValue).subtract(t.getMonetaryAmount()).toMoney();
        if (!taxes.isZero())
            t.addUnit(new Unit(Unit.Type.TAX, taxes));
    }).wrap(t -> new TransactionItem(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) Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) 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) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 57 with DocumentType

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

the class DkbPDFExtractor method addBuyTransaction.

private void addBuyTransaction() {
    DocumentType type = new DocumentType("Wertpapier Abrechnung Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("Wertpapier Abrechnung Kauf");
    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 58 with DocumentType

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

the class DkbPDFExtractor method addDividendTransaction.

private void addDividendTransaction() {
    DocumentType type = new DocumentType("Dividendengutschrift");
    this.addDocumentTyp(type);
    Block block = new Block("Dividendengutschrift");
    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").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(^St\\Dck) (?<shares>[\\d,.]*) (?<name>.*) (?<isin>[^ ]*) (\\((?<wkn>.*)\\).*)$").assign((t, v) -> {
        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("(^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) 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 59 with DocumentType

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

the class FinTechGroupBankPDFExtractor method addRemoveNewFormatTransaction.

// since ~2015
@SuppressWarnings("nls")
private void addRemoveNewFormatTransaction() {
    DocumentType type = new DocumentType("Gutschrifts- / Belastungsanzeige");
    this.addDocumentTyp(type);
    Block block = new Block("Kundennummer(.*)");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section("wkn", "isin", "name", "shares").match(// 
    "(?s)(?<wkn>\\w{6}+)(\\s+)(?<isin>\\w{12}+)(\\s+)(?<name>.*?)(\\s+)(?<shares>[\\.\\d]+(,\\d*)?)(.*)").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(v.get("shares")));
    }).section("date").match(// 
    "Fälligkeitstag(\\s*):(\\s+)(?<date>\\d+.\\d+.\\d{4})(.*)").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("amount", "currency").optional().match("(.*)Geldgegenwert(\\*{1,3})(.*)(\\s*):(\\s*)(?<amount>[\\d.]+,\\d+)(\\s+)(?<currency>\\w{3}+)(.*)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section().optional().match("(.*)Bestand haben wir wertlos ausgebucht(.*)").assign((t, v) -> {
        t.setCurrencyCode(t.getAccountTransaction().getSecurity().getCurrencyCode());
        t.setAmount(0L);
        t.getPortfolioTransaction().setType(PortfolioTransaction.Type.TRANSFER_OUT);
        t.setType(PortfolioTransaction.Type.TRANSFER_OUT);
    }).section("fee", "currency").optional().match(".* Provision *(?<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(".* Eigene Spesen *(?<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(".* \\*Fremde Spesen *(?<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("tax", "currency").optional().match(// 
    "(.*)Einbeh. Steuer(.*):(\\s*)(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).wrap(t -> new BuySellEntryItem(t)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) 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) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 60 with DocumentType

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

the class FinTechGroupBankPDFExtractor method addRemoveTransaction.

@SuppressWarnings("nls")
private void addRemoveTransaction() {
    DocumentType type = new DocumentType("Bestandsausbuchung");
    this.addDocumentTyp(type);
    Block block = new Block("Bestandsausbuchung(.*)");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section("date").match(// 
    "Fälligkeitstag(\\s*):(\\s+)(?<date>\\d+.\\d+.\\d{4})(.*)").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name").match(// 
    "Bestandsausbuchung *(?<name>.*) *\\((?<isin>[^/]*)\\)").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
    }).section("shares", "notation").match(// 
    "^Stk\\.\\/Nominale(.*):(\\s+)(?<shares>[\\.\\d]+(,\\d*)?)(\\s*)(?<notation>\\w{3}+)(.*)[Einbeh]+(.*)").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("amount", "currency").optional().match("(.*)Geldgegenwert\\*\\*(.*)(\\s*):(\\s*)(?<amount>[\\d.]+,\\d+)(\\s+)(?<currency>\\w{3}+)(.*)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section().optional().match("(.*)Bestand haben wir wertlos ausgebucht(.*)").assign((t, v) -> {
        t.setCurrencyCode(t.getAccountTransaction().getSecurity().getCurrencyCode());
        t.setAmount(0L);
        t.getPortfolioTransaction().setType(PortfolioTransaction.Type.TRANSFER_OUT);
        t.setType(PortfolioTransaction.Type.TRANSFER_OUT);
    }).section("fee", "currency").optional().match(".* Provision *(?<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(".* Eigene Spesen *(?<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(".* \\*Fremde Spesen *(?<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("tax", "currency").optional().match(// 
    "(.*)Einbeh. Steuer(.*):(\\s*)(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).wrap(t -> new BuySellEntryItem(t)));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) 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) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Aggregations

Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)86 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)86 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