use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class ComdirectPDFExtractor method addBuyTransaction.
@SuppressWarnings("nls")
private void addBuyTransaction() {
DocumentType type = new DocumentType("Wertpapierkauf");
this.addDocumentTyp(type);
Block block = new Block("^(\\* )?Wertpapierkauf *.*");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
}).section(//
"date").match(//
"Geschäftstag *: (?<date>\\d+.\\d+.\\d{4}+) .*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("isin", "name", //
"wkn").find(//
"Wertpapier-Bezeichnung *WPKNR/ISIN *").match(//
"^(?<name>(\\S{1,} )*) *(?<wkn>\\S*) *$").match(//
"(\\S{1,} )* *(?<isin>\\S*) *$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").optional().match(//
"^St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("shares").optional().match(//
"^ Summe *St\\. *(?<shares>[\\d.]+(,\\d+)?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", //
"currency").find(//
".*Zu Ihren Lasten( vor Steuern)? *").match(//
".* \\d+.\\d+.\\d{4}+ *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+).*").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
}).section("tax").optional().match(//
"^a *b *g *e *f *ü *h *r *t *e *S *t *e *u *e *r *n *(?<tax>.*)$").assign((t, v) -> {
Unit unit = createTaxUnit(v.get("tax"));
if (unit == null || unit.getAmount().isZero())
return;
t.getPortfolioTransaction().addUnit(unit);
MutableMoney total = MutableMoney.of(t.getPortfolioTransaction().getCurrencyCode());
total.add(t.getPortfolioTransaction().getMonetaryAmount());
total.add(unit.getAmount());
t.setMonetaryAmount(total.toMoney());
}).wrap(t -> {
if (t.getPortfolioTransaction().getShares() == 0)
throw new IllegalArgumentException(Messages.PDFMsgMissingShares);
return new BuySellEntryItem(t);
});
addFeesSection(pdfTransaction);
block.set(pdfTransaction);
addTaxRefunds(type, "^(\\* )?Wertpapierkauf *.*");
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class ComdirectPDFExtractor method addDividendTransaction.
@SuppressWarnings("nls")
private void addDividendTransaction() {
DocumentType dividende = new DocumentType("Abrechnung Dividendengutschrift");
this.addDocumentTyp(dividende);
DocumentType ertrag = new DocumentType("Abrechnung Ertragsgutschrift");
this.addDocumentTyp(ertrag);
Block block = new Block(".*G *u *t *s *c *h *r *i *f *t *f *ä *l *l *i *g *e *r *W *e *r *t *p *a *p *i *e *r *- *E *r *t *r *ä *g *e *");
dividende.addBlock(block);
ertrag.addBlock(block);
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DIVIDENDS);
return t;
}).section("wkn", "name", "isin", "shares").optional().match(//
"^\\s*(p\\s*e\\s*r) *\\+?[\\d .]+ (?<name>.*) (?<wkn>.*)").match(//
"^\\s*(S\\s*T\\s*K) *(?<shares>\\+?[\\d .]+,\\+?[\\d ]+).* .* {4}(?<isin>.*)$").assign((t, v) -> {
v.put("isin", stripBlanks(v.get("isin")));
v.put("wkn", stripBlanks(v.get("wkn")));
t.setSecurity(getOrCreateSecurity(v));
t.setShares(asShares(stripBlanks(v.get("shares"))));
}).section("currency", "amount", //
"date").find(//
".*Zu Ihren Gunsten vor Steuern *").match(//
"^.*(?<date>\\d{2}.\\d{2}.\\d{4}) *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *$").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
t.setDateTime(asDate(v.get("date")));
}).section("currency", //
"gross").optional().find("^Bruttobetrag: *(?<currency>\\w{3}+) *(?<gross>[\\d.]+,\\d+)").assign((t, v) -> {
long gross = asAmount(v.get("gross"));
long tax = gross - t.getAmount();
Unit unit = new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), tax));
if (unit.getAmount().getCurrencyCode().equals(t.getCurrencyCode()))
t.addUnit(unit);
}).wrap(TransactionItem::new));
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class ComdirectPDFExtractor method addTaxTransaction.
@SuppressWarnings("nls")
private void addTaxTransaction() {
// TODO 1: combine with dividend-transaction of other file
// TODO 2: not matched by buy/sell with taxes...
// just char sequence
DocumentType type = new DocumentType("Steuerliche Behandlung: Ausländische Dividende");
// type.setMustExclude("Wertpapierkauf");
this.addDocumentTyp(type);
Block block = new Block("^\\s*Steuerliche Behandlung:.*");
type.addBlock(block);
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.TAXES);
return t;
}).section("wkn", "name", "isin", "shares").optional().match(//
"^(Stk.)\\W*(?<shares>\\d[\\d .,]*)(?<name>.*),\\W*(WKN / ISIN:)(?<wkn>.*)/(?<isin>.*)$").assign((t, v) -> {
v.put("isin", stripBlanks(v.get("isin")));
v.put("wkn", stripBlanks(v.get("wkn")));
t.setSecurity(getOrCreateSecurity(v));
t.setShares(asShares(stripBlanks(v.get("shares"))));
}).section(//
"date").match(//
"^.*Die Gutschrift erfolgt mit Valuta\\s+(?<date>\\d{2}.\\d{2}.\\d{4}).*$").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
}).section("tax", "currency").optional().match(//
"^\\s*(K\\s*a\\s*p\\s*i\\s*t\\s*a\\s*l\\s*e\\s*r\\s*t\\s*r\\s*a\\s*g\\s*s\\s*t\\s*e\\s*u\\s*e\\s*r)" + //
"(?<currency>[A-Z\\s]+)(?<tax>[\\d\\s,-]+)$").assign((t, v) -> {
v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
}).section("tax", "currency").optional().match("^\\s*(K\\s*i\\s*r\\s*c\\s*h\\s*e\\s*n\\s*s\\s*t\\s*e\\s*u\\s*e\\s*r)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
}).section("tax", "currency").optional().match("^\\s*(S\\s*o\\s*l\\s*i\\s*d\\s*a\\s*r\\s*i\\s*t\\s*ä\\s*t\\s*s\\s*z\\s*u\\s*s\\s*c\\s*h\\s*l\\s*a\\s*g)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")))));
}).section("tax", // abgeführte Steuern
"currency").match("^\\s*(a\\s*b\\s*g\\s*e\\s*f\\s*ü\\s*h\\s*r\\s*t\\s*e\\s*S\\s*t\\s*e\\s*u\\s*er\\s*n)" + "(?<currency>[A-Z\\s_]+)(?<tax>[\\d\\s,-_]+)$").assign((t, v) -> {
v.put("currency", stripBlanksAndUnderscores(v.get("currency")));
v.put("tax", stripBlanksAndUnderscores(v.get("tax")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("tax")));
}).wrap(TransactionItem::new));
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class ConsorsbankPDFExtractor method addQ42017DividendTransaction.
@SuppressWarnings("nls")
private void addQ42017DividendTransaction() {
DocumentType type = new DocumentType("Dividendengutschrift");
this.addDocumentTyp(type);
Block block = new Block("Dividendengutschrift.*");
type.addBlock(block);
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction t = new AccountTransaction();
t.setType(AccountTransaction.Type.DIVIDENDS);
return t;
}).section("name", "wkn", "isin", //
"currency").find(//
"Wertpapierbezeichnung WKN ISIN").match(//
"(?<name>.*) (?<wkn>[^ ]*) (?<isin>[^ ]*)$").match("Dividende pro Stück ([\\d.]+,\\d+) (?<currency>\\w{3}+).*").assign((t, v) -> {
t.setSecurity(getOrCreateSecurity(v));
}).section("amount", //
"currency").match("Netto zugunsten IBAN (.*) (?<amount>[\\d.]+,\\d+) (?<currency>\\w{3}+)$").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
}).section(//
"shares").match(//
"(?<shares>[\\d.]+(,\\d+)?) Stück").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section(//
"date").match("Valuta (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("exchangeRate", "fxAmount", "fxCurrency", "amount", "currency").optional().match("Brutto in (\\w{3}+) (?<fxAmount>[\\d.]+,\\d+) (?<fxCurrency>\\w{3}+)").match(//
"Devisenkurs (?<exchangeRate>[\\d.]+,\\d+) (\\w{3}+) / (\\w{3}+)").match(//
"Brutto in (\\w{3}+) (?<amount>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
BigDecimal rate = asExchangeRate(v.get("exchangeRate"));
BigDecimal inverseRate = BigDecimal.ONE.divide(rate, 10, BigDecimal.ROUND_HALF_DOWN);
type.getCurrentContext().put("exchangeRate", inverseRate.toPlainString());
Money fxAmount = Money.of(asCurrencyCode(v.get("fxCurrency")), asAmount(v.get("fxAmount")));
Money amount = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("amount")));
if (!t.getCurrencyCode().equals(t.getSecurity().getCurrencyCode())) {
Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, amount, fxAmount, inverseRate);
t.addUnit(grossValue);
}
}).section("tax", "currency").optional().match("abzgl. Quellensteuer .* (\\w{3}+) (?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)").assign((t, v) -> {
Money tax = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")));
if (tax.getCurrencyCode().equals(t.getCurrencyCode())) {
t.addUnit(new Unit(Unit.Type.TAX, tax));
} else if (type.getCurrentContext().containsKey("exchangeRate")) {
BigDecimal exchangeRate = new BigDecimal(type.getCurrentContext().get("exchangeRate"));
Money txTax = Money.of(t.getCurrencyCode(), BigDecimal.valueOf(tax.getAmount()).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
t.addUnit(new Unit(Unit.Type.TAX, txTax));
// update gross value if necessary
if (!t.getCurrencyCode().equals(t.getSecurity().getCurrencyCode())) {
Unit grossValue = t.getUnit(Unit.Type.GROSS_VALUE).get();
t.removeUnit(grossValue);
t.addUnit(new Unit(Unit.Type.GROSS_VALUE, grossValue.getAmount().subtract(txTax), grossValue.getForex().subtract(tax), grossValue.getExchangeRate()));
}
}
}).section("tax", "currency").optional().match("abzgl. Kapitalertragsteuer .* (\\w{3}+) (?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)$").assign((t, v) -> {
Money tax = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")));
t.addUnit(new Unit(Unit.Type.TAX, tax));
}).section("tax", "currency").optional().match("abzgl. Solidaritätszuschlag .* (\\w{3}+) (?<tax>[\\d.]+,\\d+) (?<currency>\\w{3}+)$").assign((t, v) -> {
Money tax = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("tax")));
t.addUnit(new Unit(Unit.Type.TAX, tax));
}).wrap(t -> t.getAmount() != 0 ? new TransactionItem(t) : null));
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class ConsorsbankPDFExtractor method addPreemptiveBuyTransaction.
@SuppressWarnings("nls")
private void addPreemptiveBuyTransaction() {
DocumentType type = new DocumentType("BEZUG");
this.addDocumentTyp(type);
Block block = new Block("^BEZUG AM .*$");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
block.set(pdfTransaction);
pdfTransaction.subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
});
//
pdfTransaction.section("wkn", "isin", "name", "currency").find(//
"(Wertpapier|Bezeichnung) WKN ISIN").match(//
"^(?<name>.*) (?<wkn>[^ ]*) (?<isin>[^ ]*)$").match("(Kurs|Preis pro Anteil) (\\d+,\\d+) (?<currency>\\w{3}+) .*").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(//
"shares").find(//
"Einheit Umsatz( F\\Dlligkeit)?").match(//
"^ST (?<shares>[\\d.]+(,\\d+)?).*$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", "currency").match(//
"Wert (?<date>\\d+.\\d+.\\d{4}+) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setDate(asDate(v.get("date")));
}).wrap(BuySellEntryItem::new);
addFeesSectionsTransaction(pdfTransaction);
}
Aggregations