Search in sources :

Example 6 with PortfolioTransferEntry

use of name.abuchen.portfolio.model.PortfolioTransferEntry 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);
}
Also used : Transaction(name.abuchen.portfolio.model.Transaction) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry)

Example 7 with PortfolioTransferEntry

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

the class Issue371PurchaseValueWithTransfers method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
    "Issue371PurchaseValueWithTransfers.xml"));
    Security adidas = client.getSecurities().get(0);
    // $NON-NLS-1$
    assertThat(adidas.getName(), is("Adidas AG"));
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2010-11-20"), // $NON-NLS-1$
    LocalDate.parse("2015-11-20"));
    // make sure that the transfer entry exists
    assertThat(client.getPortfolios().size(), is(2));
    assertThat(client.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).filter(t -> t.getSecurity() == adidas).filter(t -> t.getCrossEntry() instanceof PortfolioTransferEntry).filter(t -> t.getType() == PortfolioTransaction.Type.TRANSFER_IN).findAny().isPresent(), is(true));
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, period.getEndDate());
    SecurityPosition securityPosition = snapshot.getPositionsByVehicle().get(adidas).getPosition();
    SecurityPerformanceSnapshot securitySnapshot = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord securityRecord = securitySnapshot.getRecords().get(0);
    assertThat(securityRecord.getSecurity(), is(adidas));
    assertThat(securityPosition.getFIFOPurchaseValue(), is(securityRecord.getFifoCost()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Assert.assertThat(org.junit.Assert.assertThat) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Test(org.junit.Test)

Example 8 with PortfolioTransferEntry

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

the class ReviewExtractedItemsPage method addColumns.

private void addColumns(TableViewer viewer, TableColumnLayout layout) {
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnStatus);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public Image getImage(ExtractedEntry element) {
            Images image = null;
            switch(element.getMaxCode()) {
                case WARNING:
                    image = Images.WARNING;
                    break;
                case ERROR:
                    image = Images.ERROR;
                    break;
                case OK:
                default:
            }
            return image != null ? image.image() : null;
        }

        @Override
        public String getText(ExtractedEntry entry) {
            // $NON-NLS-1$
            return "";
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(22, true));
    column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnDate);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            LocalDateTime date = entry.getItem().getDate();
            return date != null ? Values.DateTime.format(date) : null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
    column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnTransactionType);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            return entry.getItem().getTypeInformation();
        }

        @Override
        public Image getImage(ExtractedEntry entry) {
            Annotated subject = entry.getItem().getSubject();
            if (subject instanceof AccountTransaction)
                return Images.ACCOUNT.image();
            else if (subject instanceof PortfolioTransaction)
                return Images.PORTFOLIO.image();
            else if (subject instanceof Security)
                return Images.SECURITY.image();
            else if (subject instanceof BuySellEntry)
                return Images.PORTFOLIO.image();
            else if (subject instanceof AccountTransferEntry)
                return Images.ACCOUNT.image();
            else if (subject instanceof PortfolioTransferEntry)
                return Images.PORTFOLIO.image();
            else
                return null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(100, true));
    column = new TableViewerColumn(viewer, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnAmount);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            Money amount = entry.getItem().getAmount();
            return amount != null ? Values.Money.format(amount) : null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
    column = new TableViewerColumn(viewer, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnShares);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            return Values.Share.formatNonZero(entry.getItem().getShares());
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80, true));
    column = new TableViewerColumn(viewer, SWT.NONE);
    column.getColumn().setText(Messages.ColumnSecurity);
    column.setLabelProvider(new // NOSONAR
    FormattedLabelProvider() {

        @Override
        public String getText(ExtractedEntry entry) {
            Security security = entry.getItem().getSecurity();
            return security != null ? security.getName() : null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(250, true));
}
Also used : LocalDateTime(java.time.LocalDateTime) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Images(name.abuchen.portfolio.ui.Images) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) StyledString(org.eclipse.jface.viewers.StyledString) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) Annotated(name.abuchen.portfolio.model.Annotated) Money(name.abuchen.portfolio.money.Money) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry)

Aggregations

PortfolioTransferEntry (name.abuchen.portfolio.model.PortfolioTransferEntry)8 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)6 Client (name.abuchen.portfolio.model.Client)5 Security (name.abuchen.portfolio.model.Security)5 LocalDate (java.time.LocalDate)4 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)4 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)4 Test (org.junit.Test)4 LocalDateTime (java.time.LocalDateTime)3 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)3 Account (name.abuchen.portfolio.model.Account)3 Portfolio (name.abuchen.portfolio.model.Portfolio)3 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)3 Money (name.abuchen.portfolio.money.Money)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 Assert.assertThat (org.junit.Assert.assertThat)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 AccountBuilder (name.abuchen.portfolio.AccountBuilder)2