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