use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class SplitsDialog method modifyTransaction.
private void modifyTransaction(int index) {
TransactionEntry t = model.getTransactionAt(index);
if (t.getCreditAccount() == account) {
// this is a credit
tabbedPane.setSelectedComponent(creditPanel);
creditPanel.modifyTransaction(t);
} else {
tabbedPane.setSelectedComponent(debitPanel);
debitPanel.modifyTransaction(t);
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class TransactionPanel method newTransaction.
void newTransaction(final Transaction t) {
clearForm();
splits = null;
// handles any exchange rate that may exist
amountField.setDecimal(t.getAmount(getAccount()).abs());
// Must consider if this is a concatenated memo to set the field correctly
memoField.setText(t.isMemoConcatenated() ? t.getMemo() : t.getTransactionMemo());
payeeField.setText(t.getPayee());
numberField.setText(t.getNumber());
datePanel.setDate(t.getLocalDate());
setReconciledState(t.getReconciled(getAccount()));
if (t.getTransactionType() == TransactionType.SPLITENTRY) {
// display common account
accountPanel.setSelectedAccount(t.getCommonAccount());
accountPanel.setEnabled(false);
if (canModifyTransaction(t)) {
// split as the same base account
// clone the splits for modification
splits = new ArrayList<>();
for (TransactionEntry entry : t.getTransactionEntries()) {
try {
splits.add((TransactionEntry) entry.clone());
} catch (CloneNotSupportedException e) {
Logger.getLogger(TransactionPanel.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
amountField.setEditable(false);
amountField.setDecimal(t.getAmount(this.getAccount()).abs());
} else {
// not the same common account, can only modify the entry
splitsButton.setEnabled(false);
payeeField.setEditable(false);
numberField.setEnabled(false);
datePanel.setEditable(false);
// Override
memoField.setText(t.getMemo(getAccount()));
//memoField.setEnabled(true);
amountField.setEditable(true);
amountField.setDecimal(t.getAmount(this.getAccount()).abs());
for (TransactionEntry entry : t.getTransactionEntries()) {
if (entry.getCreditAccount() == this.getAccount()) {
accountPanel.setExchangedAmount(entry.getDebitAmount().abs());
break;
} else if (entry.getDebitAccount() == this.getAccount()) {
accountPanel.setExchangedAmount(entry.getCreditAmount());
break;
}
}
}
} else if (t instanceof InvestmentTransaction) {
Logger logger = Logger.getLogger(TransactionPanel.class.getName());
logger.warning("unsupported transaction type");
} else {
// DoubleEntryTransaction
accountPanel.setEnabled(!t.areAccountsHidden());
amountField.setEnabled(true);
datePanel.setEditable(true);
}
// setup the accountCombo correctly
if (t.getTransactionType() == TransactionType.DOUBLEENTRY) {
TransactionEntry entry = t.getTransactionEntries().get(0);
if (panelType == PanelType.DECREASE) {
accountPanel.setSelectedAccount(entry.getCreditAccount());
accountPanel.setExchangedAmount(entry.getCreditAmount());
} else {
accountPanel.setSelectedAccount(entry.getDebitAccount());
accountPanel.setExchangedAmount(entry.getDebitAmount().abs());
}
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class TransactionPanel method buildTransactionEntry.
private 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(accountPanel.getExchangedAmount().abs().negate());
}
} else {
entry.setCreditAccount(getAccount());
entry.setDebitAccount(accountPanel.getSelectedAccount());
if (hasEqualCurrencies()) {
entry.setAmount(amountField.getDecimal().abs());
} else {
entry.setCreditAmount(accountPanel.getExchangedAmount().abs());
}
}
entry.setReconciled(account, getReconciledState());
return entry;
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class TransactionPanel method modifyTransaction.
/**
* Modifies an existing transaction.
*/
@Override
public void modifyTransaction(final Transaction t) {
// check for a locked account and issue a warning if necessary
if (t.areAccountsLocked()) {
clearForm();
StaticUIMethods.displayError(rb.getString("Message.TransactionModifyLocked"));
return;
}
// load the form
newTransaction(t);
// save reference to old transaction
modTrans = t;
modTrans = attachmentPanel.modifyTransaction(modTrans);
// disable editing if already concatenated
memoField.setEnabled(!modTrans.isMemoConcatenated());
if (!canModifyTransaction(t) && t.getTransactionType() == TransactionType.SPLITENTRY) {
for (TransactionEntry entry : t.getTransactionEntries()) {
if (entry.getCreditAccount().equals(getAccount()) || entry.getDebitAccount().equals(getAccount())) {
modEntry = entry;
// override to allow editing the entry
memoField.setEnabled(true);
break;
}
}
if (modEntry == null) {
Logger logger = Logger.getLogger(TransactionPanel.class.getName());
logger.warning("Was not able to modify the transaction");
}
}
}
use of jgnash.engine.TransactionEntry in project jgnash by ccavanaugh.
the class AdjustmentPanel method convertAction.
/**
* Helps convert an existing single entry transaction into a double entry transaction
*/
private void convertAction() {
AccountListDialog d = new AccountListDialog();
d.disableAccount(getAccount());
d.disablePlaceHolders();
d.setVisible(true);
if (!d.getReturnStatus()) {
return;
}
Account opp = d.getAccount();
Transaction t = new Transaction();
t.setDate(datePanel.getLocalDate());
t.setNumber(numberField.getText());
t.setPayee(payeeField.getText());
TransactionEntry entry = new TransactionEntry();
entry.setMemo(memoField.getText());
if (amountField.getDecimal().signum() >= 0) {
entry.setCreditAccount(getAccount());
entry.setDebitAccount(opp);
} else {
entry.setDebitAccount(getAccount());
entry.setCreditAccount(opp);
}
entry.setCreditAmount(amountField.getDecimal().abs());
entry.setDebitAmount(amountField.getDecimal().abs().negate());
ReconcileManager.reconcileTransaction(getAccount(), t, getReconciledState());
t.addTransactionEntry(entry);
Transaction tran = TransactionDialog.showDialog(getAccount(), t);
if (tran != null) {
if (getEngine().removeTransaction(modTrans)) {
getEngine().addTransaction(tran);
}
clearForm();
}
}
Aggregations