use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SlipController method newTransaction.
private void newTransaction(final Transaction t) {
clearForm();
amountField.setDecimal(t.getAmount(accountProperty().get()).abs());
// Must consider if this is a concatenated memo to set the field correctly
memoTextField.setText(t.isMemoConcatenated() ? t.getMemo() : t.getTransactionMemo());
payeeTextField.setText(t.getPayee());
numberComboBox.setValue(t.getNumber());
datePicker.setValue(t.getLocalDate());
setReconciledState(t.getReconciled(accountProperty().get()));
if (t.getTransactionType() == TransactionType.SPLITENTRY) {
if (canModifyTransaction(t)) {
// split common account is the same as the base account
// clone the splits for modification
transactionEntries.clear();
for (final TransactionEntry entry : t.getTransactionEntries()) {
try {
transactionEntries.add((TransactionEntry) entry.clone());
} catch (final CloneNotSupportedException e) {
Logger.getLogger(SlipController.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
amountField.setDecimal(t.getAmount(accountProperty().get()).abs());
} else {
// not the same common account, can only modify the entry
splitsButton.setDisable(true);
payeeTextField.setEditable(false);
numberComboBox.setDisable(true);
datePicker.setEditable(false);
// Override
memoTextField.setText(t.getMemo(account.get()));
amountField.setDecimal(t.getAmount(accountProperty().get()).abs());
for (final TransactionEntry entry : t.getTransactionEntries()) {
if (entry.getCreditAccount() == accountProperty().get()) {
accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs());
break;
} else if (entry.getDebitAccount() == accountProperty().get()) {
accountExchangePane.setExchangedAmount(entry.getCreditAmount());
break;
}
}
}
} else if (t instanceof InvestmentTransaction) {
Logger logger = Logger.getLogger(SlipController.class.getName());
logger.warning("unsupported transaction type");
} else {
// DoubleEntryTransaction
datePicker.setEditable(true);
}
// setup the accountCombo correctly
if (t.getTransactionType() == TransactionType.DOUBLEENTRY) {
TransactionEntry entry = t.getTransactionEntries().get(0);
if (slipType == SlipType.DECREASE) {
accountExchangePane.setSelectedAccount(entry.getCreditAccount());
accountExchangePane.setExchangedAmount(entry.getCreditAmount());
} else {
accountExchangePane.setSelectedAccount(entry.getDebitAccount());
accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs());
}
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SlipController method buildTransactionEntry.
private TransactionEntry buildTransactionEntry() {
final TransactionEntry entry = new TransactionEntry();
entry.setMemo(memoTextField.getText());
final 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(accountExchangePane.exchangeAmountProperty().get().abs().negate());
}
} else {
entry.setCreditAccount(account.get());
entry.setDebitAccount(accountExchangePane.getSelectedAccount());
if (hasEqualCurrencies()) {
entry.setAmount(amountField.getDecimal().abs());
} else {
entry.setCreditAmount(accountExchangePane.exchangeAmountProperty().get().abs());
}
}
entry.setReconciled(account.get(), getReconciledState());
return entry;
}
use of jgnash.engine.TransactionEntry 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.TransactionEntry in project jgnash by ccavanaugh.
the class GainLossPane method getTransactions.
public List<TransactionEntry> getTransactions() {
final List<TransactionEntry> feeList = gainLossDialog.getTransactionEntries();
// adjust the cash balance of the investment account
if (feeList.isEmpty() && getDecimal().compareTo(BigDecimal.ZERO) != 0) {
// ignore zero balance fees
TransactionEntry fee = new TransactionEntry(accountProperty().get(), getDecimal().abs().negate());
fee.setTransactionTag(TransactionTag.INVESTMENT_FEE);
feeList.add(fee);
}
return feeList;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class GainLossTransactionEntrySlipController method buildTransactionEntry.
@Override
TransactionEntry buildTransactionEntry() {
final TransactionEntry entry = super.buildTransactionEntry();
entry.setTransactionTag(TransactionTag.GAIN_LOSS);
return entry;
}
Aggregations