mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
101 lines
2.6 KiB
PHP
101 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* AutoCompleteController.php
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
* This software may be modified and distributed under the terms of the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
*
|
|
* See the LICENSE file for details.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace FireflyIII\Http\Controllers\Json;
|
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
|
use FireflyIII\Models\Account;
|
|
use FireflyIII\Models\AccountType;
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
use Response;
|
|
|
|
/**
|
|
* Class AutoCompleteController
|
|
*
|
|
* @package FireflyIII\Http\Controllers\Json
|
|
*/
|
|
class AutoCompleteController extends Controller
|
|
{
|
|
|
|
/**
|
|
* Returns a JSON list of all accounts.
|
|
*
|
|
* @param AccountRepositoryInterface $repository
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*
|
|
*/
|
|
public function allAccounts(AccountRepositoryInterface $repository)
|
|
{
|
|
$return = array_unique(
|
|
$repository->getAccountsByType(
|
|
[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]
|
|
)->pluck('name')->toArray()
|
|
);
|
|
sort($return);
|
|
|
|
return Response::json($return);
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns a JSON list of all beneficiaries.
|
|
*
|
|
* @param AccountRepositoryInterface $repository
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*
|
|
*/
|
|
public function expenseAccounts(AccountRepositoryInterface $repository)
|
|
{
|
|
$set = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]);
|
|
$filtered = $set->filter(
|
|
function (Account $account) {
|
|
if ($account->active) {
|
|
return $account;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
);
|
|
$return = array_unique($filtered->pluck('name')->toArray());
|
|
|
|
sort($return);
|
|
|
|
return Response::json($return);
|
|
}
|
|
|
|
/**
|
|
* @param AccountRepositoryInterface $repository
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*
|
|
*/
|
|
public function revenueAccounts(AccountRepositoryInterface $repository)
|
|
{
|
|
$set = $repository->getAccountsByType([AccountType::REVENUE]);
|
|
$filtered = $set->filter(
|
|
function (Account $account) {
|
|
if ($account->active) {
|
|
return $account;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
);
|
|
$return = array_unique($filtered->pluck('name')->toArray());
|
|
sort($return);
|
|
|
|
return Response::json($return);
|
|
}
|
|
|
|
} |