Search in sources :

Example 51 with Account

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

the class ProfitLossTextReport method getBalances.

private List<BigDecimal> getBalances(final Account a, final AccountType type) {
    final List<BigDecimal> balances = new ArrayList<>();
    for (final Account child : a.getChildren(Comparators.getAccountByCode())) {
        if ((child.getTransactionCount() > 0) && type == child.getAccountType()) {
            final BigDecimal acctBal = balanceConverter.apply(child.getAccountType(), child.getBalance(startDate, endDate, baseCommodity));
            // output account name and balance
            reportText.add(formatAccountName(child.getName()) + " " + formatDecimal(acctBal));
            balances.add(acctBal);
        }
        if (child.isParent()) {
            balances.addAll(getBalances(child, type));
        }
    }
    return balances;
}
Also used : Account(jgnash.engine.Account) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 52 with Account

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

the class AccountsViewController method getTreeTableRow.

private TreeTableRow<Account> getTreeTableRow() {
    final TreeTableRow<Account> treeTableRow = new TreeTableRow<>();
    treeTableRow.setOnMouseClicked(event -> {
        if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2) {
            if (selectedAccount.get() != null && !selectedAccount.get().isPlaceHolder()) {
                Platform.runLater(AccountsViewController.this::handleZoomAccountAction);
            }
        }
    });
    final ContextMenu rowMenu = new ContextMenu();
    final MenuItem newItem = new MenuItem(resources.getString("Menu.New.Name"));
    newItem.setOnAction(event -> handleNewAccountAction());
    final MenuItem modifyItem = new MenuItem(resources.getString("Menu.Modify.Name"));
    modifyItem.setOnAction(event -> handleModifyAccountAction());
    final MenuItem deleteItem = new MenuItem(resources.getString("Menu.Delete.Name"));
    deleteItem.setOnAction(event -> handleDeleteAccountAction());
    deleteItem.disableProperty().bind(deleteButton.disabledProperty());
    final MenuItem visibilityMenuItem = new MenuItem(resources.getString("Menu.Hide.Name"));
    visibilityMenuItem.setOnAction(event -> handleModifyAccountAction());
    visibilityMenuItem.setOnAction(event -> new Thread(() -> {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        if (engine != null) {
            engine.toggleAccountVisibility(selectedAccount.get());
        }
    }).start());
    final MenuItem reconcileItem = new MenuItem(resources.getString("Menu.Reconcile.Name"));
    reconcileItem.setOnAction(event -> handleReconcileAction());
    rowMenu.getItems().addAll(newItem, modifyItem, deleteItem, new SeparatorMenuItem(), visibilityMenuItem, new SeparatorMenuItem(), reconcileItem);
    rowMenu.setOnShowing(event -> visibilityMenuItem.setText(selectedAccount.get().isVisible() ? resources.getString("Menu.Hide.Name") : resources.getString("Menu.Show.Name")));
    treeTableRow.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(treeTableRow.itemProperty())).then(rowMenu).otherwise((ContextMenu) null));
    return treeTableRow;
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) TreeTableRow(javafx.scene.control.TreeTableRow) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Engine(jgnash.engine.Engine)

Example 53 with Account

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

the class AccountsViewController method loadAccountTree.

private void loadAccountTree() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    if (engine != null) {
        final RootAccount r = engine.getRootAccount();
        final TreeItem<Account> root = new TreeItem<>(r);
        root.setExpanded(true);
        treeTableView.setRoot(root);
        loadChildren(root);
    } else {
        treeTableView.setRoot(null);
    }
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount) TreeItem(javafx.scene.control.TreeItem) Engine(jgnash.engine.Engine)

Example 54 with Account

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

the class AccountsViewController method updateButtonStates.

private void updateButtonStates() {
    JavaFXUtils.runLater(() -> {
        final Account account = selectedAccount.get();
        if (account != null) {
            final int count = account.getTransactionCount();
            deleteButton.setDisable(count > 0 || account.getChildCount() > 0);
            reconcileButton.setDisable(count <= 0);
            zoomButton.setDisable(account.isPlaceHolder());
        } else {
            deleteButton.setDisable(true);
            reconcileButton.setDisable(true);
            zoomButton.setDisable(true);
        }
    });
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account)

Example 55 with Account

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

the class AccountsViewController method initializeTreeTableView.

@SuppressWarnings("unchecked")
private void initializeTreeTableView() {
    // don't show the root
    treeTableView.setShowRoot(false);
    // required for editable columns
    treeTableView.setEditable(true);
    treeTableView.setTableMenuButtonVisible(true);
    treeTableView.setRowFactory(ttv -> getTreeTableRow());
    // force resize policy for better default appearance
    treeTableView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
    // hide the horizontal scrollbar and prevent ghosting
    treeTableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
    final TreeTableColumn<Account, String> nameColumn = new TreeTableColumn<>(resources.getString("Column.Account"));
    nameColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getName()));
    final TreeTableColumn<Account, Integer> entriesColumn = new TreeTableColumn<>(resources.getString("Column.Entries"));
    entriesColumn.setCellValueFactory(param -> new SimpleIntegerProperty(param.getValue().getValue().getTransactionCount()).asObject());
    final TreeTableColumn<Account, BigDecimal> balanceColumn = new TreeTableColumn<>(resources.getString("Column.Balance"));
    balanceColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(param.getValue().getValue().getAccountType(), param.getValue().getValue().getTreeBalance())));
    balanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());
    final TreeTableColumn<Account, BigDecimal> reconciledBalanceColumn = new TreeTableColumn<>(resources.getString("Column.ReconciledBalance"));
    reconciledBalanceColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(param.getValue().getValue().getAccountType(), param.getValue().getValue().getReconciledTreeBalance())));
    reconciledBalanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());
    final TreeTableColumn<Account, String> currencyColumn = new TreeTableColumn<>(resources.getString("Column.Currency"));
    currencyColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getCurrencyNode().getSymbol()));
    final TreeTableColumn<Account, String> typeColumn = new TreeTableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getAccountType().toString()));
    final TreeTableColumn<Account, Integer> codeColumn = new TreeTableColumn<>(resources.getString("Column.Code"));
    codeColumn.setEditable(true);
    codeColumn.setCellValueFactory(param -> new SimpleIntegerProperty(param.getValue().getValue().getAccountCode()).asObject());
    codeColumn.setCellFactory(param -> new IntegerTreeTableCell<>());
    codeColumn.setOnEditCommit(event -> updateAccountCode(event.getRowValue().getValue(), event.getNewValue()));
    treeTableView.getColumns().addAll(nameColumn, codeColumn, entriesColumn, balanceColumn, reconciledBalanceColumn, currencyColumn, typeColumn);
    restoreColumnVisibility();
    installListeners();
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) BigDecimal(java.math.BigDecimal) TreeTableColumn(javafx.scene.control.TreeTableColumn) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty)

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