Search in sources :

Example 61 with PortfolioTransaction

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

the class FinTechGroupBankPDFExtractor method addTransferInOutTransaction.

// example is from 2016-12-01
@SuppressWarnings("nls")
private void addTransferInOutTransaction() {
    DocumentType type = new DocumentType("Gutschrifts-/Belastungsanzeige");
    this.addDocumentTyp(type);
    Block block = new Block("Depoteingang .*");
    type.addBlock(block);
    block.set(new Transaction<PortfolioTransaction>().subject(() -> {
        PortfolioTransaction entry = new PortfolioTransaction();
        entry.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
        return entry;
    }).section("date").match(// 
    "Datum(\\s*):(\\s+)(?<date>\\d+.\\d+.\\d{4})").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("isin", "name").match(// 
    "Depoteingang *(?<name>.*) *\\((?<isin>[^/]*)\\)").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
    }).section("shares", "notation").match(// 
    "^Stk\\.\\/Nominale(\\s*):(\\s+)(?<shares>[\\.\\d]+(,\\d*)?) *(?<notation>St\\.|\\w{3}+)(.*)").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("rate", "currency").match("^Kurs(\\s*):(\\s+)(?<rate>[\\d.]+,\\d+)(\\s+)(?<currency>\\w{3}+)(\\s+)(.*)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("rate")) * t.getShares() / Values.Share.factor());
    }).section("tax", "currency").optional().match(// 
    "(.*)Einbeh. Steuer(.*):(\\s*)(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).wrap(t -> new TransactionItem(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) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit)

Example 62 with PortfolioTransaction

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

the class HelloBankPDFExtractor method addBuyTransaction.

@SuppressWarnings("nls")
private void addBuyTransaction() {
    DocumentType type = new DocumentType("Geschäftsart: Kauf");
    this.addDocumentTyp(type);
    Block block = new Block("Geschäftsart: 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").match(// 
    "Titel: (?<isin>\\S*) (?<name>.*)$").match("Kurs: [\\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("amount", // 
    "currency").match("Zu Lasten .* -(?<amount>[\\d+,.]*) (?<currency>\\w{3}+) *$").assign((t, v) -> {
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section(// 
    "date").match("Handelszeit: (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("fee", // 
    "currency").optional().match("Grundgebühr: -(?<fee>[\\d+,.]*) (?<currency>\\w{3}+) *").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: -(?<fee>[\\d+,.]*) (?<currency>\\w{3}+) *").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("gross", "currency", // 
    "exchangeRate").optional().match(// 
    "Kurswert: -(?<gross>[\\d+,.-]*) (?<currency>\\w{3}+) *").match("-[\\d+,.-]* \\w{3}+ *").match("Devisenkurs: (?<exchangeRate>[\\d+,.]*) \\(\\d+.\\d+.\\d{4}+\\) -[\\d+,.]* \\w{3}+ *").assign((t, v) -> {
        long gross = asAmount(v.get("gross"));
        String currency = asCurrencyCode(v.get("currency"));
        BigDecimal exchangeRate = BigDecimal.ONE.divide(asExchangeRate(v.get("exchangeRate")), 10, BigDecimal.ROUND_HALF_UP);
        PortfolioTransaction tx = t.getPortfolioTransaction();
        if (currency.equals(tx.getSecurity().getCurrencyCode())) {
            long convertedGross = BigDecimal.valueOf(gross).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
            tx.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(tx.getCurrencyCode(), convertedGross), Money.of(currency, gross), exchangeRate));
        }
    }).wrap(BuySellEntryItem::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) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) 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) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 63 with PortfolioTransaction

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

the class HelloBankPDFExtractor method addSellTransaction.

@SuppressWarnings("nls")
private void addSellTransaction() {
    DocumentType type = new DocumentType("Geschäftsart: Verkauf");
    this.addDocumentTyp(type);
    Block block = new Block("Geschäftsart: Verkauf");
    type.addBlock(block);
    block.set(new Transaction<BuySellEntry>().subject(() -> {
        BuySellEntry entry = new BuySellEntry();
        entry.setType(PortfolioTransaction.Type.SELL);
        return entry;
    }).section("isin", "name", // 
    "currency").match(// 
    "Titel: (?<isin>\\S*) (?<name>.*)$").match("Kurs: [\\d+,.]* (?<currency>\\w{3}+) *").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").match("^Abgang: (?<shares>[\\d+,.]*) Stk.*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", // 
    "currency").match("Zu Gunsten .* (?<amount>[\\d+,.]*) (?<currency>\\w{3}+) *$").assign((t, v) -> {
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section(// 
    "date").match("Handelszeit: (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("fee", // 
    "currency").optional().match("Grundgebühr: -(?<fee>[\\d+,.]*) (?<currency>\\w{3}+) *").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: -(?<fee>[\\d+,.]*) (?<currency>\\w{3}+) *").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: -(?<fee>[\\d+,.]*) (?<currency>\\w{3}+) *").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("gross", "tax", "currency", // 
    "exchangeRate").match(// 
    "Kurswert: (?<gross>[\\d+,.-]*) (?<currency>\\w{3}+) *").match(// 
    "Kapitalertragsteuer: -(?<tax>[\\d+,.-]*) \\w{3}+ *").match(// 
    "[\\d+,.-]* \\w{3}+ *").match("Devisenkurs: (?<exchangeRate>[\\d+,.]*) \\(\\d+.\\d+.\\d{4}+\\) [\\d+,.]* \\w{3}+ *").assign((t, v) -> {
        long gross = asAmount(v.get("gross"));
        long tax = asAmount(v.get("tax"));
        String currency = asCurrencyCode(v.get("currency"));
        BigDecimal exchangeRate = BigDecimal.ONE.divide(asExchangeRate(v.get("exchangeRate")), 10, BigDecimal.ROUND_HALF_UP);
        PortfolioTransaction tx = t.getPortfolioTransaction();
        if (currency.equals(tx.getSecurity().getCurrencyCode())) {
            long convertedGross = BigDecimal.valueOf(gross).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
            tx.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(tx.getCurrencyCode(), convertedGross), Money.of(currency, gross), exchangeRate));
            long convertedTax = BigDecimal.valueOf(tax).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
            tx.addUnit(new Unit(Unit.Type.TAX, Money.of(tx.getCurrencyCode(), convertedTax), Money.of(currency, tax), exchangeRate));
        } else {
            long convertedTax = BigDecimal.valueOf(tax).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
            tx.addUnit(new Unit(Unit.Type.TAX, Money.of(tx.getCurrencyCode(), convertedTax)));
        }
    }).wrap(BuySellEntryItem::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) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) 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) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 64 with PortfolioTransaction

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

the class OnvistaPDFExtractor method addExchangeTransaction.

private void addExchangeTransaction() {
    DocumentType type = new DocumentType("Umtausch");
    this.addDocumentTyp(type);
    Block block = new Block("(Aus|Ein)buchung:(.*)");
    type.addBlock(block);
    Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        PortfolioTransaction entry = new PortfolioTransaction();
        entry.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
        return entry;
    });
    block.set(pdfTransaction);
    // 
    pdfTransaction.section("name", "isin").find(// 
    "Gattungsbezeichnung ISIN").match(// 
    "(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
        // Merken für evtl. Steuerrückerstattung:
        type.getCurrentContext().put("isin", v.get("isin"));
    }).section(// 
    "transactiontype").match(// 
    "^(?<transactiontype>.*buchung:)(.*)").assign((t, v) -> {
        String transactiontype = v.get("transactiontype");
        if ("Einbuchung:".equalsIgnoreCase(transactiontype)) {
            t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
        } else if ("Ausbuchung:".equalsIgnoreCase(transactiontype)) {
            t.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
        } else {
        // TODO: evtl. Warnung/Hinweis ausgeben?
        }
    }).section(// 
    "date").find("(.*)(Schlusstag|Ex-Tag|Wert Konto-Nr.*)").match(// 
    "(.*)(^|\\s+)(?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("currency", "amount").optional().find("(.*)(Schlusstag|Ex-Tag|Wert Konto-Nr.*|Wert Betrag zu Ihren.*)").match("(^|\\s+)(\\d+\\.\\d+\\.\\d{4}+)?(\\s)?(\\d+)?(\\s)?(?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)").assign((t, v) -> t.setAmount(asAmount(v.get("amount")))).section("notation", // 
    "shares").find("Nominal(.*)").match(// 
    "(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?)(.*)").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")));
        }
        t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
    }).wrap(TransactionItem::new);
    addTaxesSectionsTransaction(pdfTransaction);
    addTaxBlock(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) 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) 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 65 with PortfolioTransaction

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

the class OnvistaPDFExtractor method addCapitalIncreaseTransaction.

private void addCapitalIncreaseTransaction() {
    DocumentType type = new DocumentType("Kapitalerhöhung");
    this.addDocumentTyp(type);
    Block block = new Block("Kapitalerhöhung(.*)");
    type.addBlock(block);
    Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        PortfolioTransaction entry = new PortfolioTransaction();
        entry.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
        return entry;
    });
    block.set(pdfTransaction);
    pdfTransaction.section("date").match(// 
    "(.*), (?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("name", // 
    "isin").find(// 
    "Einbuchung:(\\s*)").find(// 
    "Gattungsbezeichnung ISIN").match(// 
    "(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("notation", // 
    "shares").find(// 
    "Nominal(.*)").match(// 
    "(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?)(.*)").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")));
        }
        t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
    }).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) 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) 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

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28