Search in sources :

Example 26 with Account

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

the class IncomeExpensePayeePieChartDialogController method initialize.

@FXML
public void initialize() {
    // Respect animation preference
    debitPieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    creditPieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    creditPieChart.getStylesheets().addAll(CHART_CSS);
    debitPieChart.getStylesheets().addAll(CHART_CSS);
    creditPieChart.centerTitleProperty().set(resources.getString("Column.Credit"));
    debitPieChart.centerTitleProperty().set(resources.getString("Column.Debit"));
    accountComboBox.setPredicate(AccountComboBox.getShowAllPredicate());
    if (preferences.get(LAST_ACCOUNT, null) != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        final Account account = engine.getAccountByUuid(preferences.get(LAST_ACCOUNT, null));
        if (account != null) {
            accountComboBox.setValue(account);
        }
    }
    startDatePicker.setValue(endDatePicker.getValue().minusYears(1));
    final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
        if (newValue != null) {
            updateCharts();
            preferences.put(LAST_ACCOUNT, accountComboBox.getValue().getUuid());
        }
    };
    accountComboBox.valueProperty().addListener(listener);
    startDatePicker.valueProperty().addListener(listener);
    endDatePicker.valueProperty().addListener(listener);
    creditPieChart.setLegendSide(Side.BOTTOM);
    debitPieChart.setLegendSide(Side.BOTTOM);
    // Load in the first aux payee text field
    insertAuxPayeeTextField();
    restoreFilters();
    // Expand the titled pane if filters are being used
    Platform.runLater(() -> {
        if (getPayeeTextFields().size() > 1) {
            titledPane.setExpanded(true);
        }
    });
    // Push the initial load to the end of the platform thread for better startup and nicer visual effect
    Platform.runLater(this::updateCharts);
}
Also used : DoughnutChart(jgnash.uifx.control.DoughnutChart) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) TextInputControl(javafx.scene.control.TextInputControl) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) Side(javafx.geometry.Side) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) EncodeDecode(jgnash.util.EncodeDecode) BigDecimal(java.math.BigDecimal) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) CurrencyNode(jgnash.engine.CurrencyNode) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) InjectFXML(jgnash.uifx.util.InjectFXML) TitledPane(javafx.scene.control.TitledPane) NotNull(jgnash.util.NotNull) Comparators(jgnash.engine.Comparators) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) List(java.util.List) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) Account(jgnash.engine.Account) ObservableList(javafx.collections.ObservableList) PayeePredicate(jgnash.util.function.PayeePredicate) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) DatePickerEx(jgnash.uifx.control.DatePickerEx) CollectionUtils(jgnash.util.CollectionUtils) Options(jgnash.uifx.Options) Account(jgnash.engine.Account) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 27 with Account

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

the class ImportPageTwoController method buildTableView.

private void buildTableView() {
    final TableColumn<ImportTransaction, ImportState> stateColumn = new TableColumn<>();
    stateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getState()));
    stateColumn.setCellFactory(param -> {
        TableCell<ImportTransaction, ImportState> cell = new ImportStateTableCell();
        cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
            if (event.getClickCount() > 1) {
                final ImportTransaction t = tableView.getItems().get(((TableCell<?, ?>) event.getSource()).getTableRow().getIndex());
                if (t.getState() == ImportState.EQUAL) {
                    t.setState(ImportState.NOT_EQUAL);
                } else if (t.getState() == ImportState.NOT_EQUAL) {
                    t.setState(ImportState.EQUAL);
                } else if (t.getState() == ImportState.NEW) {
                    t.setState(ImportState.IGNORE);
                } else if (t.getState() == ImportState.IGNORE) {
                    t.setState(ImportState.NEW);
                }
                Platform.runLater(tableView::refresh);
            }
        });
        return cell;
    });
    tableView.getColumns().add(stateColumn);
    final TableColumn<ImportTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDatePosted()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<ImportTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCheckNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<ImportTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<ImportTransaction, String> memoColumn = new TableColumn<>(resources.getString("Column.Memo"));
    memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
    tableView.getColumns().add(memoColumn);
    final TableColumn<ImportTransaction, Account> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount());
        }
        return null;
    });
    accountColumn.setCellFactory(param -> new AccountComboBoxTableCell<>());
    accountColumn.setEditable(true);
    accountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setAccount(event.getNewValue());
        lastAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(accountColumn);
    incomeAccountColumn = new TableColumn<>(resources.getString("Column.Income"));
    incomeAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getGainsAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getGainsAccount());
        }
        return null;
    });
    incomeAccountColumn.setCellFactory(param -> new IncomeAccountComboBoxTableCell<>());
    incomeAccountColumn.setEditable(true);
    incomeAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setGainsAccount(event.getNewValue());
        lastGainsAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(incomeAccountColumn);
    expenseAccountColumn = new TableColumn<>(resources.getString("Column.Expense"));
    expenseAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getFeesAccount() != null) {
            if (param.getValue().getFees().compareTo(BigDecimal.ZERO) != 0) {
                return new SimpleObjectProperty<>(param.getValue().getFeesAccount());
            } else {
                return new SimpleObjectProperty<>(NOP_EXPENSE_ACCOUNT);
            }
        }
        return null;
    });
    expenseAccountColumn.setCellFactory(param -> new ExpenseAccountComboBoxTableCell<>());
    expenseAccountColumn.setEditable(true);
    expenseAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setFeesAccount(event.getNewValue());
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(expenseAccountColumn);
    final TableColumn<ImportTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAmount()));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(numberFormat));
    amountColumn.setCellFactory(param -> {
        final TableCell<ImportTransaction, BigDecimal> cell = new BigDecimalTableCell<>(numberFormat);
        cell.indexProperty().addListener((observable, oldValue, newValue) -> {
            final int index = newValue.intValue();
            if (index >= 0 && index < tableView.itemsProperty().get().size()) {
                cell.setTooltip(new Tooltip(tableView.itemsProperty().get().get(index).getToolTip()));
            }
        });
        return cell;
    });
    tableView.getColumns().add(amountColumn);
    typeColumn = new TableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(param -> {
        TransactionType transactionType = TransactionType.SINGLENTRY;
        if (param.getValue().isInvestmentTransaction()) {
            transactionType = param.getValue().getTransactionType();
        } else if (!param.getValue().getAccount().equals(baseAccount)) {
            transactionType = TransactionType.DOUBLEENTRY;
        }
        return new SimpleStringProperty(transactionType.toString());
    });
    tableView.getColumns().add(typeColumn);
}
Also used : Account(jgnash.engine.Account) TransactionType(jgnash.engine.TransactionType) ImportState(jgnash.convert.imports.ImportState) LocalDate(java.time.LocalDate) ImportTransaction(jgnash.convert.imports.ImportTransaction) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) Tooltip(javafx.scene.control.Tooltip) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty)

Example 28 with Account

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

the class ControlsTest method createEngine.

private Engine createEngine() throws IOException {
    try {
        testFile = Files.createTempFile("test", DataStoreType.BINARY_XSTREAM.getDataStore().getFileExt()).toFile().getAbsolutePath();
        tempFile = testFile;
    } catch (IOException e1) {
        Logger.getLogger(ControlsTest.class.getName()).log(Level.SEVERE, e1.getLocalizedMessage(), e1);
    }
    EngineFactory.deleteDatabase(testFile);
    final Engine engine = EngineFactory.bootLocalEngine(testFile, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD, DataStoreType.BINARY_XSTREAM);
    Objects.requireNonNull(engine);
    CurrencyNode node = engine.getDefaultCurrency();
    if (!node.getSymbol().equals("USD")) {
        engine.setDefaultCurrency(DefaultCurrencies.buildNode(Locale.US));
    }
    node = engine.getCurrency("CAD");
    if (node == null) {
        node = DefaultCurrencies.buildNode(Locale.CANADA);
        assertNotNull(node);
        assertTrue(engine.addCurrency(node));
    }
    Account account = new Account(AccountType.BANK, engine.getDefaultCurrency());
    account.setName("Bank Accounts");
    engine.addAccount(engine.getRootAccount(), account);
    SecurityNode securityNode = new SecurityNode();
    securityNode.setSymbol("GGG");
    securityNode.setDescription("Google");
    securityNode.setReportedCurrencyNode(engine.getDefaultCurrency());
    engine.addSecurity(securityNode);
    securityNode = new SecurityNode();
    securityNode.setSymbol("MSFT");
    securityNode.setDescription("Microsoft");
    securityNode.setReportedCurrencyNode(engine.getDefaultCurrency());
    engine.addSecurity(securityNode);
    return engine;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode) IOException(java.io.IOException) Engine(jgnash.engine.Engine)

Example 29 with Account

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

the class BudgetPeriodModel method updateBudgetPeriod.

private void updateBudgetPeriod(final Message message) {
    Budget updatedBudget = message.getObject(MessageProperty.BUDGET);
    if (updatedBudget.equals(budget)) {
        Account account = message.getObject(MessageProperty.ACCOUNT);
        fireUpdate(account.getAncestors());
    }
}
Also used : Account(jgnash.engine.Account) Budget(jgnash.engine.budget.Budget)

Example 30 with Account

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

the class BudgetPeriodModel method processTransactionEvent.

private void processTransactionEvent(final Message message) {
    final Transaction transaction = message.getObject(MessageProperty.TRANSACTION);
    if (isBetween(transaction.getLocalDate())) {
        // don't update unless needed
        // build a list of accounts include ancestors that will be impacted by the transaction changes
        final Set<Account> accounts = new HashSet<>();
        for (Account account : transaction.getAccounts()) {
            accounts.addAll(account.getAncestors());
        }
        fireUpdate(accounts);
    }
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) HashSet(java.util.HashSet)

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