use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class SBrokerPDFExtractor method addBuyTransaction.
@SuppressWarnings("nls")
private void addBuyTransaction() {
DocumentType type = new DocumentType("Kauf");
this.addDocumentTyp(type);
Block block = new Block("Kauf .*");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
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 Lasten").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)));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class UnicreditPDFExtractor method addBuyTransaction.
@SuppressWarnings("nls")
private void addBuyTransaction() {
DocumentType type = new DocumentType("UniCredit");
this.addDocumentTyp(type);
Block block = new Block("W e r t p a p i e r - A b r e c h n u n g K a u f .*");
type.addBlock(block);
block.set(new Transaction<BuySellEntry>().subject(() -> {
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
return entry;
}).section("name", "wkn", "isin").find("Nennbetrag Wertpapierbezeichnung Wertpapierkennnummer/ISIN").match("^(?<name>.*) (?<wkn>[^ ]*)$").match("^.* (?<isin>[A-Z]{2}[A-Z\\d]{9}\\d)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section("shares").match("^ST *(?<shares>[\\.\\d]+[,\\d]*)$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", "currency").match("^Belastung.* (?<currency>\\w{3}) (?<amount>[\\d.]+,\\d{2})$").assign((t, v) -> {
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
t.setAmount(asAmount(v.get("amount")));
}).section("date").match("^Valuta (?<date>\\d+\\.\\d+\\.\\d{4}) .*").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("fee", "currency").optional().match("^Brokerkommission.* (?<currency>\\w{3}) (?<fee>[\\d.]+,\\d{2})$").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("^Transaktionsentgelt.* (?<currency>\\w{3}) (?<fee>[\\d.]+,\\d{2})$").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("^Provision.* (?<currency>\\w{3}) (?<fee>[\\d.]+,\\d{2})$").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)));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CSVAccountTransactionExtractor method extract.
@Override
void extract(List<Item> items, String[] rawValues, Map<String, Column> field2column) throws ParseException {
// check if we have a security
Security security = getSecurity(rawValues, field2column, s -> s.setCurrencyCode(getCurrencyCode(Messages.CSVColumn_TransactionCurrency, rawValues, field2column)));
// check for the transaction amount
Money amount = getMoney(rawValues, field2column);
// determine type (if not explicitly given by import)
Type type = inferType(rawValues, field2column, security, amount);
// extract remaining fields
LocalDateTime date = getDate(Messages.CSVColumn_Date, rawValues, field2column);
if (date == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Date), 0);
String note = getText(Messages.CSVColumn_Note, rawValues, field2column);
Long shares = getShares(Messages.CSVColumn_Shares, rawValues, field2column);
Long taxes = getAmount(Messages.CSVColumn_Taxes, rawValues, field2column);
switch(type) {
case TRANSFER_IN:
case TRANSFER_OUT:
AccountTransferEntry entry = new AccountTransferEntry();
entry.setAmount(Math.abs(amount.getAmount()));
entry.setCurrencyCode(amount.getCurrencyCode());
entry.setDate(date);
entry.setNote(note);
items.add(new AccountTransferItem(entry, type == Type.TRANSFER_OUT));
break;
case BUY:
case SELL:
if (security == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingSecurity, // $NON-NLS-1$
new StringJoiner(", ").add(Messages.CSVColumn_ISIN).add(Messages.CSVColumn_TickerSymbol).add(Messages.CSVColumn_WKN).toString()), 0);
if (shares == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingField, Messages.CSVColumn_Shares), 0);
BuySellEntry buySellEntry = new BuySellEntry();
buySellEntry.setType(PortfolioTransaction.Type.valueOf(type.name()));
buySellEntry.setAmount(Math.abs(amount.getAmount()));
buySellEntry.setShares(Math.abs(shares));
buySellEntry.setCurrencyCode(amount.getCurrencyCode());
buySellEntry.setSecurity(security);
buySellEntry.setDate(date);
buySellEntry.setNote(note);
items.add(new BuySellEntryItem(buySellEntry));
break;
case DIVIDENDS:
if (security == null)
throw new ParseException(MessageFormat.format(Messages.CSVImportMissingSecurity, // $NON-NLS-1$
new StringJoiner(", ").add(Messages.CSVColumn_ISIN).add(Messages.CSVColumn_TickerSymbol).add(Messages.CSVColumn_WKN).toString()), 0);
case DEPOSIT:
case TAXES:
case TAX_REFUND:
case FEES:
case FEES_REFUND:
case INTEREST:
case INTEREST_CHARGE:
case REMOVAL:
AccountTransaction t = new AccountTransaction();
t.setType(type);
t.setAmount(Math.abs(amount.getAmount()));
t.setCurrencyCode(amount.getCurrencyCode());
if (type == Type.DIVIDENDS || type == Type.TAX_REFUND)
t.setSecurity(security);
t.setDateTime(date);
t.setNote(note);
if (shares != null && type == Type.DIVIDENDS)
t.setShares(Math.abs(shares));
if (type == Type.DIVIDENDS && taxes != null && taxes.longValue() != 0)
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), Math.abs(taxes))));
items.add(new TransactionItem(t));
break;
default:
throw new IllegalArgumentException(type.toString());
}
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CSVExporter method exportPortfolioTransactions.
public void exportPortfolioTransactions(File file, Portfolio portfolio) throws IOException {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
printer.println(new String[] { //
Messages.CSVColumn_Date, //
Messages.CSVColumn_Type, //
Messages.CSVColumn_Value, //
Messages.CSVColumn_TransactionCurrency, //
Messages.CSVColumn_GrossAmount, //
Messages.CSVColumn_CurrencyGrossAmount, //
Messages.CSVColumn_ExchangeRate, //
Messages.CSVColumn_Fees, //
Messages.CSVColumn_Taxes, //
Messages.CSVColumn_Shares, //
Messages.CSVColumn_ISIN, //
Messages.CSVColumn_WKN, //
Messages.CSVColumn_TickerSymbol, //
Messages.CSVColumn_SecurityName, Messages.CSVColumn_Note });
for (PortfolioTransaction t : portfolio.getTransactions()) {
printer.print(t.getDateTime().toString());
printer.print(t.getType().toString());
printer.print(Values.Amount.format(t.getType().isLiquidation() ? -t.getAmount() : t.getAmount()));
printer.print(t.getCurrencyCode());
// gross amount
Optional<Unit> grossAmount = t.getUnit(Unit.Type.GROSS_VALUE);
if (grossAmount.isPresent()) {
Money forex = grossAmount.get().getForex();
printer.print(Values.Amount.format(forex.getAmount()));
printer.print(forex.getCurrencyCode());
printer.print(Values.ExchangeRate.format(grossAmount.get().getExchangeRate()));
} else {
// $NON-NLS-1$
printer.print("");
// $NON-NLS-1$
printer.print("");
// $NON-NLS-1$
printer.print("");
}
printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.FEE).getAmount()));
printer.print(Values.Amount.format(t.getUnitSum(Unit.Type.TAX).getAmount()));
printer.print(Values.Share.format(t.getShares()));
printSecurityInfo(printer, t);
printer.print(escapeNull(t.getNote()));
printer.println();
}
}
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CSVPortfolioTransactionExtractor method extractGrossAmount.
private Unit extractGrossAmount(String[] rawValues, Map<String, Column> field2column, Money amount) throws ParseException {
Long grossAmount = getAmount(Messages.CSVColumn_GrossAmount, rawValues, field2column);
String currencyCode = getCurrencyCode(Messages.CSVColumn_CurrencyGrossAmount, rawValues, field2column);
BigDecimal exchangeRate = getBigDecimal(Messages.CSVColumn_ExchangeRate, rawValues, field2column);
// amount currency equals the transaction currency, no unit is created
if (currencyCode == null || amount.getCurrencyCode().equals(currencyCode))
return null;
// if no gross amount is given at all, no unit
if (grossAmount == null || grossAmount.longValue() == 0)
return null;
// if no exchange rate is available, not unit to create
if (exchangeRate == null || exchangeRate.compareTo(BigDecimal.ZERO) == 0)
return null;
Money forex = Money.of(currencyCode, Math.abs(grossAmount.longValue()));
BigDecimal grossAmountConverted = exchangeRate.multiply(BigDecimal.valueOf(grossAmount));
Money converted = Money.of(amount.getCurrencyCode(), Math.round(grossAmountConverted.doubleValue()));
return new Unit(Unit.Type.GROSS_VALUE, converted, forex, exchangeRate);
}
Aggregations