Search in sources :

Example 6 with CurrencyConverterImpl

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

the class AbstractSecurityTransactionModel method updateSharesAndQuote.

protected void updateSharesAndQuote() {
    // do not auto-suggest shares and quote when editing an existing transaction
    if (hasSource())
        return;
    if (type == PortfolioTransaction.Type.SELL || type == PortfolioTransaction.Type.DELIVERY_OUTBOUND) {
        boolean hasPosition = false;
        if (portfolio != null) {
            // since the security position has always the currency of the
            // investment vehicle, actually no conversion is needed. Hence
            // we can use an arbitrary converter.
            CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), CurrencyUnit.EUR);
            PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, converter, date);
            SecurityPosition position = snapshot.getPositionsBySecurity().get(security);
            if (position != null) {
                setShares(position.getShares());
                setTotal(position.calculateValue().getAmount());
                hasPosition = true;
            }
        }
        if (!hasPosition) {
            setShares(0);
            setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
        }
    } else {
        setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
    }
}
Also used : SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) BigDecimal(java.math.BigDecimal) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 7 with CurrencyConverterImpl

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

the class AccountTransactionDialog method sharesMenuAboutToShow.

private // NOSONAR
void sharesMenuAboutToShow(// NOSONAR
IMenuManager manager) {
    manager.add(new LabelOnly(Messages.DividendsDialogTitleShares));
    CurrencyConverter converter = new CurrencyConverterImpl(model.getExchangeRateProviderFactory(), client.getBaseCurrency());
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, model().getDate());
    if (snapshot != null && model().getSecurity() != null) {
        PortfolioSnapshot jointPortfolio = snapshot.getJointPortfolio();
        addAction(manager, jointPortfolio, Messages.ColumnSharesOwned);
        List<PortfolioSnapshot> list = snapshot.getPortfolios();
        if (list.size() > 1) {
            for (PortfolioSnapshot ps : list) addAction(manager, ps, ps.getPortfolio().getName());
        }
    }
    manager.add(new Action(Messages.DividendsDialogLabelSpecialDistribution) {

        @Override
        public void run() {
            model().setShares(0);
        }
    });
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Action(org.eclipse.jface.action.Action) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 8 with CurrencyConverterImpl

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

the class AccountTransactionModel method updateShares.

private void updateShares() {
    // transaction
    if (sourceTransaction != null)
        return;
    if (!supportsShares() || security == null)
        return;
    CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), client.getBaseCurrency());
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, date);
    SecurityPosition p = snapshot.getJointPortfolio().getPositionsBySecurity().get(security);
    setShares(p != null ? p.getShares() : 0);
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 9 with CurrencyConverterImpl

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

the class CreateInvestmentPlanTxJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        if (startAfterOtherJob != null)
            startAfterOtherJob.join();
        Map<InvestmentPlan, List<PortfolioTransaction>> tx = new HashMap<>();
        CurrencyConverterImpl converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
        getClient().getPlans().stream().filter(InvestmentPlan::isAutoGenerate).forEach(plan -> {
            List<PortfolioTransaction> transactions = plan.generateTransactions(converter);
            if (!transactions.isEmpty())
                tx.put(plan, transactions);
        });
        if (!tx.isEmpty()) {
            Display.getDefault().asyncExec(() -> {
                String message;
                if (tx.size() == 1) {
                    Entry<InvestmentPlan, List<PortfolioTransaction>> entry = tx.entrySet().iterator().next();
                    message = MessageFormat.format(Messages.InvestmentPlanTxCreated, entry.getKey().getName(), entry.getValue().size());
                } else {
                    int count = tx.values().stream().mapToInt(List::size).sum();
                    StringBuilder builder = new StringBuilder();
                    builder.append(MessageFormat.format(Messages.InvestmentPlanTxForMultiplePlansCreated, count));
                    for (Entry<InvestmentPlan, List<PortfolioTransaction>> entry : tx.entrySet()) builder.append(// $NON-NLS-1$
                    MessageFormat.format(// $NON-NLS-1$
                    "\n{0}: {1}", // $NON-NLS-1$
                    entry.getKey().getName(), entry.getValue().size()));
                    message = builder.toString();
                }
                // FIXME Oxygen supports custom button labels
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.LabelInfo, message);
            });
        }
    } catch (// NOSONAR
    InterruptedException ignore) {
    // ignore
    }
    return Status.OK_STATUS;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) HashMap(java.util.HashMap) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) List(java.util.List) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl)

Example 10 with CurrencyConverterImpl

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

the class SecurityTransferModel method updateSharesAndQuote.

private void updateSharesAndQuote() {
    // transaction
    if (source != null)
        return;
    SecurityPosition position = null;
    if (security != null) {
        CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), client.getBaseCurrency());
        PortfolioSnapshot snapshot = sourcePortfolio != null ? PortfolioSnapshot.create(sourcePortfolio, converter, date) : ClientSnapshot.create(client, converter, date).getJointPortfolio();
        position = snapshot.getPositionsBySecurity().get(security);
    }
    if (position != null) {
        setShares(position.getShares());
        // setAmount will also set quote
        setAmount(position.calculateValue().getAmount());
    } else if (security != null) {
        setShares(0);
        setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
    } else {
        setShares(0);
        setQuote(BigDecimal.ZERO);
    }
}
Also used : SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) BigDecimal(java.math.BigDecimal) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Aggregations

CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)14 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)9 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)4 Composite (org.eclipse.swt.widgets.Composite)4 Client (name.abuchen.portfolio.model.Client)3 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)3 PortfolioSnapshot (name.abuchen.portfolio.snapshot.PortfolioSnapshot)3 SecurityPosition (name.abuchen.portfolio.snapshot.SecurityPosition)3 Column (name.abuchen.portfolio.ui.util.viewers.Column)3 NameColumn (name.abuchen.portfolio.ui.views.columns.NameColumn)3 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 List (java.util.List)2 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)2 InvestmentPlan (name.abuchen.portfolio.model.InvestmentPlan)2 Transaction (name.abuchen.portfolio.model.Transaction)2