mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #2966
This commit is contained in:
parent
2485f74302
commit
a2a980e3de
@ -125,6 +125,14 @@ class AutoCompleteController extends Controller
|
|||||||
$filtered = $result->unique('description');
|
$filtered = $result->unique('description');
|
||||||
$limited = $filtered->slice(0, 15);
|
$limited = $filtered->slice(0, 15);
|
||||||
$array = $limited->toArray();
|
$array = $limited->toArray();
|
||||||
|
// duplicate 'description' value into 'name':
|
||||||
|
$array = array_map(
|
||||||
|
static function (array $journal) {
|
||||||
|
$journal['name'] = $journal['description'];
|
||||||
|
|
||||||
|
return $journal;
|
||||||
|
}, $array
|
||||||
|
);
|
||||||
|
|
||||||
return response()->json(array_values($array));
|
return response()->json(array_values($array));
|
||||||
}
|
}
|
||||||
@ -174,6 +182,38 @@ class AutoCompleteController extends Controller
|
|||||||
return response()->json($array);
|
return response()->json($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An auto-complete specifically for asset accounts and liabilities, used when mass updating and for rules mostly.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function assetAccounts(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$search = $request->get('search');
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
|
||||||
|
// filter the account types:
|
||||||
|
$allowedAccountTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||||
|
Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes);
|
||||||
|
|
||||||
|
$return = [];
|
||||||
|
$result = $repository->searchAccount((string)$search, $allowedAccountTypes);
|
||||||
|
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($result as $account) {
|
||||||
|
$return[] = [
|
||||||
|
'id' => $account->id,
|
||||||
|
'name' => $account->name,
|
||||||
|
'type' => $account->accountType->type,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json($return);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
@ -283,39 +323,6 @@ class AutoCompleteController extends Controller
|
|||||||
return response()->json($return);
|
return response()->json($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An auto-complete specifically for asset accounts and liabilities, used when mass updating and for rules mostly.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function assetAccounts(Request $request): JsonResponse
|
|
||||||
{
|
|
||||||
$search = $request->get('search');
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
|
||||||
|
|
||||||
// filter the account types:
|
|
||||||
$allowedAccountTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
|
||||||
Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes);
|
|
||||||
|
|
||||||
$return = [];
|
|
||||||
$result = $repository->searchAccount((string)$search, $allowedAccountTypes);
|
|
||||||
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($result as $account) {
|
|
||||||
$return[] = [
|
|
||||||
'id' => $account->id,
|
|
||||||
'name' => $account->name,
|
|
||||||
'type' => $account->accountType->type,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json($return);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
@ -328,12 +335,12 @@ class AutoCompleteController extends Controller
|
|||||||
/** @var AccountRepositoryInterface $accountRepos */
|
/** @var AccountRepositoryInterface $accountRepos */
|
||||||
$accountRepos = app(AccountRepositoryInterface::class);
|
$accountRepos = app(AccountRepositoryInterface::class);
|
||||||
|
|
||||||
$piggies = $repository->getPiggyBanks();
|
$piggies = $repository->getPiggyBanks();
|
||||||
$defaultCurrency = \Amount::getDefaultCurrency();
|
$defaultCurrency = \Amount::getDefaultCurrency();
|
||||||
$response = [];
|
$response = [];
|
||||||
/** @var PiggyBank $piggy */
|
/** @var PiggyBank $piggy */
|
||||||
foreach ($piggies as $piggy) {
|
foreach ($piggies as $piggy) {
|
||||||
$currency = $accountRepos->getAccountCurrency($piggy->account) ?? $defaultCurrency;
|
$currency = $accountRepos->getAccountCurrency($piggy->account) ?? $defaultCurrency;
|
||||||
$currentAmount = $repository->getRepetition($piggy)->currentamount ?? '0';
|
$currentAmount = $repository->getRepetition($piggy)->currentamount ?? '0';
|
||||||
$piggy->name_with_amount = sprintf(
|
$piggy->name_with_amount = sprintf(
|
||||||
'%s (%s / %s)',
|
'%s (%s / %s)',
|
||||||
@ -341,7 +348,7 @@ class AutoCompleteController extends Controller
|
|||||||
app('amount')->formatAnything($currency, $currentAmount, false),
|
app('amount')->formatAnything($currency, $currentAmount, false),
|
||||||
app('amount')->formatAnything($currency, $piggy->targetamount, false),
|
app('amount')->formatAnything($currency, $piggy->targetamount, false),
|
||||||
);
|
);
|
||||||
$response[] = $piggy->toArray();
|
$response[] = $piggy->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($response);
|
return response()->json($response);
|
||||||
|
Loading…
Reference in New Issue
Block a user