Search in sources :

Example 96 with AccountTransaction

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

the class DkbPDFExtractor method addInvestmentEarningTransaction.

private void addInvestmentEarningTransaction() {
    DocumentType type = new DocumentType("Investmenterträge", (context, lines) -> {
        Pattern pattern = Pattern.compile("Devisenkurs (?<term>\\w{3}+) / (?<base>\\w{3}+) (?<exchangeRate>[\\d,.]*)");
        for (String line : lines) {
            Matcher m = pattern.matcher(line);
            if (m.matches())
                context.put(EXCHANGE_RATE, m.group("exchangeRate"));
        }
    });
    this.addDocumentTyp(type);
    Block block = new Block("Gutschrift von Investmenterträgen");
    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", "currency").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(^St\\Dck) (?<shares>[\\d,.]*) (?<name>.*)$").match(// 
    ".*").match(// 
    "(?<isin>[^ ]*) \\((?<wkn>.*)\\)$").match("^Ertrag pro St. [\\d,.]* (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setShares(asShares(v.get("shares")));
        t.setSecurity(getOrCreateSecurity(v));
    }).section("date", "amount").match("(^Ausmachender Betrag) (?<amount>[\\d,.]*)(.*) (?<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) 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 97 with AccountTransaction

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

the class DkbPDFExtractor method addTaxReturnBlock.

private void addTaxReturnBlock(DocumentType type) {
    // optional: Steuererstattung
    Block block = new Block("^Kapitalertragsteuer (.*) (\\w{3}+) ([\\d.-]+,\\d+)(\\+) (\\w{3}+)(.*)");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction entry = new AccountTransaction();
        entry.setType(AccountTransaction.Type.TAX_REFUND);
        return entry;
    }).section("tax", "currency").optional().match("^Kapitalertragsteuer (.*) (\\w{3}+) (?<tax>[\\d.-]+,\\d+)(\\+) (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("tax")));
    }).section("soli", "currency").optional().match("^Solidarit(.*) (\\w{3}+) (?<soli>[\\d.-]+,\\d+)(\\+) (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(t.getAmount() + asAmount(v.get("soli")));
    }).section("kirchenst", "currency").optional().match("^Kirchensteuer (.*) (\\w{3}+) (?<kirchenst>[\\d.-]+,\\d+)(\\+) (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(t.getAmount() + asAmount(v.get("kirchenst")));
    }).section("date").match("(^Den Betrag buchen wir mit Valuta) (?<date>\\d+.\\d+.\\d{4}+) zu Lasten des Kontos (.*)").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        v.put("isin", type.getCurrentContext().get("isin"));
        t.setSecurity(getOrCreateSecurity(v));
    }).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) 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) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 98 with AccountTransaction

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

the class FinTechGroupBankPDFExtractor method addDepositAndWithdrawalTransaction.

@SuppressWarnings("nls")
private void addDepositAndWithdrawalTransaction() {
    final DocumentType type = new DocumentType("Kontoauszug Nr:", (context, lines) -> {
        Pattern pYear = Pattern.compile("Kontoauszug Nr:[ ]*\\d+/(\\d+).*");
        Pattern pCurrency = Pattern.compile("Kontow.hrung:[ ]+(\\w{3}+)");
        // read the current context here
        for (String line : lines) {
            Matcher m = pYear.matcher(line);
            if (m.matches()) {
                context.put("year", m.group(1));
            }
            m = pCurrency.matcher(line);
            if (m.matches()) {
                context.put("currency", m.group(1));
            }
        }
    });
    this.addDocumentTyp(type);
    // deposit, add value to account
    // 01.01. 01.01. xyz 123,45+
    Block block = new Block("\\d+\\.\\d+\\.[ ]+\\d+\\.\\d+\\.[ ]+.berweisung[ ]+[\\d.-]+,\\d+[+-]");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.DEPOSIT);
        return t;
    }).section("valuta", "amount", "sign").match("\\d+.\\d+.[ ]+(?<valuta>\\d+.\\d+.)[ ]+.berweisung[ ]+(?<amount>[\\d.-]+,\\d+)(?<sign>[+-])").assign((t, v) -> {
        Map<String, String> context = type.getCurrentContext();
        String date = v.get("valuta");
        if (date != null) {
            // create a long date from the year in the
            // context
            t.setDateTime(asDate(date + context.get("year")));
        }
        t.setNote(v.get("text"));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(context.get("currency")));
        // check for withdrawals
        String sign = v.get("sign");
        if ("-".equals(sign)) {
            // change type for withdrawals
            t.setType(AccountTransaction.Type.REMOVAL);
        }
    }).wrap(t -> new TransactionItem(t)));
    // fees for foreign dividends, subtract value from account
    block = new Block("\\d+\\.\\d+\\.[ ]+\\d+\\.\\d+\\.[ ]+Geb.hr Kapitaltransaktion Ausland[ ]+[\\d.-]+,\\d+[-]");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.FEES);
        return t;
    }).section("valuta", "amount").match("\\d+.\\d+.[ ]+(?<valuta>\\d+.\\d+.)[ ]+Geb.hr Kapitaltransaktion Ausland[ ]+(?<amount>[\\d.-]+,\\d+)[-]").assign((t, v) -> {
        Map<String, String> context = type.getCurrentContext();
        String date = v.get("valuta");
        if (date != null) {
            // create a long date from the year in the
            // context
            t.setDateTime(asDate(date + context.get("year")));
        }
        t.setNote(v.get("text"));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(context.get("currency")));
    }).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) 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 99 with AccountTransaction

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

the class FinTechGroupBankPDFExtractor method addTaxReturnBlock.

@SuppressWarnings("nls")
private void addTaxReturnBlock(DocumentType type) {
    // optional: Steuererstattung
    Block block = new Block("Nr.(\\d*)/(\\d*) *Verkauf.*");
    type.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction entry = new AccountTransaction();
        entry.setType(AccountTransaction.Type.TAX_REFUND);
        return entry;
    }).section("taxreturn").optional().match(".* \\*\\*Einbeh. Steuer *: *(?<taxreturn>-[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("taxreturn")));
    }).section("wkn", "isin", "name").match("Nr.(\\d*)/(\\d*) *Verkauf *(?<name>.*) *\\((?<isin>[^/]*)/(?<wkn>[^)]*)\\)").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
    }).section("shares", "date").match("^davon ausgef\\. *: (?<shares>[.\\d]+,\\d*) St\\. *Schlusstag *: *(?<date>\\d+.\\d+.\\d{4}+), \\d+:\\d+ Uhr").assign((t, v) -> {
        t.setShares(asShares(v.get("shares")));
        t.setDateTime(asDate(v.get("date")));
    }).wrap(t -> {
        if (t.getCurrencyCode() != null && t.getAmount() != 0)
            return new TransactionItem(t);
        return null;
    }));
}
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) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 100 with AccountTransaction

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

the class FinTechGroupBankPDFExtractor method addDividendTransaction.

@SuppressWarnings("nls")
private void addDividendTransaction() {
    DocumentType type1 = new DocumentType("Dividendengutschrift für inländische Wertpapiere");
    DocumentType type2 = new DocumentType("Ertragsmitteilung");
    DocumentType type3 = new DocumentType("Zinsgutschrift");
    this.addDocumentTyp(type1);
    this.addDocumentTyp(type2);
    this.addDocumentTyp(type3);
    Block block = new Block("Ihre Depotnummer.*");
    type1.addBlock(block);
    type2.addBlock(block);
    type3.addBlock(block);
    block.set(new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.DIVIDENDS);
        return t;
    }).section("wkn", "isin", "name").match("Nr\\.(\\d*) * (?<name>.*) *\\((?<isin>[^/]*)/(?<wkn>[^)]*)\\)").assign((t, v) -> {
        t.setSecurity(getOrCreateSecurity(v));
    }).section(// 
    "shares").match("^St\\.[^:]+: *(?<shares>[\\.\\d]+(,\\d*)?).*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", // 
    "currency").match(// 
    ".* Endbetrag *: *(?<amount>[\\d.-]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        t.setAmount(asAmount(v.get("amount")));
    }).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")))))).section(// 
    "date").match("Valuta * : *(?<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) 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) 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

AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)218 Client (name.abuchen.portfolio.model.Client)169 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)152 Money (name.abuchen.portfolio.money.Money)148 IOException (java.io.IOException)141 Unit (name.abuchen.portfolio.model.Transaction.Unit)135 Test (org.junit.Test)133 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)131 Security (name.abuchen.portfolio.model.Security)129 ArrayList (java.util.ArrayList)125 Values (name.abuchen.portfolio.money.Values)117 List (java.util.List)110 LocalDateTime (java.time.LocalDateTime)109 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)103 CoreMatchers.is (org.hamcrest.CoreMatchers.is)102 Assert.assertThat (org.junit.Assert.assertThat)102 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)99 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)99 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)99 Optional (java.util.Optional)87