use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class HelloBankPDFExtractor method addDividendTransaction.
@SuppressWarnings("nls")
private void addDividendTransaction() {
DocumentType type = new DocumentType("Geschäftsart: Ertrag", (context, lines) -> {
Pattern exchangeRatePattern = Pattern.compile("Devisenkurs: (?<exchangeRate>[\\d+,.]*) \\(\\d+.\\d+.\\d{4}+\\) [\\d+,.]* \\w{3}+ *");
for (String line : lines) {
Matcher matcher = exchangeRatePattern.matcher(line);
if (matcher.matches())
context.put("exchangeRate", matcher.group(1));
}
});
this.addDocumentTyp(type);
Block block = new Block("Geschäftsart: Ertrag");
type.addBlock(block);
BiConsumer<AccountTransaction, Map<String, String>> taxProcessor = (t, v) -> {
long tax = asAmount(v.get("tax"));
String currency = asCurrencyCode(v.get("currency"));
if (currency.equals(t.getCurrencyCode())) {
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), tax)));
} else {
String exchangeRateString = type.getCurrentContext().get("exchangeRate");
if (exchangeRateString != null) {
BigDecimal exchangeRate = BigDecimal.ONE.divide(asExchangeRate(exchangeRateString), 10, BigDecimal.ROUND_HALF_UP);
if (currency.equals(t.getSecurity().getCurrencyCode())) {
long convertedTax = BigDecimal.valueOf(tax).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), convertedTax), Money.of(currency, tax), exchangeRate));
} else {
long convertedTax = BigDecimal.valueOf(tax).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), convertedTax)));
}
}
}
};
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction transaction = new AccountTransaction();
transaction.setType(AccountTransaction.Type.DIVIDENDS);
return transaction;
}).section("isin", "name", //
"currency").match(//
"Titel: (?<isin>\\S*) (?<name>.*)$").match("Dividende: [\\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(//
"Valuta (?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("tax", //
"currency").optional().match("Inkassoprovision: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match("Umsatzsteuer: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match(//
"Fremde Spesen: -(?<tax>[\\d+,.-]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match(//
"KESt Ausländische Dividende: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match(//
"Quellensteuer[^.]*: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("gross", //
"currency").optional().match("Bruttoertrag: (?<gross>[\\d+,.-]*) (?<currency>\\w{3}+) *").assign((t, v) -> {
long gross = asAmount(v.get("gross"));
String currency = asCurrencyCode(v.get("currency"));
if (currency.equals(t.getSecurity().getCurrencyCode())) {
String exchangeRateString = type.getCurrentContext().get("exchangeRate");
if (exchangeRateString != null) {
BigDecimal exchangeRate = BigDecimal.ONE.divide(asExchangeRate(exchangeRateString), 10, BigDecimal.ROUND_HALF_UP);
long convertedGross = BigDecimal.valueOf(gross).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(t.getCurrencyCode(), convertedGross), Money.of(currency, gross), exchangeRate));
}
}
}).wrap(TransactionItem::new));
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class INGDiBaExtractor method addDividendengutschrift.
@SuppressWarnings("nls")
private void addDividendengutschrift() {
final DocumentType type = new DocumentType("Dividendengutschrift", isJointAccount);
this.addDocumentTyp(type);
Block block = new Block("Dividendengutschrift");
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(//
"Ex-Tag (?<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);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class INGDiBaExtractor method addTaxSectionToBuySellEntry.
@SuppressWarnings("nls")
private void addTaxSectionToBuySellEntry(DocumentType type, Transaction<BuySellEntry> transaction) {
// Kapitalerstragsteuer (Einzelkonto)
//
transaction.section("tax", "currency").optional().match("Kapitalertragsteuer \\d+,\\d+ ?% (?<currency>\\w{3}+) (?<tax>[\\d.]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).section("tax1", "currency1", "tax2", "currency2").optional().match("KapSt anteilig 50,00 ?% \\d+,\\d+ ?% (?<currency1>\\w{3}+) (?<tax1>[\\d.]+,\\d+)").match("KapSt anteilig 50,00 ?% \\d+,\\d+ ?% (?<currency2>\\w{3}+) (?<tax2>[\\d.]+,\\d+)").assign((t, v) -> {
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency1")), asAmount(v.get("tax1")))));
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency2")), asAmount(v.get("tax2")))));
}).section("tax", "currency").optional().match("Solidarit.tszuschlag \\d+,\\d+ ?% (?<currency>\\w{3}+) (?<tax>[\\d.]+,\\d+)").assign((t, v) -> {
if (!Boolean.parseBoolean(type.getCurrentContext().get(IS_JOINT_ACCOUNT)))
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
}).section("tax1", "currency1", "tax2", "currency2").optional().match("Solidarit.tszuschlag \\d+,\\d+ ?% (?<currency1>\\w{3}+) (?<tax1>[\\d.]+,\\d+)").match("Solidarit.tszuschlag \\d+,\\d+ ?% (?<currency2>\\w{3}+) (?<tax2>[\\d.]+,\\d+)").assign((t, v) -> {
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency1")), asAmount(v.get("tax1")))));
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency2")), asAmount(v.get("tax2")))));
}).section("tax", "currency").optional().match("Kirchensteuer \\d+,\\d+ ?% (?<currency>\\w{3}+) (?<tax>[\\d.]+,\\d+)").assign((t, v) -> {
if (!Boolean.parseBoolean(type.getCurrentContext().get(IS_JOINT_ACCOUNT)))
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
}).section("tax1", "currency1", "tax2", "currency2").optional().match("Kirchensteuer \\d+,\\d+ ?% (?<currency1>\\w{3}+) (?<tax1>[\\d.]+,\\d+)").match("Kirchensteuer \\d+,\\d+ ?% (?<currency2>\\w{3}+) (?<tax2>[\\d.]+,\\d+)").assign((t, v) -> {
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency1")), asAmount(v.get("tax1")))));
t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency2")), asAmount(v.get("tax2")))));
});
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType 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);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class OnvistaPDFExtractor method addTaxBlock.
private void addTaxBlock(DocumentType type) {
// optional: Steuer dem Konto buchen
Block block = new Block("(Kapitalertragsteuer)(.*)-$");
type.addBlock(block);
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.TAXES);
return entry;
}).section("tax").optional().match("^Kapitalertragsteuer (?<currency>\\w{3}+) (?<tax>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("tax")));
}).section("soli").optional().match("^Solidaritätszuschlag (?<currency>\\w{3}+) (?<soli>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(t.getAmount() + asAmount(v.get("soli")));
}).section("kirchenst").optional().match("^Kirchensteuer (?<currency>\\w{3}+) (?<kirchenst>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(-)").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(t.getAmount() + asAmount(v.get("kirchenst")));
}).section("date", "currency").optional().find("Wert(\\s+)Konto-Nr.(\\s+)Betrag zu Ihren Lasten(\\s*)$").match("(^|\\s+)(?<date>\\d+\\.\\d+\\.\\d{4}+)(\\s)(\\d+)(\\s)(?<currency>\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{2})?)").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
v.put("isin", type.getCurrentContext().get("isin"));
t.setSecurity(getOrCreateSecurity(v));
}).wrap(TransactionItem::new));
}
Aggregations