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();
}
}
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;
});
}
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;
}
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();
}
});
});
}
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);
}
}
Aggregations