use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AbstractSlipController method handleEnterAction.
@FXML
@Override
public void handleEnterAction() {
if (modTrans == null) {
// new transaction
Transaction newTrans = buildTransaction();
ReconcileManager.reconcileTransaction(account.get(), newTrans, getReconciledState());
// chain the transaction build
newTrans = attachmentPane.buildTransaction(newTrans);
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null) {
if (!engine.addTransaction(newTrans)) {
StaticUIMethods.displayError(resources.getString("Message.Error.TranAddFail"));
}
}
} else {
Transaction newTrans = buildTransaction();
// restore the reconciled state of the previous old transaction
for (final Account a : modTrans.getAccounts()) {
if (!a.equals(account.get())) {
ReconcileManager.reconcileTransaction(a, newTrans, modTrans.getReconciled(a));
}
}
/*
* Reconcile the modified transaction for this account.
* This must be performed last to ensure consistent results per the ReconcileManager rules
*/
ReconcileManager.reconcileTransaction(account.get(), newTrans, getReconciledState());
// chain the transaction build
newTrans = attachmentPane.buildTransaction(newTrans);
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null && engine.removeTransaction(modTrans)) {
engine.addTransaction(newTrans);
}
}
clearForm();
focusFirstComponent();
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BudgetTableController method loadChildren.
private synchronized void loadChildren(final TreeItem<Account> parentItem) {
final Account parent = parentItem.getValue();
parent.getChildren(Comparators.getAccountByCode()).stream().filter(budgetResultsModel::includeAccount).forEach(child -> {
final TreeItem<Account> childItem = new TreeItem<>(child);
childItem.setExpanded(true);
parentItem.getChildren().add(childItem);
if (child.getChildCount() > 0) {
loadChildren(childItem);
}
});
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BudgetTableController method calculateMinSummaryWidthColumnWidth.
private double calculateMinSummaryWidthColumnWidth() {
double max = 0;
for (final BudgetPeriodDescriptor descriptor : budgetResultsModel.getDescriptorList()) {
max = Math.max(max, calculateMinColumnWidth(descriptor));
}
for (final Account account : expandedAccountList) {
max = Math.max(max, calculateMinColumnWidth(account));
}
max = Math.max(max, JavaFXUtils.getDisplayedTextWidth(resources.getString("Column.Budgeted") + BORDER_MARGIN, null));
max = Math.max(max, JavaFXUtils.getDisplayedTextWidth(resources.getString("Column.Actual") + BORDER_MARGIN, null));
max = Math.max(max, JavaFXUtils.getDisplayedTextWidth(resources.getString("Column.Remaining") + BORDER_MARGIN, null));
return Math.ceil(max);
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BudgetTableController method loadAccountTree.
private void loadAccountTree() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final TreeItem<Account> root = new TreeItem<>(engine.getRootAccount());
root.setExpanded(true);
accountTreeView.setRoot(root);
loadChildren(root);
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BasicRegisterTableController method getBalanceAt.
private BigDecimal getBalanceAt(final Transaction transaction) {
BigDecimal balance = BigDecimal.ZERO;
final Account account = this.account.get();
if (account != null) {
final int index = sortedList.indexOf(transaction);
for (int i = 0; i <= index; i++) {
balance = balance.add(sortedList.get(i).getAmount(account));
}
}
return balance;
}
Aggregations