use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction 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);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class OnvistaPDFExtractor method addRemoveDididendRightsTransaction.
private void addRemoveDididendRightsTransaction() {
DocumentType type = new DocumentType("Wertlose Ausbuchung");
this.addDocumentTyp(type);
Block block = new Block("Wertlose Ausbuchung(.*)");
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(//
"Ausbuchung:(\\s*)").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).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.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
t.setDateTime(asDate(v.get("date")));
}).wrap(TransactionItem::new);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction in project portfolio by buchen.
the class OnvistaPDFExtractor method addBuyTransaction.
private void addBuyTransaction() {
DocumentType type = new DocumentType("Wir haben für Sie gekauft");
this.addDocumentTyp(type);
Block block = new Block("Wir haben für Sie gekauft(.*)");
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", "time", "amount", //
"currency").match("Handelstag (?<date>\\d+.\\d+.\\d{4}+) (.*)").match("Handelszeit (?<time>\\d+:\\d+)(.*)").find("Wert(\\s+)Konto-Nr. Betrag zu Ihren Lasten(\\s*)$").match("(\\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"), v.get("time")));
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.Transaction in project portfolio by buchen.
the class SBrokerPDFExtractor method addSellTransaction.
@SuppressWarnings("nls")
private void addSellTransaction() {
DocumentType type = new DocumentType("Verkauf");
this.addDocumentTyp(type);
Block block = new Block("Verkauf .*");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.SELL);
return entry;
}).section("isin", //
"name").find(//
"Gattungsbezeichnung ISIN").match("(?<name>.*) Inhaber-Anteile (?<isin>.*)").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("date", "amount", //
"currency").find("Wert Konto-Nr. Betrag zu Ihren Gunsten").match(//
"(?<date>\\d+.\\d+.\\d{4}) \\d{2}/\\d{4}/\\d{3} (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)").assign((t, v) -> {
t.setDate(asDate(v.get("date")));
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).section(//
"shares").match(//
"^STK (?<shares>\\d+,\\d+?) .*").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("fee", "currency").optional().match(//
".* Orderentgelt (?<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(//
".* Börsengebühr (?<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")))))).wrap(t -> new BuySellEntryItem(t)));
}
Aggregations