Search in sources :

Example 26 with Transaction

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);
}
Also used : Engine(jgnash.engine.Engine) TransactionAgePredicate(jgnash.util.function.TransactionAgePredicate) TableViewManager(jgnash.uifx.util.TableViewManager) MessageBus(jgnash.engine.message.MessageBus) BigDecimal(java.math.BigDecimal) MessageProperty(jgnash.engine.message.MessageProperty) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) MessageChannel(jgnash.engine.message.MessageChannel) ContextMenu(javafx.scene.control.ContextMenu) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TableView(javafx.scene.control.TableView) MemoPredicate(jgnash.util.function.MemoPredicate) MessageListener(jgnash.engine.message.MessageListener) SortedList(javafx.collections.transformation.SortedList) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) Predicate(java.util.function.Predicate) RecurringEntryDialog(jgnash.uifx.views.recurring.RecurringEntryDialog) FilteredList(javafx.collections.transformation.FilteredList) Set(java.util.Set) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) TransactionType(jgnash.engine.TransactionType) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) ReconciledPredicate(jgnash.util.function.ReconciledPredicate) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) Message(jgnash.engine.message.Message) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) ResourceUtils(jgnash.util.ResourceUtils) FXCollections(javafx.collections.FXCollections) Bindings(javafx.beans.binding.Bindings) IntegerProperty(javafx.beans.property.IntegerProperty) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle) AccountBalanceDisplayManager(jgnash.uifx.views.AccountBalanceDisplayManager) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Callback(javafx.util.Callback) ThemeManager(jgnash.uifx.skin.ThemeManager) Tooltip(javafx.scene.control.Tooltip) ReconciledState(jgnash.engine.ReconciledState) ObjectProperty(javafx.beans.property.ObjectProperty) Label(javafx.scene.control.Label) TableRow(javafx.scene.control.TableRow) Reminder(jgnash.engine.recurring.Reminder) Menu(javafx.scene.control.Menu) TimeUnit(java.util.concurrent.TimeUnit) CommodityFormat(jgnash.text.CommodityFormat) ChronoUnit(java.time.temporal.ChronoUnit) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) StyleClass(jgnash.uifx.skin.StyleClass) Account(jgnash.engine.Account) PayeePredicate(jgnash.util.function.PayeePredicate) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) Options(jgnash.uifx.Options) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) FXML(javafx.fxml.FXML)

Example 27 with 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;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) LocalDate(java.time.LocalDate) NotNull(jgnash.util.NotNull)

Example 28 with 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);
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) NotNull(jgnash.util.NotNull)

Example 29 with 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()));
}
Also used : FXML(javafx.fxml.FXML) BigDecimal(java.math.BigDecimal) List(java.util.List) NotNull(jgnash.util.NotNull) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) ChangeListener(javafx.beans.value.ChangeListener) TransactionEntry(jgnash.engine.TransactionEntry) TransactionEntryReinvestDivX(jgnash.engine.TransactionEntryReinvestDivX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionFactory(jgnash.engine.TransactionFactory) TransactionType(jgnash.engine.TransactionType) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntryReinvestDivX(jgnash.engine.TransactionEntryReinvestDivX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Example 30 with Transaction

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()));
}
Also used : NotNull(jgnash.util.NotNull) Transaction(jgnash.engine.Transaction) Logger(java.util.logging.Logger) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionType(jgnash.engine.TransactionType) FXML(javafx.fxml.FXML) BigDecimal(java.math.BigDecimal) List(java.util.List) TransactionEntrySellX(jgnash.engine.TransactionEntrySellX) InvestmentTransaction(jgnash.engine.InvestmentTransaction) ChangeListener(javafx.beans.value.ChangeListener) TransactionFactory(jgnash.engine.TransactionFactory) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntrySellX(jgnash.engine.TransactionEntrySellX) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry)

Aggregations

Transaction (jgnash.engine.Transaction)81 InvestmentTransaction (jgnash.engine.InvestmentTransaction)39 Account (jgnash.engine.Account)27 BigDecimal (java.math.BigDecimal)24 Engine (jgnash.engine.Engine)22 TransactionEntry (jgnash.engine.TransactionEntry)18 NotNull (jgnash.util.NotNull)13 List (java.util.List)10 LocalDate (java.time.LocalDate)9 FXML (javafx.fxml.FXML)9 AbstractInvestmentTransactionEntry (jgnash.engine.AbstractInvestmentTransactionEntry)9 ArrayList (java.util.ArrayList)7 TransactionType (jgnash.engine.TransactionType)7 ResourceBundle (java.util.ResourceBundle)6 TransactionFactory (jgnash.engine.TransactionFactory)6 NumberFormat (java.text.NumberFormat)5 Objects (java.util.Objects)5 ChangeListener (javafx.beans.value.ChangeListener)5 EngineFactory (jgnash.engine.EngineFactory)5 Message (jgnash.engine.message.Message)5