Search in sources :

Example 6 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class JpaCommodityDAO method getActiveCurrencies.

/*
     * @see jgnash.engine.CommodityDAOInterface#getActiveAccountCommodities()
     */
@Override
public Set<CurrencyNode> getActiveCurrencies() {
    Set<CurrencyNode> currencyNodeSet = Collections.emptySet();
    try {
        Future<Set<CurrencyNode>> future = executorService.submit(() -> {
            emLock.lock();
            try {
                final TypedQuery<Account> q = em.createQuery("SELECT a FROM Account a WHERE a.markedForRemoval = false", Account.class);
                final List<Account> accountList = q.getResultList();
                final Set<CurrencyNode> currencies = new HashSet<>();
                for (final Account account : accountList) {
                    currencies.add(account.getCurrencyNode());
                    currencies.addAll(account.getSecurities().parallelStream().map(SecurityNode::getReportedCurrencyNode).collect(Collectors.toList()));
                }
                return currencies;
            } finally {
                emLock.unlock();
            }
        });
        currencyNodeSet = future.get();
    } catch (final InterruptedException | ExecutionException e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    return currencyNodeSet;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Set(java.util.Set) HashSet(java.util.HashSet) SecurityNode(jgnash.engine.SecurityNode) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 7 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class BudgetResultsModel method getDepth.

/**
     * Returns the depth of the account relative to topmost account in the
     * budget hierarchy.
     *
     * @param account Account to get depth for
     * @return depth depth relative to accounts to be shown in the budget
     * @see Account#getDepth()
     */
int getDepth(final Account account) {
    int depth = 0;
    Account parent = account.getParent();
    while (parent != null) {
        if (accounts.contains(parent)) {
            depth++;
        }
        parent = parent.getParent();
    }
    return depth;
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account)

Example 8 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class RecurringPropertiesController method showReminder.

void showReminder(final Reminder reminder) {
    final Account a = reminder.getAccount();
    if (a != null) {
        accountComboBox.setValue(a);
    } else {
        System.err.println("did not find account");
    }
    transaction = reminder.getTransaction();
    if (transaction != null) {
        payeeTextField.setText(transaction.getPayee());
    }
    descriptionTextField.setText(reminder.getDescription());
    enabledCheckBox.setSelected(reminder.isEnabled());
    startDatePicker.setValue(reminder.getStartDate());
    notesTextArea.setText(reminder.getNotes());
    tabs.getSelectionModel().select(tabMap.get(reminder.getClass()));
    ((RecurringTabController) tabs.getSelectionModel().getSelectedItem().getUserData()).setReminder(reminder);
    if (reminder.getLastDate() != null) {
        final LocalDate lastOccurrence = reminder.getLastDate();
        lastOccurrenceTextField.setText(dateFormatter.format(lastOccurrence));
    }
    autoEnterCheckBox.setSelected(reminder.isAutoCreate());
    daysBeforeTextField.setInteger(reminder.getDaysAdvance());
}
Also used : Account(jgnash.engine.Account) LocalDate(java.time.LocalDate)

Example 9 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class StaticAccountsMethods method showNewAccountPropertiesDialog.

static void showNewAccountPropertiesDialog(@Nullable final Account parentAccount) {
    final Stage dialog = new Stage(StageStyle.DECORATED);
    dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.initOwner(MainView.getPrimaryStage());
    dialog.setTitle(ResourceUtils.getString("Title.NewAccount"));
    final AccountPropertiesController controller = FXMLUtils.loadFXML(o -> dialog.setScene(new Scene((Parent) o)), "AccountProperties.fxml", ResourceUtils.getBundle());
    dialog.getScene().getStylesheets().addAll(MainView.DEFAULT_CSS);
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    controller.setSelectedCurrency(engine.getDefaultCurrency());
    controller.setParentAccount(parentAccount != null ? parentAccount : engine.getRootAccount());
    dialog.setResizable(false);
    StageUtils.addBoundsListener(dialog, AccountPropertiesController.class, MainView.getPrimaryStage());
    dialog.showAndWait();
    if (controller.getResult()) {
        Account account = controller.getTemplate();
        engine.addAccount(account.getParent(), account);
    }
}
Also used : Account(jgnash.engine.Account) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine)

Example 10 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class BudgetTableController method buildAccountPeriodResultsColumn.

private TableColumn<Account, BigDecimal> buildAccountPeriodResultsColumn(final int index) {
    final BudgetPeriodDescriptor descriptor = budgetResultsModel.getDescriptorList().get(index);
    final TableColumn<Account, BigDecimal> headerColumn = new TableColumn<>(descriptor.getPeriodDescription());
    final TableColumn<Account, BigDecimal> budgetedColumn = new TableColumn<>(resources.getString("Column.Budgeted"));
    budgetedColumn.setCellValueFactory(param -> {
        if (param.getValue() != null) {
            return new SimpleObjectProperty<>(budgetResultsModel.getResults(descriptor, param.getValue()).getBudgeted());
        }
        return new SimpleObjectProperty<>(BigDecimal.ZERO);
    });
    budgetedColumn.setCellFactory(param -> new AccountCommodityFormatTableCell());
    budgetedColumn.minWidthProperty().bind(columnWidth);
    budgetedColumn.maxWidthProperty().bind(columnWidth);
    budgetedColumn.setSortable(false);
    budgetedColumn.resizableProperty().set(false);
    headerColumn.getColumns().add(budgetedColumn);
    final TableColumn<Account, BigDecimal> actualColumn = new TableColumn<>(resources.getString("Column.Actual"));
    actualColumn.setCellValueFactory(param -> {
        if (param.getValue() != null) {
            return new SimpleObjectProperty<>(budgetResultsModel.getResults(descriptor, param.getValue()).getChange());
        }
        return new SimpleObjectProperty<>(BigDecimal.ZERO);
    });
    actualColumn.setCellFactory(param -> new AccountCommodityFormatTableCell());
    actualColumn.minWidthProperty().bind(columnWidth);
    actualColumn.maxWidthProperty().bind(columnWidth);
    actualColumn.setSortable(false);
    actualColumn.resizableProperty().set(false);
    headerColumn.getColumns().add(actualColumn);
    final TableColumn<Account, BigDecimal> remainingColumn = new TableColumn<>(resources.getString("Column.Remaining"));
    remainingColumn.setCellValueFactory(param -> {
        if (param.getValue() != null) {
            return new SimpleObjectProperty<>(budgetResultsModel.getResults(descriptor, param.getValue()).getRemaining());
        }
        return new SimpleObjectProperty<>(BigDecimal.ZERO);
    });
    remainingColumn.setCellFactory(param -> new AccountCommodityFormatTableCell());
    // the max width is not bound to allow last column to grow and fill any voids
    remainingColumn.minWidthProperty().bind(remainingColumnWidth);
    remainingColumn.maxWidthProperty().bind(remainingColumnWidth);
    remainingColumn.setSortable(false);
    remainingColumn.resizableProperty().set(false);
    headerColumn.getColumns().add(remainingColumn);
    headerColumn.resizableProperty().set(false);
    return headerColumn;
}
Also used : Account(jgnash.engine.Account) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) TableColumn(javafx.scene.control.TableColumn) TreeTableColumn(javafx.scene.control.TreeTableColumn) BigDecimal(java.math.BigDecimal)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9