use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.
the class OnvistaPDFExtractor method addTaxReturnTransaction.
private void addTaxReturnTransaction() {
DocumentType type = new DocumentType("Steuerausgleich nach § 43a");
this.addDocumentTyp(type);
Block block1 = new Block("Wir haben für Sie (ge|ver)kauft(.*)");
type.addBlock(block1);
Block block2 = new Block("(Aus|Ein)buchung:(.*)");
type.addBlock(block2);
Transaction<AccountTransaction> taxRefundTransaction = new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.TAX_REFUND);
return entry;
}).section("name", //
"isin").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).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+)Abrechnungs-Nr.(\\s+)Betrag zu Ihren Gunsten(\\s*)$").match("(^|\\s+)(?<date>\\d+\\.\\d+\\.\\d{4}+)(\\s)(\\d+)?(\\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")));
}).wrap(t -> t.getAmount() != 0 ? new TransactionItem(t) : null);
block1.set(taxRefundTransaction);
block2.set(taxRefundTransaction);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.
the class OnvistaPDFExtractor method addTransferInTransaction.
private void addTransferInTransaction() {
DocumentType type = new DocumentType("Wir erhielten zu Gunsten Ihres Depots");
this.addDocumentTyp(type);
Block block = new Block("Wir erhielten zu Gunsten Ihres Depots(.*)");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.TRANSFER_IN);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("name", "isin").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("notation", "shares", //
"date").find("Nominal Schlusstag Wert").match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?) (\\d+.\\d+.\\d{4}+) (?<date>\\d+.\\d+.\\d{4}+)(.*)").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.setDate(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(t.getPortfolioTransaction().getSecurity().getCurrencyCode()));
}).wrap(BuySellEntryItem::new);
addFeesSectionsTransaction(pdfTransaction);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.
the class OnvistaPDFExtractor method addChangeTransaction.
private void addChangeTransaction() {
DocumentType type = new DocumentType("Bestätigung");
this.addDocumentTyp(type);
Block block = new Block("Bestätigung(.*)");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("name", "isin").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("notation", //
"shares").find("Nominal Kurs").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")));
}
}).section("date", "amount", //
"currency").find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Lasten(\\s*)$").match("(?<date>\\d+.\\d+.\\d{4}+) (\\d{6,12}) (?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)$").assign((t, v) -> {
t.setDate(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).wrap(BuySellEntryItem::new);
addFeesSectionsTransaction(pdfTransaction);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.
the class OnvistaPDFExtractor method addCompensationTransaction.
private void addCompensationTransaction() {
DocumentType type = new DocumentType("Abfindung");
this.addDocumentTyp(type);
Block block = new Block("Ausbuchung(.*)");
type.addBlock(block);
Transaction<BuySellEntry> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("name", "isin").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(//
"transactiontype").match(//
"^(?<transactiontype>.*buchung:)(.*)").assign((t, v) -> {
String transactiontype = v.get("transactiontype");
if ("Einbuchung:".equalsIgnoreCase(transactiontype)) {
t.getAccountTransaction().setType(AccountTransaction.Type.BUY);
t.getPortfolioTransaction().setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
} else if ("Ausbuchung:".equalsIgnoreCase(transactiontype)) {
t.getAccountTransaction().setType(AccountTransaction.Type.SELL);
t.getPortfolioTransaction().setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
} else {
// TODO: evtl. Warnung/Hinweis ausgeben?
}
}).section("notation", "shares", //
"date").find("Nominal Ex-Tag").match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?) (?<date>\\d+.\\d+.\\d{4}+)(.*)").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.setDate(asDate(v.get("date")));
t.setCurrencyCode(asCurrencyCode(t.getPortfolioTransaction().getSecurity().getCurrencyCode()));
}).section("date", "amount", "currency").find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Gunsten(\\s*)$").match("(?<date>\\d+.\\d+.\\d{4}+) (\\d{6,12}) (?<currency>\\w{3}+) (?<amount>\\d{1,3}(\\.\\d{3})*(,\\d{2})?)").assign((t, v) -> {
t.setDate(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).wrap(BuySellEntryItem::new);
addFeesSectionsTransaction(pdfTransaction);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block in project portfolio by buchen.
the class OnvistaPDFExtractor method addDepositTransaction.
private void addDepositTransaction() {
final DocumentType type = new DocumentType("Depotauszug", (context, lines) -> {
Pattern pDate = Pattern.compile("Depotauszug per (\\d+.\\d+.\\d{4}+)?(.*)");
Pattern pCurrency = Pattern.compile("(.*)Bewertung in[ ]+(\\w{3}+)");
// read the current context here
for (String line : lines) {
Matcher m = pDate.matcher(line);
if (m.matches()) {
context.put("date", m.group(1));
}
m = pCurrency.matcher(line);
if (m.matches()) {
context.put("currency", m.group(2));
}
}
});
this.addDocumentTyp(type);
Block block = new Block("(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?)(.*)");
type.addBlock(block);
Transaction<PortfolioTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
PortfolioTransaction entry = new PortfolioTransaction();
entry.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
return entry;
});
block.set(pdfTransaction);
// Die WP-Bezeichnung muss hier leider über mehrere Zeilen hinweg
// zusammengesucht werden, da im Depotauszug-PDF-Extrakt leider
// (zumindest teilweise) Zeilenumbrüche innerhalb des Namens sind... (s.
// Beispiel-Datei: OnvistaDepotauszug.txt)
pdfTransaction.section("notation", "shares", "nameP1").optional().match("(?<notation>^\\w{3}+) (?<shares>\\d{1,3}(\\.\\d{3})*(,\\d{3,})?) (?<nameP1>.*)").assign((t, v) -> {
type.getCurrentContext().put("nameP1", v.get("nameP1"));
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("nameP3").optional().find("(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (.*)").match("^(?<nameP3>^.*?)(\\s*)").assign((t, v) -> type.getCurrentContext().put("nameP3", v.get("nameP3"))).section("nameP2", "isin").optional().match("(?<nameP2>.* )(?<isin>\\w{12}+) (.*)").assign((t, v) -> {
type.getCurrentContext().put("nameP2", v.get("nameP2"));
type.getCurrentContext().put("isin", v.get("isin"));
}).section("nameP4").optional().find("^(.*) (\\w{12}+) (.*)").match("^(?<nameP4>^.*\\.*)$").assign((t, v) -> type.getCurrentContext().put("nameP4", v.get("nameP4"))).section(//
"combine").match(//
"(?<combine>.*)").assign((t, v) -> {
String name = type.getCurrentContext().get("nameP1") + type.getCurrentContext().get("nameP2") + type.getCurrentContext().get("nameP3") + type.getCurrentContext().get("nameP4");
v.put("isin", type.getCurrentContext().get("isin"));
if (name.indexOf(v.get("isin")) > -1) {
name = name.substring(0, name.indexOf(v.get("isin")));
}
if (name.indexOf("STK ") > -1) {
name = name.substring(0, name.indexOf("STK "));
}
// WP-Bezeichnung nachbearbeiten, kann doppelte
// Leerzeichen enthalten...
name = name.replaceAll("\\s+", " ");
// oder auch überflüssige Nullen (00)...
name = name.replaceAll("0+%", "%");
// oder <Leerzeichen><Punkt> ( .)
name = name.replaceAll("\\s+\\.", ".");
v.put("name", name);
t.setSecurity(getOrCreateSecurity(v));
if (t.getDateTime() == null) {
t.setDateTime(asDate(type.getCurrentContext().get("date")));
}
if (t.getCurrencyCode() == null) {
t.setCurrencyCode(asCurrencyCode(type.getCurrentContext().get("currency")));
}
}).wrap(TransactionItem::new);
}
Aggregations