Search in sources :

Example 11 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class ConsorsbankPDFExtractor method newDividendTransaction.

@SuppressWarnings("nls")
private Transaction<AccountTransaction> newDividendTransaction(DocumentType type) {
    return new Transaction<AccountTransaction>().subject(() -> {
        AccountTransaction t = new AccountTransaction();
        t.setType(AccountTransaction.Type.DIVIDENDS);
        return t;
    }).section("amount", // 
    "currency").match(// 
    "BRUTTO *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *").assign((t, v) -> {
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section("wkn", "name", // 
    "shares").match(// 
    "ST *(?<shares>[\\d.]+(,\\d+)?) *WKN: *(?<wkn>\\S*) *").match(// 
    "^(?<name>.*)$").assign((t, v) -> {
        // reuse currency from transaction when creating a
        // new security upon import
        v.put("currency", t.getCurrencyCode());
        t.setSecurity(getOrCreateSecurity(v));
        t.setShares(asShares(v.get("shares")));
    }).section("rate", "amount", "currency").optional().match(// 
    "UMGER.ZUM DEV.-KURS *(?<rate>[\\d.]+,\\d+) *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *").assign((t, v) -> {
        Money currentMonetaryAmount = t.getMonetaryAmount();
        BigDecimal rate = asExchangeRate(v.get("rate"));
        type.getCurrentContext().put("exchangeRate", rate.toPlainString());
        BigDecimal accountMoneyValue = BigDecimal.valueOf(t.getAmount()).divide(rate, RoundingMode.HALF_DOWN);
        String currencyCode = asCurrencyCode(v.get("currency"));
        t.setMonetaryAmount(Money.of(currencyCode, asAmount(v.get("amount"))));
        // currencies -> add gross value
        if (!t.getCurrencyCode().equals(t.getSecurity().getCurrencyCode())) {
            Money accountMoney = Money.of(currencyCode, Math.round(accountMoneyValue.doubleValue()));
            // replace BRUTTO (which is in foreign currency)
            // with the value in transaction currency
            BigDecimal inverseRate = BigDecimal.ONE.divide(rate, 10, BigDecimal.ROUND_HALF_DOWN);
            Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, accountMoney, currentMonetaryAmount, inverseRate);
            t.addUnit(grossValue);
        }
    }).section("kapst", "currency").optional().match("KAPST .*(?<currency>\\w{3}+) *(?<kapst>[\\d.]+,\\d+) *").assign((t, v) -> t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("kapst")))))).section("solz", "currency").optional().match(// 
    "SOLZ .*(?<currency>\\w{3}+) *(?<solz>[\\d.]+,\\d+) *").assign((t, v) -> {
        String currency = asCurrencyCode(v.get("currency"));
        if (currency.equals(t.getCurrencyCode())) {
            t.addUnit(new Unit(Unit.Type.TAX, Money.of(asCurrencyCode(currency), asAmount(v.get("solz")))));
        }
    }).section("qust", "currency", "forexcurrency", "forex").optional().match("QUST [\\d.]+,\\d+ *% *(?<currency>\\w{3}+) *(?<qust>[\\d.]+,\\d+) *(?<forexcurrency>\\w{3}+) *(?<forex>[\\d.]+,\\d+) *").assign((t, v) -> {
        Optional<Unit> grossValueOption = t.getUnit(Type.GROSS_VALUE);
        Money money = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("qust")));
        if (grossValueOption.isPresent()) {
            Money forex = Money.of(asCurrencyCode(v.get("forexcurrency")), asAmount(v.get("forex")));
            t.addUnit(new Unit(Unit.Type.TAX, money, forex, grossValueOption.get().getExchangeRate()));
        } else {
            t.addUnit(new Unit(Unit.Type.TAX, money));
        }
    }).section(// 
    "date").match("WERT (?<date>\\d+.\\d+.\\d{4}+).*").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("currency", "amount").optional().match("WERT \\d+.\\d+.\\d{4}+ *(?<currency>\\w{3}+) *(?<amount>[\\d.]+,\\d+) *").assign((t, v) -> {
        String currencyCode = asCurrencyCode(v.get("currency"));
        Money money = Money.of(currencyCode, asAmount(v.get("amount")));
        t.setMonetaryAmount(money);
    }).section("currency", "forexpenses").optional().match(// 
    "FREMDE SPESEN *(?<currency>\\w{3}+) *(?<forexpenses>[\\d.]+,\\d+) *").assign((t, v) -> {
        Optional<Unit> grossValueOption = t.getUnit(Type.GROSS_VALUE);
        long forexAmount = asAmount(v.get("forexpenses"));
        if (grossValueOption.isPresent()) {
            BigDecimal exchangeRate = grossValueOption.get().getExchangeRate();
            long convertedMoney = Math.round(exchangeRate.multiply(BigDecimal.valueOf(forexAmount)).doubleValue());
            Money money = Money.of(t.getCurrencyCode(), convertedMoney);
            Money forex = Money.of(asCurrencyCode(v.get("currency")), forexAmount);
            t.addUnit(new Unit(Unit.Type.TAX, money, forex, grossValueOption.get().getExchangeRate()));
        } else {
            BigDecimal exchangeRate = new BigDecimal(type.getCurrentContext().get("exchangeRate"));
            long convertedMoney = BigDecimal.valueOf(forexAmount).divide(exchangeRate, RoundingMode.HALF_UP).longValue();
            Money money = Money.of(t.getCurrencyCode(), convertedMoney);
            t.addUnit(new Unit(Unit.Type.TAX, money));
        }
    }).wrap(t -> t.getAmount() != 0 ? new TransactionItem(t) : null);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Type(name.abuchen.portfolio.model.Transaction.Unit.Type) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) Optional(java.util.Optional) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) RoundingMode(java.math.RoundingMode) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Optional(java.util.Optional) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 12 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class DABPDFExtractor 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", // 
    "currency").find(// 
    "Gattungsbezeichnung ISIN").match("^(?<name>.*) (?<isin>[^ ]*)$").match("STK [\\d.]+(,\\d+)? (?<currency>\\w{3}+) ([\\d.]+,\\d+)$").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").find(// 
    "Nominal Kurs").match("^STK (?<shares>[\\d.]+(,\\d+)?) (\\w{3}+) ([\\d.]+,\\d+)$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", // 
    "currency").optional().find("Wert Konto-Nr. Betrag zu Ihren Lasten").match("^(\\d+.\\d+.\\d{4}+) ([0-9]*) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section("amount", "currency", "exchangeRate", "forex", "forexCurrency").optional().find(".* Ausmachender Betrag (?<forexCurrency>\\w{3}+) (?<forex>[\\d.]+,\\d+)-").find("Wert Konto-Nr. Devisenkurs Betrag zu Ihren Lasten").match("^(\\d+.\\d+.\\d{4}+) ([0-9]*) .../... (?<exchangeRate>[\\d.]+,\\d+) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
        Money amount = Money.of(asCurrencyCode(v.get("currency")), asAmount(v.get("amount")));
        t.setMonetaryAmount(amount);
        BigDecimal exchangeRate = // 
        BigDecimal.ONE.divide(asExchangeRate(v.get("exchangeRate")), 10, BigDecimal.ROUND_HALF_DOWN);
        Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("forex")));
        Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, amount, forex, exchangeRate);
        t.getPortfolioTransaction().addUnit(grossValue);
    }).section(// 
    "date").match("^Handelstag (?<date>\\d+.\\d+.\\d{4}+) .*$").assign((t, v) -> t.setDate(asDate(v.get("date")))).section("fees", // 
    "currency").optional().match("^.* Provision (?<currency>\\w{3}+) (?<fees>[\\d.]+,\\d+)-$").assign((t, v) -> {
        String currency = asCurrencyCode(v.get("currency"));
        // FIXME forex fees must update gross value
        if (currency.equals(t.getAccountTransaction().getCurrencyCode())) {
            t.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(currency, asAmount(v.get("fees")))));
        }
    }).wrap(t -> {
        if (t.getPortfolioTransaction().getAmount() == 0L)
            throw new IllegalArgumentException("No amount found");
        return new BuySellEntryItem(t);
    }));
}
Also used : BigDecimal(java.math.BigDecimal) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Map(java.util.Map) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 13 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class DABPDFExtractor method addDividendTransaction.

@SuppressWarnings("nls")
private void addDividendTransaction() {
    DocumentType type = new DocumentType("Dividende");
    this.addDocumentTyp(type);
    Block block = new Block("^Dividendengutschrift .*$");
    type.addBlock(block);
    Transaction<AccountTransaction> pdfTransaction = new Transaction<>();
    pdfTransaction.subject(() -> {
        AccountTransaction entry = new AccountTransaction();
        entry.setType(AccountTransaction.Type.DIVIDENDS);
        return entry;
    });
    block.set(pdfTransaction);
    // 
    pdfTransaction.section("isin", "name", "currency").find(// 
    "Gattungsbezeichnung ISIN").match(// 
    "^(?<name>.*) (?<isin>[^ ]*)$").match("STK ([\\d.]+(,\\d+)?) (\\d+.\\d+.\\d{4}+) (\\d+.\\d+.\\d{4}+) (?<currency>\\w{3}+) (\\d+,\\d+)").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(// 
    "shares").find(// 
    "Nominal Ex-Tag Zahltag .*").match("^STK (?<shares>[\\d.]+(,\\d+)?) .*$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("date", "amount", // 
    "currency").optional().find("Wert *Konto-Nr. *Betrag *zu *Ihren *Gunsten").match("^(?<date>\\d+.\\d+.\\d{4}+) ([0-9]*) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
    }).section("date", "amount", "currency", "forexCurrency", // 
    "exchangeRate").optional().find("Wert Konto-Nr. Devisenkurs Betrag zu Ihren Gunsten").match("^(?<date>\\d+.\\d+.\\d{4}+) ([0-9]*) \\w{3}+/(?<forexCurrency>\\w{3}+) (?<exchangeRate>[\\d.]+,\\d+) (?<currency>\\w{3}+) (?<amount>[\\d.]+,\\d+)$").assign((t, v) -> {
        t.setDateTime(asDate(v.get("date")));
        t.setAmount(asAmount(v.get("amount")));
        t.setCurrencyCode(asCurrencyCode(v.get("currency")));
        BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate")).setScale(10, BigDecimal.ROUND_HALF_DOWN);
        Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), Math.round(t.getAmount() / exchangeRate.doubleValue()));
        Unit unit = new Unit(Unit.Type.GROSS_VALUE, t.getMonetaryAmount(), forex, exchangeRate);
        if (unit.getForex().getCurrencyCode().equals(t.getSecurity().getCurrencyCode()))
            t.addUnit(unit);
    }).section("forex", "localCurrency", "forexCurrency", // 
    "exchangeRate").optional().find("Wert Konto-Nr. Betrag zu Ihren Gunsten").match("^(\\d+.\\d+.\\d{4}+) ([0-9]*) (\\w{3}+) (?<forex>[\\d.]+,\\d+)$").match("Devisenkurs: (?<localCurrency>\\w{3}+)/(?<forexCurrency>\\w{3}+) (?<exchangeRate>[\\d.]+,\\d+)").assign((t, v) -> {
        BigDecimal exchangeRate = asExchangeRate(v.get("exchangeRate")).setScale(10, BigDecimal.ROUND_HALF_DOWN);
        Money forex = Money.of(asCurrencyCode(v.get("forexCurrency")), asAmount(v.get("forex")));
        Money localAmount = Money.of(v.get("localCurrency"), Math.round(forex.getAmount() / Double.parseDouble(v.get("exchangeRate").replace(',', '.'))));
        t.setAmount(forex.getAmount());
        t.setCurrencyCode(forex.getCurrencyCode());
        Unit unit = new Unit(Unit.Type.GROSS_VALUE, forex, localAmount, exchangeRate);
        if (unit.getForex().getCurrencyCode().equals(t.getSecurity().getCurrencyCode()))
            t.addUnit(unit);
    }).wrap(t -> {
        if (t.getAmount() == 0)
            throw new IllegalArgumentException("No dividend amount found.");
        return new TransactionItem(t);
    });
    addTaxesSectionsTransaction(type, pdfTransaction);
}
Also used : BigDecimal(java.math.BigDecimal) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Map(java.util.Map) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) IOException(java.io.IOException) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DocumentType(name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType) Block(name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Unit(name.abuchen.portfolio.model.Transaction.Unit) BigDecimal(java.math.BigDecimal)

Example 14 with Money

use of name.abuchen.portfolio.money.Money in project portfolio by buchen.

the class CheckCurrenciesAction method process.

@Override
public Status process(PortfolioTransaction transaction, Portfolio portfolio) {
    Security security = transaction.getSecurity();
    if (security == null)
        return new Status(Status.Code.ERROR, MessageFormat.format(Messages.MsgCheckMissingSecurity, transaction.getType().toString()));
    Status status = checkGrossValueAndUnitsAgainstSecurity(transaction);
    if (status.getCode() != Status.Code.OK)
        return status;
    if (transaction.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND || transaction.getType() == PortfolioTransaction.Type.SELL) {
        // tax + fees must be < than transaction amount
        Money taxAndFees = // 
        transaction.getUnits().filter(// 
        u -> u.getType() == Unit.Type.TAX || u.getType() == Unit.Type.FEE).map(// 
        u -> u.getAmount()).collect(MoneyCollectors.sum(transaction.getCurrencyCode()));
        if (!transaction.getMonetaryAmount().isGreaterOrEqualThan(taxAndFees))
            return new Status(Status.Code.ERROR, MessageFormat.format(Messages.MsgCheckTaxAndFeesTooHigh, Values.Money.format(transaction.getMonetaryAmount()), Values.Money.format(taxAndFees)));
    }
    return Status.OK_STATUS;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Transaction(name.abuchen.portfolio.model.Transaction) Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Set(java.util.Set) Security(name.abuchen.portfolio.model.Security) Messages(name.abuchen.portfolio.Messages) MessageFormat(java.text.MessageFormat) Unit(name.abuchen.portfolio.model.Transaction.Unit) MoneyCollectors(name.abuchen.portfolio.money.MoneyCollectors) Optional(java.util.Optional) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) EnumSet(java.util.EnumSet) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Money(name.abuchen.portfolio.money.Money) Security(name.abuchen.portfolio.model.Security)

Example 15 with Money

use of name.abuchen.portfolio.money.Money 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());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Money(name.abuchen.portfolio.money.Money) Type(name.abuchen.portfolio.model.AccountTransaction.Type) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ParseException(java.text.ParseException) StringJoiner(java.util.StringJoiner)

Aggregations

Money (name.abuchen.portfolio.money.Money)38 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)18 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)16 Client (name.abuchen.portfolio.model.Client)15 BigDecimal (java.math.BigDecimal)13 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)13 MutableMoney (name.abuchen.portfolio.money.MutableMoney)12 IOException (java.io.IOException)10 Security (name.abuchen.portfolio.model.Security)10 Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)9 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)9 Transaction (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction)9 Map (java.util.Map)8 Account (name.abuchen.portfolio.model.Account)7 AssetPosition (name.abuchen.portfolio.snapshot.AssetPosition)7 LocalDate (java.time.LocalDate)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Portfolio (name.abuchen.portfolio.model.Portfolio)6