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