Search in sources :

Example 1 with Block

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

the class BankSLMPDFExtractor method addSellTransaction.

@SuppressWarnings("nls")
private void addSellTransaction() {
    DocumentType type = new DocumentType("abrechnung - Verkauf");
    this.addDocumentTyp(type);
    Block block = new Block("B.rsenabrechnung - Verkauf");
    type.addBlock(block);
    Transaction<BuySellEntry> extractor = new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section("date", "shares", "name", "wkn", "currency").match(// 
    "Wir haben f.r Sie am (?<date>\\d+.\\d+.\\d{4}+) verkauft.").match(// 
    "^(?<shares>[\\d.']+) .*$").match(// 
    "^(?<name>.*)$").match(// 
    "^Valor: (?<wkn>[^ ]*)$").match(// 
    "Total Kurswert (?<currency>\\w{3}+) .*").assign((t, v) -> {
        t.setDate(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"));
    }).wrap(t -> new BuySellEntryItem(t));
    addForexGrossValue(extractor);
    addFeesSection(extractor);
    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) 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 2 with Block

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

the class ComdirectPDFExtractor method addSellTransaction.

@SuppressWarnings("nls")
private void addSellTransaction() {
    DocumentType type = new DocumentType("Wertpapierverkauf");
    this.addDocumentTyp(type);
    Block block = new Block("^(\\* )?Wertpapierverkauf *.*");
    type.addBlock(block);
    Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section(// 
    "date").match(// 
    "Geschäftstag *: (?<date>\\d+.\\d+.\\d{4}+) .*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name", // 
    "wkn").find(// 
    "Wertpapier-Bezeichnung *WPKNR/ISIN *").match(// 
    "^(?<name>(\\S{1,} )*) *(?<wkn>\\S*) *$").match(// 
    "(\\S{1,} )* *(?<isin>\\S*) *$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").optional().match(// 
    "^St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("shares").optional().match(// 
    "^ Summe *St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", // 
    "currency").find(// 
    ".*Zu Ihren Gunsten vor Steuern *").match(// 
    ".* \\d+.\\d+.\\d{4}+ *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+).*").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section("tax").optional().match(// 
    "^a *b *g *e *f *ü *h *r *t *e *S *t *e *u *e *r *n *(?<tax>.*)$").assign((t, v) -> {
        Unit unit = createTaxUnit(v.get("tax"));
        if (unit == null || unit.getAmount().isZero())
            return;
        t.getPortfolioTransaction().addUnit(unit);
        MutableMoney total = MutableMoney.of(t.getPortfolioTransaction().getCurrencyCode());
        total.add(t.getPortfolioTransaction().getMonetaryAmount());
        total.subtract(unit.getAmount());
        t.setMonetaryAmount(total.toMoney());
    }).wrap(BuySellEntryItem::new);
    addFeesSection(pdfTransaction);
    block.set(pdfTransaction);
    addTaxRefunds(type, "^(\\* )?Wertpapierverkauf *.*");
}
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) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) MutableMoney(name.abuchen.portfolio.money.MutableMoney) 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 3 with Block

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

the class ComdirectPDFExtractor method addTaxRefunds.

@SuppressWarnings("nls")
private void addTaxRefunds(DocumentType type, String blockMarker) {
    // tax refunds --> separate transaction
    Block block = new Block(blockMarker);
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.TAX_REFUND);
        return t;
    }).section(// 
    "date").match(// 
    "Geschäftstag *: (?<date>\\d+.\\d+.\\d{4}+) .*").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("isin", "name", // 
    "wkn").find(// 
    "Wertpapier-Bezeichnung *WPKNR/ISIN *").match(// 
    "^(?<name>(\\S{1,} )*) *(?<wkn>\\S*) *$").match(// 
    "(\\S{1,} )* *(?<isin>\\S*) *$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("tax").optional().match(// 
    "^e *r *s *t *a *t *t *e *t *e *S *t *e *u *e *r *n *(?<tax>.*)$").assign((t, v) -> {
        Unit unit = createTaxUnit(v.get("tax"));
        if (unit == null || unit.getAmount().isZero())
            return;
        t.setMonetaryAmount(unit.getAmount());
    }).wrap(t -> t.getAmount() == 0L ? null : 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) Messages(name.abuchen.portfolio.Messages) MutableMoney(name.abuchen.portfolio.money.MutableMoney) Matcher(java.util.regex.Matcher) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Pattern(java.util.regex.Pattern) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 4 with Block

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

the class CommerzbankPDFExtractor method addBuyTransaction.

private void addBuyTransaction() {
    DocumentType type = new DocumentType("W e r t p a p i e r k a u f");
    this.addDocumentTyp(type);
    Block block = new Block("W e r t p a p i e r k a u f");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("amount", // 
    "currency").match(".*Zu I h r e n L a s t e n.*").match("^.* (\\d \\d . \\d \\d . \\d \\d \\d \\d) (?<currency>\\w{3}+)(?<amount>( \\d)*( \\.)?( \\d)* ,( \\d)*)$").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(stripBlanks(v.get("amount"))));
    }).section(// 
    "date").match("G e s c h ä f t s t a g : (?<date>\\d \\d . \\d \\d . \\d \\d \\d \\d) .*").assign((t, v) -> t.setDate(asDate(stripBlanks(v.get("date"))))).section(// 
    "shares").match("S t . (?<shares>[\\d ,.]*) .*").assign((t, v) -> t.setShares(asShares(stripBlanks(v.get("shares"))))).section("wkn", "name", "isin", "currency").match(".*W e r t p a p i e r - B e z e i c h n u n g.*").match("(?<name>.*) (?<wkn>\\S*)").match(// 
    "^IBAN.*$").match("^(?<isin>.*) (?<currency>\\w{3}+) (\\d \\d . \\d \\d . \\d \\d \\d \\d) (\\w{3}+)(( \\d)*( \\.)?( \\d)* ,( \\d)*)$").assign((t, v) -> {
        v.put("isin", stripBlanks(v.get("isin")));
        t.setSecurity(getOrCreateSecurity(v));
    }).wrap(BuySellEntryItem::new));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) 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) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)

Example 5 with Block

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

the class CommerzbankPDFExtractor method addDividendTransaction.

private void addDividendTransaction() {
    DocumentType type = new DocumentType("E r t r a g s g u t s c h r i f t");
    this.addDocumentTyp(type);
    Block block = new Block("E r t r a g s g u t s c h r i f t");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction transaction = new AccountTransaction();
        transaction.setType(AccountTransaction.Type.DIVIDENDS);
        return transaction;
    }).section("date", "amount", // 
    "currency").match(".*Zu I h r e n Gunsten.*").match("^.* (?<date>\\d \\d . \\d \\d . \\d \\d \\d \\d) (?<currency>\\w{3}+)(?<amount>( \\d)*( \\.)?( \\d)* ,( \\d)*)$").assign((t, v) -> {
        t.setDateTime(asDate(stripBlanks(v.get("date"))));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(stripBlanks(v.get("amount"))));
    }).section("wkn", "name", "shares", "isin").match(".*W e r t p a p i e r - B e z e i c h n u n g.*").match("p e r \\d \\d . \\d \\d . \\d \\d \\d \\d (?<name>.*) (?<wkn>\\S*)").match("^STK (?<shares>(\\d )*(\\. )?(\\d )*, (\\d )*).* (?<isin>\\S*)$").assign((t, v) -> {
        // if necessary, create the security with the
        // currency of the transaction
        v.put("currency", t.getCurrencyCode());
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(stripBlanks(v.get("shares"))));
    }).wrap(TransactionItem::new));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) 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) 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