2017-08-15 17:34:34 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AutoCompleteController.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2017-08-15 17:34:34 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-08-15 17:34:34 +02:00
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Json;
|
|
|
|
|
2019-09-15 08:16:43 +02:00
|
|
|
use Carbon\Carbon;
|
2017-08-15 17:34:34 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2019-05-04 20:58:43 +02:00
|
|
|
use FireflyIII\Models\Account;
|
2017-08-15 17:34:34 +02:00
|
|
|
use FireflyIII\Models\AccountType;
|
2019-11-10 07:26:49 +01:00
|
|
|
use FireflyIII\Models\PiggyBank;
|
2019-05-04 20:58:43 +02:00
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2020-01-21 18:02:49 +01:00
|
|
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
2019-05-04 20:58:43 +02:00
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
2019-07-01 20:22:35 +02:00
|
|
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
2019-05-04 20:58:43 +02:00
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
2019-08-27 07:26:32 +02:00
|
|
|
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
2019-07-01 20:22:35 +02:00
|
|
|
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
|
2018-06-01 22:04:52 +02:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2018-09-23 06:57:00 +02:00
|
|
|
use Illuminate\Http\Request;
|
2019-05-04 20:58:43 +02:00
|
|
|
use Log;
|
2017-08-15 17:34:34 +02:00
|
|
|
|
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class AutoCompleteController.
|
2018-07-20 14:34:56 +02:00
|
|
|
*
|
2019-06-29 19:47:31 +02:00
|
|
|
* TODO autocomplete for transaction types.
|
|
|
|
*
|
2017-08-15 17:34:34 +02:00
|
|
|
*/
|
|
|
|
class AutoCompleteController extends Controller
|
|
|
|
{
|
2018-04-07 06:19:40 +02:00
|
|
|
|
2019-05-04 20:58:43 +02:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function accounts(Request $request): JsonResponse
|
|
|
|
{
|
|
|
|
$accountTypes = explode(',', $request->get('types') ?? '');
|
2019-07-01 20:22:35 +02:00
|
|
|
$search = $request->get('search');
|
2019-05-04 20:58:43 +02:00
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
// filter the account types:
|
|
|
|
$allowedAccountTypes = [AccountType::ASSET, AccountType::EXPENSE, AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,];
|
2019-09-15 08:16:43 +02:00
|
|
|
$balanceTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,];
|
2019-05-04 20:58:43 +02:00
|
|
|
$filteredAccountTypes = [];
|
|
|
|
foreach ($accountTypes as $type) {
|
|
|
|
if (in_array($type, $allowedAccountTypes, true)) {
|
|
|
|
$filteredAccountTypes[] = $type;
|
|
|
|
}
|
|
|
|
}
|
2019-08-12 18:17:43 +02:00
|
|
|
if (0 === count($filteredAccountTypes)) {
|
|
|
|
$filteredAccountTypes = $allowedAccountTypes;
|
|
|
|
}
|
2019-08-02 05:25:24 +02:00
|
|
|
Log::debug(sprintf('Now in accounts("%s"). Filtering results.', $search), $filteredAccountTypes);
|
2019-05-04 20:58:43 +02:00
|
|
|
|
|
|
|
$return = [];
|
|
|
|
$result = $repository->searchAccount((string)$search, $filteredAccountTypes);
|
|
|
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
|
|
|
|
|
|
|
/** @var Account $account */
|
|
|
|
foreach ($result as $account) {
|
2019-09-15 08:16:43 +02:00
|
|
|
$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));
|
|
|
|
}
|
|
|
|
|
2019-05-04 20:58:43 +02:00
|
|
|
$return[] = [
|
|
|
|
'id' => $account->id,
|
|
|
|
'name' => $account->name,
|
2019-09-15 08:16:43 +02:00
|
|
|
'name_with_balance' => $nameWithBalance,
|
2019-05-04 20:58:43 +02:00
|
|
|
'type' => $account->accountType->type,
|
|
|
|
'currency_id' => $currency->id,
|
|
|
|
'currency_name' => $currency->name,
|
|
|
|
'currency_code' => $currency->code,
|
|
|
|
'currency_decimal_places' => $currency->decimal_places,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return response()->json($return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-01 20:22:35 +02:00
|
|
|
* Searches in the titles of all transaction journals.
|
|
|
|
* The result is limited to the top 15 unique results.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
2019-08-27 07:26:32 +02:00
|
|
|
*
|
2019-07-01 20:22:35 +02:00
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function allJournals(Request $request): JsonResponse
|
|
|
|
{
|
|
|
|
$search = (string)$request->get('search');
|
|
|
|
/** @var JournalRepositoryInterface $repository */
|
|
|
|
$repository = app(JournalRepositoryInterface::class);
|
|
|
|
$result = $repository->searchJournalDescriptions($search);
|
|
|
|
|
|
|
|
// limit and unique
|
|
|
|
$filtered = $result->unique('description');
|
|
|
|
$limited = $filtered->slice(0, 15);
|
|
|
|
$array = $limited->toArray();
|
2020-01-08 06:05:00 +01:00
|
|
|
// duplicate 'description' value into 'name':
|
|
|
|
$array = array_map(
|
|
|
|
static function (array $journal) {
|
|
|
|
$journal['name'] = $journal['description'];
|
|
|
|
|
|
|
|
return $journal;
|
|
|
|
}, $array
|
|
|
|
);
|
2019-08-27 07:26:32 +02:00
|
|
|
|
2019-08-22 19:07:01 +02:00
|
|
|
return response()->json(array_values($array));
|
2019-07-20 06:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches in the titles of all transaction journals.
|
|
|
|
* The result is limited to the top 15 unique results.
|
|
|
|
*
|
|
|
|
* If the query is numeric, it will append the journal with that particular ID.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
2019-08-27 07:26:32 +02:00
|
|
|
*
|
2019-07-20 06:47:34 +02:00
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function allJournalsWithID(Request $request): JsonResponse
|
|
|
|
{
|
|
|
|
$search = (string)$request->get('search');
|
|
|
|
/** @var JournalRepositoryInterface $repository */
|
|
|
|
$repository = app(JournalRepositoryInterface::class);
|
2019-08-27 07:26:32 +02:00
|
|
|
|
|
|
|
/** @var TransactionGroupRepositoryInterface $groupRepos */
|
|
|
|
$groupRepos = app(TransactionGroupRepositoryInterface::class);
|
|
|
|
|
|
|
|
$result = $repository->searchJournalDescriptions($search);
|
|
|
|
$array = [];
|
2019-07-20 06:47:34 +02:00
|
|
|
if (is_numeric($search)) {
|
2019-08-27 07:26:32 +02:00
|
|
|
// search for group, not journal.
|
|
|
|
$firstResult = $groupRepos->find((int)$search);
|
2019-07-20 06:47:34 +02:00
|
|
|
if (null !== $firstResult) {
|
2019-08-27 07:26:32 +02:00
|
|
|
// group may contain multiple journals, each a result:
|
|
|
|
foreach ($firstResult->transactionJournals as $journal) {
|
|
|
|
$array[] = $journal->toArray();
|
|
|
|
}
|
2019-07-20 06:47:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// if not numeric, search ahead!
|
|
|
|
|
|
|
|
// limit and unique
|
2019-08-27 07:26:32 +02:00
|
|
|
$limited = $result->slice(0, 15);
|
|
|
|
$array = array_merge($array, $limited->toArray());
|
2019-07-20 06:47:34 +02:00
|
|
|
foreach ($array as $index => $item) {
|
|
|
|
// give another key for consistency
|
2019-08-13 18:38:15 +02:00
|
|
|
$array[$index]['name'] = sprintf('#%d: %s', $item['transaction_group_id'], $item['description']);
|
2019-07-20 06:47:34 +02:00
|
|
|
}
|
|
|
|
|
2019-07-01 20:22:35 +02:00
|
|
|
|
2019-07-20 06:47:34 +02:00
|
|
|
return response()->json($array);
|
2019-07-01 20:22:35 +02:00
|
|
|
}
|
|
|
|
|
2020-01-08 06:05:00 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2020-01-21 18:02:49 +01:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
|
|
|
public function bills(Request $request): JsonResponse
|
|
|
|
{
|
|
|
|
$query = (string)$request->get('search');
|
|
|
|
/** @var BillRepositoryInterface $repository */
|
|
|
|
$repository = app(BillRepositoryInterface::class);
|
|
|
|
$result = $repository->searchBill($query);
|
|
|
|
|
|
|
|
return response()->json($result->toArray());
|
|
|
|
}
|
|
|
|
|
2019-07-01 20:22:35 +02:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
2019-08-27 07:26:32 +02:00
|
|
|
*
|
2019-05-04 20:58:43 +02:00
|
|
|
* @return JsonResponse
|
2019-07-24 19:02:41 +02:00
|
|
|
* @codeCoverageIgnore
|
2019-05-04 20:58:43 +02:00
|
|
|
*/
|
2019-07-01 20:22:35 +02:00
|
|
|
public function budgets(Request $request): JsonResponse
|
2019-05-04 20:58:43 +02:00
|
|
|
{
|
2019-07-01 20:22:35 +02:00
|
|
|
$search = (string)$request->get('search');
|
2019-05-04 20:58:43 +02:00
|
|
|
/** @var BudgetRepositoryInterface $repository */
|
|
|
|
$repository = app(BudgetRepositoryInterface::class);
|
2019-07-01 20:22:35 +02:00
|
|
|
$result = $repository->searchBudget($search);
|
2019-05-04 20:58:43 +02:00
|
|
|
|
2019-07-01 20:22:35 +02:00
|
|
|
return response()->json($result->toArray());
|
2019-05-04 20:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
2019-06-29 19:47:31 +02:00
|
|
|
* @codeCoverageIgnore
|
2019-05-04 20:58:43 +02:00
|
|
|
*/
|
|
|
|
public function categories(Request $request): JsonResponse
|
|
|
|
{
|
2019-07-01 20:22:35 +02:00
|
|
|
$query = (string)$request->get('search');
|
2019-05-04 20:58:43 +02:00
|
|
|
/** @var CategoryRepositoryInterface $repository */
|
|
|
|
$repository = app(CategoryRepositoryInterface::class);
|
|
|
|
$result = $repository->searchCategory($query);
|
|
|
|
|
|
|
|
return response()->json($result->toArray());
|
|
|
|
}
|
|
|
|
|
2019-07-01 20:22:35 +02:00
|
|
|
/**
|
|
|
|
* @return JsonResponse
|
2019-07-24 19:02:41 +02:00
|
|
|
* @codeCoverageIgnore
|
2019-07-01 20:22:35 +02:00
|
|
|
*/
|
2019-08-27 07:26:32 +02:00
|
|
|
public function currencies(): JsonResponse
|
2019-07-01 20:22:35 +02:00
|
|
|
{
|
|
|
|
/** @var CurrencyRepositoryInterface $repository */
|
|
|
|
$repository = app(CurrencyRepositoryInterface::class);
|
2019-08-27 07:26:32 +02:00
|
|
|
$return = [];
|
|
|
|
$collection = $repository->getAll();
|
|
|
|
|
|
|
|
/** @var TransactionCurrency $currency */
|
|
|
|
foreach ($collection as $currency) {
|
|
|
|
$return[] = [
|
|
|
|
'id' => $currency->id,
|
|
|
|
'name' => $currency->name,
|
|
|
|
'code' => $currency->code,
|
|
|
|
'symbol' => $currency->symbol,
|
|
|
|
'enabled' => $currency->enabled,
|
|
|
|
'decimal_places' => $currency->decimal_places,
|
|
|
|
];
|
2019-07-01 20:22:35 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 07:26:32 +02:00
|
|
|
return response()->json($return);
|
2019-07-01 20:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2019-08-27 07:26:32 +02:00
|
|
|
public function currencyNames(Request $request): JsonResponse
|
2019-07-01 20:22:35 +02:00
|
|
|
{
|
|
|
|
$query = (string)$request->get('search');
|
2019-08-27 07:26:32 +02:00
|
|
|
/** @var CurrencyRepositoryInterface $repository */
|
|
|
|
$repository = app(CurrencyRepositoryInterface::class);
|
|
|
|
$result = $repository->searchCurrency($query)->toArray();
|
|
|
|
foreach ($result as $index => $item) {
|
|
|
|
$result[$index]['name'] = sprintf('%s (%s)', $item['name'], $item['code']);
|
2019-07-01 20:22:35 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 07:26:32 +02:00
|
|
|
return response()->json($result);
|
2019-07-01 20:22:35 +02:00
|
|
|
}
|
|
|
|
|
2019-05-04 20:58:43 +02:00
|
|
|
/**
|
2019-08-27 07:26:32 +02:00
|
|
|
* An auto-complete specifically for expense accounts, used when mass updating mostly.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
2019-05-04 20:58:43 +02:00
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
2019-08-27 07:26:32 +02:00
|
|
|
public function expenseAccounts(Request $request): JsonResponse
|
2019-05-04 20:58:43 +02:00
|
|
|
{
|
2019-08-27 07:26:32 +02:00
|
|
|
$search = $request->get('search');
|
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
2019-05-04 20:58:43 +02:00
|
|
|
|
2019-08-27 07:26:32 +02:00
|
|
|
// filter the account types:
|
|
|
|
$allowedAccountTypes = [AccountType::EXPENSE];
|
|
|
|
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) {
|
2019-05-04 20:58:43 +02:00
|
|
|
$return[] = [
|
2019-08-27 07:26:32 +02:00
|
|
|
'id' => $account->id,
|
|
|
|
'name' => $account->name,
|
|
|
|
'type' => $account->accountType->type,
|
2019-05-04 20:58:43 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($return);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return JsonResponse
|
2019-06-29 19:47:31 +02:00
|
|
|
* @codeCoverageIgnore
|
2019-05-04 20:58:43 +02:00
|
|
|
*/
|
|
|
|
public function piggyBanks(): JsonResponse
|
|
|
|
{
|
|
|
|
/** @var PiggyBankRepositoryInterface $repository */
|
|
|
|
$repository = app(PiggyBankRepositoryInterface::class);
|
|
|
|
|
2019-11-10 07:26:49 +01:00
|
|
|
/** @var AccountRepositoryInterface $accountRepos */
|
|
|
|
$accountRepos = app(AccountRepositoryInterface::class);
|
|
|
|
|
2020-01-08 06:05:00 +01:00
|
|
|
$piggies = $repository->getPiggyBanks();
|
2019-11-10 07:26:49 +01:00
|
|
|
$defaultCurrency = \Amount::getDefaultCurrency();
|
2020-01-08 06:05:00 +01:00
|
|
|
$response = [];
|
2019-11-10 07:26:49 +01:00
|
|
|
/** @var PiggyBank $piggy */
|
|
|
|
foreach ($piggies as $piggy) {
|
2020-01-08 06:05:00 +01:00
|
|
|
$currency = $accountRepos->getAccountCurrency($piggy->account) ?? $defaultCurrency;
|
2019-11-10 07:26:49 +01:00
|
|
|
$currentAmount = $repository->getRepetition($piggy)->currentamount ?? '0';
|
|
|
|
$piggy->name_with_amount = sprintf(
|
|
|
|
'%s (%s / %s)',
|
|
|
|
$piggy->name,
|
|
|
|
app('amount')->formatAnything($currency, $currentAmount, false),
|
|
|
|
app('amount')->formatAnything($currency, $piggy->targetamount, false),
|
|
|
|
);
|
2020-01-08 06:05:00 +01:00
|
|
|
$response[] = $piggy->toArray();
|
2019-11-10 07:26:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($response);
|
2019-05-04 20:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-27 07:26:32 +02:00
|
|
|
* An auto-complete specifically for revenue accounts, used when converting transactions mostly.
|
|
|
|
*
|
2019-06-29 19:47:31 +02:00
|
|
|
* @param Request $request
|
2019-08-27 07:26:32 +02:00
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function revenueAccounts(Request $request): JsonResponse
|
|
|
|
{
|
|
|
|
$search = $request->get('search');
|
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
|
|
|
|
|
|
|
// filter the account types:
|
|
|
|
$allowedAccountTypes = [AccountType::REVENUE];
|
|
|
|
Log::debug('Now in revenueAccounts(). Filtering results.', $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
|
|
|
|
*
|
2019-05-04 20:58:43 +02:00
|
|
|
* @return JsonResponse
|
2019-06-29 19:47:31 +02:00
|
|
|
* @codeCoverageIgnore
|
2019-05-04 20:58:43 +02:00
|
|
|
*/
|
|
|
|
public function tags(Request $request): JsonResponse
|
|
|
|
{
|
2019-07-01 20:22:35 +02:00
|
|
|
$search = (string)$request->get('search');
|
2019-05-04 20:58:43 +02:00
|
|
|
/** @var TagRepositoryInterface $repository */
|
|
|
|
$repository = app(TagRepositoryInterface::class);
|
2019-07-01 20:22:35 +02:00
|
|
|
$result = $repository->searchTags($search);
|
|
|
|
$array = $result->toArray();
|
|
|
|
foreach ($array as $index => $item) {
|
|
|
|
// rename field for consistency.
|
|
|
|
$array[$index]['name'] = $item['tag'];
|
|
|
|
}
|
2019-05-04 20:58:43 +02:00
|
|
|
|
2019-07-01 20:22:35 +02:00
|
|
|
return response()->json($array);
|
2019-05-04 20:58:43 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 07:26:32 +02:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
|
|
|
public function transactionTypes(Request $request): JsonResponse
|
|
|
|
{
|
|
|
|
$query = (string)$request->get('search');
|
|
|
|
/** @var TransactionTypeRepositoryInterface $repository */
|
|
|
|
$repository = app(TransactionTypeRepositoryInterface::class);
|
|
|
|
$array = $repository->searchTypes($query)->toArray();
|
|
|
|
|
|
|
|
foreach ($array as $index => $item) {
|
|
|
|
// different key for consistency.
|
|
|
|
$array[$index]['name'] = $item['type'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($array);
|
|
|
|
}
|
|
|
|
|
2017-08-31 06:47:18 +02:00
|
|
|
}
|