use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class DividendsViewModel method calculate.
private void calculate() {
// determine the number of full months within period
LocalDate now = LocalDate.now();
if (startYear > now.getYear())
throw new IllegalArgumentException();
this.noOfmonths = (now.getYear() - startYear) * 12 + now.getMonthValue();
Predicate<Transaction> predicate = new ReportingPeriod.FromXtoY(LocalDate.of(startYear - 1, Month.DECEMBER, 31), now).containsTransaction();
Map<InvestmentVehicle, Line> vehicle2line = new HashMap<>();
this.sum = new Line(null, this.noOfmonths);
this.transactions = new ArrayList<>();
Client filteredClient = clientFilter.getSelectedFilter().filter(client);
for (Account account : filteredClient.getAccounts()) {
for (AccountTransaction t : account.getTransactions()) {
if (t.getType() != AccountTransaction.Type.DIVIDENDS)
continue;
if (!predicate.test(t))
continue;
transactions.add(new TransactionPair<>(account, t));
Money dividendValue = useGrossValue ? t.getGrossValue() : t.getMonetaryAmount();
long value = dividendValue.with(converter.at(t.getDateTime())).getAmount();
int index = (t.getDateTime().getYear() - startYear) * 12 + t.getDateTime().getMonthValue() - 1;
Line line = vehicle2line.computeIfAbsent(t.getSecurity(), s -> new Line(s, noOfmonths));
line.values[index] += value;
line.sum += value;
sum.values[index] += value;
sum.sum += value;
}
}
this.lines = new ArrayList<>(vehicle2line.values());
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class SecurityTransferModel method applyChanges.
@Override
public void applyChanges() {
if (security == null)
throw new UnsupportedOperationException(Messages.MsgMissingSecurity);
if (sourcePortfolio == null)
throw new UnsupportedOperationException(Messages.MsgPortfolioFromMissing);
if (targetPortfolio == null)
throw new UnsupportedOperationException(Messages.MsgPortfolioToMissing);
PortfolioTransferEntry t;
if (source != null && sourcePortfolio.equals(source.getOwner(source.getSourceTransaction())) && targetPortfolio.equals(source.getOwner(source.getTargetTransaction()))) {
// transaction stays in same accounts
t = source;
} else {
if (source != null) {
@SuppressWarnings("unchecked") TransactionOwner<Transaction> owner = (TransactionOwner<Transaction>) source.getOwner(source.getSourceTransaction());
owner.deleteTransaction(source.getSourceTransaction(), client);
source = null;
}
t = new PortfolioTransferEntry(sourcePortfolio, targetPortfolio);
t.insert();
}
t.setSecurity(security);
t.setDate(LocalDateTime.of(date, time));
t.setShares(shares);
t.setAmount(amount);
t.setCurrencyCode(security.getCurrencyCode());
t.setNote(note);
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class SecurityListView method createTransactionTable.
// //////////////////////////////////////////////////////////////
// tab item: transactions
// //////////////////////////////////////////////////////////////
protected Composite createTransactionTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
transactions = new TableViewer(container, SWT.FULL_SELECTION);
ColumnViewerToolTipSupport.enableFor(transactions, ToolTip.NO_RECREATE);
ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
SecurityListView.class.getSimpleName() + "@transactions4", // $NON-NLS-1$
getPreferenceStore(), // $NON-NLS-1$
transactions, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.DateTime.format(((TransactionPair<?>) element).getTransaction().getDateTime());
}
});
column.setSorter(ColumnViewerSorter.create((o1, o2) -> ((TransactionPair<?>) o1).getTransaction().getDateTime().compareTo(((TransactionPair<?>) o2).getTransaction().getDateTime())), SWT.UP);
support.addColumn(column);
column = new Column(Messages.ColumnTransactionType, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
if (t instanceof PortfolioTransaction)
return ((PortfolioTransaction) t).getType().toString();
else if (t instanceof AccountTransaction)
return ((AccountTransaction) t).getType().toString();
else
return null;
}
});
support.addColumn(column);
column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
column.setLabelProvider(new SharesLabelProvider() {
@Override
public Long getValue(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
if (t instanceof PortfolioTransaction) {
return ((PortfolioTransaction) t).getShares();
} else if (t instanceof AccountTransaction) {
long shares = ((AccountTransaction) t).getShares();
return shares != 0 ? shares : null;
}
return null;
}
});
support.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
return Values.Money.format(t.getMonetaryAmount(), getClient().getBaseCurrency());
}
});
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
long a1 = ((TransactionPair<?>) o1).getTransaction().getAmount();
long a2 = ((TransactionPair<?>) o2).getTransaction().getAmount();
return a1 > a2 ? 1 : a1 < a2 ? -1 : 0;
}));
support.addColumn(column);
column = new Column(Messages.ColumnPerShare, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPerShare_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
if (t instanceof PortfolioTransaction) {
return Values.Quote.format(((PortfolioTransaction) t).getGrossPricePerShare(), getClient().getBaseCurrency());
} else if (t instanceof AccountTransaction) {
long shares = ((AccountTransaction) t).getShares();
if (shares != 0) {
long perShare = Math.round(((AccountTransaction) t).getGrossValueAmount() * Values.Share.divider() * Values.Quote.factorToMoney() / shares);
return Values.Quote.format(Quote.of(t.getCurrencyCode(), perShare));
}
}
return null;
}
});
support.addColumn(column);
column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnFees_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
return Values.Money.format(t.getUnitSum(Unit.Type.FEE), getClient().getBaseCurrency());
}
});
support.addColumn(column);
column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnTaxes_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
return Values.Money.format(t.getUnitSum(Unit.Type.TAX), getClient().getBaseCurrency());
}
});
support.addColumn(column);
column = new Column(Messages.ColumnPortfolio, SWT.NONE, 120);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TransactionOwner<?> owner = ((TransactionPair<?>) element).getOwner();
if (owner instanceof Portfolio)
return owner.toString();
return null;
}
});
support.addColumn(column);
column = new Column(Messages.ColumnOffsetAccount, SWT.NONE, 120);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TransactionPair<?> pair = (TransactionPair<?>) element;
Transaction t = pair.getTransaction();
if (t instanceof PortfolioTransaction)
return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
else
return pair.getOwner().toString();
}
});
support.addColumn(column);
column = new NoteColumn();
column.setEditingSupport(null);
support.addColumn(column);
support.createColumns();
transactions.getTable().setHeaderVisible(true);
transactions.getTable().setLinesVisible(true);
transactions.setContentProvider(ArrayContentProvider.getInstance());
hookContextMenu(transactions.getControl(), this::transactionMenuAboutToShow);
hookKeyListener();
return container;
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class PerformanceView method addFeesColumn.
private void addFeesColumn(ShowHideColumnHelper support) {
Column column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
if (t instanceof AccountTransaction) {
AccountTransaction at = (AccountTransaction) t;
switch(at.getType()) {
case FEES:
return Values.Money.format(t.getMonetaryAmount(), getClient().getBaseCurrency());
case FEES_REFUND:
return Values.Money.format(t.getMonetaryAmount().multiply(-1), getClient().getBaseCurrency());
default:
}
}
return Values.Money.format(t.getUnitSum(Unit.Type.FEE), getClient().getBaseCurrency());
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getUnitSum(Unit.Type.FEE)));
support.addColumn(column);
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class PerformanceView method addTaxesColumn.
private void addTaxesColumn(ShowHideColumnHelper support) {
Column column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
if (t instanceof AccountTransaction) {
AccountTransaction at = (AccountTransaction) t;
switch(at.getType()) {
case TAXES:
return Values.Money.format(at.getMonetaryAmount(), getClient().getBaseCurrency());
case TAX_REFUND:
return Values.Money.format(at.getMonetaryAmount().multiply(-1), getClient().getBaseCurrency());
default:
}
}
return Values.Money.format(t.getUnitSum(Unit.Type.TAX), getClient().getBaseCurrency());
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getUnitSum(Unit.Type.TAX)));
support.addColumn(column);
}
Aggregations