Search in sources :

Example 21 with Transaction

use of jgnash.engine.Transaction in project jgnash by ccavanaugh.

the class GenericImport method importTransactions.

public static void importTransactions(@NotNull final List<? extends ImportTransaction> transactions, @NotNull final Account baseAccount) {
    Objects.requireNonNull(transactions);
    Objects.requireNonNull(baseAccount);
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final ImportTransaction tran : transactions) {
        Objects.requireNonNull(tran.getAccount());
        if (tran.getState() == ImportState.NEW || tran.getState() == ImportState.NOT_EQUAL) {
            // do not import matched transactions
            Transaction transaction;
            if (tran.isInvestmentTransaction()) {
                if (baseAccount.getAccountType().getAccountGroup() == AccountGroup.INVEST) {
                    System.out.println("Create investment transaction");
                } else {
                    // Signal an error
                    System.out.println("Base account was not an investment account type");
                }
            }
            if (baseAccount.equals(tran.getAccount())) {
                // single entry oTran
                transaction = TransactionFactory.generateSingleEntryTransaction(baseAccount, tran.getAmount(), tran.getDatePosted(), tran.getMemo(), tran.getPayee(), tran.getCheckNumber());
            } else {
                // double entry
                if (tran.getAmount().signum() >= 0) {
                    transaction = TransactionFactory.generateDoubleEntryTransaction(baseAccount, tran.getAccount(), tran.getAmount().abs(), tran.getDatePosted(), tran.getMemo(), tran.getPayee(), tran.getCheckNumber());
                } else {
                    transaction = TransactionFactory.generateDoubleEntryTransaction(tran.getAccount(), baseAccount, tran.getAmount().abs(), tran.getDatePosted(), tran.getMemo(), tran.getPayee(), tran.getCheckNumber());
                }
            }
            // add the new transaction
            if (transaction != null) {
                transaction.setFitid(tran.getFITID());
                engine.addTransaction(transaction);
            }
        }
    }
}
Also used : Transaction(jgnash.engine.Transaction) Engine(jgnash.engine.Engine)

Example 22 with Transaction

use of jgnash.engine.Transaction in project jgnash by ccavanaugh.

the class IncomeExpensePayeePieChartDialogController method getTransactions.

private List<TranTuple> getTransactions(final Account account, final List<TranTuple> transactions, final LocalDate startDate, final LocalDate endDate) {
    for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
        TranTuple tuple = new TranTuple(account, transaction);
        transactions.add(tuple);
    }
    for (final Account child : account.getChildren(Comparators.getAccountByCode())) {
        getTransactions(child, transactions, startDate, endDate);
    }
    return transactions;
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction)

Example 23 with Transaction

use of jgnash.engine.Transaction in project jgnash by ccavanaugh.

the class BasicRegisterTableController method buildTable.

@Override
protected void buildTable() {
    final String[] columnNames = RegisterFactory.getColumnNames(accountProperty().get().getAccountType());
    final TableColumn<Transaction, LocalDate> dateColumn = new TableColumn<>(columnNames[0]);
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
    dateColumn.setCellFactory(cell -> new TransactionDateTableCell());
    tableView.getColumns().add(dateColumn);
    final TableColumn<Transaction, LocalDateTime> dateTimeColumn = new TableColumn<>(columnNames[1]);
    dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getTimestamp()));
    dateTimeColumn.setCellFactory(cell -> new TransactionDateTimeTableCell());
    tableView.getColumns().add(dateTimeColumn);
    final TableColumn<Transaction, String> numberColumn = new TableColumn<>(columnNames[2]);
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getNumber()));
    numberColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(numberColumn);
    final TableColumn<Transaction, String> payeeColumn = new TableColumn<>(columnNames[3]);
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    payeeColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(payeeColumn);
    final TableColumn<Transaction, String> memoColumn = new TableColumn<>(columnNames[4]);
    memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
    memoColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(memoColumn);
    final TableColumn<Transaction, String> accountColumn = new TableColumn<>(columnNames[5]);
    accountColumn.setCellValueFactory(param -> new AccountNameWrapper(param.getValue()));
    accountColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(accountColumn);
    final TableColumn<Transaction, String> reconciledColumn = new TableColumn<>(columnNames[6]);
    reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciled(account.get()).toString()));
    reconciledColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(reconciledColumn);
    final TableColumn<Transaction, BigDecimal> increaseColumn = new TableColumn<>(columnNames[7]);
    increaseColumn.setCellValueFactory(param -> new IncreaseAmountProperty(param.getValue().getAmount(accountProperty().getValue())));
    increaseColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
    tableView.getColumns().add(increaseColumn);
    final TableColumn<Transaction, BigDecimal> decreaseColumn = new TableColumn<>(columnNames[8]);
    decreaseColumn.setCellValueFactory(param -> new DecreaseAmountProperty(param.getValue().getAmount(accountProperty().getValue())));
    decreaseColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
    tableView.getColumns().add(decreaseColumn);
    final TableColumn<Transaction, BigDecimal> balanceColumn = new TableColumn<>(columnNames[9]);
    balanceColumn.setCellValueFactory(param -> {
        final AccountType accountType = accountProperty().getValue().getAccountType();
        return new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(accountType, getBalanceAt(param.getValue())));
    });
    balanceColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getFullNumberFormat(account.get().getCurrencyNode())));
    // do not allow a sort on the balance
    balanceColumn.setSortable(false);
    tableView.getColumns().add(balanceColumn);
    tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    tableViewManager.setColumnFormatFactory(param -> {
        if (param == balanceColumn) {
            return CommodityFormat.getFullNumberFormat(accountProperty().getValue().getCurrencyNode());
        } else if (param == increaseColumn || param == decreaseColumn) {
            return CommodityFormat.getShortNumberFormat(accountProperty().getValue().getCurrencyNode());
        } else if (param == dateColumn) {
            return DateUtils.getShortDateFormatter().toFormat();
        } else if (param == dateTimeColumn) {
            return DateUtils.getShortDateTimeFormatter().toFormat();
        }
        return null;
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) AccountType(jgnash.engine.AccountType) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 24 with Transaction

use of jgnash.engine.Transaction in project jgnash by ccavanaugh.

the class BuyShareSlipController method modifyTransaction.

@Override
public void modifyTransaction(@NotNull final Transaction transaction) {
    if (transaction.getTransactionType() != TransactionType.BUYSHARE || !(transaction instanceof InvestmentTransaction)) {
        throw new IllegalArgumentException(resources.getString("Message.Error.InvalidTransactionType"));
    }
    clearForm();
    datePicker.setValue(transaction.getLocalDate());
    numberComboBox.setValue(transaction.getNumber());
    List<TransactionEntry> entries = transaction.getTransactionEntries();
    feePane.setTransactionEntries(((InvestmentTransaction) transaction).getInvestmentFeeEntries());
    entries.stream().filter(e -> e instanceof TransactionEntryBuyX).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 {
            accountExchangePane.setSelectedAccount(entry.getCreditAccount());
            accountExchangePane.setExchangedAmount(entry.getCreditAmount());
        }
    });
    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) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX) InvestmentTransaction(jgnash.engine.InvestmentTransaction) ChangeListener(javafx.beans.value.ChangeListener) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionFactory(jgnash.engine.TransactionFactory) TransactionType(jgnash.engine.TransactionType) InvestmentTransaction(jgnash.engine.InvestmentTransaction) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntry(jgnash.engine.TransactionEntry) AbstractInvestmentTransactionEntry(jgnash.engine.AbstractInvestmentTransactionEntry) TransactionEntryBuyX(jgnash.engine.TransactionEntryBuyX)

Example 25 with Transaction

use of jgnash.engine.Transaction in project jgnash by ccavanaugh.

the class RegisterTableController method handleJumpAction.

void handleJumpAction() {
    Transaction t = selectedTransaction.get();
    if (t != null) {
        if (t.getTransactionType() == TransactionType.DOUBLEENTRY) {
            final Set<Account> set = t.getAccounts();
            set.stream().filter(a -> !account.get().equals(a)).forEach(a -> RegisterStage.getRegisterStage(a).show(t));
        } else if (t.getTransactionType() == TransactionType.SPLITENTRY) {
            final Account common = t.getCommonAccount();
            if (!account.get().equals(common)) {
                RegisterStage.getRegisterStage(common).show(t);
            }
        } else if (t instanceof InvestmentTransaction) {
            final Account invest = ((InvestmentTransaction) t).getInvestmentAccount();
            if (!account.get().equals(invest)) {
                RegisterStage.getRegisterStage(invest).show(t);
            }
        }
    }
}
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) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

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