/**
   * Add Cash as a separate, automatic asset class that uses all the cash amounts from the
   * investment accounts.
   *
   * @param assetAllocation Main asset allocation object.
   */
  private void addCash(AssetClass assetAllocation) {
    // get all investment accounts, their currencies and cash balances.
    AccountRepository repo = new AccountRepository(getContext());
    AccountService accountService = new AccountService(getContext());
    List<String> investmentAccounts = new ArrayList<>();
    investmentAccounts.add(AccountTypes.INVESTMENT.toString());
    CurrencyService currencyService = new CurrencyService(getContext());
    int destinationCurrency = currencyService.getBaseCurrencyId();
    Money zero = MoneyFactory.fromDouble(0);

    List<Account> accounts = accountService.loadAccounts(false, false, investmentAccounts);

    Money sum = MoneyFactory.fromDouble(0);

    // Get the balances in base currency.
    for (Account account : accounts) {
      int sourceCurrency = account.getCurrencyId();
      Money amountInBase =
          currencyService.doCurrencyExchange(
              destinationCurrency, account.getInitialBalance(), sourceCurrency);
      sum = sum.add(amountInBase);
    }

    // add the cash asset class
    // todo: the allocation needs to be editable!
    AssetClass cash = AssetClass.create(getContext().getString(R.string.cash));
    cash.setType(ItemType.Cash);
    cash.setAllocation(zero);
    cash.setCurrentAllocation(zero);
    cash.setDifference(zero);
    cash.setValue(sum);

    assetAllocation.addChild(cash);
  }
  private String getFormattedAccountBalance(Context context, Account account) {
    WhereStatementGenerator where = new WhereStatementGenerator();
    where.addStatement(QueryAccountBills.ACCOUNTID, "=", account.getId());
    String selection = where.getWhere();

    AccountService service = new AccountService(context);
    Money total = service.loadBalance(selection);

    // format the amount
    CurrencyService currencyService = new CurrencyService(context);
    String summary = currencyService.getCurrencyFormatted(account.getCurrencyId(), total);

    return summary;
  }
  private void displayAccountInfo(Context context, String defaultAccountId, RemoteViews views) {
    int accountId = Integer.parseInt(defaultAccountId);
    Account account = loadAccount(context, accountId);
    if (account == null) return;

    //        CharSequence widgetText = SingleAccountWidgetConfigureActivity.loadTitlePref(context,
    // appWidgetId);

    //        views.setTextViewText(R.id.appwidget_text, widgetText);

    // display the account name
    //        String accountName = getAccountName(context, accountId);
    String accountName = account.getName();
    views.setTextViewText(R.id.accountNameTextView, accountName);

    // get account balance (for this account?)
    String balance = getFormattedAccountBalance(context, account);
    views.setTextViewText(R.id.balanceTextView, balance);
  }