Search in sources :

Example 1 with InvestmentVehicle

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

the class DividendsViewModel method calculate.

private void calculate() {
    // determine the number of full months within period
    LocalDate now = LocalDate.now();
    if (startYear > now.getYear())
        throw new IllegalArgumentException();
    this.noOfmonths = (now.getYear() - startYear) * 12 + now.getMonthValue();
    Predicate<Transaction> predicate = new ReportingPeriod.FromXtoY(LocalDate.of(startYear - 1, Month.DECEMBER, 31), now).containsTransaction();
    Map<InvestmentVehicle, Line> vehicle2line = new HashMap<>();
    this.sum = new Line(null, this.noOfmonths);
    this.transactions = new ArrayList<>();
    Client filteredClient = clientFilter.getSelectedFilter().filter(client);
    for (Account account : filteredClient.getAccounts()) {
        for (AccountTransaction t : account.getTransactions()) {
            if (t.getType() != AccountTransaction.Type.DIVIDENDS)
                continue;
            if (!predicate.test(t))
                continue;
            transactions.add(new TransactionPair<>(account, t));
            Money dividendValue = useGrossValue ? t.getGrossValue() : t.getMonetaryAmount();
            long value = dividendValue.with(converter.at(t.getDateTime())).getAmount();
            int index = (t.getDateTime().getYear() - startYear) * 12 + t.getDateTime().getMonthValue() - 1;
            Line line = vehicle2line.computeIfAbsent(t.getSecurity(), s -> new Line(s, noOfmonths));
            line.values[index] += value;
            line.sum += value;
            sum.values[index] += value;
            sum.sum += value;
        }
    }
    this.lines = new ArrayList<>(vehicle2line.values());
}
Also used : Account(name.abuchen.portfolio.model.Account) HashMap(java.util.HashMap) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) LocalDate(java.time.LocalDate) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Money(name.abuchen.portfolio.money.Money) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) Client(name.abuchen.portfolio.model.Client)

Example 2 with InvestmentVehicle

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

the class AbstractNodeTreeViewer method doChangeAssignmentWeight.

private void doChangeAssignmentWeight(TaxonomyNode node, int oldWeight) {
    int change = oldWeight - node.getWeight();
    if (// was 'fixed' after editing, e.g. was >= 100%
    change == 0)
        return;
    if (node.getWeight() == 0)
        node.getParent().removeChild(node);
    // change total weight as recorded in the model
    InvestmentVehicle investmentVehicle = node.getAssignment().getInvestmentVehicle();
    final int totalWeight = getModel().getWeightByInvestmentVehicle(investmentVehicle) - change;
    getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight);
    // check if change is fixing weight errors -> no new unassigned vehicles
    change = Math.min(change, Classification.ONE_HUNDRED_PERCENT - totalWeight);
    if (change == 0)
        return;
    // change existing unassigned node *or* create new unassigned node
    TaxonomyNode unassigned = getModel().getUnassignedNode().getChildByInvestmentVehicle(investmentVehicle);
    if (unassigned != null) {
        // change existing node in unassigned category
        int newWeight = unassigned.getWeight() + change;
        if (newWeight <= 0) {
            getModel().getUnassignedNode().removeChild(unassigned);
            getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight - unassigned.getWeight());
        } else {
            unassigned.setWeight(newWeight);
            getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight + change);
        }
    } else if (change > 0) {
        // create a new node, but only if change is positive
        Assignment assignment = new Assignment(investmentVehicle);
        assignment.setWeight(change);
        getModel().getUnassignedNode().addChild(assignment);
        getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight + change);
    }
// do not fire model change -> called within modification listener
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 3 with InvestmentVehicle

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

the class TaxonomyNode method moveTo.

private void moveTo(int index, TaxonomyNode target) {
    Classification classification = target.getClassification();
    if (classification == null)
        throw new UnsupportedOperationException();
    if (isAssignment()) {
        InvestmentVehicle investmentVehicle = getAssignment().getInvestmentVehicle();
        TaxonomyNode sibling = target.getChildByInvestmentVehicle(investmentVehicle);
        if (sibling != null) {
            sibling.absorb(this);
            return;
        }
    }
    // change parent, update children collections and rank
    this.getParent().removeChild(this);
    this.parent = target;
    if (isClassification()) {
        getClassification().setParent(classification);
        classification.getChildren().add(getClassification());
    } else {
        classification.getAssignments().add(getAssignment());
    }
    List<TaxonomyNode> siblings = target.getChildren();
    if (index == -1)
        index = siblings.size();
    int insertAt = target.isRoot() ? Math.min(index, siblings.size() - 1) : index;
    siblings.add(insertAt, this);
    for (int ii = 0; ii < siblings.size(); ii++) siblings.get(ii).setRank(ii);
}
Also used : Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 4 with InvestmentVehicle

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

the class DividendsMatrixTab method createMonthColumn.

private void createMonthColumn(TableViewer records, TableColumnLayout layout, LocalDate start, int index) {
    TableViewerColumn column = new TableViewerColumn(records, SWT.RIGHT);
    column.getColumn().setText(formatter.format(start));
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Line line = (DividendsViewModel.Line) element;
            return line.getVehicle() != null ? Values.Amount.formatNonZero(line.getValue(index)) : Values.Amount.format(line.getValue(index));
        }

        @Override
        public String getToolTipText(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return TextUtil.tooltip(vehicle != null ? vehicle.getName() : null);
        }

        @Override
        public Font getFont(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? null : boldFont;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(50));
}
Also used : Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Font(org.eclipse.swt.graphics.Font)

Example 5 with InvestmentVehicle

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

the class DividendsMatrixTab method createSecurityColumn.

protected void createSecurityColumn(TableViewer records, TableColumnLayout layout, boolean isSorted) {
    TableViewerColumn column = new TableViewerColumn(records, SWT.NONE);
    column.getColumn().setText(Messages.ColumnSecurity);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? Images.SECURITY.image() : null;
        }

        @Override
        public String getText(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? vehicle.getName() : Messages.ColumnSum;
        }

        @Override
        public Font getFont(Object element) {
            InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
            return vehicle != null ? null : boldFont;
        }
    });
    ColumnViewerSorter.create((o1, o2) -> {
        int direction = ColumnViewerSorter.SortingContext.getSortDirection();
        DividendsViewModel.Line line1 = (DividendsViewModel.Line) o1;
        DividendsViewModel.Line line2 = (DividendsViewModel.Line) o2;
        if (line1.getVehicle() == null)
            return direction == SWT.DOWN ? 1 : -1;
        if (line2.getVehicle() == null)
            return direction == SWT.DOWN ? -1 : 1;
        String n1 = line1.getVehicle().getName();
        String n2 = line2.getVehicle().getName();
        return n1.compareToIgnoreCase(n2);
    }).attachTo(records, column, isSorted);
    layout.setColumnData(column.getColumn(), new ColumnPixelData(200));
}
Also used : Values(name.abuchen.portfolio.money.Values) TableViewer(org.eclipse.jface.viewers.TableViewer) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) TableColumn(org.eclipse.swt.widgets.TableColumn) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) JFaceResources(org.eclipse.jface.resource.JFaceResources) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) TextUtil(name.abuchen.portfolio.util.TextUtil) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) Font(org.eclipse.swt.graphics.Font) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) Month(java.time.Month) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) IMenuManager(org.eclipse.jface.action.IMenuManager) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) SWT(org.eclipse.swt.SWT) ToolTip(org.eclipse.jface.window.ToolTip) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Image(org.eclipse.swt.graphics.Image) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Font(org.eclipse.swt.graphics.Font)

Aggregations

InvestmentVehicle (name.abuchen.portfolio.model.InvestmentVehicle)10 Line (name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line)4 LocalDate (java.time.LocalDate)3 HashMap (java.util.HashMap)3 Classification (name.abuchen.portfolio.model.Classification)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)3 Font (org.eclipse.swt.graphics.Font)3 Assignment (name.abuchen.portfolio.model.Classification.Assignment)2 Security (name.abuchen.portfolio.model.Security)2 SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)2 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)2 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Composite (org.eclipse.swt.widgets.Composite)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 MessageFormat (java.text.MessageFormat)1 Month (java.time.Month)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1