Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Updated API code.
James Cole30d653faee84
diff --git a/app/Api/V1/Controllers/Autocomplete/AccountController.php b/app/Api/V1/Controllers/Autocomplete/AccountController.phpindex 9dfec18862..1121928794 100644--- a/app/Api/V1/Controllers/Autocomplete/AccountController.php+++ b/app/Api/V1/Controllers/Autocomplete/AccountController.php@@ -90,7 +90,7 @@ class AccountController extends Controller}$return[] = [- 'id' => $account->id,+ 'id' => (string)$account->id,'name' => $account->name,'name_with_balance' => $nameWithBalance,'type' => $account->accountType->type,diff --git a/app/Api/V1/Controllers/Autocomplete/BillController.php b/app/Api/V1/Controllers/Autocomplete/BillController.phpindex 890996dd2b..2038883f2e 100644--- a/app/Api/V1/Controllers/Autocomplete/BillController.php+++ b/app/Api/V1/Controllers/Autocomplete/BillController.php@@ -69,7 +69,7 @@ class BillController extends Controller$filtered = $result->map(static function (Bill $item) {return [- 'id' => $item->id,+ 'id' => (string)$item->id,'name' => $item->name,];}diff --git a/app/Api/V1/Controllers/Autocomplete/BudgetController.php b/app/Api/V1/Controllers/Autocomplete/BudgetController.phpindex 066a1b2c15..616989d2f2 100644--- a/app/Api/V1/Controllers/Autocomplete/BudgetController.php+++ b/app/Api/V1/Controllers/Autocomplete/BudgetController.php@@ -69,7 +69,7 @@ class BudgetController extends Controller$filtered = $result->map(static function (Budget $item) {return [- 'id' => $item->id,+ 'id' => (string)$item->id,'name' => $item->name,];}diff --git a/app/Api/V1/Controllers/Autocomplete/CategoryController.php b/app/Api/V1/Controllers/Autocomplete/CategoryController.phpindex 878defc648..ab05ebf504 100644--- a/app/Api/V1/Controllers/Autocomplete/CategoryController.php+++ b/app/Api/V1/Controllers/Autocomplete/CategoryController.php@@ -68,7 +68,7 @@ class CategoryController extends Controller$filtered = $result->map(static function (Category $item) {return [- 'id' => $item->id,+ 'id' => (string)$item->id,'name' => $item->name,];}diff --git a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php b/app/Api/V1/Controllers/Autocomplete/CurrencyController.phpindex 5f17ca3bb2..fe6cc5648f 100644--- a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php+++ b/app/Api/V1/Controllers/Autocomplete/CurrencyController.php@@ -71,7 +71,7 @@ class CurrencyController extends Controller/** @var TransactionCurrency $currency */foreach ($collection as $currency) {$result[] = [- 'id' => $currency->id,+ 'id' => (string) $currency->id,'name' => sprintf('%s (%s)', $currency->name, $currency->code),'code' => $currency->code,'symbol' => $currency->symbol,@@ -96,7 +96,7 @@ class CurrencyController extends Controller/** @var TransactionCurrency $currency */foreach ($collection as $currency) {$result[] = [- 'id' => $currency->id,+ 'id' => (string) $currency->id,'name' => $currency->name,'code' => $currency->code,'symbol' => $currency->symbol,diff --git a/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.php b/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.phpindex 4ab1885c4f..bfa257dca4 100644--- a/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.php+++ b/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.php@@ -71,7 +71,7 @@ class ObjectGroupController extends Controller/** @var ObjectGroup $account */foreach ($result as $objectGroup) {$return[] = [- 'id' => $objectGroup->id,+ 'id' => (string)$objectGroup->id,'name' => $objectGroup->title,'title' => $objectGroup->title,];diff --git a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.phpindex fc2c682a91..c1499c9f25 100644--- a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php+++ b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php@@ -78,7 +78,7 @@ class PiggyBankController extends Controllerforeach ($piggies as $piggy) {$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;$response[] = [- 'id' => $piggy->id,+ 'id' => (string)$piggy->id,'name' => $piggy->name,'currency_id' => $currency->id,'currency_name' => $currency->name,@@ -106,7 +106,7 @@ class PiggyBankController extends Controller$currency = $this->accountRepository->getAccountCurrency($piggy->account) ?? $defaultCurrency;$currentAmount = $this->piggyRepository->getRepetition($piggy)->currentamount ?? '0';$response[] = [- 'id' => $piggy->id,+ 'id' => (string)$piggy->id,'name' => $piggy->name,'name_with_balance' => sprintf('%s (%s / %s)', $piggy->name, app('amount')->formatAnything($currency, $currentAmount, false),diff --git a/app/Api/V1/Controllers/Autocomplete/RecurrenceController.php b/app/Api/V1/Controllers/Autocomplete/RecurrenceController.phpindex 75785eec08..01f2584a29 100644--- a/app/Api/V1/Controllers/Autocomplete/RecurrenceController.php+++ b/app/Api/V1/Controllers/Autocomplete/RecurrenceController.php@@ -25,11 +25,56 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;use FireflyIII\Api\V1\Controllers\Controller;+use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;+use FireflyIII\Models\Rule;+use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;+use Illuminate\Http\JsonResponse;/*** Class RecurrenceController*/class RecurrenceController extends Controller{+ private RecurringRepositoryInterface $repository;+++ /**+ * RecurrenceController constructor.+ */+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ $this->repository = app(RecurringRepositoryInterface::class);+ $this->repository->setUser(auth()->user());++ return $next($request);+ }+ );+ }++ /**+ * @param AutocompleteRequest $request+ *+ * @return JsonResponse+ */+ public function recurring(AutocompleteRequest $request): JsonResponse+ {+ $data = $request->getData();+ $rules = $this->repository->searchRecurrence($data['query'], $data['limit']);+ $response = [];++ /** @var Rule $rule */+ foreach ($rules as $rule) {+ $response[] = [+ 'id' => (string)$rule->id,+ 'name' => $rule->title,+ 'description' => $rule->description,+ ];+ }++ return response()->json($response);+ }}diff --git a/app/Api/V1/Controllers/Autocomplete/RuleController.php b/app/Api/V1/Controllers/Autocomplete/RuleController.phpindex fd7453d05a..cbd9022ed2 100644--- a/app/Api/V1/Controllers/Autocomplete/RuleController.php+++ b/app/Api/V1/Controllers/Autocomplete/RuleController.php@@ -25,11 +25,56 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;use FireflyIII\Api\V1\Controllers\Controller;+use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;+use FireflyIII\Models\Rule;+use FireflyIII\Repositories\Rule\RuleRepositoryInterface;+use Illuminate\Http\JsonResponse;/*** Class RuleController*/class RuleController extends Controller{+ private RuleRepositoryInterface $repository;+++ /**+ * RuleController constructor.+ */+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ $this->repository = app(RuleRepositoryInterface::class);+ $this->repository->setUser(auth()->user());++ return $next($request);+ }+ );+ }++ /**+ * @param AutocompleteRequest $request+ *+ * @return JsonResponse+ */+ public function rules(AutocompleteRequest $request): JsonResponse+ {+ $data = $request->getData();+ $rules = $this->repository->searchRule($data['query'], $data['limit']);+ $response = [];++ /** @var Rule $rule */+ foreach ($rules as $rule) {+ $response[] = [+ 'id' => (string)$rule->id,+ 'name' => $rule->title,+ 'description' => $rule->description,+ ];+ }++ return response()->json($response);+ }}diff --git a/app/Api/V1/Controllers/Autocomplete/RuleGroupController.php b/app/Api/V1/Controllers/Autocomplete/RuleGroupController.phpindex bbc598e40b..d67ae1c01c 100644--- a/app/Api/V1/Controllers/Autocomplete/RuleGroupController.php+++ b/app/Api/V1/Controllers/Autocomplete/RuleGroupController.php@@ -25,11 +25,55 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;use FireflyIII\Api\V1\Controllers\Controller;+use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;+use FireflyIII\Models\RuleGroup;+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;+use Illuminate\Http\JsonResponse;/*** Class RuleGroupController*/class RuleGroupController extends Controller{+ private RuleGroupRepositoryInterface $repository;++ /**+ * RuleGroupController constructor.+ */+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ $this->repository = app(RuleGroupRepositoryInterface::class);+ $this->repository->setUser(auth()->user());++ return $next($request);+ }+ );+ }++ /**+ * @param AutocompleteRequest $request+ *+ * @return JsonResponse+ */+ public function ruleGroups(AutocompleteRequest $request): JsonResponse+ {+ $data = $request->getData();+ $groups = $this->repository->searchRuleGroup($data['query'], $data['limit']);+ $response = [];++ /** @var RuleGroup $group */+ foreach ($groups as $group) {+ $response[] = [+ 'id' => (string)$group->id,+ 'name' => $group->title,+ 'description' => $group->description,+ ];+ }++ return response()->json($response);+ }}diff --git a/app/Api/V1/Controllers/Autocomplete/TagController.php b/app/Api/V1/Controllers/Autocomplete/TagController.phpindex 5b2aeabc67..ef26cd12fe 100644--- a/app/Api/V1/Controllers/Autocomplete/TagController.php+++ b/app/Api/V1/Controllers/Autocomplete/TagController.php@@ -71,7 +71,7 @@ class TagController extends Controller/** @var Tag $tag */foreach ($result as $tag) {$array[] = [- 'id' => $tag->id,+ 'id' => (string)$tag->id,'name' => $tag->tag,'tag' => $tag->tag,];diff --git a/app/Api/V1/Controllers/Autocomplete/TransactionController.php b/app/Api/V1/Controllers/Autocomplete/TransactionController.phpindex 7a0a9b480b..680e72bba4 100644--- a/app/Api/V1/Controllers/Autocomplete/TransactionController.php+++ b/app/Api/V1/Controllers/Autocomplete/TransactionController.php@@ -81,8 +81,8 @@ class TransactionController extends Controller/** @var TransactionJournal $journal */foreach ($filtered as $journal) {$array[] = [- 'id' => $journal->id,- 'transaction_group_id' => $journal->transaction_group_id,+ 'id' => (string)$journal->id,+ 'transaction_group_id' => (string)$journal->transaction_group_id,'name' => $journal->description,'description' => $journal->description,];@@ -120,8 +120,8 @@ class TransactionController extends Controller/** @var TransactionJournal $journal */foreach ($result as $journal) {$array[] = [- 'id' => $journal->id,- 'transaction_group_id' => $journal->transaction_group_id,+ 'id' => (string)$journal->id,+ 'transaction_group_id' => (string)$journal->transaction_group_id,'name' => sprintf('#%d: %s', $journal->transaction_group_id, $journal->description),'description' => sprintf('#%d: %s', $journal->transaction_group_id, $journal->description),];diff --git a/app/Api/V1/Controllers/Autocomplete/TransactionTypeController.php b/app/Api/V1/Controllers/Autocomplete/TransactionTypeController.phpindex 5dcee6c308..38faca2036 100644--- a/app/Api/V1/Controllers/Autocomplete/TransactionTypeController.php+++ b/app/Api/V1/Controllers/Autocomplete/TransactionTypeController.php@@ -69,7 +69,7 @@ class TransactionTypeController extends Controllerforeach ($types as $type) {// different key for consistency.$array[] = [- 'id' => $type->id,+ 'id' =>(string) $type->id,'name' => $type->type,'type' => $type->type,];diff --git a/app/Api/V1/Controllers/Chart/AccountController.php b/app/Api/V1/Controllers/Chart/AccountController.phpindex 283c7d3785..7547cbb248 100644--- a/app/Api/V1/Controllers/Chart/AccountController.php+++ b/app/Api/V1/Controllers/Chart/AccountController.php@@ -193,7 +193,7 @@ class AccountController extends Controller}$currentSet = ['label' => $account->name,- 'currency_id' => $currency->id,+ 'currency_id' => (string) $currency->id,'currency_code' => $currency->code,'currency_symbol' => $currency->symbol,'currency_decimal_places' => $currency->decimal_places,diff --git a/app/Api/V1/Controllers/Insight/Expense/AccountController.php b/app/Api/V1/Controllers/Insight/Expense/AccountController.phpindex 16c937591f..214ea2cb26 100644--- a/app/Api/V1/Controllers/Insight/Expense/AccountController.php+++ b/app/Api/V1/Controllers/Insight/Expense/AccountController.php@@ -143,6 +143,65 @@ class AccountController extends Controller}+ // sort temp array by amount.+ $amounts = array_column($tempData, 'difference_float');+ array_multisort($amounts, SORT_ASC, $tempData);++ return response()->json($tempData);+ }++ /**+ * @param DateRequest $request+ *+ * @return JsonResponse+ */+ public function asset(DateRequest $request): JsonResponse+ {+ $dates = $request->getAll();+ /** @var Carbon $start */+ $start = $dates['start'];+ /** @var Carbon $end */+ $end = $dates['end'];++ $start->subDay();++ // prep some vars:+ $currencies = [];+ $tempData = [];++ // grab all accounts and names+ $accounts = $this->repository->getAccountsByType([AccountType::ASSET]);+ $accountNames = $this->extractNames($accounts);+ $startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);+ $endBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $end);++ // loop the end balances. This is an array for each account ($expenses)+ foreach ($endBalances as $accountId => $expenses) {+ $accountId = (int)$accountId;+ // loop each expense entry (each entry can be a different currency).+ foreach ($expenses as $currencyId => $endAmount) {+ $currencyId = (int)$currencyId;++ // see if there is an accompanying start amount.+ // grab the difference and find the currency.+ $startAmount = $startBalances[$accountId][$currencyId] ?? '0';+ $diff = bcsub($endAmount, $startAmount);+ $currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);+ if (0 !== bccomp($diff, '0')) {+ // store the values in a temporary array.+ $tempData[] = [+ 'id' => $accountId,+ 'name' => $accountNames[$accountId],+ 'difference' => bcmul($diff, '-1'),+ 'difference_float' => ((float)$diff) * -1,+ 'currency_id' => (string) $currencyId,+ 'currency_code' => $currencies[$currencyId]->code,+ ];+ }+ }+ }++// sort temp array by amount.$amounts = array_column($tempData, 'difference_float');array_multisort($amounts, SORT_ASC, $tempData);diff --git a/app/Api/V1/Controllers/Insight/Expense/BudgetController.php b/app/Api/V1/Controllers/Insight/Expense/BudgetController.phpnew file mode 100644index 0000000000..34a48645cb--- /dev/null+++ b/app/Api/V1/Controllers/Insight/Expense/BudgetController.php@@ -0,0 +1,95 @@+<?php+/*+ * BudgetController.php+ * Copyright (c) 2021 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * 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.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * 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/>.+ */++namespace FireflyIII\Api\V1\Controllers\Insight\Expense;+++use Carbon\Carbon;+use FireflyIII\Api\V1\Controllers\Controller;+use FireflyIII\Api\V1\Requests\DateRequest;+use FireflyIII\Models\Budget;+use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;+use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;+use Illuminate\Http\JsonResponse;+use Illuminate\Support\Collection;++/**+ * Class BudgetController+ */+class BudgetController extends Controller+{+ private OperationsRepositoryInterface $opsRepository;+ private BudgetRepositoryInterface $repository;++ /**+ * AccountController constructor.+ *+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ $this->opsRepository = app(OperationsRepositoryInterface::class);+ $this->repository = app(BudgetRepositoryInterface::class);+ $this->opsRepository->setUser(auth()->user());+ $this->repository->setUser(auth()->user());++ return $next($request);+ }+ );+ }++ /**+ * @param DateRequest $request+ *+ * @return JsonResponse+ */+ public function budget(DateRequest $request): JsonResponse+ {+ $dates = $request->getAll();+ /** @var Carbon $start */+ $start = $dates['start'];+ /** @var Carbon $end */+ $end = $dates['end'];+ $result = [];+ $budgets = $this->repository->getActiveBudgets();+ /** @var Budget $budget */+ foreach ($budgets as $budget) {+ $expenses = $this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget]), null);+ /** @var array $expense */+ foreach ($expenses as $expense) {+ $result[] = [+ 'id' => (string)$budget->id,+ 'name' => $budget->name,+ 'difference' => $expense['sum'],+ 'difference_float' => (float)$expense['sum'],+ 'currency_id' => (string)$expense['currency_id'],+ 'currency_code' => $expense['currency_code'],+ ];+ }+ }++ return response()->json($result);+ }++}\ No newline at end of filediff --git a/app/Api/V1/Controllers/Insight/Expense/PeriodController.php b/app/Api/V1/Controllers/Insight/Expense/PeriodController.phpnew file mode 100644index 0000000000..30e2291266--- /dev/null+++ b/app/Api/V1/Controllers/Insight/Expense/PeriodController.php@@ -0,0 +1,85 @@+<?php+/*+ * PeriodController.php+ * Copyright (c) 2021 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * 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.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * 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/>.+ */++namespace FireflyIII\Api\V1\Controllers\Insight\Expense;+++use Carbon\Carbon;+use FireflyIII\Api\V1\Controllers\Controller;+use FireflyIII\Api\V1\Requests\DateRequest;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;+use FireflyIII\Models\TransactionType;+use Illuminate\Http\JsonResponse;++/**+ * Class PeriodController+ */+class PeriodController extends Controller+{++ /**+ * @param DateRequest $request+ *+ * @return JsonResponse+ */+ public function total(DateRequest $request): JsonResponse+ {+ $dates = $request->getAll();+ /** @var Carbon $start */+ $start = $dates['start'];+ /** @var Carbon $end */+ $end = $dates['end'];+ $response = [];++ // collect all expenses in this period (regardless of type)+ $collector = app(GroupCollectorInterface::class);+ $collector->setTypes([TransactionType::WITHDRAWAL])->setRange($start, $end);+ $genericSet = $collector->getExtractedJournals();+ foreach ($genericSet as $journal) {+ $currencyId = (int)$journal['currency_id'];+ $foreignCurrencyId = (int)$journal['foreign_currency_id'];++ if (0 !== $currencyId) {+ $response[$currencyId] = $response[$currencyId] ?? [+ 'difference' => '0',+ 'difference_float' => 0,+ 'currency_id' => (string)$currencyId,+ 'currency_code' => $journal['currency_code'],+ ];+ $response[$currencyId]['difference'] = bcadd($response[$currencyId]['difference'], $journal['amount']);+ $response[$currencyId]['difference_float'] = (float)$response[$currencyId]['difference'];+ }+ if (0 !== $foreignCurrencyId) {+ $response[$foreignCurrencyId] = $response[$foreignCurrencyId] ?? [+ 'difference' => '0',+ 'difference_float' => 0,+ 'currency_id' => (string)$foreignCurrencyId,+ 'currency_code' => $journal['foreign_currency_code'],+ ];+ $response[$foreignCurrencyId]['difference'] = bcadd($response[$foreignCurrencyId]['difference'], $journal['foreign_amount']);+ $response[$foreignCurrencyId]['difference_float'] = (float)$response[$foreignCurrencyId]['difference'];+ }+ }++ return response()->json(array_values($response));+ }++}\ No newline at end of filediff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.phpindex 97671ed50e..4c7eed9c21 100644--- a/app/Repositories/Recurring/RecurringRepository.php+++ b/app/Repositories/Recurring/RecurringRepository.php@@ -53,6 +53,7 @@ use Log;class RecurringRepository implements RecurringRepositoryInterface{use CalculateRangeOccurrences, CalculateXOccurrences, CalculateXOccurrencesSince, FiltersWeekends;+private User $user;@@ -522,6 +523,7 @@ class RecurringRepository implements RecurringRepositoryInterface// filter out everything if "repeat_until" is set.$repeatUntil = $repetition->recurrence->repeat_until;+return $this->filterMaxDate($repeatUntil, $occurrences);}@@ -560,16 +562,16 @@ class RecurringRepository implements RecurringRepositoryInterfacepublic function totalTransactions(Recurrence $recurrence, RecurrenceRepetition $repetition): int{// if repeat = null just return 0.- if (null === $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) {+ if (null === $recurrence->repeat_until && 0 === (int)$recurrence->repetitions) {return 0;}// expect X transactions then stop. Return that number- if (null === $recurrence->repeat_until && 0 !== (int) $recurrence->repetitions) {- return (int) $recurrence->repetitions;+ if (null === $recurrence->repeat_until && 0 !== (int)$recurrence->repetitions) {+ return (int)$recurrence->repetitions;}// need to calculate, this depends on the repetition:- if (null !== $recurrence->repeat_until && 0 === (int) $recurrence->repetitions) {+ if (null !== $recurrence->repeat_until && 0 === (int)$recurrence->repetitions) {$occurrences = $this->getOccurrencesInRange($repetition, $recurrence->first_date ?? today(), $recurrence->repeat_until);return count($occurrences);@@ -577,4 +579,19 @@ class RecurringRepository implements RecurringRepositoryInterfacereturn 0;}++ /**+ * @inheritDoc+ */+ public function searchRecurrence(string $query, int $limit): Collection+ {+ $search = $this->user->recurrences();+ if ('' !== $query) {+ $search->where('recurrences.title', 'LIKE', sprintf('%%%s%%', $query));+ }+ $search+ ->orderBy('recurrences.title', 'ASC');++ return $search->take($limit)->get(['id', 'title', 'description']);+ }}diff --git a/app/Repositories/Recurring/RecurringRepositoryInterface.php b/app/Repositories/Recurring/RecurringRepositoryInterface.phpindex ddca5c2b21..71996f203d 100644--- a/app/Repositories/Recurring/RecurringRepositoryInterface.php+++ b/app/Repositories/Recurring/RecurringRepositoryInterface.php@@ -44,6 +44,14 @@ interface RecurringRepositoryInterface*/public function destroyAll(): void;+ /**+ * @param string $query+ * @param int $limit+ *+ * @return Collection+ */+ public function searchRecurrence(string $query, int $limit): Collection;+/*** Calculate how many transactions are to be expected from this recurrence.*diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.phpindex ac49dd5c41..dfd44c40c7 100644--- a/app/Repositories/Rule/RuleRepository.php+++ b/app/Repositories/Rule/RuleRepository.php@@ -565,4 +565,19 @@ class RuleRepository implements RuleRepositoryInterfacereturn implode(' ', $params);}++ /**+ * @inheritDoc+ */+ public function searchRule(string $query, int $limit): Collection+ {+ $search = $this->user->rules();+ if ('' !== $query) {+ $search->where('rules.title', 'LIKE', sprintf('%%%s%%', $query));+ }+ $search->orderBy('rules.order', 'ASC')+ ->orderBy('rules.title', 'ASC');++ return $search->take($limit)->get(['id','title','description']);+ }}diff --git a/app/Repositories/Rule/RuleRepositoryInterface.php b/app/Repositories/Rule/RuleRepositoryInterface.phpindex d49199c4fc..2b59bfc297 100644--- a/app/Repositories/Rule/RuleRepositoryInterface.php+++ b/app/Repositories/Rule/RuleRepositoryInterface.php@@ -39,6 +39,14 @@ interface RuleRepositoryInterface*/public function count(): int;+ /**+ * @param string $query+ * @param int $limit+ *+ * @return Collection+ */+ public function searchRule(string $query, int $limit): Collection;+/*** Return search query for rule.*diff --git a/app/Repositories/RuleGroup/RuleGroupRepository.php b/app/Repositories/RuleGroup/RuleGroupRepository.phpindex 421e01a531..b67da9bc7a 100644--- a/app/Repositories/RuleGroup/RuleGroupRepository.php+++ b/app/Repositories/RuleGroup/RuleGroupRepository.php@@ -388,4 +388,19 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface$group->delete();}}++ /**+ * @inheritDoc+ */+ public function searchRuleGroup(string $query, int $limit): Collection+ {+ $search = $this->user->ruleGroups();+ if ('' !== $query) {+ $search->where('rule_groups.title', 'LIKE', sprintf('%%%s%%', $query));+ }+ $search->orderBy('rule_groups.order', 'ASC')+ ->orderBy('rule_groups.title', 'ASC');++ return $search->take($limit)->get(['id','title','description']);+ }}diff --git a/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php b/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.phpindex 216fefdf57..8845b69e6e 100644--- a/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php+++ b/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php@@ -36,6 +36,14 @@ interface RuleGroupRepositoryInterface*/public function destroyAll(): void;+ /**+ * @param string $query+ * @param int $limit+ *+ * @return Collection+ */+ public function searchRuleGroup(string $query, int $limit): Collection;+/*** @return int*/@@ -155,7 +163,7 @@ interface RuleGroupRepositoryInterface/*** @param RuleGroup $ruleGroup- * @param array $data+ * @param array $data** @return RuleGroup*/diff --git a/routes/api.php b/routes/api.phpindex 89b3bbd782..820281bf15 100644--- a/routes/api.php+++ b/routes/api.php@@ -42,10 +42,9 @@ Route::group(Route::get('object-groups', ['uses' => 'ObjectGroupController@objectGroups', 'as' => 'object-groups']);Route::get('piggy-banks', ['uses' => 'PiggyBankController@piggyBanks', 'as' => 'piggy-banks']);Route::get('piggy-banks-with-balance', ['uses' => 'PiggyBankController@piggyBanksWithBalance', 'as' => 'piggy-banks-with-balance']);- // TODO create me:+ Route::get('recurring', ['uses' => 'RecurrenceController@recurring', 'as' => 'recurring']);Route::get('rules', ['uses' => 'RuleController@rules', 'as' => 'rules']);- // TODO create me:- Route::get('rule-groups', ['uses' => 'RuleGroupController@rules', 'as' => 'rule-groups']);+ Route::get('rule-groups', ['uses' => 'RuleGroupController@ruleGroups', 'as' => 'rule-groups']);Route::get('tags', ['uses' => 'TagController@tags', 'as' => 'tags']);Route::get('transactions', ['uses' => 'TransactionController@transactions', 'as' => 'transactions']);Route::get('transactions-with-id', ['uses' => 'TransactionController@transactionsWithID', 'as' => 'transactions-with-id']);@@ -85,54 +84,8 @@ Route::group(});---------------------/**- * SUMMARY CONTROLLER- */-// BASIC-Route::group(- ['namespace' => 'FireflyIII\Api\V1\Controllers\Summary', 'prefix' => 'summary',- 'as' => 'api.v1.summary.',],- static function () {- Route::get('basic', ['uses' => 'BasicController@basic', 'as' => 'basic']);- }-);--/**- * DATA CONTROLLERS- *- */--//// EXPORT-//Route::group(-// ['namespace' => 'FireflyIII\Api\V1\Controllers\Data\Export', 'prefix' => 'data/export',-// 'as' => 'api.v1.data.export.',],-// static function () {-// Route::get('transactions', ['uses' => 'TransactionController@export', 'as' => 'transactions']);-// }-//);-/**- * INSIGHT CONTROLLERS+ * INSIGHTS ROUTES*/// Insight in expenses:@@ -141,16 +94,12 @@ Route::group('as' => 'api.v1.insight.expense.',],static function () {// Insight in expenses.-- // TODO grouped by expense account or asset account:Route::get('expense', ['uses' => 'AccountController@expense', 'as' => 'expense']);Route::get('asset', ['uses' => 'AccountController@asset', 'as' => 'asset']);-- // TODO total:Route::get('total', ['uses' => 'PeriodController@total', 'as' => 'total']);+ Route::get('budget', ['uses' => 'BudgetController@budget', 'as' => 'budget']);// TODO Budget/no budget and budget limit- Route::get('budget', ['uses' => 'BudgetController@budget', 'as' => 'budget']);Route::get('no-budget', ['uses' => 'BudgetController@noBudget', 'as' => 'no-budget']);// TODO category and no category@@ -200,6 +149,56 @@ Route::group(++++++++++/**+ * SUMMARY CONTROLLER+ */+// BASIC+Route::group(+ ['namespace' => 'FireflyIII\Api\V1\Controllers\Summary', 'prefix' => 'summary',+ 'as' => 'api.v1.summary.',],+ static function () {+ Route::get('basic', ['uses' => 'BasicController@basic', 'as' => 'basic']);+ }+);++/**+ * DATA CONTROLLERS+ *+ */++//// EXPORT+//Route::group(+// ['namespace' => 'FireflyIII\Api\V1\Controllers\Data\Export', 'prefix' => 'data/export',+// 'as' => 'api.v1.data.export.',],+// static function () {+// Route::get('transactions', ['uses' => 'TransactionController@export', 'as' => 'transactions']);+// }+//);++/**+ * INSIGHT CONTROLLERS+ */++++++++++++/*** System and configuration controllers*/