diff --git a/jgnash-core/src/main/java/jgnash/engine/InvestmentPerformanceSummary.java b/jgnash-core/src/main/java/jgnash/engine/InvestmentPerformanceSummary.java index ed9c9e192..5e34e2d44 100644 --- a/jgnash-core/src/main/java/jgnash/engine/InvestmentPerformanceSummary.java +++ b/jgnash-core/src/main/java/jgnash/engine/InvestmentPerformanceSummary.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -61,10 +62,6 @@ public InvestmentPerformanceSummary(final Account account, final LocalDate start this.recursive = recursive; - if (!account.memberOf(AccountGroup.INVEST)) { - throw new IllegalArgumentException("The account is not a valid type"); - } - this.baseCurrency = account.getCurrencyNode(); this.account = account; @@ -79,54 +76,65 @@ public InvestmentPerformanceSummary(final Account account, final LocalDate start setEndDate(endDate); } - transactions = account.getTransactions(getStartDate(), getEndDate()); - - if (recursive && account.getChildCount() > 0) { - collectSubAccountTransactions(account, transactions); - } + transactions = new ArrayList<>(); + collectAccountTransactions(account, transactions); Collections.sort(transactions); } public static Pair getTransactionDateRange(final Account account, final boolean recursive) { - List transactions = new ArrayList<>(account.getSortedTransactionList()); - - if (recursive && account.getChildCount() > 0) { - _collectSubAccountTransactions(account, transactions); - } + List transactions = new ArrayList<>(); + _collectAccountTransactions(account, recursive, transactions); transactions.sort(null); - return new ImmutablePair<>(transactions.get(0).getLocalDate(), - transactions.get(transactions.size() - 1).getLocalDate()); + if (transactions.size() > 0) { + return new ImmutablePair<>(transactions.get(0).getLocalDate(), + transactions.get(transactions.size() - 1).getLocalDate()); + } else { + LocalDate now = LocalDate.now(); + return new ImmutablePair<>(now, now); + } } - private static void _collectSubAccountTransactions(final Account account, final List transactions) { - for (final Account child : account.getChildren(Comparators.getAccountByCode())) { - transactions.addAll(child.getSortedTransactionList()); + private static void _collectAccountTransactions(final Account account, final boolean recursive, final List transactions) { + if (account.memberOf(AccountGroup.INVEST)) { + transactions.addAll(account.getSortedTransactionList()); + } - if (child.getChildCount() > 0) { - _collectSubAccountTransactions(child, transactions); + if (recursive) { + for (final Account child : account.getChildren(Comparators.getAccountByCode())) { + if (child.getChildCount() > 0) { + _collectAccountTransactions(child, recursive, transactions); + } } } } - private void collectSubAccountTransactions(final Account account, final List transactions) { - for (final Account child : account.getChildren(Comparators.getAccountByCode())) { - transactions.addAll(child.getTransactions(getStartDate(), getEndDate())); - - if (child.getChildCount() > 0) { - collectSubAccountTransactions(child, transactions); + private void collectAccountTransactions(final Account account, final List transactions) { + if (account.memberOf(AccountGroup.INVEST)) { + transactions.addAll(account.getTransactions(getStartDate(), getEndDate())); + } + + if (recursive) { + for (final Account child : account.getChildren(Comparators.getAccountByCode())) { + if (child.getChildCount() > 0) { + collectAccountTransactions(child, transactions); + } } } } - private void collectSubAccountSecurities(final Account account, final Set securities) { - for (final Account child : account.getChildren(Comparators.getAccountByCode())) { - securities.addAll(child.getSecurities()); - - if (child.getChildCount() > 0) { - collectSubAccountSecurities(child, securities); + private void collectAccountSecurities(final Account account, final Set securities) { + if (account.memberOf(AccountGroup.INVEST)) { + securities.addAll(account.getSecurities()); + } + + if (recursive) { + for (final Account child : account.getChildren(Comparators.getAccountByCode())) { + if (child.getChildCount() > 0) { + collectAccountSecurities(child, securities); + } } } } @@ -375,11 +383,8 @@ private void calculateInternalRateOfReturn(final SecurityPerformanceData data, f public void runCalculations() { - Set nodes = account.getSecurities(); - - if (recursive) { - collectSubAccountSecurities(account, nodes); - } + Set nodes = new TreeSet<>(); + collectAccountSecurities(account, nodes); for (final SecurityNode node : nodes) { SecurityPerformanceData data = new SecurityPerformanceData(node); diff --git a/jgnash-fx/src/main/java/jgnash/uifx/control/AccountComboBox.java b/jgnash-fx/src/main/java/jgnash/uifx/control/AccountComboBox.java index 3dd471bc1..c9c598053 100644 --- a/jgnash-fx/src/main/java/jgnash/uifx/control/AccountComboBox.java +++ b/jgnash-fx/src/main/java/jgnash/uifx/control/AccountComboBox.java @@ -166,7 +166,8 @@ public void setPredicate(final Predicate predicate) { private void selectDefaultAccount() { // Set a default account, must use the filtered list because that is what is visible if (filteredList.size() > 0) { - JavaFXUtils.runLater(() -> setValue(filteredList.get(0))); + final Account account = filteredList.get(0); + JavaFXUtils.runLater(() -> setValue(account)); } } diff --git a/jgnash-fx/src/main/java/jgnash/uifx/views/register/SlipController.java b/jgnash-fx/src/main/java/jgnash/uifx/views/register/SlipController.java index ff2df12ee..8c508d3a8 100644 --- a/jgnash-fx/src/main/java/jgnash/uifx/views/register/SlipController.java +++ b/jgnash-fx/src/main/java/jgnash/uifx/views/register/SlipController.java @@ -292,10 +292,12 @@ private void newTransaction(final Transaction t) { for (final TransactionEntry entry : t.getTransactionEntries()) { if (entry.getCreditAccount() == accountProperty().get()) { accountExchangePane.setExchangedAmount(entry.getDebitAmount().abs()); + accountExchangePane.setSelectedAccount(entry.getDebitAccount()); tagPane.setSelectedTags(entry.getTags()); break; } else if (entry.getDebitAccount() == accountProperty().get()) { accountExchangePane.setExchangedAmount(entry.getCreditAmount()); + accountExchangePane.setSelectedAccount(entry.getCreditAccount()); tagPane.setSelectedTags(entry.getTags()); break; }