Search in sources :

Example 21 with Account

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

the class BudgetResultsExportTest method testExportBudgetResultsModel.

@Test
public void testExportBudgetResultsModel() throws Exception {
    final String file = Files.createTempFile("budget-", DataStoreType.XML.getDataStore().getFileExt()).toString();
    EngineFactory.deleteDatabase(file);
    Engine e = EngineFactory.bootLocalEngine(file, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD, DataStoreType.XML);
    e.setCreateBackups(false);
    CurrencyNode node = e.getDefaultCurrency();
    Account account1 = new Account(AccountType.EXPENSE, node);
    account1.setName("Expense 1");
    e.addAccount(e.getRootAccount(), account1);
    Account account2 = new Account(AccountType.EXPENSE, node);
    account2.setName("Expense 2");
    e.addAccount(e.getRootAccount(), account2);
    Budget budget = new Budget();
    budget.setName("My Budget");
    budget.setDescription("Test");
    budget.setBudgetPeriod(Period.MONTHLY);
    assertTrue(e.addBudget(budget));
    BudgetResultsModel model = new BudgetResultsModel(budget, 2012, node, false);
    final Path exportFile = Files.createTempFile("testworkbook", ".xls");
    BudgetResultsExport.exportBudgetResultsModel(exportFile, model);
    assertTrue(Files.exists(exportFile));
    Files.delete(exportFile);
    EngineFactory.closeEngine(EngineFactory.DEFAULT);
    Files.deleteIfExists(Paths.get(file));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Path(java.nio.file.Path) Account(jgnash.engine.Account) Engine(jgnash.engine.Engine) Test(org.junit.Test)

Example 22 with Account

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

the class AccountBalanceChartController method trimAuxAccountCombos.

private void trimAuxAccountCombos() {
    final List<AccountComboBox> empty = auxAccountComboBoxList.stream().filter(accountComboBox -> accountComboBox.getValue() == NOP_ACCOUNT).collect(Collectors.toList());
    // Reverse order so we leave the last empty at the bottom
    Collections.reverse(empty);
    // work backwards through the list to avoid use of an iterator, and leave at least one empty account combo
    for (int i = empty.size() - 1; i > 0; i--) {
        final AccountComboBox accountComboBox = empty.get(i);
        accountComboVBox.getChildren().remove(accountComboBox);
        auxAccountComboBoxList.remove(accountComboBox);
        accountComboBox.valueProperty().removeListener(auxListener);
    }
}
Also used : Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) EngineFactory(jgnash.engine.EngineFactory) StackPane(javafx.scene.layout.StackPane) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) EncodeDecode(jgnash.util.EncodeDecode) BigDecimal(java.math.BigDecimal) Nullable(jgnash.util.Nullable) ResourceBundle(java.util.ResourceBundle) ComboBox(javafx.scene.control.ComboBox) AccountType(jgnash.engine.AccountType) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) DateUtils(jgnash.time.DateUtils) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) Collection(java.util.Collection) CheckBox(javafx.scene.control.CheckBox) BarChart(javafx.scene.chart.BarChart) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) StoredObject(jgnash.engine.StoredObject) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) RadioButton(javafx.scene.control.RadioButton) Account(jgnash.engine.Account) ReportPeriodUtils(jgnash.report.ReportPeriodUtils) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) ReportPeriod(jgnash.report.ReportPeriod) DatePickerEx(jgnash.uifx.control.DatePickerEx) Options(jgnash.uifx.Options) AccountComboBox(jgnash.uifx.control.AccountComboBox)

Example 23 with Account

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

the class AccountBalanceChartController method getSelectedAccounts.

private Collection<Account> getSelectedAccounts() {
    // Use a list for consistent sort order
    final List<Account> accountList = new ArrayList<>();
    accountList.add(accountComboBox.getValue());
    for (final AccountComboBox auxAccountComboBox : auxAccountComboBoxList) {
        final Account account = auxAccountComboBox.getValue();
        if (account != NOP_ACCOUNT && !accountList.contains(account)) {
            accountList.add(account);
        }
    }
    return accountList;
}
Also used : Account(jgnash.engine.Account) AccountComboBox(jgnash.uifx.control.AccountComboBox) ArrayList(java.util.ArrayList)

Example 24 with Account

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

the class AccountBalanceChartController method initialize.

@FXML
public void initialize() {
    accountComboBox.setPredicate(AccountComboBox.getShowAllPredicate());
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    periodComboBox.getItems().addAll(ReportPeriod.MONTHLY, ReportPeriod.QUARTERLY, ReportPeriod.YEARLY);
    periodComboBox.setValue(ReportPeriod.values()[preferences.getInt(REPORT_PERIOD, ReportPeriod.MONTHLY.ordinal())]);
    defaultCurrency = engine.getDefaultCurrency();
    numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
    barChart.getStylesheets().addAll(CHART_CSS);
    barChart.getYAxis().setLabel(defaultCurrency.getSymbol());
    barChart.barGapProperty().set(BAR_GAP);
    barChart.setCategoryGap(CATEGORY_GAP);
    barChart.setLegendVisible(false);
    barChart.getXAxis().setLabel(resources.getString("Column.Period"));
    barChart.getYAxis().setLabel(resources.getString("Column.Balance") + " : " + defaultCurrency.getSymbol());
    // Respect animation preference
    barChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    startDatePicker.setValue(DateUtils.getFirstDayOfTheMonth(endDatePicker.getValue().minusMonths(12)));
    // Force a defaults
    includeSubAccounts.setSelected(preferences.getBoolean(SUB_ACCOUNTS, true));
    runningBalanceRadioButton.setSelected(preferences.getBoolean(RUNNING_BALANCE, true));
    endingBalanceRadioButton.setSelected(preferences.getBoolean(ENDING_BALANCE, false));
    invertBalanceCheckBox.setSelected(preferences.getBoolean(INVERT_BALANCES, true));
    restoreSelectedAccounts();
    accountComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            defaultCurrency = newValue.getCurrencyNode();
            numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
            Platform.runLater(AccountBalanceChartController.this::updateChart);
            Platform.runLater(AccountBalanceChartController.this::saveSelectedAccounts);
        }
    });
    // Generic listener.  No super efficient but reduces listener count
    final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
        if (newValue != null) {
            Platform.runLater(AccountBalanceChartController.this::updateChart);
            preferences.putBoolean(ENDING_BALANCE, endingBalanceRadioButton.isSelected());
            preferences.putBoolean(RUNNING_BALANCE, runningBalanceRadioButton.isSelected());
            preferences.putBoolean(SUB_ACCOUNTS, includeSubAccounts.isSelected());
            preferences.putInt(REPORT_PERIOD, periodComboBox.getValue().ordinal());
            preferences.putBoolean(INVERT_BALANCES, invertBalanceCheckBox.isSelected());
        }
    };
    // load the initial aux account combo
    addAuxAccountCombo(null);
    periodComboBox.valueProperty().addListener(listener);
    startDatePicker.valueProperty().addListener(listener);
    endDatePicker.valueProperty().addListener(listener);
    runningBalanceRadioButton.selectedProperty().addListener(listener);
    endingBalanceRadioButton.selectedProperty().addListener(listener);
    includeSubAccounts.selectedProperty().addListener(listener);
    invertBalanceCheckBox.selectedProperty().addListener(listener);
    // Push the initial load to the end of the platform thread for better startup and a nicer visual effect
    Platform.runLater(this::updateChart);
}
Also used : Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) EngineFactory(jgnash.engine.EngineFactory) StackPane(javafx.scene.layout.StackPane) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) EncodeDecode(jgnash.util.EncodeDecode) BigDecimal(java.math.BigDecimal) Nullable(jgnash.util.Nullable) ResourceBundle(java.util.ResourceBundle) ComboBox(javafx.scene.control.ComboBox) AccountType(jgnash.engine.AccountType) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) DateUtils(jgnash.time.DateUtils) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) Collection(java.util.Collection) CheckBox(javafx.scene.control.CheckBox) BarChart(javafx.scene.chart.BarChart) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) StoredObject(jgnash.engine.StoredObject) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) RadioButton(javafx.scene.control.RadioButton) Account(jgnash.engine.Account) ReportPeriodUtils(jgnash.report.ReportPeriodUtils) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) ReportPeriod(jgnash.report.ReportPeriod) DatePickerEx(jgnash.uifx.control.DatePickerEx) Options(jgnash.uifx.Options) StoredObject(jgnash.engine.StoredObject) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 25 with Account

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

the class IncomeExpenseBarChartDialogController method updateChart.

private void updateChart() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final List<Account> incomeAccounts = engine.getIncomeAccountList();
    final List<Account> expenseAccounts = engine.getExpenseAccountList();
    barChart.getData().clear();
    final List<ReportPeriodUtils.Descriptor> descriptors = ReportPeriodUtils.getDescriptors(periodComboBox.getValue(), startDatePicker.getValue(), endDatePicker.getValue());
    // Income Series
    final XYChart.Series<String, Number> incomeSeries = new XYChart.Series<>();
    incomeSeries.setName(AccountType.INCOME.toString());
    barChart.getData().add(incomeSeries);
    // Expense Series
    final XYChart.Series<String, Number> expenseSeries = new XYChart.Series<>();
    expenseSeries.setName(AccountType.EXPENSE.toString());
    barChart.getData().add(expenseSeries);
    // Profit Series
    final XYChart.Series<String, Number> profitSeries = new XYChart.Series<>();
    profitSeries.setName(resources.getString("Word.NetIncome"));
    barChart.getData().add(profitSeries);
    for (final ReportPeriodUtils.Descriptor descriptor : descriptors) {
        final BigDecimal income = getSum(incomeAccounts, descriptor.getStartDate(), descriptor.getEndDate());
        final BigDecimal expense = getSum(expenseAccounts, descriptor.getStartDate(), descriptor.getEndDate());
        incomeSeries.getData().add(new XYChart.Data<>(descriptor.getLabel(), income));
        expenseSeries.getData().add(new XYChart.Data<>(descriptor.getLabel(), expense));
        profitSeries.getData().add(new XYChart.Data<>(descriptor.getLabel(), income.add(expense)));
    }
    int descriptorsIndex = 0;
    for (final XYChart.Data<String, Number> data : incomeSeries.getData()) {
        Tooltip.install(data.getNode(), new Tooltip(numberFormat.format(data.getYValue())));
        setupPieChartLaunch(data, AccountType.INCOME, descriptors.get(descriptorsIndex).getStartDate(), descriptors.get(descriptorsIndex).getEndDate());
        descriptorsIndex++;
    }
    descriptorsIndex = 0;
    for (final XYChart.Data<String, Number> data : expenseSeries.getData()) {
        Tooltip.install(data.getNode(), new Tooltip(numberFormat.format(data.getYValue())));
        setupPieChartLaunch(data, AccountType.EXPENSE, descriptors.get(descriptorsIndex).getStartDate(), descriptors.get(descriptorsIndex).getEndDate());
        descriptorsIndex++;
    }
    for (final XYChart.Data<String, Number> data : profitSeries.getData()) {
        Tooltip.install(data.getNode(), new Tooltip(numberFormat.format(data.getYValue())));
    }
}
Also used : Account(jgnash.engine.Account) ReportPeriodUtils(jgnash.report.ReportPeriodUtils) Tooltip(javafx.scene.control.Tooltip) BigDecimal(java.math.BigDecimal) XYChart(javafx.scene.chart.XYChart) Engine(jgnash.engine.Engine)

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