use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountTools method modifyAccount.
static void modifyAccount(final Account account) {
if (account == null) {
return;
}
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final ResourceBundle rb = ResourceUtils.getBundle();
final Account parentAccount = account.getParent();
if (parentAccount == null) {
if (engine.getRootAccount() == null) {
// no root account at all, file was closed
return;
}
account.setParent(engine.getRootAccount());
}
AccountDialog dlg = new AccountDialog();
dlg.setTitle(rb.getString("Title.ModifyAccount"));
dlg.setModifyingAccount(account);
dlg.setParentAccount(account.getParent());
dlg.setAccountName(account.getName());
dlg.setAccountDescription(account.getDescription());
dlg.setAccountCode(account.getAccountCode());
dlg.setAccountNumber(account.getAccountNumber());
dlg.setBankId(account.getBankId());
dlg.setCurrency(account.getCurrencyNode());
dlg.setAccountNotes(account.getNotes());
dlg.setAccountLocked(account.isLocked());
dlg.setAccountVisible(account.isVisible());
dlg.setExcludedFromBudget(account.isExcludedFromBudget());
if (account.getAccountType().getAccountGroup() == AccountGroup.INVEST) {
dlg.setAccountSecurities(account.getSecurities());
}
dlg.setAccountType(account.getAccountType());
dlg.disableAccountType(account.getAccountType());
if (account.getTransactionCount() > 0) {
dlg.disableAccountCurrency();
}
if (account.getTransactionCount() > 0) {
dlg.setPlaceholderEnabled(false);
} else {
dlg.setAccountPlaceholder(account.isPlaceHolder());
}
dlg.setVisible(true);
if (dlg.returnStatus()) {
Account tAccount = new Account(dlg.getAccountType(), dlg.getCurrency());
// set the data
tAccount.setAccountCode(dlg.getAccountCode());
tAccount.setAccountNumber(dlg.getAccountNumber());
tAccount.setBankId(dlg.getBankId());
tAccount.setName(dlg.getAccountName());
tAccount.setDescription(dlg.getAccountDescription());
tAccount.setNotes(dlg.getAccountNotes());
tAccount.setLocked(dlg.isAccountLocked());
tAccount.setPlaceHolder(dlg.isAccountPlaceholder());
if (dlg.getParentAccount() == account) {
tAccount.setParent(account.getParent());
Logger.getLogger(AccountTools.class.getName()).warning("Prevented an attempt to assign accounts parent to itself");
} else {
tAccount.setParent(dlg.getParentAccount());
}
tAccount.setVisible(dlg.isAccountVisible());
tAccount.setExcludedFromBudget(dlg.isExcludedFromBudget());
if (!engine.modifyAccount(tAccount, account)) {
StaticUIMethods.displayError(rb.getString("Message.Error.AccountUpdate"));
}
if (account.getAccountType().getAccountGroup() == AccountGroup.INVEST) {
if (!engine.updateAccountSecurities(account, dlg.getAccountSecurities())) {
StaticUIMethods.displayError(rb.getString("Message.Error.SecurityAccountUpdate"));
}
}
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AmortizeDialog method fillForm.
private void fillForm() {
interestField.setDecimal(ao.getRate());
loanAmountField.setDecimal(ao.getPrincipal());
loanTermField.setIntValue(ao.getLength());
payPeriodsField.setIntValue(ao.getPaymentPeriods());
intPeriodsField.setIntValue(ao.getInterestPeriods());
feesField.setDecimal(ao.getFees());
memoField.setText(ao.getMemo());
payeeField.setText(ao.getPayee());
dateField.setDate(ao.getDate());
daysField.setDecimal(ao.getDaysPerYear());
useDaysButton.setSelected(ao.getUseDailyRate());
daysField.setEnabled(ao.getUseDailyRate());
Account a = ao.getBankAccount();
if (a != null) {
bankAccount = a;
bankAccButton.setText(a.getName());
}
a = ao.getInterestAccount();
if (a != null) {
interestAccount = a;
interestAccButton.setText(a.getName());
}
a = ao.getFeesAccount();
if (a != null) {
feesAccount = a;
feesAccButton.setText(a.getName());
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AmortizeDialog method actionPerformed.
/**
* Invoked when an action occurs.
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cancelButton) {
closeDialog();
} else if (e.getSource() == okButton) {
result = true;
closeDialog();
} else if (e.getSource() == bankAccButton) {
Account a = showAccountListDialog(bankAccount);
if (a != null) {
bankAccount = a;
bankAccButton.setText(a.getName());
} else {
bankAccButton.setText(rb.getString("Word.None"));
}
} else if (e.getSource() == interestAccButton) {
Account a = showAccountListDialog(interestAccount);
if (a != null) {
interestAccount = a;
interestAccButton.setText(a.getName());
} else {
interestAccButton.setText(rb.getString("Word.None"));
}
} else if (e.getSource() == feesAccButton) {
Account a = showAccountListDialog(feesAccount);
if (a != null) {
feesAccount = a;
feesAccButton.setText(a.getName());
} else {
feesAccButton.setText(rb.getString("Word.None"));
}
} else if (e.getSource() == useDaysButton) {
daysField.setEnabled(useDaysButton.isSelected());
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountListTreePane method messagePosted.
@Override
public void messagePosted(final Message event) {
if (event.getEvent() == ChannelEvent.FILE_CLOSING) {
EventQueue.invokeLater(AccountListTreePane.this::close);
return;
}
if (EngineFactory.getEngine(EngineFactory.DEFAULT) == null) {
return;
}
final Account a = event.getObject(MessageProperty.ACCOUNT);
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case ACCOUNT_ADD:
model.reload();
expand();
break;
case ACCOUNT_MODIFY:
model.reload();
expand();
break;
case ACCOUNT_REMOVE:
if (a != null && selectedAccount != null) {
if (selectedAccount.equals(a)) {
selectedAccount = null;
}
model.removeAccount(a);
} else {
model.reload();
expand();
}
break;
case ACCOUNT_VISIBILITY_CHANGE:
model.reload();
expand();
break;
case FILE_LOAD_SUCCESS:
refresh();
expand();
break;
default:
// ignore any other messages that don't belong to us
break;
}
});
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BuySharePanel method modifyTransaction.
@Override
public void modifyTransaction(final Transaction tran) {
if (!(tran instanceof InvestmentTransaction)) {
throw new IllegalArgumentException("bad tranType");
}
clearForm();
datePanel.setDate(tran.getLocalDate());
List<TransactionEntry> entries = tran.getTransactionEntries();
feePanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentFeeEntries());
entries.stream().filter(e -> e instanceof TransactionEntryBuyX).forEach(e -> {
AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityCombo.setSelectedNode(entry.getSecurityNode());
if (entry.getCreditAccount().equals(account)) {
accountExchangePanel.setSelectedAccount(entry.getDebitAccount());
accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
} else {
accountExchangePanel.setSelectedAccount(entry.getCreditAccount());
accountExchangePanel.setExchangedAmount(entry.getCreditAmount());
}
});
updateTotalField();
modTrans = tran;
setReconciledState(tran.getReconciled(getAccount()));
}
Aggregations