Search in sources :

Example 31 with Transaction

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

the class SlipController method handleEnterAction.

@Override
public void handleEnterAction() {
    if (modEntry.get() != null && modTrans != null) {
        try {
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            Objects.requireNonNull(engine);
            // clone the transaction
            final Transaction t = (Transaction) modTrans.clone();
            // remove the modifying entry from the clone
            t.removeTransactionEntry(modEntry.get());
            // generate new TransactionEntry
            final TransactionEntry e = buildTransactionEntry();
            // add it to the clone
            t.addTransactionEntry(e);
            ReconcileManager.reconcileTransaction(account.get(), t, getReconciledState());
            if (engine.removeTransaction(modTrans)) {
                engine.addTransaction(t);
            }
            clearForm();
            focusFirstComponent();
        } catch (CloneNotSupportedException e) {
            Logger.getLogger(SlipController.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    } else {
        super.handleEnterAction();
    }
}
Also used : Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) Engine(jgnash.engine.Engine) TransactionEntry(jgnash.engine.TransactionEntry)

Example 32 with Transaction

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

the class InvestmentRegisterTableController 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> typeColumn = new TableColumn<>(columnNames[2]);
    typeColumn.setCellValueFactory(param -> new TransactionTypeWrapper(param.getValue()));
    typeColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(typeColumn);
    final TableColumn<Transaction, String> investmentColumn = new TableColumn<>(columnNames[3]);
    investmentColumn.setCellValueFactory(param -> new TransactionSymbolWrapper(param.getValue()));
    investmentColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(investmentColumn);
    final TableColumn<Transaction, String> memoColumn = new TableColumn<>(columnNames[4]);
    memoColumn.setCellValueFactory(param -> new MemoWrapper(param.getValue()));
    memoColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(memoColumn);
    final TableColumn<Transaction, String> reconciledColumn = new TableColumn<>(columnNames[5]);
    reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciled(account.getValue()).toString()));
    reconciledColumn.setCellFactory(cell -> new TransactionStringTableCell());
    tableView.getColumns().add(reconciledColumn);
    final TableColumn<Transaction, BigDecimal> quantityColumn = new TableColumn<>(columnNames[6]);
    quantityColumn.setCellValueFactory(param -> new QuantityProperty(param.getValue()));
    quantityColumn.setCellFactory(cell -> new InvestmentTransactionQuantityTableCell());
    tableView.getColumns().add(quantityColumn);
    final TableColumn<Transaction, BigDecimal> priceColumn = new TableColumn<>(columnNames[7]);
    priceColumn.setCellValueFactory(param -> new PriceProperty(param.getValue()));
    priceColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
    tableView.getColumns().add(priceColumn);
    final TableColumn<Transaction, BigDecimal> netColumn = new TableColumn<>(columnNames[8]);
    netColumn.setCellValueFactory(param -> new AmountProperty(param.getValue()));
    netColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(CommodityFormat.getShortNumberFormat(account.get().getCurrencyNode())));
    tableView.getColumns().add(netColumn);
    tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    tableViewManager.setColumnFormatFactory(param -> {
        if (param == netColumn) {
            return CommodityFormat.getFullNumberFormat(accountProperty().getValue().getCurrencyNode());
        } else if (param == quantityColumn) {
            return getQuantityColumnFormat();
        } else if (param == priceColumn) {
            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) BigDecimal(java.math.BigDecimal) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction)

Example 33 with Transaction

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

the class DividendSlipController method buildTransaction.

@NotNull
@Override
public Transaction buildTransaction() {
    BigDecimal incomeExchangedAmount = decimalTextField.getDecimal().negate();
    BigDecimal accountExchangedAmount = decimalTextField.getDecimal();
    if (!incomeExchangePane.getSelectedAccount().getCurrencyNode().equals(accountProperty().get().getCurrencyNode())) {
        incomeExchangedAmount = incomeExchangePane.exchangeAmountProperty().get().negate();
    }
    if (!accountExchangePane.getSelectedAccount().getCurrencyNode().equals(accountProperty().get().getCurrencyNode())) {
        accountExchangedAmount = accountExchangePane.exchangeAmountProperty().get();
    }
    final Transaction transaction = TransactionFactory.generateDividendXTransaction(incomeExchangePane.getSelectedAccount(), accountProperty().get(), accountExchangePane.getSelectedAccount(), securityComboBox.getValue(), decimalTextField.getDecimal(), incomeExchangedAmount, accountExchangedAmount, datePicker.getValue(), memoTextField.getText());
    transaction.setNumber(numberComboBox.getValue());
    return transaction;
}
Also used : Transaction(jgnash.engine.Transaction) BigDecimal(java.math.BigDecimal) NotNull(jgnash.util.NotNull)

Example 34 with Transaction

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

the class AdjustmentSlipController method convertAction.

@FXML
private void convertAction() {
    final Optional<Account> accountOptional = StaticAccountsMethods.selectAccount(null, account.get());
    accountOptional.ifPresent(opp -> {
        final Transaction t = new Transaction();
        t.setDate(datePicker.getValue());
        t.setNumber(numberComboBox.getValue());
        t.setPayee(payeeTextField.getText());
        final TransactionEntry entry = new TransactionEntry();
        entry.setMemo(memoTextField.getText());
        if (amountField.getDecimal().signum() >= 0) {
            entry.setCreditAccount(account.get());
            entry.setDebitAccount(opp);
        } else {
            entry.setDebitAccount(account.get());
            entry.setCreditAccount(opp);
        }
        entry.setCreditAmount(amountField.getDecimal().abs());
        entry.setDebitAmount(amountField.getDecimal().abs().negate());
        t.addTransactionEntry(entry);
        ReconcileManager.reconcileTransaction(account.get(), t, getReconciledState());
        TransactionDialog.showAndWait(account.get(), t, transaction -> {
            if (transaction != null) {
                final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                Objects.requireNonNull(engine);
                if (engine.removeTransaction(modTrans)) {
                    engine.addTransaction(transaction);
                }
                clearForm();
            }
        });
    });
}
Also used : Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) TransactionEntry(jgnash.engine.TransactionEntry) Engine(jgnash.engine.Engine) FXML(javafx.fxml.FXML)

Example 35 with Transaction

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

the class InvestmentTransactionQuantityTableCell method updateItem.

@Override
protected void updateItem(final BigDecimal amount, final boolean empty) {
    // required
    super.updateItem(amount, empty);
    if (!empty && amount != null && getTableRow() != null) {
        final Transaction transaction = (Transaction) getTableRow().getItem();
        if (transaction instanceof InvestmentTransaction) {
            final NumberFormat format = CommodityFormat.getShortNumberFormat(((InvestmentTransaction) transaction).getSecurityNode());
            applyFormat(amount, format);
        } else {
            setText(null);
        }
    } else {
        setText(null);
    }
}
Also used : InvestmentTransaction(jgnash.engine.InvestmentTransaction) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) NumberFormat(java.text.NumberFormat)

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