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();
}
}
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();
}
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);
}
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();
}
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;
}
Aggregations