Skip to content

Commit

Permalink
Updated dividends view + chart to (optionally) show gross dividends
Browse files Browse the repository at this point in the history
Issue: #219
  • Loading branch information
buchen committed May 29, 2016
1 parent 2de258f commit 6a387ca
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public class Messages extends NLS
public static String LabelUnknownVersion;
public static String LabelUnnamedXml;
public static String LabelUpdatesAvailable;
public static String LabelUseGrossDividends;
public static String LabelValueInboundDelivery;
public static String LabelValueOutboundDelivery;
public static String LabelViewPieChart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ LabelUnnamedXml = unnamed.xml

LabelUpdatesAvailable = Updates Available

LabelUseGrossDividends = Use gross dividends

LabelValueInboundDelivery = Value of Inbound Delivery

LabelValueOutboundDelivery = Value of Outbound Delivery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ LabelUnnamedXml = ohnenamen.xml

LabelUpdatesAvailable = Eine neue Version ist verf\u00FCgbar

LabelUseGrossDividends = Bruttodividende verwenden

LabelValueInboundDelivery = Wert der Einlieferung

LabelValueOutboundDelivery = Wert der Auslieferung
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void setupModel()
model.updateWith(year);
model.addUpdateListener(() -> preferences.setValue(KEY_YEAR, model.getStartYear()));
}

@Override
public void notifyModelUpdated()
{
Expand Down Expand Up @@ -85,6 +86,25 @@ public void menuAboutToShow(IMenuManager manager)
}
}
};

new AbstractDropDown(toolBar, Messages.MenuConfigureChart, Images.CONFIG.image(), SWT.NONE)
{
@Override
public void menuAboutToShow(IMenuManager manager)
{
Action action = new Action(Messages.LabelUseGrossDividends)
{
@Override
public void run()
{
model.setUseGrossValue(!model.usesGrossValue());
model.recalculate();
}
};
action.setChecked(model.usesGrossValue());
manager.add(action);
}
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import name.abuchen.portfolio.model.Transaction;
import name.abuchen.portfolio.model.TransactionPair;
import name.abuchen.portfolio.money.CurrencyConverter;
import name.abuchen.portfolio.money.Money;
import name.abuchen.portfolio.snapshot.ReportingPeriod;

public class DividendsViewModel
Expand Down Expand Up @@ -64,6 +65,8 @@ public long getSum()
private Line sum;
private List<TransactionPair<AccountTransaction>> transactions;

private boolean useGrossValue = true;

public DividendsViewModel(CurrencyConverter converter, Client client)
{
this.converter = converter;
Expand All @@ -90,6 +93,16 @@ public Line getSum()
return sum;
}

public boolean usesGrossValue()
{
return useGrossValue;
}

public void setUseGrossValue(boolean useGrossValue)
{
this.useGrossValue = useGrossValue;
}

/**
* Returns all lines including the sum line
*/
Expand Down Expand Up @@ -145,9 +158,10 @@ private void calculate()
if (!predicate.test(t))
continue;

transactions.add(new TransactionPair<AccountTransaction>(account, t));
transactions.add(new TransactionPair<>(account, t));

long value = converter.at(t.getDate()).apply(t.getMonetaryAmount()).getAmount();
Money dividendValue = useGrossValue ? t.getGrossValue() : t.getMonetaryAmount();
long value = dividendValue.with(converter.at(t.getDate())).getAmount();
int index = (t.getDate().getYear() - startYear) * 12 + t.getDate().getMonthValue() - 1;

Line line = vehicle2line.computeIfAbsent(t.getSecurity(), s -> new Line(s, noOfmonths));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import name.abuchen.portfolio.model.AccountTransaction;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.Transaction.Unit;
import name.abuchen.portfolio.model.TransactionPair;
import name.abuchen.portfolio.money.Values;
import name.abuchen.portfolio.ui.Images;
Expand Down Expand Up @@ -68,8 +70,8 @@ public Control createControl(Composite parent)

tableViewer = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);

ShowHideColumnHelper support = new ShowHideColumnHelper(TransactionsTab.class.getSimpleName(), preferences,
tableViewer, layout);
ShowHideColumnHelper support = new ShowHideColumnHelper(TransactionsTab.class.getSimpleName() + "@v2", //$NON-NLS-1$
preferences, tableViewer, layout);

addColumns(support);
support.createColumns();
Expand Down Expand Up @@ -124,6 +126,34 @@ public Long getValue(Object element)
ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getShares()).attachTo(column);
support.addColumn(column);

column = new Column(Messages.ColumnGrossValue, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object element)
{
return Values.Money.format(
((AccountTransaction) ((TransactionPair<?>) element).getTransaction()).getGrossValue(),
client.getBaseCurrency());
}
});
ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getMonetaryAmount()).attachTo(column);
support.addColumn(column);

column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object element)
{
return Values.Money.format(((TransactionPair<?>) element).getTransaction().getUnitSum(Unit.Type.TAX),
client.getBaseCurrency());
}
});
ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getUnitSum(Unit.Type.TAX))
.attachTo(column);
support.addColumn(column);

column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider()
{
Expand Down

0 comments on commit 6a387ca

Please sign in to comment.