This commit is contained in:
James Cole
2019-09-15 08:16:43 +02:00
parent 2cc7721007
commit 412b914f66
4 changed files with 14 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@@ -62,6 +63,7 @@ class AutoCompleteController extends Controller
// filter the account types:
$allowedAccountTypes = [AccountType::ASSET, AccountType::EXPENSE, AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,];
$balanceTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,];
$filteredAccountTypes = [];
foreach ($accountTypes as $type) {
if (in_array($type, $allowedAccountTypes, true)) {
@@ -79,11 +81,18 @@ class AutoCompleteController extends Controller
/** @var Account $account */
foreach ($result as $account) {
$currency = $repository->getAccountCurrency($account);
$currency = $currency ?? $defaultCurrency;
$nameWithBalance = $account->name;
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
if (in_array($account->accountType->type, $balanceTypes, true)) {
$balance = app('steam')->balance($account, new Carbon);
$nameWithBalance = sprintf('%s (%s)', $account->name, app('amount')->formatAnything($currency, $balance, false));
}
$return[] = [
'id' => $account->id,
'name' => $account->name,
'name_with_balance' => $nameWithBalance,
'type' => $account->accountType->type,
'currency_id' => $currency->id,
'currency_name' => $currency->name,