use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class ConsorsbankPDFExtractor method newDividendTransaction.
@SuppressWarnings("nls")
private Transaction<AccountTransaction> newDividendTransaction(DocumentType type) {
return new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DIVIDENDS);
return t;
}).section("amount", //
"currency").match(//
"BRUTTO *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *").assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).section("wkn", "name", //
"shares").match(//
"ST *(?<shares>[\\d.]+(,\\d+)?) *WKN: *(?<wkn>\\S*) *").match(//
"^(?<name>.*)$").assign((t, v) -> {
// reuse currency from transaction when creating a
// new security upon import
v.put("currency", t.getCurrencyCode());
t.setSecurity(getOrCreateSecurity(v));
t.setShares(asShares(v.get("shares")));
}).section("rate", "amount", "currency").optional().match(//
"UMGER.ZUM DEV.-KURS *(?<rate>[\\d.]+,\\d+) *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *").assign((t, v) -> {
Money currentMonetaryAmount = t.getMonetaryAmount();
BigDecimal rate = asExchangeRate(v.get("rate"));
type.getCurrentContext().put("exchangeRate", rate.toPlainString());
BigDecimal accountMoneyValue = BigDecimal.valueOf(t.getAmount()).divide(rate, RoundingMode.HALF_DOWN);
String currencyCode = asCurrencyCode(v.get("currency"));
t.setMonetaryAmount(Money.of(currencyCode, asAmount(v.get("amount"))));
// currencies -> add gross value
if (!t.getCurrencyCode().equals(t.getSecurity().getCurrencyCode())) {
Money accountMoney = Money.of(currencyCode, Math.round(accountMoneyValue.doubleValue()));
// replace BRUTTO (which is in foreign currency)
// with the value in transaction currency
BigDecimal inverseRate = BigDecimal.ONE.divide(rate, 10, BigDecimal.ROUND_HALF_DOWN);
Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, accountMoney, currentMonetaryAmount, inverseRate);
t.addUnit(grossValue);
}
}).section("kapst", "currency").optional().match("KAPST .*(?<currency>\\w{3}+) *(?<kapst>[\\d.]+,\\d+) *").assign((t, v) -> t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("kapst")))))).section("solz", "currency").optional().match(//
"SOLZ .*(?<currency>\\w{3}+) *(?<solz>[\\d.]+,\\d+) *").assign((t, v) -> {
String currency = asCurrencyCode(v.get("currency"));
if (currency.equals(t.getCurrencyCode())) {
t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(currency), asAmount(v.get("solz")))));
}
}).section("qust", "currency", "forexcurrency", "forex").optional().match("QUST [\\d.]+,\\d+ *% *(?<currency>\\w{3}+) *(?<qust>[\\d.]+,\\d+) *(?<forexcurrency>\\w{3}+) *(?<forex>[\\d.]+,\\d+) *").assign((t, v) -> {
Optional<Unit> grossValueOption = t.getUnit(Type.GROSS_VALUE);
Money money = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("qust")));
if (grossValueOption.isPresent()) {
Money forex = Money.of(asCurrencyCode(v.get("forexcurrency")), asAmount(v.get("forex")));
t.addUnit(new Unit(Unit.Type.TAX, money, forex, grossValueOption.get().getExchangeRate()));
} else {
t.addUnit(new Unit(Unit.Type.TAX, money));
}
}).section(//
"date").match("WERT (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("currency", "amount").optional().match("WERT \\d+.\\d+.\\d{4}+ *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *").assign((t, v) -> {
String currencyCode = asCurrencyCode(v.get("currency"));
Money money = Money.of(currencyCode, asAmount(v.get("amount")));
t.setMonetaryAmount(money);
}).section("currency", "forexpenses").optional().match(//
"FREMDE SPESEN *(?<currency>\\w{3}+) *(?<forexpenses>[\\d.]+,\\d+) *").assign((t, v) -> {
Optional<Unit> grossValueOption = t.getUnit(Type.GROSS_VALUE);
long forexAmount = asAmount(v.get("forexpenses"));
if (grossValueOption.isPresent()) {
BigDecimal exchangeRate = grossValueOption.get().getExchangeRate();
long convertedMoney = Math.round(exchangeRate.multiply(BigDecimal.valueOf(forexAmount)).doubleValue());
Money money = Money.of(t.getCurrencyCode(), convertedMoney);
Money forex = Money.of(asCurrencyCode(v.get("currency")), forexAmount);
t.addUnit(new Unit(Unit.Type.TAX, money, forex, grossValueOption.get().getExchangeRate()));
} else {
BigDecimal exchangeRate = new BigDecimal(type.getCurrentContext().get("exchangeRate"));
long convertedMoney = BigDecimal.valueOf(forexAmount).divide(exchangeRate, RoundingMode.HALF_UP).longValue();
Money money = Money.of(t.getCurrencyCode(), convertedMoney);
t.addUnit(new Unit(Unit.Type.TAX, money));
}
}).wrap(t -> t.getAmount() != 0 ? new TransactionItem(t) : null);
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class ConsorsbankPDFExtractor method addTaxAdjustmentTransaction.
@SuppressWarnings("nls")
private void addTaxAdjustmentTransaction() {
DocumentType type = new DocumentType("Nachträgliche Verlustverrechnung");
this.addDocumentTyp(type);
Block block = new Block(" Erstattung/Belastung \\(-\\) von Steuern");
type.addBlock(block);
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.TAX_REFUND);
// nirgends im Dokument ist die Währung aufgeführt.
t.setCurrencyCode(CurrencyUnit.EUR);
return t;
}).section("date").match(" *Den Steuerausgleich buchen wir mit Wertstellung (?<date>\\d+.\\d+.\\d{4}) .*").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("amount").find(" *Erstattung/Belastung \\(-\\) von Steuern *").find(" *=* *").match(" *(?<amount>[\\d.]+,\\d{2}) *").assign((t, v) -> t.setAmount(asAmount(v.get("amount")))).wrap(t -> new TransactionItem(t)));
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class DABPDFExtractor method addProceedsTransaction.
@SuppressWarnings("nls")
private void addProceedsTransaction() {
DocumentType type = new DocumentType("Erträgnisgutschrift");
this.addDocumentTyp(type);
// Block zweimal vorhanden, finde direkt 2. Block
Block block = new Block("^Erträgnisgutschrift (?!aus).*$");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DIVIDENDS);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("name", "isin").find("Gattungsbezeichnung ISIN").match("^(?<name>.*) (?<isin>[^ ]*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").find("Nominal Ex-Tag Zahltag .*").match("^STK (?<shares>[\\d.]+(,\\d+)?) .*$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", "currency").optional().find("Wert\\s*Konto-Nr.\\s*Betrag\\s*zu\\s*Ihren\\s*Gunsten").match("^(?<date>\\d+.\\d+.\\d{4}+)\\s*([0-9]*) (?<currency>\\w{3}+)\\s*(?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).section("date", "amount", //
"currency").optional().find("Wert\\s*Konto-Nr.\\s*Devisenkurs\\s*Betrag\\s*zu\\s*Ihren\\s*Gunsten").match("^(?<date>\\d+.\\d+.\\d{4}+)\\s*([0-9]*)\\s*(\\w{3}+)\\/(?<forign>\\w{3}+)\\s*(?<rate>[\\d.]+(,\\d+)?)\\s*(?<currency>\\w{3}+)\\s*(?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).wrap(t -> {
if (t.getAmount() == 0)
throw new IllegalArgumentException("No dividend amount found.");
return new TransactionItem(t);
});
addTaxesSectionsTransaction(type, pdfTransaction);
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class DABPDFExtractor method addDividendTransaction.
@SuppressWarnings("nls")
private void addDividendTransaction() {
DocumentType type = new DocumentType("Dividende");
this.addDocumentTyp(type);
Block block = new Block("^Dividendengutschrift .*$");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DIVIDENDS);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("isin", "name", "currency").find(//
"Gattungsbezeichnung ISIN").match(//
"^(?<name>.*) (?<isin>[^ ]*)$").match("STK ([\\d.]+(,\\d+)?) (\\d+.\\d+.\\d{4}+) (\\d+.\\d+.\\d{4}+) (?<currency>\\w{3}+) (\\d+,\\d+)").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(//
"shares").find(//
"Nominal Ex-Tag Zahltag .*").match("^STK (?<shares>[\\d.]+(,\\d+)?) .*$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", //
"currency").optional().find("Wert *Konto-Nr. *Betrag *zu *Ihren *Gunsten").match("^(?<date>\\d+.\\d+.\\d{4}+) ([0-9]*) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).section("date", "amount", "currency", "forexCurrency", //
"exchangeRate").optional().find("Wert Konto-Nr. Devisenkurs Betrag zu Ihren Gunsten").match("^(?<date>\\d+.\\d+.\\d{4}+) ([0-9]*) \\w{3}+/(?<forexCurrency>\\w{3}+) (?<exchangeRate>[\\d.]+,\\d+) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate")).setScale(10, BigDecimal.ROUND_HALF_DOWN);
Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), Math.round(t.getAmount() / exchangeRate.doubleValue()));
Unit unit = new Unit(Unit.Type.GROSS_VALUE, t.getMonetaryAmount(), forex, exchangeRate);
if (unit.getForex().getCurrencyCode().equals(t.getSecurity().getCurrencyCode()))
t.addUnit(unit);
}).section("forex", "localCurrency", "forexCurrency", //
"exchangeRate").optional().find("Wert Konto-Nr. Betrag zu Ihren Gunsten").match("^(\\d+.\\d+.\\d{4}+) ([0-9]*) (\\w{3}+) (?<forex>[\\d.]+,\\d+)$").match("Devisenkurs: (?<localCurrency>\\w{3}+)/(?<forexCurrency>\\w{3}+) (?<exchangeRate>[\\d.]+,\\d+)").assign((t, v) -> {
BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate")).setScale(10, BigDecimal.ROUND_HALF_DOWN);
Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("forex")));
Money localAmount = Money.of(v.get("localCurrency"), Math.round(forex.getAmount() / Double.parseDouble(v.get("exchangeRate").replace(',', '.'))));
t.setAmount(forex.getAmount());
t.setCurrencyCode(forex.getCurrencyCode());
Unit unit = new Unit(Unit.Type.GROSS_VALUE, forex, localAmount, exchangeRate);
if (unit.getForex().getCurrencyCode().equals(t.getSecurity().getCurrencyCode()))
t.addUnit(unit);
}).wrap(t -> {
if (t.getAmount() == 0)
throw new IllegalArgumentException("No dividend amount found.");
return new TransactionItem(t);
});
addTaxesSectionsTransaction(type, pdfTransaction);
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class DkbPDFExtractor method addInterestTransaction.
private void addInterestTransaction() {
DocumentType type = new DocumentType("Zinsgutschrift");
this.addDocumentTyp(type);
Block block = new Block("Zinsgutschrift");
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("notation", "shares", "name", "isin", "wkn").find("Nominale Wertpapierbezeichnung ISIN \\(WKN\\)").match("(?<notation>^St\\Dck|^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{2,})?) (?<name>.*) (?<isin>[^ ]*) (\\((?<wkn>.*)\\).*)$").assign((t, v) -> {
String notation = v.get("notation");
if (notation != null && !(notation.startsWith("St") && notation.endsWith("ck"))) {
// Prozent-Notierung, Workaround..
t.setShares(asShares(v.get("shares")) / 100);
} else {
t.setShares(asShares(v.get("shares")));
}
t.setSecurity(getOrCreateSecurity(v));
}).section("date", "amount").match("(^Ausmachender Betrag) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)(.*) (?<currency>\\w{3}+)").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);
}
Aggregations