use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class AbstractRegisterPanel method deleteAction.
protected void deleteAction() {
Transaction[] trans = getSelectedTransactions();
if (RegisterFactory.isConfirmTransactionDeleteEnabled()) {
if (!confirmTransactionRemoval(trans.length)) {
return;
}
}
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
// walk through the array and delete each transaction
for (Transaction tran : trans) {
if (engine.removeTransaction(tran)) {
if (tran.getAttachment() != null) {
if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(rb.getString("Question.DeleteAttachment")), rb.getString("Title.DeleteAttachment"))) {
if (!engine.removeAttachment(tran.getAttachment())) {
StaticUIMethods.displayError(ResourceUtils.getString("Message.Error.DeleteAttachment", tran.getAttachment()));
}
}
}
}
}
// Request focus as it may have been lost
requestFocusInWindow();
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterPanel method modifyTransaction.
@Override
protected void modifyTransaction(final int index) {
if (index >= model.getRowCount()) {
throw new IllegalArgumentException("RegisterPanel: should not have exceeded model size");
}
Transaction t = model.getTransactionAt(index);
if (t instanceof InvestmentTransaction) {
((AbstractEntryFormPanel) tabbedPane.getSelectedComponent()).clearForm();
InvestmentTransactionDialog.showDialog((InvestmentTransaction) t);
return;
}
if (t.getTransactionType() == TransactionType.SINGLENTRY) {
tabbedPane.setSelectedComponent(adjustPanel);
adjustPanel.modifyTransaction(t);
} else if (t.getAmount(account).signum() >= 0) {
tabbedPane.setSelectedComponent(creditPanel);
creditPanel.modifyTransaction(t);
} else {
tabbedPane.setSelectedComponent(debitPanel);
debitPanel.modifyTransaction(t);
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class PayeePieChart method createPieDataSet.
private PieDataset[] createPieDataSet(final Account a) {
final DefaultPieDataset[] returnValue = new DefaultPieDataset[2];
returnValue[CREDIT] = new DefaultPieDataset();
returnValue[DEBIT] = new DefaultPieDataset();
if (a != null) {
//System.out.print("Account = "); System.out.println(a);
Map<String, BigDecimal> names = new HashMap<>();
List<TranTuple> list = getTransactions(a, new ArrayList<>(), startField.getLocalDate(), endField.getLocalDate());
CurrencyNode currency = a.getCurrencyNode();
for (final TranTuple tranTuple : list) {
Transaction tran = tranTuple.transaction;
Account account = tranTuple.account;
String payee = tran.getPayee();
BigDecimal sum = tran.getAmount(account);
sum = sum.multiply(account.getCurrencyNode().getExchangeRate(currency));
if (useFilters.isSelected()) {
for (String aFilterList : filterList) {
PayeeMatcher pm = new PayeeMatcher(aFilterList, false);
if (pm.matches(tran)) {
payee = aFilterList;
//System.out.println(filterList.get(i));
break;
}
}
}
if (names.containsKey(payee)) {
sum = sum.add(names.get(payee));
}
names.put(payee, sum);
}
for (final Map.Entry<String, BigDecimal> entry : names.entrySet()) {
BigDecimal value = entry.getValue();
if (value.compareTo(BigDecimal.ZERO) == -1) {
value = value.negate();
returnValue[DEBIT].setValue(entry.getKey(), value);
} else {
returnValue[CREDIT].setValue(entry.getKey(), value);
}
}
}
return returnValue;
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class InvestmentRegisterTableModel method getInternalValueAt.
@Override
public Object getInternalValueAt(int row, int col) {
InvestmentTransaction _t = null;
Transaction t = getTransactionAt(row);
if (t instanceof InvestmentTransaction) {
_t = (InvestmentTransaction) t;
}
switch(col) {
case 0:
return t.getLocalDate();
case 1:
if (_t != null) {
return _t.getTransactionType().toString();
} else if (t.getAmount(account).signum() > 0) {
return rb.getString("Item.CashDeposit");
}
return rb.getString("Item.CashWithdrawal");
case 2:
if (_t != null) {
return _t.getSecurityNode().getSymbol();
}
return t.getMemo();
case 3:
return t.getReconciled(account).toString();
case // quantity
4:
if (_t != null) {
BigDecimal quantity = _t.getQuantity();
if (quantity.compareTo(BigDecimal.ZERO) != 0) {
return quantity;
}
}
return null;
case // price
5:
if (_t != null) {
BigDecimal price = _t.getPrice();
if (price.compareTo(BigDecimal.ZERO) != 0) {
return price;
}
}
return null;
case // net cash amount
6:
if (_t != null) {
return _t.getNetCashValue();
}
return t.getAmount(account);
default:
return ERROR;
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTableModel method getInternalValueAt.
@Override
protected Object getInternalValueAt(int row, int col) {
Transaction t = getTransactionAt(row);
BigDecimal amount = t.getAmount(account);
int signum = amount.signum();
switch(col) {
case 0:
return t.getLocalDate();
case 1:
return t.getNumber();
case 2:
return t.getPayee();
case 3:
return t.getMemo();
case 4:
if (t instanceof InvestmentTransaction) {
return ((InvestmentTransaction) t).getInvestmentAccount().getName();
}
int count = t.size();
if (count > 1) {
return "[ " + count + " " + split + " ]";
}
Account creditAccount = t.getTransactionEntries().get(0).getCreditAccount();
if (creditAccount != account) {
return creditAccount.getName();
}
return t.getTransactionEntries().get(0).getDebitAccount().getName();
case 5:
return t.getReconciled(account).toString();
case 6:
if (signum >= 0) {
return amount;
}
return null;
case 7:
if (signum < 0) {
return amount.abs();
}
return null;
case 8:
return getBalanceAt(row);
default:
return ERROR;
}
}
Aggregations