use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SellShareSlipController method buildTransaction.
@NotNull
@Override
public Transaction buildTransaction() {
final BigDecimal exchangeRate = accountExchangePane.getExchangeRate();
final List<TransactionEntry> gains = gainLossPane.getTransactions();
final List<TransactionEntry> fees = feePane.getTransactions();
final Transaction transaction = TransactionFactory.generateSellXTransaction(accountExchangePane.getSelectedAccount(), accountProperty().get(), securityComboBox.getValue(), priceField.getDecimal(), quantityField.getDecimal(), exchangeRate, datePicker.getValue(), memoTextField.getText(), fees, gains);
transaction.setNumber(numberComboBox.getValue());
transaction.setTags(TransactionEntrySellX.class, tagPane.getSelectedTags());
return attachmentPane.buildTransaction(transaction);
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SlipController method modifyTransaction.
@Override
public void modifyTransaction(@NotNull final Transaction transaction) {
if (transaction.areAccountsLocked()) {
clearForm();
StaticUIMethods.displayError(resources.getString("Message.TransactionModifyLocked"));
return;
}
// load the form
newTransaction(transaction);
// save reference to old transaction
modTrans = transaction;
modTrans = attachmentPane.modifyTransaction(modTrans);
tagPane.setSelectedTags(transaction.getTags(account.get()));
// Set state of memo concatenation
concatenated.setValue(modTrans.isMemoConcatenated());
if (!canModifyTransaction(transaction) && transaction.getTransactionType() == TransactionType.SPLITENTRY) {
for (final TransactionEntry entry : transaction.getTransactionEntries()) {
if (entry.getCreditAccount().equals(accountProperty().get()) || entry.getDebitAccount().equals(accountProperty().get())) {
modEntry.setValue(entry);
// override to allow editing the entry
concatenated.setValue(false);
break;
}
}
if (modEntry.get() == null) {
Logger logger = Logger.getLogger(SlipController.class.getName());
logger.warning("Was not able to modify the transaction");
}
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SplitTransactionDialog method deleteAction.
@Override
void deleteAction() {
final TransactionEntry entry = tableView.getSelectionModel().getSelectedItem();
if (entry != null) {
tableView.getSelectionModel().clearSelection();
((SplitTransactionSlipController) tabPane.getSelectionModel().getSelectedItem().getUserData()).clearForm();
getTransactionEntries().remove(entry);
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SplitTransactionSlipController method buildTransactionEntry.
@Override
TransactionEntry buildTransactionEntry() {
TransactionEntry entry = new TransactionEntry();
entry.setMemo(memoField.getText());
int signum = amountField.getDecimal().signum();
if ((slipType == SlipType.DECREASE && signum >= 0) || (slipType == SlipType.INCREASE && signum < 0)) {
entry.setCreditAccount(accountExchangePane.getSelectedAccount());
entry.setDebitAccount(account.get());
if (hasEqualCurrencies()) {
entry.setAmount(amountField.getDecimal().abs());
} else {
entry.setDebitAmount(amountField.getDecimal().abs().negate());
entry.setCreditAmount(accountExchangePane.exchangeAmountProperty().get().abs());
}
} else {
entry.setCreditAccount(account.get());
entry.setDebitAccount(accountExchangePane.getSelectedAccount());
if (hasEqualCurrencies()) {
entry.setAmount(amountField.getDecimal().abs());
} else {
entry.setCreditAmount(amountField.getDecimal().abs());
entry.setDebitAmount(accountExchangePane.exchangeAmountProperty().get().abs().negate());
}
}
entry.setReconciled(account.get(), getReconciledState());
entry.setTags(tagPane.getSelectedTags());
return entry;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class ApiTest method testTransactionAPI.
@Test
void testTransactionAPI() {
final String ACCOUNT_NAME = "testAccount";
final CurrencyNode node = e.getDefaultCurrency();
final Account a = new Account(AccountType.BANK, node);
a.setName(ACCOUNT_NAME);
e.addAccount(e.getRootAccount(), a);
// Test single entry transaction
final Transaction transaction = TransactionFactory.generateSingleEntryTransaction(a, BigDecimal.TEN, LocalDate.now(), "memo", "payee", "1");
e.addTransaction(transaction);
assertTrue(a.contains(transaction));
assertEquals(0, a.indexOf(transaction));
assertEquals(TransactionType.SINGLENTRY, transaction.getTransactionType());
for (final TransactionEntry transactionEntry : transaction.getTransactionEntries()) {
assertFalse(transactionEntry.isMultiCurrency());
}
}
Aggregations