Search in sources :

Example 66 with Block

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

the class BaaderBankPDFExtractor method addDepositTransaction.

@SuppressWarnings("nls")
private void addDepositTransaction() {
    final DocumentType type = new DocumentType("Perioden-Kontoauszug", (context, lines) -> {
        Pattern pCurrency = Pattern.compile("Perioden-Kontoauszug:[ ]+(\\w{3}+)-Konto");
        // read the current context here
        for (String line : lines) {
            Matcher m = pCurrency.matcher(line);
            if (m.matches()) {
                context.put("currency", m.group(1));
            }
        }
    });
    this.addDocumentTyp(type);
    // deposit, add value to account
    // 01.01.2020 Lastschrift aktiv 01.01.2020 123,45
    Block block = new Block("\\d+\\.\\d+\\.\\d{4}[ ]+Lastschrift aktiv[ ]+\\d+\\.\\d+\\.\\d{4}[ ]+[\\d.]+,\\d{2}");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.DEPOSIT);
        return t;
    }).section("valuta", "amount").match("\\d+\\.\\d+\\.\\d{4}[ ]+Lastschrift aktiv[ ]+(?<valuta>\\d+\\.\\d+\\.\\d{4})[ ]+(?<amount>[\\d.]+,\\d{2})").assign((t, v) -> {
        Map<String, String> context = type.getCurrentContext();
        t.setCurrencyCode(asCurrencyCode(context.get("currency")));
        t.setDateTime(asDate(v.get("valuta")));
        t.setAmount(asAmount(v.get("amount")));
    // t.setNote(v.get("text"));
    }).wrap(t -> new TransactionItem(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) 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)

Example 67 with Block

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

the class BankSLMPDFExtractor method addDividendTransaction.

@SuppressWarnings("nls")
private void addDividendTransaction() {
    DocumentType type = new DocumentType("Dividende");
    this.addDocumentTyp(type);
    Block block = new Block("Dividende");
    type.addBlock(block);
    Transaction<AccountTransaction> extractor = new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction transaction = new AccountTransaction();
        transaction.setType(AccountTransaction.Type.DIVIDENDS);
        return transaction;
    }).section("date", "shares", "name", "wkn", "currency").match(// 
    "Am (?<date>\\d+.\\d+.\\d{4}+) wurde folgende Dividende gutgeschrieben:").match(// 
    "^.*$").match(// 
    "^(?<name>.*)$").match(// 
    "^Valor: (?<wkn>[^ ]*)$").match(// 
    "Brutto \\((?<shares>[\\d.']+) \\* ... ([\\d.']+)\\) (?<currency>\\w{3}+) ([\\d.']+)").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setShares(asShares(v.get("shares")));
        t.setSecurity(getOrCreateSecurity(v));
    }).section("amount", // 
    "currency").match(// 
    "Netto (?<currency>\\w{3}+) (?<amount>[\\d.']+)").assign((t, v) -> {
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(v.get("currency"));
    }).section("fees", "currency").optional().match(// 
    ".* Verrechnungssteuer (?<currency>\\w{3}+) -(?<fees>[\\d.']+)").assign((t, v) -> t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fees")))))).section("fees", "currency").optional().match(// 
    ".* Quellensteuer (?<currency>\\w{3}+) -(?<fees>[\\d.']+)").assign((t, v) -> t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fees")))))).section("fees", "currency").optional().match(// 
    ".* Nicht r.ckforderbare Steuern (?<currency>\\w{3}+) -(?<fees>[\\d.']+)").assign((t, v) -> t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fees")))))).section("grossValue", "forexSum", "forexCurrency", "totalValue", "currency", // 
    "exchangeRate").optional().match(// 
    "Brutto \\(([\\d.']+) \\* ... ([\\d.']+)\\) (\\w{3}+) (?<grossValue>[\\d.']+)").match(// 
    "Netto (?<forexCurrency>\\w{3}+) (?<forexSum>[\\d.']+)").match(// 
    "Change ... / ... (?<exchangeRate>[\\d.']+) (?<currency>\\w{3}+) (?<totalValue>[\\d.'-]+)").assign((t, v) -> {
        // NOSONAR
        // if we end up in the branch, then we have forex
        // dividends and must convert taxes in local
        // currency
        Money totalValue = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("totalValue")));
        t.setMonetaryAmount(totalValue);
        // keep tax units in case we need to convert them
        List<Unit> tax = t.getUnits().collect(Collectors.toList());
        t.clearUnits();
        Money forexGrossValue = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("grossValue")));
        BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate"));
        Money grossValue = Money.of(totalValue.getCurrencyCode(), Math.round(exchangeRate.doubleValue() * forexGrossValue.getAmount()));
        Unit unit = new Unit(Unit.Type.GROSS_VALUE, grossValue, forexGrossValue, exchangeRate);
        t.addUnit(unit);
        // convert tax units
        tax.stream().forEach(u -> {
            if (u.getAmount().getCurrencyCode().equals(t.getCurrencyCode())) {
                t.addUnit(u);
            } else {
                Money txm = Money.of(t.getCurrencyCode(), Math.round(exchangeRate.doubleValue() * u.getAmount().getAmount()));
                Unit fu = new Unit(Unit.Type.TAX, txm, u.getAmount(), exchangeRate);
                t.addUnit(fu);
            }
        });
    }).wrap(t -> new TransactionItem(t));
    block.set(extractor);
}
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) Collectors(java.util.stream.Collectors) NumberFormat(java.text.NumberFormat) BigDecimal(java.math.BigDecimal) List(java.util.List) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Locale(java.util.Locale) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ParseException(java.text.ParseException) Money(name.abuchen.portfolio.money.Money) 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) List(java.util.List) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 68 with Block

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

the class HelloBankPDFExtractor method addInboundDelivery.

@SuppressWarnings("nls")
private void addInboundDelivery() {
    DocumentType type = new DocumentType("Freier Erhalt");
    this.addDocumentTyp(type);
    Block block = new Block("Gesch.ftsart: Freier Erhalt");
    type.addBlock(block);
    block.set(new Transaction<PortfolioTransaction>().subject(() -> {
        PortfolioTransaction transaction = new PortfolioTransaction();
        transaction.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
        return transaction;
    }).section("isin", "name", // 
    "currency").match(// 
    "Titel: (?<isin>\\S*) (?<name>.*)$").match("steuerlicher Anschaffungswert: [\\d+,.-]* (?<currency>\\w{3}+) *").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").match("^Zugang: (?<shares>[\\d+,.]*) Stk.*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section(// 
    "date").match("Kassatag: (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("amount", // 
    "currency").match("steuerlicher Anschaffungswert: (?<amount>[\\d+,.-]*) (?<currency>\\w{3}+) *").assign((t, v) -> t.setMonetaryAmount(Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("amount"))))).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) 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) BiConsumer(java.util.function.BiConsumer) 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 69 with Block

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

the class INGDiBaExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Wertpapierabrechnung Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("Wertpapierabrechnung Kauf.*");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        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( St.ck)? (?<shares>[\\d.]+(,\\d+)?).*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section(// 
    "date").match(// 
    "(Ausf.hrungstag . -zeit|Ausf.hrungstag|Schlusstag . -zeit|Schlusstag) (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("amount", // 
    "currency").match(// 
    "Endbetrag zu Ihren Lasten (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section("fee", "currency").optional().match(// 
    "Handelsplatzgeb.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")))))).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(// 
    "Handelsentgelt (?<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 -> {
        if (t.getPortfolioTransaction().getDateTime() == null)
            throw new IllegalArgumentException("Missing date");
        return 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) 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) 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)

Example 70 with Block

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

the class INGDiBaExtractor method addErtragsgutschrift.

@SuppressWarnings("nls")
private void addErtragsgutschrift() {
    DocumentType type = new DocumentType("Ertragsgutschrift", isJointAccount);
    this.addDocumentTyp(type);
    Block block = new Block("Ertragsgutschrift");
    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(// 
    "Zahltag (?<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)

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