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()));
}
}
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);
}
});
}
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);
}
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;
}
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);
}
}
Aggregations