Search in sources :

Example 31 with Portfolio

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

the class TransactionCurrencyCheck method execute.

@Override
public List<Issue> execute(Client client) {
    Set<Object> transactions = new HashSet<Object>();
    for (Account account : client.getAccounts()) {
        account.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<AccountTransaction>(account, t)));
    }
    for (Portfolio portfolio : client.getPortfolios()) {
        portfolio.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<PortfolioTransaction>(portfolio, t)));
    }
    List<Issue> issues = new ArrayList<Issue>();
    for (Object t : transactions) {
        if (t instanceof TransactionPair<?>) {
            @SuppressWarnings("unchecked") TransactionPair<Transaction> pair = (TransactionPair<Transaction>) t;
            issues.add(new TransactionMissingCurrencyIssue(client, pair));
        } else if (t instanceof BuySellEntry) {
            // attempt to fix it if both currencies are identical. If a fix
            // involves currency conversion plus exchange rates, just offer
            // to delete the transaction.
            BuySellEntry entry = (BuySellEntry) t;
            String accountCurrency = entry.getAccount().getCurrencyCode();
            String securityCurrency = entry.getPortfolioTransaction().getSecurity().getCurrencyCode();
            @SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getAccountTransaction()), entry.getAccountTransaction());
            issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(accountCurrency, securityCurrency)));
        } else if (t instanceof AccountTransferEntry) {
            // same story as with purchases: only offer to fix if currencies
            // match
            AccountTransferEntry entry = (AccountTransferEntry) t;
            String sourceCurrency = entry.getSourceAccount().getCurrencyCode();
            String targetCurrency = entry.getTargetAccount().getCurrencyCode();
            @SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
            issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(sourceCurrency, targetCurrency)));
        } else if (t instanceof PortfolioTransferEntry) {
            // transferring a security involves no currency change because
            // the currency is defined the security itself
            PortfolioTransferEntry entry = (PortfolioTransferEntry) t;
            @SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
            issues.add(new TransactionMissingCurrencyIssue(client, pair));
        } else {
            throw new IllegalArgumentException();
        }
    }
    return issues;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Set(java.util.Set) QuickFix(name.abuchen.portfolio.checks.QuickFix) Messages(name.abuchen.portfolio.Messages) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Issue(name.abuchen.portfolio.checks.Issue) HashSet(java.util.HashSet) Objects(java.util.Objects) Check(name.abuchen.portfolio.checks.Check) List(java.util.List) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) LocalDate(java.time.LocalDate) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) TransactionPair(name.abuchen.portfolio.model.TransactionPair) Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Issue(name.abuchen.portfolio.checks.Issue) Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) HashSet(java.util.HashSet) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry)

Example 32 with Portfolio

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

the class NewPortfolioAccountPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    GridLayoutFactory.fillDefaults().numColumns(5).applyTo(container);
    Label lblPort = new Label(container, SWT.NULL);
    lblPort.setText(Messages.ColumnPortfolio);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblPort);
    final Text portfolioName = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(portfolioName);
    Label lblAcc = new Label(container, SWT.NULL);
    lblAcc.setText(Messages.ColumnReferenceAccount);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblAcc);
    final Text accountName = new Text(container, SWT.BORDER | SWT.SINGLE);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(accountName);
    final List<Pair> data = new ArrayList<Pair>();
    Button button = new Button(container, SWT.PUSH);
    button.setText(Messages.NewFileWizardButtonAdd);
    GridDataFactory.fillDefaults().applyTo(button);
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().span(5, 1).grab(true, true).applyTo(tableContainer);
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    final TableViewer tViewer = new TableViewer(tableContainer);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String portName = portfolioName.getText();
            String acnName = accountName.getText();
            if (portName.length() > 0 && acnName.length() > 0) {
                Account account = new Account();
                account.setName(acnName);
                account.setCurrencyCode(client.getBaseCurrency());
                Portfolio portfolio = new Portfolio();
                portfolio.setName(portName);
                portfolio.setReferenceAccount(account);
                client.addAccount(account);
                client.addPortfolio(portfolio);
                data.add(new Pair(portName, acnName));
                tViewer.refresh();
                // delete previous input
                // $NON-NLS-1$
                accountName.setText("");
                // $NON-NLS-1$
                portfolioName.setText("");
                // focus first input field
                portfolioName.setFocus();
                setPageComplete(true);
            }
        }
    });
    Table table = tViewer.getTable();
    table.setEnabled(false);
    table.setHeaderVisible(true);
    table.setLinesVisible(false);
    tViewer.setContentProvider(ArrayContentProvider.getInstance());
    tViewer.setInput(data);
    TableViewerColumn pCol = new TableViewerColumn(tViewer, SWT.NONE);
    layout.setColumnData(pCol.getColumn(), new ColumnWeightData(50));
    pCol.getColumn().setText(Messages.ColumnPortfolio);
    pCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Pair) element).portfolio;
        }

        @Override
        public Image getImage(Object element) {
            return Images.PORTFOLIO.image();
        }
    });
    TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE);
    layout.setColumnData(aCol.getColumn(), new ColumnWeightData(50));
    aCol.getColumn().setText(Messages.ColumnReferenceAccount);
    aCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Pair) element).account;
        }

        @Override
        public Image getImage(Object element) {
            return Images.ACCOUNT.image();
        }
    });
    container.pack();
    setPageComplete(false);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Account(name.abuchen.portfolio.model.Account) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Portfolio(name.abuchen.portfolio.model.Portfolio) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 33 with Portfolio

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

the class ExportWizard method performFinish.

@Override
public boolean performFinish() {
    Object exportItem = exportPage.getExportItem();
    Class<?> exportClass = exportPage.getExportClass();
    File file = getFile(exportItem);
    if (file == null)
        return false;
    try {
        // account transactions
        if (exportItem == AccountTransaction.class) {
            new CSVExporter().exportAccountTransactions(file, client.getAccounts());
        } else if (exportClass == AccountTransaction.class) {
            new CSVExporter().exportAccountTransactions(file, (Account) exportItem);
        } else // portfolio transactions
        if (exportItem == PortfolioTransaction.class) {
            new CSVExporter().exportPortfolioTransactions(file, client.getPortfolios());
        } else if (exportClass == PortfolioTransaction.class) {
            new CSVExporter().exportPortfolioTransactions(file, (Portfolio) exportItem);
        } else // master data
        if (exportItem == Security.class) {
            new CSVExporter().exportSecurityMasterData(new File(file, Messages.ExportWizardSecurityMasterData + ".csv"), // $NON-NLS-1$
            client.getSecurities());
        } else if (exportClass == Security.class) {
            if (Messages.ExportWizardSecurityMasterData.equals(exportItem))
                new CSVExporter().exportSecurityMasterData(file, client.getSecurities());
            else if (Messages.ExportWizardMergedSecurityPrices.equals(exportItem))
                new CSVExporter().exportMergedSecurityPrices(file, client.getSecurities());
            else if (Messages.ExportWizardAllTransactionsAktienfreundeNet.equals(exportItem))
                new AktienfreundeNetExporter().exportAllTransactions(file, client);
        } else // historical quotes
        if (exportItem == SecurityPrice.class) {
            new CSVExporter().exportSecurityPrices(file, client.getSecurities());
        } else if (exportClass == SecurityPrice.class) {
            new CSVExporter().exportSecurityPrices(file, (Security) exportItem);
        } else {
            throw new UnsupportedOperationException(MessageFormat.format(Messages.ExportWizardUnsupportedExport, exportClass, exportItem));
        }
    } catch (IOException e) {
        PortfolioPlugin.log(e);
        MessageDialog.openError(getShell(), Messages.ExportWizardErrorExporting, e.getMessage());
    }
    return true;
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Security(name.abuchen.portfolio.model.Security) CSVExporter(name.abuchen.portfolio.datatransfer.csv.CSVExporter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AktienfreundeNetExporter(name.abuchen.portfolio.datatransfer.csv.AktienfreundeNetExporter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) File(java.io.File)

Example 34 with Portfolio

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

the class ExportWizard method getFile.

private File getFile(Object exportItem) {
    File file = null;
    if (exportItem instanceof Class) {
        DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
        directoryDialog.setMessage(Messages.ExportWizardSelectDirectory);
        String dir = directoryDialog.open();
        if (dir != null)
            file = new File(dir);
    } else {
        String name = null;
        if (exportItem instanceof Account)
            name = ((Account) exportItem).getName();
        else if (exportItem instanceof Portfolio)
            name = ((Portfolio) exportItem).getName();
        else if (exportItem instanceof Security)
            name = ((Security) exportItem).getIsin();
        else if (exportItem instanceof String)
            name = (String) exportItem;
        FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
        dialog.setOverwrite(true);
        if (name != null)
            // $NON-NLS-1$
            dialog.setFileName(TextUtil.sanitizeFilename(name + ".csv"));
        String fileName = dialog.open();
        if (fileName != null)
            file = new File(fileName);
    }
    return file;
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 35 with Portfolio

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

the class DataSeriesSet method buildCommonDataSeries.

private void buildCommonDataSeries(Client client, IPreferenceStore preferences, ColorWheel wheel) {
    int index = client.getSecurities().size();
    for (Security security : client.getSecurities()) {
        // as equity data series (only as benchmark)
        if (security.getCurrencyCode() == null)
            continue;
        availableSeries.add(new // 
        DataSeries(// 
        DataSeries.Type.SECURITY, // 
        security, // 
        security.getName(), wheel.getRGB(index++)));
    }
    for (Portfolio portfolio : client.getPortfolios()) availableSeries.add(new // 
    DataSeries(// 
    DataSeries.Type.PORTFOLIO, // 
    portfolio, // 
    portfolio.getName(), wheel.getRGB(index++)));
    // portfolio + reference account
    for (Portfolio portfolio : client.getPortfolios()) {
        DataSeries series = new DataSeries(DataSeries.Type.PORTFOLIO_PLUS_ACCOUNT, portfolio, // $NON-NLS-1$
        portfolio.getName() + " + " + portfolio.getReferenceAccount().getName(), wheel.getRGB(index++));
        availableSeries.add(series);
    }
    // custom client filters
    ClientFilterMenu menu = new ClientFilterMenu(client, preferences);
    // quick fix: users can create duplicate client filters that end up to
    // have the same UUID. Avoid adding both violates the precondition that
    // every data series must have a unique id
    Set<String> addedSeries = new HashSet<>();
    for (ClientFilterMenu.Item item : menu.getCustomItems()) {
        DataSeries series = new DataSeries(DataSeries.Type.CLIENT_FILTER, item, item.getLabel(), wheel.getRGB(index++));
        if (addedSeries.add(series.getUUID()))
            availableSeries.add(series);
    }
    for (Account account : client.getAccounts()) availableSeries.add(new DataSeries(DataSeries.Type.ACCOUNT, account, account.getName(), wheel.getRGB(index++)));
    for (Taxonomy taxonomy : client.getTaxonomies()) {
        taxonomy.foreach(new Taxonomy.Visitor() {

            @Override
            public void visit(Classification classification) {
                if (classification.getParent() == null)
                    return;
                availableSeries.add(new DataSeries(DataSeries.Type.CLASSIFICATION, classification, classification.getName(), Colors.toRGB(classification.getColor())));
            }
        });
    }
}
Also used : Account(name.abuchen.portfolio.model.Account) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Classification(name.abuchen.portfolio.model.Classification) ClientDataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries.ClientDataSeries) ClientFilterMenu(name.abuchen.portfolio.ui.util.ClientFilterMenu) HashSet(java.util.HashSet)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8