use of jgnash.engine.CommodityNode in project jgnash by ccavanaugh.
the class AccountSecurityComboBox method messagePosted.
@Override
public void messagePosted(final Message event) {
final Account a = event.getObject(MessageProperty.ACCOUNT);
if (account.equals(a)) {
final SecurityNode node = event.getObject(MessageProperty.COMMODITY);
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case ACCOUNT_REMOVE:
MessageBus.getInstance().unregisterListener(AccountSecurityComboBox.this, MessageChannel.ACCOUNT, MessageChannel.COMMODITY);
model.removeAllElements();
account = null;
break;
case ACCOUNT_SECURITY_ADD:
model.addElement(node);
break;
case SECURITY_REMOVE:
case ACCOUNT_SECURITY_REMOVE:
final CommodityNode commodityNode = getSelectedNode();
model.removeElement(node);
if (commodityNode != null && node != null) {
if (commodityNode.equals(node)) {
setSelectedItem(null);
}
}
break;
case SECURITY_MODIFY:
updateNode(node);
break;
default:
}
});
}
}
use of jgnash.engine.CommodityNode in project jgnash by ccavanaugh.
the class ModifyCurrencyController method messagePosted.
@Override
public void messagePosted(final Message message) {
final CommodityNode node = message.getObject(MessageProperty.COMMODITY);
if (node instanceof CurrencyNode) {
switch(message.getEvent()) {
case CURRENCY_REMOVE:
listView.getItems().remove(node);
if (node.equals(selectedCurrency.get())) {
handleClearAction();
}
break;
case CURRENCY_REMOVE_FAILED:
StaticUIMethods.displayError(resources.getString("Message.Warn.CurrencyInUse"));
break;
case CURRENCY_ADD:
case CONFIG_MODIFY:
handleClearAction();
loadModel();
break;
case CURRENCY_ADD_FAILED:
StaticUIMethods.displayError(resources.getString("Message.Error.AddCurrency"));
break;
case CURRENCY_MODIFY_FAILED:
StaticUIMethods.displayError(resources.getString("Message.Error.ModifyCurrency"));
break;
default:
}
}
}
use of jgnash.engine.CommodityNode in project jgnash by ccavanaugh.
the class LiabilityRegisterPanel method paymentActionDebit.
/* creates the payment transaction relative to the debit account */
private void paymentActionDebit() {
AmortizeObject ao = account.getAmortizeObject();
if (ao != null) {
Transaction tran = null;
DateChkNumberDialog d = new DateChkNumberDialog(ao.getBankAccount(), rb.getString("Title.NewTrans"));
d.setVisible(true);
if (!d.getResult()) {
return;
}
BigDecimal balance = account.getBalance().abs();
double payment = ao.getPayment();
double interest;
if (ao.getUseDailyRate()) {
LocalDate today = d.getDate();
LocalDate last;
if (account.getTransactionCount() > 0) {
last = account.getTransactionAt(account.getTransactionCount() - 1).getLocalDate();
} else {
last = today;
}
// get the interest portion
interest = ao.getIPayment(balance, last, today);
} else {
// get the interest portion
interest = ao.getIPayment(balance);
}
// get debit account
Account bank = ao.getBankAccount();
if (bank != null) {
CommodityNode n = bank.getCurrencyNode();
Transaction transaction = new Transaction();
transaction.setDate(d.getDate());
transaction.setNumber(d.getNumber());
transaction.setPayee(ao.getPayee());
// transaction is made relative to the debit/checking account
TransactionEntry e = new TransactionEntry();
// this entry is the principal payment
e.setCreditAccount(account);
e.setDebitAccount(bank);
e.setAmount(n.round(payment - interest));
e.setMemo(ao.getMemo());
transaction.addTransactionEntry(e);
// handle interest portion of the payment
Account i = ao.getInterestAccount();
if (i != null && interest != 0.0) {
e = new TransactionEntry();
e.setCreditAccount(i);
e.setDebitAccount(bank);
e.setAmount(n.round(interest));
e.setMemo(rb.getString("Word.Interest"));
transaction.addTransactionEntry(e);
//System.out.println(e.getAmount());
}
// a fee has been assigned
if (ao.getFees().compareTo(BigDecimal.ZERO) != 0) {
Account f = ao.getFeesAccount();
if (f != null) {
e = new TransactionEntry();
e.setCreditAccount(f);
e.setDebitAccount(bank);
e.setAmount(ao.getFees());
e.setMemo(rb.getString("Word.Fees"));
transaction.addTransactionEntry(e);
//System.out.println(e.getAmount());
}
}
// the remainder of the balance should be loan principal
tran = transaction;
}
if (tran != null) {
// display the transaction in the register
EditTransactionDialog dlg = new EditTransactionDialog(ao.getBankAccount(), PanelType.DECREASE);
dlg.newTransaction(tran);
dlg.setVisible(true);
} else {
StaticUIMethods.displayWarning(rb.getString("Message.Warn.ConfigAmortization"));
}
} else {
// could not generate the transaction
StaticUIMethods.displayWarning(rb.getString("Message.Warn.ConfigAmortization"));
}
}
use of jgnash.engine.CommodityNode in project jgnash by ccavanaugh.
the class RegisterTable method init.
private void init() {
setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
setCellSelectionEnabled(true);
setRowSelectionAllowed(true);
setColumnSelectionAllowed(false);
getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
setShowGrid(false);
setFillsViewportHeight(true);
AccountTableModel model = (AccountTableModel) getModel();
CommodityNode node = model.getAccount().getCurrencyNode();
fullFormat = CommodityFormat.getFullNumberFormat(node);
shortFormat = CommodityFormat.getShortNumberFormat(node);
// disable tool tips to improve speed
ToolTipManager.sharedInstance().unregisterComponent(getTableHeader());
}
use of jgnash.engine.CommodityNode in project jgnash by ccavanaugh.
the class CurrencyModifyDialog method messagePosted.
@Override
public void messagePosted(final Message event) {
final CommodityNode node = event.getObject(MessageProperty.COMMODITY);
if (node instanceof CurrencyNode) {
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case CURRENCY_REMOVE:
model.removeElement((CurrencyNode) node);
if (currentCurrency.equals(node)) {
clearForm();
}
break;
case CURRENCY_REMOVE_FAILED:
JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Warn.CurrencyInUse"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
case CURRENCY_ADD:
clearForm();
model.addElement((CurrencyNode) node);
break;
case CURRENCY_ADD_FAILED:
JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Error.AddCurrency"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
case CURRENCY_MODIFY:
// node will be stale
model.removeElement((CurrencyNode) node);
model.addElement(getEngine().getCurrency(node.getSymbol()));
if (currentCurrency.equals(node)) {
updateForm();
}
break;
case CURRENCY_MODIFY_FAILED:
JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Error.ModifyCurrency"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
default:
break;
}
});
}
}
Aggregations