Search in sources :

Example 46 with DocumentType

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

the class BaaderBankPDFExtractor method addFeesAssetManagerTransaction.

@SuppressWarnings("nls")
private void addFeesAssetManagerTransaction() {
    DocumentType type = new DocumentType("Vergütung des Vermögensverwalters");
    this.addDocumentTyp(type);
    Block block = new Block("Rechnung für .*");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.FEES);
        return t;
    }).section("currency", "amount").match("Leistungen Beträge \\((?<currency>\\w{3})\\).*").match("Rechnungsbetrag *(?<amount>[\\d.]+,\\d{2}).*").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).section("date").match("Abbuchungsdatum: (?<date>\\d+.\\d+.\\d{4})").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).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) 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 47 with DocumentType

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

the class BankSLMPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("abrechnung - Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("B.rsenabrechnung - Kauf");
    type.addBlock(block);
    Transaction<BuySellEntry> extractor = new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        return entry;
    }).section("date", "shares", "name", "wkn", "currency").match(// 
    "Wir haben f.r Sie am (?<date>\\d+.\\d+.\\d{4}+) gekauft.").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 48 with DocumentType

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

the class ComdirectPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Wertpapierkauf");
    this.addDocumentTyp(type);
    Block block = new Block("^(\\* )?Wertpapierkauf *.*");
    type.addBlock(block);
    Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.BUY);
        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 Lasten( 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.add(unit.getAmount());
        t.setMonetaryAmount(total.toMoney());
    }).wrap(t -> {
        if (t.getPortfolioTransaction().getShares() == 0)
            throw new IllegalArgumentException(Messages.PDFMsgMissingShares);
        return new BuySellEntryItem(t);
    });
    addFeesSection(pdfTransaction);
    block.set(pdfTransaction);
    addTaxRefunds(type, "^(\\* )?Wertpapierkauf *.*");
}
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 49 with DocumentType

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

the class ComdirectPDFExtractor method addDividendTransaction.

@SuppressWarnings("nls")
private void addDividendTransaction() {
    DocumentType dividende = new DocumentType("Abrechnung Dividendengutschrift");
    this.addDocumentTyp(dividende);
    DocumentType ertrag = new DocumentType("Abrechnung Ertragsgutschrift");
    this.addDocumentTyp(ertrag);
    Block block = new Block(".*G *u *t *s *c *h *r *i *f *t *f *ä *l *l *i *g *e *r *W *e *r *t *p *a *p *i *e *r *- *E *r *t *r *ä *g *e *");
    dividende.addBlock(block);
    ertrag.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.DIVIDENDS);
        return t;
    }).section("wkn", "name", "isin", "shares").optional().match(// 
    "^\\s*(p\\s*e\\s*r) *\\+?[\\d .]+  (?<name>.*)      (?<wkn>.*)").match(// 
    "^\\s*(S\\s*T\\s*K) *(?<shares>\\+?[\\d .]+,\\+?[\\d ]+).*    .* {4}(?<isin>.*)$").assign((t, v) -> {
        v.put("isin", stripBlanks(v.get("isin")));
        v.put("wkn", stripBlanks(v.get("wkn")));
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(stripBlanks(v.get("shares"))));
    }).section("currency", "amount", // 
    "date").find(// 
    ".*Zu Ihren Gunsten vor Steuern *").match(// 
    "^.*(?<date>\\d{2}.\\d{2}.\\d{4}) *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *$").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
        t.setDateTime(asDate(v.get("date")));
    }).section("currency", // 
    "gross").optional().find("^Bruttobetrag: *(?<currency>\\w{3}+) *(?<gross>[\\d.]+,\\d+)").assign((t, v) -> {
        long gross = asAmount(v.get("gross"));
        long tax = gross - t.getAmount();
        Unit unit = new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), tax));
        if (unit.getAmount().getCurrencyCode().equals(t.getCurrencyCode()))
            t.addUnit(unit);
    }).wrap(TransactionItem::new));
}
Also used : 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) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 50 with DocumentType

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

the class ComdirectPDFExtractor method addTaxTransaction.

@SuppressWarnings("nls")
private void addTaxTransaction() {
    // TODO 1: combine with dividend-transaction of other file
    // TODO 2: not matched by buy/sell with taxes...
    // just char sequence
    DocumentType type = new DocumentType("Steuerliche Behandlung: Ausländische Dividende");
    // type.setMustExclude("Wertpapierkauf");
    this.addDocumentTyp(type);
    Block block = new Block("^\\s*Steuerliche Behandlung:.*");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.TAXES);
        return t;
    }).section("wkn", "name", "isin", "shares").optional().match(// 
    "^(Stk.)\\W*(?<shares>\\d[\\d .,]*)(?<name>.*),\\W*(WKN / ISIN:)(?<wkn>.*)/(?<isin>.*)$").assign((t, v) -> {
        v.put("isin", stripBlanks(v.get("isin")));
        v.put("wkn", stripBlanks(v.get("wkn")));
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(stripBlanks(v.get("shares"))));
    }).section(// 
    "date").match(// 
    "^.*Die Gutschrift erfolgt mit Valuta\\s+(?<date>\\d{2}.\\d{2}.\\d{4}).*$").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
    }).section("tax", "currency").optional().match(// 
    "^\\s*(K\\s*a\\s*p\\s*i\\s*t\\s*a\\s*l\\s*e\\s*r\\s*t\\s*r\\s*a\\s*g\\s*s\\s*t\\s*e\\s*u\\s*e\\s*r)" + // 
    "(?<currency>[A-Z\\s]+)(?<tax>[\\d\\s,-]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax", "currency").optional().match("^\\s*(K\\s*i\\s*r\\s*c\\s*h\\s*e\\s*n\\s*s\\s*t\\s*e\\s*u\\s*e\\s*r)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax", "currency").optional().match("^\\s*(S\\s*o\\s*l\\s*i\\s*d\\s*a\\s*r\\s*i\\s*t\\s*ä\\s*t\\s*s\\s*z\\s*u\\s*s\\s*c\\s*h\\s*l\\s*a\\s*g)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
    }).section("tax", // abgeführte Steuern
    "currency").match("^\\s*(a\\s*b\\s*g\\s*e\\s*f\\s*ü\\s*h\\s*r\\s*t\\s*e\\s*S\\s*t\\s*e\\s*u\\s*er\\s*n)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
        v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
        v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("tax")));
    }).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) 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) 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)

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