use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class BudgetResultsModel method areParentsIncluded.
private boolean areParentsIncluded(final Account account) {
boolean result = true;
Account parent = account.getParent();
if (parent != null && !(parent instanceof RootAccount)) {
if (!includeAccount(parent)) {
result = false;
} else {
result = areParentsIncluded(parent);
}
}
return result;
}
use of jgnash.engine.Account 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.Account in project jgnash by ccavanaugh.
the class RegisterTable method getToolTipText.
@Override
public String getToolTipText(@NotNull final MouseEvent event) {
int[] rows = getSelectedRows();
if (rows.length > 1) {
AccountTableModel model = (AccountTableModel) getModel();
Account account = model.getAccount();
CurrencyNode node = account.getCurrencyNode();
BigDecimal amount = BigDecimal.ZERO;
// correct the row indexes if the model is sorted
if (model instanceof SortedTableModel) {
for (int i = 0; i < rows.length; i++) {
rows[i] = ((SortedTableModel) model).convertRowIndexToAccount(rows[i]);
}
}
for (int row : rows) {
amount = amount.add(AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), account.getTransactionAt(row).getAmount(account)));
}
return CommodityFormat.getFullNumberFormat(node).format(amount);
}
return null;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class ApiTest method testTransactionAPI.
@Test
public void testTransactionAPI() {
final String ACCOUNT_NAME = "testAccount";
final CurrencyNode node = e.getDefaultCurrency();
final Account a = new Account(AccountType.BANK, node);
a.setName(ACCOUNT_NAME);
e.addAccount(e.getRootAccount(), a);
// Test single entry transaction
final Transaction transaction = TransactionFactory.generateSingleEntryTransaction(a, BigDecimal.TEN, LocalDate.now(), "memo", "payee", "1");
e.addTransaction(transaction);
assertEquals(TransactionType.SINGLENTRY, transaction.getTransactionType());
for (final TransactionEntry transactionEntry : transaction.getTransactionEntries()) {
assertFalse(transactionEntry.isMultiCurrency());
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class ApiTest method testAccountAttributes.
@Test
public void testAccountAttributes() throws IOException {
CurrencyNode node = e.getDefaultCurrency();
Account a = new Account(AccountType.BANK, node);
a.setName("AccountAttributes");
e.addAccount(e.getRootAccount(), a);
e.setAccountAttribute(a, "myStuff", "gobbleDeGook");
e.setAccountAttribute(a, "myKey", "myValue");
e.setAccountAttribute(a, "myNumber", BigDecimal.TEN.toString());
Account b = e.getAccountByUuid(a.getUuid());
assertEquals("gobbleDeGook", e.getAccountAttribute(b, "myStuff"));
// close and reopen to force check for persistence
closeEngine();
e = EngineFactory.bootLocalEngine(database, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD);
b = e.getAccountByUuid(a.getUuid());
assertEquals("gobbleDeGook", e.getAccountAttribute(b, "myStuff"));
assertEquals("myValue", e.getAccountAttribute(b, "myKey"));
String attribute = e.getAccountAttribute(b, "myNumber");
assertNotNull(attribute);
assertEquals(BigDecimal.TEN, new BigDecimal(attribute));
}
Aggregations