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));
}
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);
}
}
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;
}
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);
}
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())));
}
}
Aggregations