From 843a2cafbc0f454ccda4ef2fc864d7c96d7fa366 Mon Sep 17 00:00:00 2001 From: Colinas Maoling Date: Mon, 9 Jan 2017 21:40:38 +0100 Subject: [PATCH 1/3] Referring to #697: Extending SecurityEvent to handle Dividends. Data of such events stored including Currency --- .../transactions/AccountTransactionModel.java | 7 ++++++ .../portfolio/ui/views/SecuritiesChart.java | 6 ++--- .../portfolio/model/SecurityEvent.java | 22 +++++++++++++++++-- .../abuchen/portfolio/model/labels.properties | 1 + .../portfolio/model/labels_de.properties | 1 + 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/dialogs/transactions/AccountTransactionModel.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/dialogs/transactions/AccountTransactionModel.java index adf619ab36..c6c527160a 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/dialogs/transactions/AccountTransactionModel.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/dialogs/transactions/AccountTransactionModel.java @@ -13,6 +13,7 @@ import name.abuchen.portfolio.model.AccountTransaction; import name.abuchen.portfolio.model.Client; import name.abuchen.portfolio.model.Security; +import name.abuchen.portfolio.model.SecurityEvent; import name.abuchen.portfolio.model.Transaction; import name.abuchen.portfolio.money.CurrencyConverter; import name.abuchen.portfolio.money.CurrencyConverterImpl; @@ -151,6 +152,12 @@ public void applyChanges() Money.of(getSecurityCurrencyCode(), fxTaxes), // exchangeRate)); } + if (type == AccountTransaction.Type.DIVIDENDS) + { + SecurityEvent event = new SecurityEvent(date, SecurityEvent.Type.STOCK_DIVIDEND, Money.of(getFxCurrencyCode(), dividendAmount)); //$NON-NLS-1$ + security.addEvent(event); + } + } @Override diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java index c1c4f1abfb..9756f498d1 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java @@ -26,6 +26,7 @@ import name.abuchen.portfolio.model.Portfolio; import name.abuchen.portfolio.model.PortfolioTransaction; import name.abuchen.portfolio.model.Security; +import name.abuchen.portfolio.model.SecurityEvent; import name.abuchen.portfolio.model.SecurityPrice; import name.abuchen.portfolio.money.CurrencyConverter; import name.abuchen.portfolio.money.Values; @@ -221,8 +222,7 @@ private void addChartMarker() security.getEvents().stream() // .filter(e -> chartPeriod == null || chartPeriod.isBefore(e.getDate())) // - .forEach(e -> chart.addMarkerLine(e.getDate(), - Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY), e.getDetails())); - + .forEach(e -> chart.addMarkerLine(e.getDate(), + Display.getDefault().getSystemColor(e.getType() == SecurityEvent.Type.STOCK_SPLIT ? SWT.COLOR_DARK_GRAY : SWT.COLOR_MAGENTA), e.getDetails())); } } diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java index 982d842295..a8bc62e5a6 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java @@ -3,11 +3,13 @@ import java.time.LocalDate; import java.util.ResourceBundle; +import name.abuchen.portfolio.money.Money; + public class SecurityEvent { public enum Type { - STOCK_SPLIT; + STOCK_SPLIT, STOCK_DIVIDEND; private static final ResourceBundle RESOURCES = ResourceBundle.getBundle("name.abuchen.portfolio.model.labels"); //$NON-NLS-1$ @@ -20,6 +22,7 @@ public String toString() private LocalDate date; private Type type; private String details; + private Money dividend; public SecurityEvent() { @@ -31,8 +34,18 @@ public SecurityEvent(LocalDate date, Type type, String details) this.date = date; this.type = type; this.details = details; + this.dividend = null; } + public SecurityEvent(LocalDate date, Type type, Money money) + { + this.date = date; + this.type = type; + this.dividend = money; + this.details = null; + } + + public LocalDate getDate() { return date; @@ -45,6 +58,11 @@ public Type getType() public String getDetails() { - return details; + if (type == SecurityEvent.Type.STOCK_DIVIDEND) { + return dividend.toString(); + } else { + return details; + } } + } diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels.properties b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels.properties index 8cc0d1a12e..0e2699d74f 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels.properties +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels.properties @@ -13,6 +13,7 @@ account.TRANSFER_IN = Transfer (Inbound) account.TRANSFER_OUT = Transfer (Outbound) event.STOCK_SPLIT = Stock Split +event.STOCK_DIVIDEND = Dividend Payment portfolio.BUY = Buy portfolio.DELIVERY_INBOUND = Delivery (Inbound) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels_de.properties b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels_de.properties index f877e27f8b..70f8cdecb2 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels_de.properties +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/labels_de.properties @@ -13,6 +13,7 @@ account.TRANSFER_IN = Umbuchung (Eingang) account.TRANSFER_OUT = Umbuchung (Ausgang) event.STOCK_SPLIT = Aktiensplit +event.STOCK_DIVIDEND = Dividendenzahlung portfolio.BUY = Kauf portfolio.DELIVERY_INBOUND = Einlieferung From 074772e94f23d171410bde8eb942d42d268ca20b Mon Sep 17 00:00:00 2001 From: Colinas Maoling Date: Mon, 9 Jan 2017 21:56:51 +0100 Subject: [PATCH 2/3] Update SecurityEvent.java --- .../src/name/abuchen/portfolio/model/SecurityEvent.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java index a8bc62e5a6..5e4c6538cc 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/model/SecurityEvent.java @@ -58,10 +58,11 @@ public Type getType() public String getDetails() { - if (type == SecurityEvent.Type.STOCK_DIVIDEND) { - return dividend.toString(); - } else { + if (details != null) { return details; + } else { + // details == null + return dividend.toString(); } } From 384fc2c3b4bc8aefc8deb9f1ffcb32a438f0bb08 Mon Sep 17 00:00:00 2001 From: Colinas Maoling Date: Mon, 16 Jan 2017 21:40:01 +0100 Subject: [PATCH 3/3] Referring to #699. MarkerLines now generated based on AccountTransactions also --- .../portfolio/ui/views/SecuritiesChart.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java index 9756f498d1..323ee7e044 100644 --- a/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java +++ b/name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/SecuritiesChart.java @@ -22,6 +22,8 @@ import org.swtchart.ISeries; import org.swtchart.ISeries.SeriesType; +import name.abuchen.portfolio.model.Account; +import name.abuchen.portfolio.model.AccountTransaction; import name.abuchen.portfolio.model.Client; import name.abuchen.portfolio.model.Portfolio; import name.abuchen.portfolio.model.PortfolioTransaction; @@ -220,6 +222,18 @@ private void addChartMarker() } } + for (Account account : client.getAccounts()) + { + for (AccountTransaction t : account.getTransactions()) + { + if (t.getSecurity() == security && (chartPeriod == null || chartPeriod.isBefore(t.getDate())) && t.getType() == AccountTransaction.Type.DIVIDENDS) + { + Color color = Display.getDefault().getSystemColor(SWT.COLOR_DARK_CYAN); + chart.addMarkerLine(t.getDate(), color, t.getGrossValue().toString()); + } + } + } + security.getEvents().stream() // .filter(e -> chartPeriod == null || chartPeriod.isBefore(e.getDate())) // .forEach(e -> chart.addMarkerLine(e.getDate(),