use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class TransactionPanel method enterAction.
@Override
public void enterAction() {
if (validateForm()) {
if (modEntry != null && modTrans != null) {
try {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
// clone the transaction
Transaction t = (Transaction) modTrans.clone();
// remove the modifying entry from the clone
t.removeTransactionEntry(modEntry);
// generate new TransactionEntry
TransactionEntry e = buildTransactionEntry();
// add it to the clone
t.addTransactionEntry(e);
ReconcileManager.reconcileTransaction(getAccount(), t, getReconciledState());
engine.removeTransaction(modTrans);
engine.addTransaction(t);
clearForm();
fireOkAction();
focusFirstComponent();
} catch (CloneNotSupportedException e) {
Logger.getLogger(TransactionPanel.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
} else {
super.enterAction();
}
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SplitTransactionEntryPanel method buildTransactionEntry.
@Override
protected TransactionEntry buildTransactionEntry() {
TransactionEntry entry = new TransactionEntry();
entry.setMemo(memoField.getText());
int signum = amountField.getDecimal().signum();
if ((panelType == PanelType.DECREASE && signum >= 0) || (panelType == PanelType.INCREASE && signum < 0)) {
entry.setCreditAccount(accountPanel.getSelectedAccount());
entry.setDebitAccount(getAccount());
if (hasEqualCurrencies()) {
entry.setAmount(amountField.getDecimal().abs());
} else {
entry.setDebitAmount(amountField.getDecimal().abs().negate());
entry.setCreditAmount(accountPanel.getExchangedAmount().abs());
}
} else {
entry.setCreditAccount(getAccount());
entry.setDebitAccount(accountPanel.getSelectedAccount());
if (hasEqualCurrencies()) {
entry.setAmount(amountField.getDecimal().abs());
} else {
entry.setCreditAmount(amountField.getDecimal().abs());
entry.setDebitAmount(accountPanel.getExchangedAmount().abs().negate());
}
}
entry.setReconciled(account, getReconciledState());
return entry;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class AdjustmentPanel method newTransaction.
private void newTransaction(final Transaction t) {
TransactionEntry entry = t.getTransactionEntries().get(0);
memoField.setText(entry.getMemo());
amountField.setDecimal(entry.getCreditAmount());
datePanel.setDate(t.getLocalDate());
numberField.setText(t.getNumber());
payeeField.setText(t.getPayee());
setReconciledState(t.getReconciled(getAccount()));
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class RegisterTableWithSplitEntriesModel method getInternalValueAt.
@Override
protected Object getInternalValueAt(final int row, final int col) {
final TransactionWrapper wrapper = data.get(row);
BigDecimal amount;
if (wrapper.entry == null) {
amount = wrapper.transaction.getAmount(account);
} else {
amount = wrapper.entry.getAmount(account);
}
int signum = amount.signum();
/* only show details if showSplitDetails is true and account
* does not directly contain the transaction */
boolean showDetail = wrapper.entry != null && showSplitDetails;
switch(col) {
case 0:
if (showDetail) {
return null;
}
return wrapper.transaction.getLocalDate();
case 1:
if (showDetail) {
return null;
}
return wrapper.transaction.getNumber();
case 2:
if (showDetail) {
return null;
}
return wrapper.transaction.getPayee();
case 3:
if (showDetail) {
return null;
}
return wrapper.transaction.getMemo(getAccount());
case 4:
if (wrapper.entry != null && showDetail) {
TransactionEntry _t = wrapper.entry;
if (_t.getCreditAccount() != account) {
return " - " + _t.getCreditAccount().getName();
}
return " - " + _t.getDebitAccount().getName();
} else if (wrapper.entry == null && wrapper.transaction.getTransactionType() == TransactionType.DOUBLEENTRY) {
TransactionEntry _t = wrapper.transaction.getTransactionEntries().get(0);
if (_t.getCreditAccount() != account) {
return _t.getCreditAccount().getName();
}
return _t.getDebitAccount().getName();
} else if (wrapper.entry == null && wrapper.transaction.getTransactionType() == TransactionType.SINGLENTRY) {
TransactionEntry _t = wrapper.transaction.getTransactionEntries().get(0);
return _t.getCreditAccount().getName();
} else if (wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY) {
Transaction _t = wrapper.transaction;
return "[ " + _t.size() + " " + split + " ]";
} else if (wrapper.transaction instanceof InvestmentTransaction) {
return ((InvestmentTransaction) wrapper.transaction).getInvestmentAccount().getName();
} else {
return ERROR;
}
case 5:
if (wrapper.entry == null) {
return wrapper.transaction.getReconciled(account).toString();
}
return wrapper.entry.getReconciled(account).toString();
case 6:
// Don't show amount if the split details are going to be shown, otherwise totals will be wrong
if (showSplitDetails && wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY && wrapper.entry == null) {
return null;
}
if (signum >= 0) {
return amount;
}
return null;
case 7:
// Don't show amount if the split details are going to be shown, otherwise totals will be wrong
if (showSplitDetails && wrapper.transaction.getTransactionType() == TransactionType.SPLITENTRY && wrapper.entry == null) {
return null;
}
if (signum < 0) {
return amount.abs();
}
return null;
case 8:
if (showDetail) {
return null;
}
return getBalanceAt(row);
default:
return ERROR;
}
}
use of jgnash.engine.TransactionEntry 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()));
}
Aggregations