Search in sources :

Example 71 with Account

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;
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount)

Example 72 with Account

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);
}
Also used : EventQueue(java.awt.EventQueue) BigDecimal(java.math.BigDecimal) MessageProperty(jgnash.engine.message.MessageProperty) AccountBalanceDisplayManager(jgnash.ui.register.AccountBalanceDisplayManager) Transaction(jgnash.engine.Transaction) Account(jgnash.engine.Account) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntry(jgnash.engine.TransactionEntry) Collectors(java.util.stream.Collectors) Message(jgnash.engine.message.Message) ArrayList(java.util.ArrayList) TransactionType(jgnash.engine.TransactionType) Transaction(jgnash.engine.Transaction) InvestmentTransaction(jgnash.engine.InvestmentTransaction) TransactionEntry(jgnash.engine.TransactionEntry)

Example 73 with Account

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;
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) BigDecimal(java.math.BigDecimal)

Example 74 with Account

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());
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) TransactionEntry(jgnash.engine.TransactionEntry) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.Test)

Example 75 with Account

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));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) BigDecimal(java.math.BigDecimal) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.Test)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9