use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class InvestmentRegisterPanel method modifyTransaction.
@Override
protected void modifyTransaction(int index) {
Transaction t = model.getTransactionAt(index);
transactionPanel.modifyTransaction(t);
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTableWithSplitEntriesModel method updateData.
/**
* Update the internal data from the specified index. Note that this index is not relative to the account
* transaction list but to the internal data.
*
* @param startIndex internal data index from which transactions need to updated.
*/
private void updateData(final int startIndex) {
if (data == null) {
data = new ArrayList<>(0);
}
while (data.size() > startIndex) {
data.remove(startIndex);
}
for (Transaction t : account.getSortedTransactionList()) {
if (data.size() >= startIndex) {
data.add(new TransactionWrapper(t));
if (t.getTransactionType() == TransactionType.SPLITENTRY && showSplitDetails) {
/* Only detail split entries if 2 or more entries impact this account */
int splitImpact = 0;
// count the number of impacting entry(s)
for (TransactionEntry e : t.getTransactionEntries()) {
if (e.getAmount(account).signum() != 0) {
splitImpact++;
}
}
// load only the entries that impact this account
if (splitImpact > 1) {
data.addAll(t.getTransactionEntries().stream().filter(e -> e.getAmount(account).signum() != 0).map(e -> new TransactionWrapper(t, e)).collect(Collectors.toList()));
}
}
}
}
// updating the balance cache too
balanceCache.ensureCapacity(data.size());
balanceCache.clear(startIndex);
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTableWithSplitEntriesModel method getBalanceAt.
@Override
BigDecimal getBalanceAt(final int index) {
if (balanceCache.get(index) != null) {
return AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), balanceCache.get(index));
}
// cannot rely on account.getBalanceAt()
BigDecimal balance = null;
Transaction t = data.get(index).transaction;
if (account.contains(t) && data.get(index).entry == null) {
// top level only
balance = BigDecimal.ZERO;
for (int i = 0; i <= index; i++) {
Transaction tran = data.get(i).transaction;
if (data.get(i).entry == null && account.contains(tran)) {
balance = balance.add(tran.getAmount(account));
}
}
}
balanceCache.set(index, balance);
return AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), balance);
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class RegisterTableWithSplitEntriesModel method messagePosted.
@Override
public void messagePosted(final Message event) {
if (account.equals(event.getObject(MessageProperty.ACCOUNT))) {
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case FILE_CLOSING:
unregister();
break;
case TRANSACTION_ADD:
Transaction t = event.getObject(MessageProperty.TRANSACTION);
updateData();
int index = indexOfWrapper(t);
if (index >= 0) {
fireTableRowsInserted(index, index);
}
break;
case TRANSACTION_REMOVE:
updateData();
fireTableDataChanged();
break;
default:
break;
}
});
}
}
use of jgnash.engine.Transaction in project jgnash by ccavanaugh.
the class SellSharePanel 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());
gainsPanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentGainLossEntries());
entries.stream().filter(e -> e instanceof TransactionEntrySellX).forEach(e -> {
final AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e;
memoField.setText(e.getMemo());
priceField.setDecimal(entry.getPrice());
quantityField.setDecimal(entry.getQuantity());
securityCombo.setSelectedNode(entry.getSecurityNode());
accountExchangePanel.setSelectedAccount(entry.getDebitAccount());
accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs());
});
updateTotalField();
modTrans = tran;
setReconciledState(tran.getReconciled(getAccount()));
}
Aggregations