Search in sources :

Example 96 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class ClassificationTestCase method testCase10_Security30Account100_SecuritySold.

@Test
public void testCase10_Security30Account100_SecuritySold() {
    Taxonomy case10 = client.getTaxonomies().stream().filter(t -> "case_10".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification ccategory = case10.getAllClassifications().stream().filter(c -> "category".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client categoryClient = new ClientClassificationFilter(ccategory).filter(client);
    List<PortfolioTransaction> txp = categoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.SELL)), // 
    hasProperty("shares", is(Values.Share.factorize(74.8 * 0.3d))), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(698.36 * 0.3d)))))));
    List<AccountTransaction> txa = categoryClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.SELL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(698.36 * 0.3)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(688.36 - (698.36 * 0.3))))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(Values.Amount.factorize(534.86)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 97 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class ClassificationTestCase method testCase3_Security30Account50.

@Test
public void testCase3_Security30Account50() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_3".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification subcategory = case1.getAllClassifications().stream().filter(c -> "subcategory".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client subcategoryClient = new ClientClassificationFilter(subcategory).filter(client);
    List<PortfolioTransaction> txp = subcategoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txp, hasSize(1));
    assertThat(txp, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(PortfolioTransaction.Type.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 * 0.3d)))))));
    List<AccountTransaction> txa = subcategoryClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.BUY)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 * 0.3d)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 * 0.2d)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-01T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1019.80 / 2d)))))));
    // check that dividend is included without taxes
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DIVIDENDS)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(24.44 * 0.3d)))))));
    // check correction for dividend payment (w/o taxes and only 50%)
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(19.44 / 2 - 24.44 * 0.3d)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, subcategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(Values.Amount.factorize(1391.40)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 98 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class ClassificationTestCase method testCase12_ForexAccountOut100_AccountIn50.

@Test
public void testCase12_ForexAccountOut100_AccountIn50() {
    Taxonomy case12 = client.getTaxonomies().stream().filter(t -> "case_12".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification ccategory = case12.getAllClassifications().stream().filter(c -> "category".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client categoryClient = new ClientClassificationFilter(ccategory).filter(client);
    List<PortfolioTransaction> txp = categoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txp, hasSize(0));
    List<AccountTransaction> txa = categoryClient.getAccounts().stream().filter(a -> "Account Forex".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // check cash transfers
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
    txa = categoryClient.getAccounts().stream().filter(a -> "Konto 3".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(78.19 * 0.5d)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    // 343.42 EUR (Konto 3 EUR)
    // 423.52 USD / 1.2141 (exchange rate in TestCurrencyConverter)
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(// 
    Values.Amount.factorize(343.42) + Values.Amount.factorize(423.52 / 1.2141)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 99 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class ClientPerformanceSnapshotTest method testCapitalGainsWithBuyDuringReportPeriod.

@Test
public void testCapitalGainsWithBuyDuringReportPeriod() {
    Client client = new Client();
    Security security = new Security();
    security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
    security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
    client.addSecurity(security);
    Portfolio portfolio = new Portfolio();
    portfolio.setReferenceAccount(new Account());
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1_00, security, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2011, Month.JANUARY, 15, 0, 0), CurrencyUnit.EUR, 99_00, security, Values.Share.factorize(1), PortfolioTransaction.Type.DELIVERY_INBOUND, 0, 0));
    client.addPortfolio(portfolio);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 100_00 + (110_00 - 99_00))));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1210_00)));
    assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 100 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.

the class AccountListView method createTransactionTable.

protected Control createTransactionTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    transactions = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
    ColumnViewerToolTipSupport.enableFor(transactions, ToolTip.NO_RECREATE);
    ColumnEditingSupport.prepare(transactions);
    transactionsColumns = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    AccountListView.class.getSimpleName() + "@bottom5", getPreferenceStore(), transactions, layout);
    Column column = new Column(Messages.ColumnDate, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return Values.DateTime.format(((AccountTransaction) e).getDateTime());
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    ColumnViewerSorter.create(new AccountTransaction.ByDateAmountTypeAndHashCode()).attachTo(column, SWT.DOWN);
    // $NON-NLS-1$
    new DateTimeEditingSupport(AccountTransaction.class, "dateTime").addListener(this).attachTo(column);
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnTransactionType, SWT.None, 100);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            return t.getType().toString();
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "type"));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            long v = t.getAmount();
            if (t.getType().isDebit())
                v = -v;
            return Values.Money.format(Money.of(t.getCurrencyCode(), v), getClient().getBaseCurrency());
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "amount"));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.Balance, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Money balance = transaction2balance.get(e);
            return balance != null ? Values.Money.format(balance, getClient().getBaseCurrency()) : null;
        }
    });
    column.setSorter(ColumnViewerSorter.create(new AccountTransaction.ByDateAmountTypeAndHashCode()));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnSecurity, SWT.None, 250);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            return t.getSecurity() != null ? String.valueOf(t.getSecurity()) : null;
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "security"));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
    column.setLabelProvider(new SharesLabelProvider() {

        @Override
        public Long getValue(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            if (t.getCrossEntry() instanceof BuySellEntry) {
                return ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction().getShares();
            } else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0) {
                return t.getShares();
            } else {
                return null;
            }
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    new // $NON-NLS-1$
    ValueEditingSupport(// $NON-NLS-1$
    AccountTransaction.class, // $NON-NLS-1$
    "shares", // $NON-NLS-1$
    Values.Share) {

        @Override
        public boolean canEdit(Object element) {
            AccountTransaction t = (AccountTransaction) element;
            return t.getType() == AccountTransaction.Type.DIVIDENDS;
        }
    }.addListener(this).attachTo(column);
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnPerShare, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPerShare_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            if (t.getCrossEntry() instanceof BuySellEntry) {
                PortfolioTransaction pt = ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction();
                return Values.Quote.format(pt.getGrossPricePerShare(), getClient().getBaseCurrency());
            } else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0) {
                long dividendPerShare = Math.round(t.getAmount() * Values.Share.divider() * Values.Quote.factorToMoney() / t.getShares());
                return Values.Quote.format(Quote.of(t.getCurrencyCode(), dividendPerShare), getClient().getBaseCurrency());
            } else {
                return null;
            }
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnNote, SWT.None, 200);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return ((AccountTransaction) e).getNote();
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }

        @Override
        public Image getImage(Object e) {
            String note = ((AccountTransaction) e).getNote();
            return note != null && note.length() > 0 ? Images.NOTE.image() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(AccountTransaction.class, "note").attachTo(column);
    // $NON-NLS-1$
    new StringEditingSupport(AccountTransaction.class, "note").addListener(this).attachTo(column);
    transactionsColumns.addColumn(column);
    transactionsColumns.createColumns();
    transactions.getTable().setHeaderVisible(true);
    transactions.getTable().setLinesVisible(true);
    transactions.setContentProvider(ArrayContentProvider.getInstance());
    hookContextMenu(transactions.getTable(), this::fillTransactionsContextMenu);
    hookKeyListener();
    return container;
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Image(org.eclipse.swt.graphics.Image) DateTimeEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateTimeEditingSupport) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28