use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTableController method initialize.
@FXML
void initialize() {
// table view displays the sorted list of data. The comparator property must be bound
tableView.setItems(sortedList);
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
// Bind the account property
getAccountPropertyWrapper().accountProperty().bind(account);
accountNameLabel.textProperty().bind(getAccountPropertyWrapper().accountNameProperty());
balanceLabel.textProperty().bind(getAccountPropertyWrapper().accountBalanceProperty());
tableView.setTableMenuButtonVisible(true);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
// hide the horizontal scrollbar and prevent ghosting
tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
// Load the table on change and set the row factory if the account in not locked
accountProperty().addListener((observable, oldValue, newValue) -> {
loadAccount();
if (!newValue.isLocked()) {
tableView.setRowFactory(new TransactionRowFactory());
}
numberFormat = CommodityFormat.getFullNumberFormat(newValue.getCurrencyNode());
});
selectedTransaction.bind(tableView.getSelectionModel().selectedItemProperty());
// Update the selection size property when the selection list changes
tableView.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Transaction>) c -> selectionSize.set(tableView.getSelectionModel().getSelectedIndices().size()));
selectionSize.addListener((observable, oldValue, newValue) -> {
if ((Integer) newValue > 1) {
final List<Transaction> transactions = new ArrayList<>(tableView.getSelectionModel().getSelectedItems());
BigDecimal total = BigDecimal.ZERO;
for (final Transaction transaction : transactions) {
if (transaction != null) {
total = total.add(transaction.getAmount(account.get()));
}
}
selectionSummaryTooltip.setText(numberFormat.format(AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.get().getAccountType(), total)));
} else {
selectionSummaryTooltip.setText(null);
}
});
// For the table view to refresh itself if the mode changes
AccountBalanceDisplayManager.accountBalanceDisplayMode().addListener((observable, oldValue, newValue) -> tableView.refresh());
reconciledStateFilterComboBox.getItems().addAll(ReconciledStateEnum.values());
reconciledStateFilterComboBox.setValue(ReconciledStateEnum.ALL);
transactionAgeFilterComboBox.getItems().addAll(AgeEnum.values());
transactionAgeFilterComboBox.setValue(AgeEnum.ALL);
final ChangeListener<Object> filterChangeListener = (observable, oldValue, newValue) -> handleFilterChange();
reconciledStateFilterComboBox.valueProperty().addListener(filterChangeListener);
transactionAgeFilterComboBox.valueProperty().addListener(filterChangeListener);
// Rebuild filters when regex properties change
Options.regexForFiltersProperty().addListener(filterChangeListener);
if (memoFilterTextField != null) {
// memo filter may not have been initialized for all register types
memoFilterTextField.textProperty().addListener(filterChangeListener);
}
if (payeeFilterTextField != null) {
// payee filter may not have been initialized for all register types
payeeFilterTextField.textProperty().addListener(filterChangeListener);
}
// Repack the table if the font scale changes
ThemeManager.fontScaleProperty().addListener((observable, oldValue, newValue) -> tableViewManager.packTable());
// Listen for transaction events
MessageBus.getInstance().registerListener(messageBusHandler, MessageChannel.TRANSACTION);
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class SlipController method buildTransaction.
@NotNull
@Override
public Transaction buildTransaction() {
Transaction transaction;
final LocalDate date = datePicker.getValue();
if (!transactionEntries.isEmpty()) {
// build a split transaction
transaction = new Transaction();
transaction.setDate(date);
transaction.setNumber(numberComboBox.getValue());
transaction.setMemo(Options.concatenateMemosProperty().get() ? Transaction.CONCATENATE : memoTextField.getText());
transaction.setPayee(payeeTextField.getText());
transaction.addTransactionEntries(transactionEntries);
} else {
// double entry transaction
final int signum = amountField.getDecimal().signum();
final Account selectedAccount;
if (modTrans != null && modTrans.areAccountsHidden()) {
selectedAccount = getOppositeSideAccount(modTrans);
} else {
selectedAccount = accountExchangePane.getSelectedAccount();
}
if (slipType == SlipType.DECREASE && signum >= 0 || slipType == SlipType.INCREASE && signum == -1) {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(selectedAccount, account.get(), amountField.getDecimal().abs(), date, memoTextField.getText(), payeeTextField.getText(), numberComboBox.getValue());
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(selectedAccount, account.get(), accountExchangePane.exchangeAmountProperty().get().abs(), amountField.getDecimal().abs().negate(), date, memoTextField.getText(), payeeTextField.getText(), numberComboBox.getValue());
}
} else {
if (hasEqualCurrencies()) {
transaction = TransactionFactory.generateDoubleEntryTransaction(account.get(), selectedAccount, amountField.getDecimal().abs(), date, memoTextField.getText(), payeeTextField.getText(), numberComboBox.getValue());
} else {
transaction = TransactionFactory.generateDoubleEntryTransaction(account.get(), selectedAccount, amountField.getDecimal().abs(), accountExchangePane.exchangeAmountProperty().get().abs().negate(), date, memoTextField.getText(), payeeTextField.getText(), numberComboBox.getValue());
}
}
}
ReconcileManager.reconcileTransaction(account.get(), transaction, getReconciledState());
return transaction;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class SplitMergeSharesSlipController method buildTransaction.
@NotNull
@Override
public Transaction buildTransaction() {
final Transaction transaction;
if (tranType == TransactionType.SPLITSHARE) {
transaction = TransactionFactory.generateSplitXTransaction(accountProperty().get(), securityComboBox.getValue(), priceField.getDecimal(), quantityField.getDecimal(), datePicker.getValue(), memoTextField.getText());
} else {
transaction = TransactionFactory.generateMergeXTransaction(accountProperty().get(), securityComboBox.getValue(), priceField.getDecimal(), quantityField.getDecimal(), datePicker.getValue(), memoTextField.getText());
}
transaction.setNumber(numberComboBox.getValue());
return attachmentPane.buildTransaction(transaction);
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class ReinvestDividendSlipController method modifyTransaction.
@Override
public void modifyTransaction(@NotNull final Transaction transaction) {
if (!(transaction instanceof InvestmentTransaction) || transaction.getTransactionType() != TransactionType.REINVESTDIV) {
throw new IllegalArgumentException(resources.getString("Message.Error.InvalidTransactionType"));
}
clearForm();
datePicker.setValue(transaction.getLocalDate());
numberComboBox.setValue(transaction.getNumber());
feePane.setTransactionEntries(((InvestmentTransaction) transaction).getInvestmentFeeEntries());
gainLossPane.setTransactionEntries(((InvestmentTransaction) transaction).getInvestmentGainLossEntries());
transaction.getTransactionEntries().stream().filter(e -> e instanceof TransactionEntryReinvestDivX).forEach(e -> {
final AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoTextField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityComboBox.setSecurityNode(entry.getSecurityNode());
});
modTrans = transaction;
modTrans = attachmentPane.modifyTransaction(modTrans);
setReconciledState(transaction.getReconciled(accountProperty().get()));
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class SellShareSlipController method modifyTransaction.
@Override
public void modifyTransaction(@NotNull final Transaction transaction) {
if (!(transaction instanceof InvestmentTransaction) || transaction.getTransactionType() != TransactionType.SELLSHARE) {
throw new IllegalArgumentException(resources.getString("Message.Error.InvalidTransactionType"));
}
clearForm();
datePicker.setValue(transaction.getLocalDate());
numberComboBox.setValue(transaction.getNumber());
feePane.setTransactionEntries(((InvestmentTransaction) transaction).getInvestmentFeeEntries());
gainLossPane.setTransactionEntries(((InvestmentTransaction) transaction).getInvestmentGainLossEntries());
transaction.getTransactionEntries().stream().filter(e -> e instanceof TransactionEntrySellX).forEach(e -> {
final AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoTextField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityComboBox.setSecurityNode(entry.getSecurityNode());
if (entry.getCreditAccount().equals(accountProperty().get())) {
accountExchangePane.setSelectedAccount(entry.getDebitAccount());
accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs());
} else {
Logger.getLogger(SellShareSlipController.class.getName()).warning("was not expected");
}
});
modTrans = transaction;
modTrans = attachmentPane.modifyTransaction(modTrans);
setReconciledState(transaction.getReconciled(accountProperty().get()));
}
Aggregations