Skip to content

Firefly III: a personal finances manager

Fix #3901

James Cole3bd5ac21c90a
diff --git a/app/Api/V1/Controllers/CurrencyController.php b/app/Api/V1/Controllers/CurrencyController.php
index 69b6b13c14..1f8a9a709d 100644
--- a/app/Api/V1/Controllers/CurrencyController.php
+++ b/app/Api/V1/Controllers/CurrencyController.php
@@ -68,11 +68,8 @@ class CurrencyController extends Controller
{
use AccountFilter, TransactionFilter;
- /** @var CurrencyRepositoryInterface The currency repository */
- private $repository;
-
- /** @var UserRepositoryInterface The user repository */
- private $userRepository;
+ private CurrencyRepositoryInterface $repository;
+ private UserRepositoryInterface $userRepository;
/**
@@ -161,22 +158,14 @@ class CurrencyController extends Controller
*/
public function availableBudgets(TransactionCurrency $currency): JsonResponse
{
- /** @var User $admin */
- $admin = auth()->user();
-
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of available budgets. Count it and split it.
-
- /** @var BudgetRepositoryInterface $repository */
- $repository = app(BudgetRepositoryInterface::class);
-
/** @var AvailableBudgetRepositoryInterface $abRepository */
$abRepository = app(AvailableBudgetRepositoryInterface::class);
- $repository->setUser($admin);
$collection = $abRepository->getAvailableBudgetsByCurrency($currency);
$count = $collection->count();
$availableBudgets = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
@@ -208,10 +197,10 @@ class CurrencyController extends Controller
{
$manager = $this->getManager();
- /** @var BillRepositoryInterface $repository */
- $repository = app(BillRepositoryInterface::class);
+ /** @var BillRepositoryInterface $billRepos */
+ $billRepos = app(BillRepositoryInterface::class);
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
- $unfiltered = $repository->getBills();
+ $unfiltered = $billRepos->getBills();
// filter and paginate list:
$collection = $unfiltered->filter(
@@ -303,9 +292,9 @@ class CurrencyController extends Controller
*
* @param TransactionCurrency $currency
*
+ * @return JsonResponse
* @throws FireflyException
* @codeCoverageIgnore
- * @return JsonResponse
*/
public function delete(TransactionCurrency $currency): JsonResponse
{
@@ -459,9 +448,9 @@ class CurrencyController extends Controller
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
- /** @var RecurringRepositoryInterface $repository */
- $repository = app(RecurringRepositoryInterface::class);
- $unfiltered = $repository->getAll();
+ /** @var RecurringRepositoryInterface $recurringRepos */
+ $recurringRepos = app(RecurringRepositoryInterface::class);
+ $unfiltered = $recurringRepos->getAll();
// filter selection
$collection = $unfiltered->filter(
@@ -510,9 +499,9 @@ class CurrencyController extends Controller
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
- /** @var RuleRepositoryInterface $repository */
- $repository = app(RuleRepositoryInterface::class);
- $unfiltered = $repository->getAll();
+ /** @var RuleRepositoryInterface $ruleRepos */
+ $ruleRepos = app(RuleRepositoryInterface::class);
+ $unfiltered = $ruleRepos->getAll();
$collection = $unfiltered->filter(
static function (Rule $rule) use ($currency) {
@@ -594,8 +583,8 @@ class CurrencyController extends Controller
*
* @param CurrencyRequest $request
*
- * @throws FireflyException
* @return JsonResponse
+ * @throws FireflyException
*/
public function store(CurrencyRequest $request): JsonResponse
{
diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.php
index f6b8e879f4..c8cd0ece86 100644
--- a/app/Repositories/Rule/RuleRepository.php
+++ b/app/Repositories/Rule/RuleRepository.php
@@ -506,7 +506,14 @@ class RuleRepository implements RuleRepositoryInterface
*/
public function getStoreRules(): Collection
{
- $collection = $this->user->rules()->where('rules.active', 1)->with(['ruleGroup', 'ruleTriggers'])->get();
+ $collection = $this->user->rules()
+ ->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id')
+ ->where('rules.active', 1)
+ ->where('rule_groups.active', 1)
+ ->orderBy('rule_groups.order', 'ASC')
+ ->orderBy('rules.order', 'ASC')
+ ->orderBy('rules.id', 'ASC')
+ ->with(['ruleGroup', 'ruleTriggers'])->get(['rules.*']);
$filtered = new Collection;
/** @var Rule $rule */
foreach ($collection as $rule) {
@@ -525,7 +532,14 @@ class RuleRepository implements RuleRepositoryInterface
*/
public function getUpdateRules(): Collection
{
- $collection = $this->user->rules()->where('rules.active', 1)->with(['ruleGroup', 'ruleTriggers'])->get();
+ $collection = $this->user->rules()
+ ->leftJoin('rule_groups', 'rule_groups.id', '=', 'rules.rule_group_id')
+ ->where('rules.active', 1)
+ ->where('rule_groups.active', 1)
+ ->orderBy('rule_groups.order', 'ASC')
+ ->orderBy('rules.order', 'ASC')
+ ->orderBy('rules.id', 'ASC')
+ ->with(['ruleGroup', 'ruleTriggers'])->get();
$filtered = new Collection;
/** @var Rule $rule */
foreach ($collection as $rule) {