Skip to content

Firefly III: a personal finances manager

Code for #3150

James Coledebbe8918795
diff --git a/app/Api/V1/Controllers/Autocomplete/CategoryController.php b/app/Api/V1/Controllers/Autocomplete/CategoryController.php
index 0b9604819e..983c8a6f93 100644
--- a/app/Api/V1/Controllers/Autocomplete/CategoryController.php
+++ b/app/Api/V1/Controllers/Autocomplete/CategoryController.php
@@ -75,5 +75,4 @@ class CategoryController extends Controller
return response()->json($filtered);
}
-
}
diff --git a/app/Api/V1/Controllers/Autocomplete/CurrencyController.php b/app/Api/V1/Controllers/Autocomplete/CurrencyController.php
new file mode 100644
index 0000000000..8bacb7acca
--- /dev/null
+++ b/app/Api/V1/Controllers/Autocomplete/CurrencyController.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * CurrencyController.php
+ * Copyright (c) 2020 [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/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Api\V1\Controllers\Autocomplete;
+
+
+use FireflyIII\Api\V1\Controllers\Controller;
+use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
+use FireflyIII\Models\TransactionCurrency;
+use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
+use FireflyIII\User;
+use Illuminate\Http\JsonResponse;
+
+/**
+ * Class CurrencyController
+ */
+class CurrencyController extends Controller
+{
+ private CurrencyRepositoryInterface $repository;
+
+ /**
+ * CurrencyController constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->middleware(
+ function ($request, $next) {
+ /** @var User $user */
+ $user = auth()->user();
+ $this->repository = app(CurrencyRepositoryInterface::class);
+ $this->repository->setUser($user);
+
+ return $next($request);
+ }
+ );
+ }
+
+ /**
+ * @param AutocompleteRequest $request
+ *
+ * @return JsonResponse
+ * @codeCoverageIgnore
+ */
+ public function currencyWithCode(AutocompleteRequest $request): JsonResponse
+ {
+ $data = $request->getData();
+ $result = $this->repository->searchCurrency($data['query'])->toArray();
+ foreach ($result as $index => $item) {
+ $result[$index]['name'] = sprintf('%s (%s)', $item['name'], $item['code']);
+ }
+
+ return response()->json($result);
+ }
+}
diff --git a/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.php b/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.php
new file mode 100644
index 0000000000..7bf994d73c
--- /dev/null
+++ b/app/Api/V1/Controllers/Autocomplete/ObjectGroupController.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * ObjectGroupController.php
+ * Copyright (c) 2020 [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/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Api\V1\Controllers\Autocomplete;
+
+
+use FireflyIII\Api\V1\Controllers\Controller;
+use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
+use FireflyIII\Models\ObjectGroup;
+use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
+use FireflyIII\User;
+use Illuminate\Http\JsonResponse;
+
+/**
+ * Class ObjectGroupController
+ */
+class ObjectGroupController extends Controller
+{
+ private ObjectGroupRepositoryInterface $repository;
+
+ /**
+ * CurrencyController constructor.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ $this->middleware(
+ function ($request, $next) {
+ /** @var User $user */
+ $user = auth()->user();
+ $this->repository = app(ObjectGroupRepositoryInterface::class);
+ $this->repository->setUser($user);
+
+ return $next($request);
+ }
+ );
+ }
+
+ /**
+ * @param AutocompleteRequest $request
+ *
+ * @return JsonResponse
+ */
+ public function objectGroups(AutocompleteRequest $request): JsonResponse
+ {
+ $data = $request->getData();
+ $return = [];
+ $result = $this->repository->search($data['query']);
+
+ /** @var ObjectGroup $account */
+ foreach ($result as $objectGroup) {
+ $return[] = [
+ 'id' => $objectGroup->id,
+ 'title' => $objectGroup->title,
+ ];
+ }
+
+ return response()->json($return);
+ }
+
+}
diff --git a/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php
new file mode 100644
index 0000000000..095e636a76
--- /dev/null
+++ b/app/Api/V1/Controllers/Autocomplete/PiggyBankController.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * PiggyBankController.php
+ * Copyright (c) 2020 [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/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Api\V1\Controllers\Autocomplete;
+
+
+use FireflyIII\Api\V1\Controllers\Controller;
+
+/**
+ * Class PiggyBankController
+ */
+class PiggyBankController extends Controller
+{
+
+}
diff --git a/app/Api/V1/Controllers/Autocomplete/TagController.php b/app/Api/V1/Controllers/Autocomplete/TagController.php
new file mode 100644
index 0000000000..46188aeddb
--- /dev/null
+++ b/app/Api/V1/Controllers/Autocomplete/TagController.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * TagController.php
+ * Copyright (c) 2020 [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/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Api\V1\Controllers\Autocomplete;
+
+
+use FireflyIII\Api\V1\Controllers\Controller;
+
+/**
+ * Class TagController
+ */
+class TagController extends Controller
+{
+
+}
diff --git a/app/Api/V1/Controllers/Autocomplete/TransactionController.php b/app/Api/V1/Controllers/Autocomplete/TransactionController.php
new file mode 100644
index 0000000000..4e6eb3af6f
--- /dev/null
+++ b/app/Api/V1/Controllers/Autocomplete/TransactionController.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * TransactionController.php
+ * Copyright (c) 2020 [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/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Api\V1\Controllers\Autocomplete;
+
+
+use FireflyIII\Api\V1\Controllers\Controller;
+
+/**
+ * Class TransactionController
+ */
+class TransactionController extends Controller
+{
+
+}
diff --git a/app/Http/Controllers/Json/AutoCompleteController.php b/app/Http/Controllers/Json/AutoCompleteController.php
index 7072075927..64b81625e2 100644
--- a/app/Http/Controllers/Json/AutoCompleteController.php
+++ b/app/Http/Controllers/Json/AutoCompleteController.php
@@ -24,16 +24,9 @@ namespace FireflyIII\Http\Controllers\Json;
use Amount;
use FireflyIII\Http\Controllers\Controller;
-use FireflyIII\Models\Account;
-use FireflyIII\Models\AccountType;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\PiggyBank;
-use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use FireflyIII\Repositories\Bill\BillRepositoryInterface;
-use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
-use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
-use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
@@ -42,7 +35,6 @@ use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
-use Log;
/**
* Class AutoCompleteController.
@@ -130,113 +122,6 @@ class AutoCompleteController extends Controller
return response()->json($array);
}
-
- /**
- * @param Request $request
- *
- * @return JsonResponse
- * @codeCoverageIgnore
- */
- public function budgets(Request $request): JsonResponse
- {
- $search = (string) $request->get('search');
- /** @var BudgetRepositoryInterface $repository */
- $repository = app(BudgetRepositoryInterface::class);
- $result = $repository->searchBudget($search);
-
- return response()->json($result->toArray());
- }
-
- /**
- * @param Request $request
- *
- * @return JsonResponse
- * @codeCoverageIgnore
- */
- public function categories(Request $request): JsonResponse
- {
- $query = (string) $request->get('search');
- /** @var CategoryRepositoryInterface $repository */
- $repository = app(CategoryRepositoryInterface::class);
- $result = $repository->searchCategory($query);
-
- return response()->json($result->toArray());
- }
-
- /**
- * @return JsonResponse
- * @codeCoverageIgnore
- */
- public function currencies(): JsonResponse
- {
- /** @var CurrencyRepositoryInterface $repository */
- $repository = app(CurrencyRepositoryInterface::class);
- $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,
- ];
- }
-
- return response()->json($return);
- }
-
- /**
- * @param Request $request
- *
- * @return JsonResponse
- * @codeCoverageIgnore
- */
- public function currencyNames(Request $request): JsonResponse
- {
- $query = (string) $request->get('search');
- /** @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']);
- }
-
- return response()->json($result);
- }
-
-
- /**
- * An auto-complete specifically for expense accounts, used when mass updating mostly.
- *
- * @param Request $request
- *
- * @return JsonResponse
- */
- public function objectGroups(Request $request): JsonResponse
- {
- $search = $request->get('search');
-
- /** @var ObjectGroupRepositoryInterface $repository */
- $repository = app(ObjectGroupRepositoryInterface::class);
-
- $return = [];
- $result = $repository->search((string) $search);
-
- /** @var ObjectGroup $account */
- foreach ($result as $objectGroup) {
- $return[] = [
- 'id' => $objectGroup->id,
- 'title' => $objectGroup->title,
- ];
- }
-
- return response()->json($return);
- }
-
/**
* @return JsonResponse
* @codeCoverageIgnore
diff --git a/resources/assets/js/components/transactions/ForeignAmountSelect.vue b/resources/assets/js/components/transactions/ForeignAmountSelect.vue
index 9d82b62357..5ac2a3f459 100644
--- a/resources/assets/js/components/transactions/ForeignAmountSelect.vue
+++ b/resources/assets/js/components/transactions/ForeignAmountSelect.vue
@@ -192,11 +192,11 @@
enabled: true
}
];
- for (const key in res.data) {
- if (res.data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
- if (res.data[key].enabled) {
- this.currencies.push(res.data[key]);
- this.enabledCurrencies.push(res.data[key]);
+ for (const key in res.data.data) {
+ if (res.data.data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
+ if (res.data.data[key].enabled) {
+ this.currencies.push(res.data.data[key]);
+ this.enabledCurrencies.push(res.data.data[key]);
}
}
}
@@ -209,4 +209,4 @@
<style scoped>
-</style>
\ No newline at end of file
+</style>
diff --git a/routes/api.php b/routes/api.php
index e07ac77523..f639a394c2 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -65,6 +65,8 @@ Route::group(
Route::get('bills', ['uses' => 'BillController@bills', 'as' => 'bills']);
Route::get('budgets', ['uses' => 'BudgetController@budgets', 'as' => 'budgets']);
Route::get('categories', ['uses' => 'CategoryController@categories', 'as' => 'categories']);
+ Route::get('currencies', ['uses' => 'CurrencyController@currencies', 'as' => 'currencies']);
+ Route::get('object-groups', ['uses' => 'ObjectGroupController@objectGroups', 'as' => 'object-groups']);
}
);