This commit is contained in:
James Cole 2019-09-15 08:16:43 +02:00
parent 2cc7721007
commit 412b914f66
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
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,

2
public/v1/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@ -48,7 +48,7 @@
:async-src="accountAutoCompleteURI"
v-model="name"
:target="target"
item-key="name"
item-key="name_with_balance"
></typeahead>
<ul class="list-unstyled" v-for="error in this.error">
<li class="text-danger">{{ error }}</li>

View File

@ -19,7 +19,7 @@
-->
<template>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}" v-if="(this.enabledCurrencies.length > 2 && this.transactionType === 'Deposit') || this.transactionType.toLowerCase() === 'transfer'">
<div class="form-group" v-bind:class="{ 'has-error': hasError()}" v-if="null == this.transactionType || null != this.transactionType && (this.enabledCurrencies.length > 2 && this.transactionType === 'Deposit') || this.transactionType.toLowerCase() === 'transfer'">
<div class="col-sm-4">
<select class="form-control" ref="currency_select" name="foreign_currency[]" @input="handleInput">
<option