Search in sources :

Example 71 with Account

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

the class ClientSecurityFilter method addAccountTransaction.

private void addAccountTransaction(Function<Account, ReadOnlyAccount> getAccount, TransactionPair<AccountTransaction> pair) {
    AccountTransaction t = pair.getTransaction();
    switch(pair.getTransaction().getType()) {
        case DIVIDENDS:
            long taxes = t.getUnitSum(Unit.Type.TAX).getAmount();
            long amount = t.getAmount();
            getAccount.apply((Account) pair.getOwner()).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount + taxes, t.getSecurity(), t.getType()));
            getAccount.apply((Account) pair.getOwner()).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount + taxes, t.getSecurity(), AccountTransaction.Type.REMOVAL));
            break;
        case FEES:
            getAccount.apply((Account) pair.getOwner()).internalAddTransaction(t);
            getAccount.apply((Account) pair.getOwner()).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), t.getAmount(), t.getSecurity(), AccountTransaction.Type.DEPOSIT));
            break;
        case FEES_REFUND:
            getAccount.apply((Account) pair.getOwner()).internalAddTransaction(t);
            getAccount.apply((Account) pair.getOwner()).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), t.getAmount(), t.getSecurity(), AccountTransaction.Type.REMOVAL));
            break;
        case TAXES:
        case TAX_REFUND:
            // ignore taxes
            break;
        case BUY:
        case SELL:
        case DEPOSIT:
        case REMOVAL:
        case TRANSFER_IN:
        case TRANSFER_OUT:
        case INTEREST:
        case INTEREST_CHARGE:
        default:
            throw new IllegalArgumentException();
    }
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 72 with Account

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

the class ConvertDeliveryToBuySellAction method run.

@Override
public void run() {
    // delete existing transaction
    PortfolioTransaction deliveryTransaction = transaction.getTransaction();
    transaction.getOwner().deleteTransaction(deliveryTransaction, client);
    // create new buy / sell
    Portfolio portfolio = (Portfolio) transaction.getOwner();
    Account account = portfolio.getReferenceAccount();
    BuySellEntry entry = new BuySellEntry(portfolio, account);
    entry.setType(deliveryTransaction.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND ? PortfolioTransaction.Type.BUY : PortfolioTransaction.Type.SELL);
    entry.setDate(deliveryTransaction.getDateTime());
    entry.setMonetaryAmount(deliveryTransaction.getMonetaryAmount());
    entry.setSecurity(deliveryTransaction.getSecurity());
    entry.setNote(deliveryTransaction.getNote());
    entry.setShares(deliveryTransaction.getShares());
    deliveryTransaction.getUnits().forEach(entry.getPortfolioTransaction()::addUnit);
    entry.insert();
    client.markDirty();
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio)

Example 73 with Account

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

the class NewAccountPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(container);
    Label lblAcc = new Label(container, SWT.NULL);
    lblAcc.setText(Messages.ColumnAccount);
    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);
    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(3, 1).grab(true, true).applyTo(tableContainer);
    TableColumnLayout layout = new TableColumnLayout();
    tableContainer.setLayout(layout);
    tViewer = new TableViewer(tableContainer);
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String acnName = accountName.getText();
            if (acnName.length() > 0) {
                Account currentAccount = new Account();
                currentAccount.setName(acnName);
                currentAccount.setCurrencyCode(client.getBaseCurrency());
                client.addAccount(currentAccount);
                tViewer.refresh();
                // $NON-NLS-1$
                accountName.setText("");
                accountName.setFocus();
            }
        }
    });
    Table table = tViewer.getTable();
    table.setHeaderVisible(true);
    table.setEnabled(false);
    tViewer.setContentProvider(ArrayContentProvider.getInstance());
    tViewer.setInput(client.getAccounts());
    TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE);
    layout.setColumnData(aCol.getColumn(), new ColumnWeightData(50));
    aCol.getColumn().setText(Messages.ColumnAccount);
    aCol.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Account) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            return Images.ACCOUNT.image();
        }
    });
    container.pack();
    setPageComplete(true);
}
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) Label(org.eclipse.swt.widgets.Label) 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 74 with Account

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

the class DanglingAccountsCheck method execute.

@Override
public List<Issue> execute(Client client) {
    Set<Account> accounts = new HashSet<Account>(client.getAccounts());
    for (Portfolio portfolio : client.getPortfolios()) {
        Account referenceAccount = portfolio.getReferenceAccount();
        check(client, accounts, referenceAccount);
        for (PortfolioTransaction transaction : portfolio.getTransactions()) {
            CrossEntry entry = transaction.getCrossEntry();
            if (!(entry instanceof BuySellEntry))
                continue;
            Account account = (Account) entry.getCrossOwner(transaction);
            check(client, accounts, account);
        }
    }
    return Collections.emptyList();
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) CrossEntry(name.abuchen.portfolio.model.CrossEntry) HashSet(java.util.HashSet)

Example 75 with Account

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

the class MissingBuySellAccountIssue method getAvailableFixes.

@Override
public List<QuickFix> getAvailableFixes() {
    List<QuickFix> answer = new ArrayList<>();
    answer.add(new ConvertToDeliveryFix());
    if (portfolio.getReferenceAccount() != null)
        answer.add(new CreateBuySellEntryFix(portfolio.getReferenceAccount()));
    for (final Account account : client.getAccounts()) {
        if (account.equals(portfolio.getReferenceAccount()))
            continue;
        answer.add(new CreateBuySellEntryFix(account));
    }
    answer.add(new DeleteTransactionFix<PortfolioTransaction>(client, portfolio, transaction));
    return answer;
}
Also used : QuickFix(name.abuchen.portfolio.checks.QuickFix) Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ArrayList(java.util.ArrayList)

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