use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class OnvistaPDFExtractor method addSellTransaction.
private void addSellTransaction() {
DocumentType type = new DocumentType("Wir haben für Sie verkauft");
this.addDocumentTyp(type);
Block block = new Block("Wir haben für Sie verkauft(.*)");
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("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 Gunsten(\\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);
addTaxesSectionsTransaction(pdfTransaction);
addFeesSectionsTransaction(pdfTransaction);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class OnvistaPDFExtractor method addAccountStatementTransaction2017.
private void addAccountStatementTransaction2017() {
// this seems to be the new format of account statements from the year 2017
final DocumentType type = new DocumentType("Kontoauszug Nr.", (context, lines) -> {
Pattern pYear = Pattern.compile("^Kontoauszug Nr. (\\d{4}) / .*\\.(\\d{4})$");
Pattern pCurrency = Pattern.compile("^(\\w{3}+) - Verrechnungskonto: .*$");
// read the current context here
for (String line : lines) {
Matcher m = pYear.matcher(line);
if (m.matches()) {
context.put("year", m.group(1));
}
m = pCurrency.matcher(line);
if (m.matches()) {
context.put("currency", m.group(1));
}
}
});
this.addDocumentTyp(type);
// 31.10. 31.10. REF: 000017304356 37,66
Block block = new Block("^\\d+\\.\\d+\\.\\s+\\d+\\.\\d+\\.\\s+REF:\\s+\\d+\\s+[\\d.-]+,\\d+[+-]?(.*)");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DEPOSIT);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("valuta", "amount", "sign").match("^\\d+\\.\\d+\\.\\s+(?<valuta>\\d+\\.\\d+\\.)\\s+REF:\\s+\\d+\\s+(?<amount>[\\d.-]+,\\d+)(?<sign>[+-]?)(.*)").assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
String date = v.get("valuta");
if (date != null) {
// create a long date from the year in the
// context
t.setDateTime(asDate(date + context.get("year")));
}
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
// check for withdrawals
String sign = v.get("sign");
if ("-".equals(sign)) {
// change type for withdrawals
t.setType(AccountTransaction.Type.REMOVAL);
}
}).section(//
"postingtype").find(//
"\\d+\\.\\d+\\.\\s+\\d+\\.\\d+\\. REF:(.*)").match("(?<postingtype>.*?)").assign((t, v) -> {
String postingtype = v.get("postingtype");
if (postingtype != null) {
switch(postingtype) {
case "Wertpapierkauf":
case "Umtausch/Bezug":
case "Sollbuchung HSBC":
t.setType(AccountTransaction.Type.BUY);
break;
case "Wertpapierverkauf":
case "Spitze Verkauf":
case "Habenbuchung HSBC":
case "Tilgung":
t.setType(AccountTransaction.Type.SELL);
break;
case "Zinsen/Dividenden":
t.setType(AccountTransaction.Type.DIVIDENDS);
break;
case "AbgSt. Optimierung":
t.setType(AccountTransaction.Type.TAX_REFUND);
break;
default:
break;
}
}
}).wrap(t -> {
// Konto:
if (t.getType() != AccountTransaction.Type.DIVIDENDS && t.getType() != AccountTransaction.Type.BUY && t.getType() != AccountTransaction.Type.SELL && t.getType() != AccountTransaction.Type.TAX_REFUND)
return new TransactionItem(t);
return null;
});
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class OnvistaPDFExtractor method addCapitalIncreaseTransaction.
private void addCapitalIncreaseTransaction() {
DocumentType type = new DocumentType("Kapitalerhöhung");
this.addDocumentTyp(type);
Block block = new Block("Kapitalerhöhung(.*)");
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);
pdfTransaction.section("date").match(//
"(.*), (?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("name", //
"isin").find(//
"Einbuchung:(\\s*)").find(//
"Gattungsbezeichnung ISIN").match(//
"(?<name>.*) (?<isin>[^ ]\\S*)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("notation", //
"shares").find(//
"Nominal(.*)").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")));
}
t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
}).wrap(TransactionItem::new);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class OnvistaPDFExtractor method addCapitalReductionTransaction.
private void addCapitalReductionTransaction() {
DocumentType type = new DocumentType("Kapitalherabsetzung");
this.addDocumentTyp(type);
Block block = new Block("(Aus|Ein)buchung:(.*)");
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);
pdfTransaction.section("date").optional().match("(^\\w{3}+) (\\d{1,3}(\\.\\d{3})*(,\\d{3})?) (?<date>\\d+.\\d+.\\d{4}+)?(.*)").assign((t, v) -> {
t.setDateTime(asDate(v.get("date")));
type.getCurrentContext().put("date", v.get("date"));
}).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.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
} else if ("Ausbuchung:".equalsIgnoreCase(transactiontype)) {
t.setType(PortfolioTransaction.Type.DELIVERY_OUTBOUND);
} else {
// TODO: evtl. Warnung/Hinweis ausgeben?
}
}).section("notation", //
"shares").find("Nominal(.*)").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")));
}
t.setCurrencyCode(asCurrencyCode(t.getSecurity().getCurrencyCode()));
if (t.getDateTime() == null) {
t.setDateTime(asDate(type.getCurrentContext().get("date")));
}
}).wrap(TransactionItem::new);
}
use of name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType in project portfolio by buchen.
the class OnvistaPDFExtractor method addAccountStatementTransaction.
private void addAccountStatementTransaction() {
final DocumentType type = new DocumentType("KONTOAUSZUG Nr.", (context, lines) -> {
Pattern pYear = Pattern.compile("KONTOAUSZUG Nr. \\d+ per \\d+.\\d+.(\\d{4}+)?(.*)");
Pattern pCurrency = Pattern.compile("(.*)Customer Cash Account[ ]+(\\w{3}+)");
// read the current context here
for (String line : lines) {
Matcher m = pYear.matcher(line);
if (m.matches()) {
context.put("year", m.group(1));
}
m = pCurrency.matcher(line);
if (m.matches()) {
context.put("currency", m.group(2));
}
}
});
this.addDocumentTyp(type);
// 31.10. 31.10. REF: 000017304356 37,66
Block block = new Block("^\\d+\\.\\d+\\.\\s+\\d+\\.\\d+\\.\\s+REF:\\s+\\d+\\s+[\\d.-]+,\\d+[+-]?(.*)");
type.addBlock(block);
Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
pdfTransaction.subject(() -> {
AccountTransaction entry = new AccountTransaction();
entry.setType(AccountTransaction.Type.DEPOSIT);
return entry;
});
block.set(pdfTransaction);
//
pdfTransaction.section("valuta", "amount", "sign").match("^\\d+\\.\\d+\\.\\s+(?<valuta>\\d+\\.\\d+\\.)\\s+REF:\\s+\\d+\\s+(?<amount>[\\d.-]+,\\d+)(?<sign>[+-]?)(.*)").assign((t, v) -> {
Map<String, String> context = type.getCurrentContext();
String date = v.get("valuta");
if (date != null) {
// create a long date from the year in the
// context
t.setDateTime(asDate(date + context.get("year")));
}
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(context.get("currency")));
// check for withdrawals
String sign = v.get("sign");
if ("-".equals(sign)) {
// change type for withdrawals
t.setType(AccountTransaction.Type.REMOVAL);
}
}).section(//
"postingtype").find(//
"\\d+\\.\\d+\\.\\s+\\d+\\.\\d+\\. REF:(.*)").match("(?<postingtype>.*?)").assign((t, v) -> {
String postingtype = v.get("postingtype");
if (postingtype != null) {
switch(postingtype) {
case "Wertpapierkauf":
case "Umtausch/Bezug":
case "Sollbuchung HSBC":
t.setType(AccountTransaction.Type.BUY);
break;
case "Wertpapierverkauf":
case "Spitze Verkauf":
case "Habenbuchung HSBC":
case "Tilgung":
t.setType(AccountTransaction.Type.SELL);
break;
case "Zinsen/Dividenden":
t.setType(AccountTransaction.Type.DIVIDENDS);
break;
case "AbgSt. Optimierung":
t.setType(AccountTransaction.Type.TAX_REFUND);
break;
default:
break;
}
}
}).wrap(t -> {
// Konto:
if (t.getType() != AccountTransaction.Type.DIVIDENDS && t.getType() != AccountTransaction.Type.BUY && t.getType() != AccountTransaction.Type.SELL && t.getType() != AccountTransaction.Type.TAX_REFUND)
return new TransactionItem(t);
return null;
});
}
Aggregations