use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class DkbPDFExtractor method addTax.
private void addTax(DocumentType documentType, Object t, Map<String, String> v, String taxtype) {
name.abuchen.portfolio.model.Transaction tx = getTransaction(t);
String currency = asCurrencyCode(v.get("currency"));
long amount = asAmount(v.get(taxtype));
if (!currency.equals(tx.getCurrencyCode()) && documentType.getCurrentContext().containsKey(EXCHANGE_RATE)) {
BigDecimal rate = //
BigDecimal.ONE.divide(asExchangeRate(documentType.getCurrentContext().get(EXCHANGE_RATE)), 10, BigDecimal.ROUND_HALF_DOWN);
currency = tx.getCurrencyCode();
amount = rate.multiply(BigDecimal.valueOf(amount)).longValue();
}
tx.addUnit(new Unit(Unit.Type.TAX, Money.of(currency, amount)));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class FinTechGroupBankPDFExtractor method addRemoveNewFormatTransaction.
// since ~2015
@SuppressWarnings("nls")
private void addRemoveNewFormatTransaction() {
DocumentType type = new DocumentType("Gutschrifts- / Belastungsanzeige");
this.addDocumentTyp(type);
Block block = new Block("Kundennummer(.*)");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
return entry;
}).section("wkn", "isin", "name", "shares").match(//
"(?s)(?<wkn>\\w{6}+)(\\s+)(?<isin>\\w{12}+)(\\s+)(?<name>.*?)(\\s+)(?<shares>[\\.\\d]+(,\\d*)?)(.*)").assign((t, v) -> {
t.setSecurity(getOrCreateSecurity(v));
t.setShares(asShares(v.get("shares")));
}).section("date").match(//
"Fälligkeitstag(\\s*):(\\s+)(?<date>\\d+.\\d+.\\d{4})(.*)").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("amount", "currency").optional().match("(.*)Geldgegenwert(\\*{1,3})(.*)(\\s*):(\\s*)(?<amount>[\\d.]+,\\d+)(\\s+)(?<currency>\\w{3}+)(.*)").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
}).section().optional().match("(.*)Bestand haben wir wertlos ausgebucht(.*)").assign((t, v) -> {
t.setCurrencyCode(t.getAccountTransaction().getSecurity().getCurrencyCode());
t.setAmount(0L);
t.getPortfolioTransaction().setType(PortfolioTransaction.Type.TRANSFER_OUT);
t.setType(PortfolioTransaction.Type.TRANSFER_OUT);
}).section("fee", "currency").optional().match(".* Provision *(?<currency>\\w{3}+) *(?<fee>[\\d.-]+,\\d+)").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 *(?<currency>\\w{3}+) *(?<fee>[\\d.-]+,\\d+)").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 *(?<currency>\\w{3}+) *(?<fee>[\\d.-]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("tax", "currency").optional().match(//
"(.*)Einbeh. Steuer(.*):(\\s*)(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).wrap(t -> new BuySellEntryItem(t)));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class FinTechGroupBankPDFExtractor method addRemoveTransaction.
@SuppressWarnings("nls")
private void addRemoveTransaction() {
DocumentType type = new DocumentType("Bestandsausbuchung");
this.addDocumentTyp(type);
Block block = new Block("Bestandsausbuchung(.*)");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
return entry;
}).section("date").match(//
"Fälligkeitstag(\\s*):(\\s+)(?<date>\\d+.\\d+.\\d{4})(.*)").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name").match(//
"Bestandsausbuchung *(?<name>.*) *\\((?<isin>[^/]*)\\)").assign((t, v) -> {
t.setSecurity(getOrCreateSecurity(v));
}).section("shares", "notation").match(//
"^Stk\\.\\/Nominale(.*):(\\s+)(?<shares>[\\.\\d]+(,\\d*)?)(\\s*)(?<notation>\\w{3}+)(.*)[Einbeh]+(.*)").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("amount", "currency").optional().match("(.*)Geldgegenwert\\*\\*(.*)(\\s*):(\\s*)(?<amount>[\\d.]+,\\d+)(\\s+)(?<currency>\\w{3}+)(.*)").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
}).section().optional().match("(.*)Bestand haben wir wertlos ausgebucht(.*)").assign((t, v) -> {
t.setCurrencyCode(t.getAccountTransaction().getSecurity().getCurrencyCode());
t.setAmount(0L);
t.getPortfolioTransaction().setType(PortfolioTransaction.Type.TRANSFER_OUT);
t.setType(PortfolioTransaction.Type.TRANSFER_OUT);
}).section("fee", "currency").optional().match(".* Provision *(?<currency>\\w{3}+) *(?<fee>[\\d.-]+,\\d+)").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 *(?<currency>\\w{3}+) *(?<fee>[\\d.-]+,\\d+)").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 *(?<currency>\\w{3}+) *(?<fee>[\\d.-]+,\\d+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("fee")))))).section("tax", "currency").optional().match(//
"(.*)Einbeh. Steuer(.*):(\\s*)(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).wrap(t -> new BuySellEntryItem(t)));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class FinTechGroupBankPDFExtractor method addBuySellTransaction.
@SuppressWarnings("nls")
private void addBuySellTransaction() {
DocumentType type = new DocumentType("Sammelabrechnung (Wertpapierkauf/-verkauf)");
this.addDocumentTyp(type);
Block block = new Block("Nr.(\\d*)/(\\d*) *Kauf.*");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
}).section("wkn", "isin", "name").match("Nr.[0-9A-Za-z]*/(\\d*) *Kauf *(?<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.setDate(asDate(v.get("date")));
}).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("fee", "currency").optional().match(//
".* Provision *: *(?<fee>[\\d.-]+,\\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.-]+,\\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.-]+,\\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")))))).wrap(t -> new BuySellEntryItem(t)));
block = new Block("Nr.(\\d*)/(\\d*) *Verkauf.*");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
return entry;
}).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.setDate(asDate(v.get("date")));
}).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("fee", "currency").optional().match(//
".* Provision *: *(?<fee>[\\d.-]+,\\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.-]+,\\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.-]+,\\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("tax", "currency").optional().match(".* \\*\\*Einbeh. Steuer *: *(?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))))).section("taxreturn", "currency").optional().match(".* \\*\\*Einbeh. Steuer *: *(?<taxreturn>-[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
t.setAmount(t.getPortfolioTransaction().getAmount() - asAmount(v.get("taxreturn")));
}).wrap(t -> new BuySellEntryItem(t)));
addTaxReturnBlock(type);
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class FinTechGroupBankPDFExtractor method addForeignDividendTransaction.
@SuppressWarnings("nls")
private void addForeignDividendTransaction() {
DocumentType type = new DocumentType("Dividendengutschrift für ausländische Wertpapiere", (context, lines) -> {
Pattern pCurrency = Pattern.compile(".* Endbetrag .* (?<currency>\\w{3})$");
Pattern pCurrencyFx = Pattern.compile(".* Bruttodividende *: *[.\\d]+,\\d{2} (?<currencyFx>\\w{3})");
Pattern pExchangeRate = Pattern.compile("Devisenkurs *: *(?<exchangeRate>[.\\d]+,\\d+) .*");
// read the current context here
for (String line : lines) {
Matcher m = pCurrency.matcher(line);
if (m.matches()) {
context.put("currency", m.group(1));
// System.out.println("context currency found: " + context.get("currency"));
}
m = pCurrencyFx.matcher(line);
if (m.matches()) {
context.put("currencyFx", m.group(1));
// System.out.println("context currencyFx found: " + context.get("currencyFx"));
}
m = pExchangeRate.matcher(line);
if (m.matches()) {
context.put("exchangeRate", m.group(1));
// System.out.println("context exchangeRate found: " + context.get("exchangeRate"));
}
}
});
this.addDocumentTyp(type);
Block block = new Block("Ihre Depotnummer.*");
type.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) -> {
Map<String, String> context = type.getCurrentContext();
// the security must be in Fx units, otherwise, dividends and taxes cannot be in Fx units
v.put("currency", context.get("currencyFx"));
// System.out.println("Security Currency: " + context.get("currency"));
t.setSecurity(getOrCreateSecurity(v));
// System.out.println("Security Info: " + t.getSecurity().toInfoString());
}).section(//
"shares").match(//
"^St\\.[^:]+: *(?<shares>[\\.\\d]+(,\\d*)?).*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amountGrossFx", //
"currencyFx").match(//
".* Bruttodividende *: *(?<amountGrossFx>[.\\d]+,\\d{2}) (?<currencyFx>\\w{3})").assign((t, v) -> {
// get exchange rate (in Fx/EUR) and calculate inverse exchange rate (in EUR/Fx)
Map<String, String> context = type.getCurrentContext();
BigDecimal exchangeRate = asExchangeRate(context.get("exchangeRate"));
BigDecimal inverseRate = BigDecimal.ONE.divide(exchangeRate, 10, BigDecimal.ROUND_HALF_DOWN);
// set currency of transaction (should be in EUR)
String currencyCode = asCurrencyCode(context.get("currency"));
t.setCurrencyCode(currencyCode);
// get foreign currency (should be in Fx)
String currencyCodeFx = asCurrencyCode(v.get("currencyFx"));
// get gross amount and calculate equivalent in EUR
Money mAmountGrossFx = Money.of(currencyCodeFx, Math.round(asAmount(v.get("amountGrossFx"))));
BigDecimal amountGrossFxInEUR = BigDecimal.valueOf(mAmountGrossFx.getAmount()).divide(exchangeRate, 10, BigDecimal.ROUND_HALF_DOWN);
Money mAmountGrossFxInEUR = Money.of(currencyCode, Math.round(amountGrossFxInEUR.longValue()));
t.addUnit(new Unit(Unit.Type.GROSS_VALUE, mAmountGrossFxInEUR, mAmountGrossFx, inverseRate));
}).section("amountFx", "currencyFx").optional().match(//
".* Gez. Quellenst. *: *(?<amountFx>[.\\d]+,\\d{2}) (?<currencyFx>\\w{3})").assign((t, v) -> {
// get exchange rate (in Fx/EUR) and calculate inverse exchange rate (in EUR/Fx)
Map<String, String> context = type.getCurrentContext();
BigDecimal exchangeRate = asExchangeRate(context.get("exchangeRate"));
BigDecimal inverseRate = BigDecimal.ONE.divide(exchangeRate, 10, BigDecimal.ROUND_HALF_DOWN);
// get foreign currency (should be in Fx) and transaction currency (should be in EUR)
String currencyCode = asCurrencyCode(context.get("currency"));
String currencyCodeFx = asCurrencyCode(v.get("currencyFx"));
// get foreign taxes and calculate equivalent in EUR
Money mTaxesFx = Money.of(currencyCodeFx, Math.round(asAmount(v.get("amountFx"))));
BigDecimal taxesFxInEUR = BigDecimal.valueOf(mTaxesFx.getAmount()).divide(exchangeRate, 10, BigDecimal.ROUND_HALF_DOWN);
Money mTaxesFxInEUR = Money.of(currencyCode, Math.round(taxesFxInEUR.longValue()));
t.addUnit(new Unit(Unit.Type.TAX, mTaxesFxInEUR, mTaxesFx, inverseRate));
}).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)));
}
Aggregations