Search in sources :

Example 31 with Account

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

the class ClientFilterMenu method createCustomFilter.

private void createCustomFilter() {
    LabelProvider labelProvider = new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return element instanceof Account ? Images.ACCOUNT.image() : Images.PORTFOLIO.image();
        }
    };
    ListSelectionDialog dialog = new ListSelectionDialog(Display.getDefault().getActiveShell(), labelProvider);
    dialog.setTitle(Messages.LabelClientFilterDialogTitle);
    dialog.setMessage(Messages.LabelClientFilterDialogMessage);
    List<Object> elements = new ArrayList<>();
    elements.addAll(client.getPortfolios());
    elements.addAll(client.getAccounts());
    dialog.setElements(elements);
    if (dialog.open() == ListSelectionDialog.OK) {
        Object[] selected = dialog.getResult();
        if (selected.length > 0) {
            Item newItem = buildItem(selected);
            selectedItem = newItem;
            customItems.addFirst(newItem);
            if (customItems.size() > MAXIMUM_NO_CUSTOM_ITEMS)
                customItems.removeLast();
            preferences.putValue(ClientFilterDropDown.class.getSimpleName(), // $NON-NLS-1$
            String.join(// $NON-NLS-1$
            ";", customItems.stream().map(i -> i.uuids).collect(Collectors.toList())));
            listeners.forEach(l -> l.accept(newItem.filter));
        }
    }
}
Also used : Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LinkedList(java.util.LinkedList) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) IMenuManager(org.eclipse.jface.action.IMenuManager) Collections(java.util.Collections) IMenuListener(org.eclipse.jface.action.IMenuListener) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog)

Example 32 with Account

use of name.abuchen.portfolio.model.Account 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 33 with Account

use of name.abuchen.portfolio.model.Account 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 34 with Account

use of name.abuchen.portfolio.model.Account 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 35 with Account

use of name.abuchen.portfolio.model.Account 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)

Aggregations

Account (name.abuchen.portfolio.model.Account)75 Security (name.abuchen.portfolio.model.Security)39 Client (name.abuchen.portfolio.model.Client)38 Portfolio (name.abuchen.portfolio.model.Portfolio)37 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)35 Test (org.junit.Test)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)25 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)21 ArrayList (java.util.ArrayList)17 LocalDate (java.time.LocalDate)16 AccountBuilder (name.abuchen.portfolio.AccountBuilder)14 Unit (name.abuchen.portfolio.model.Transaction.Unit)14 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)13 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)12 Money (name.abuchen.portfolio.money.Money)12 Collections (java.util.Collections)11 List (java.util.List)11 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)11 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11