diff --git a/app/Crud/Account/AccountCrud.php b/app/Crud/Account/AccountCrud.php index ffc6cbf27d..e128d7a93c 100644 --- a/app/Crud/Account/AccountCrud.php +++ b/app/Crud/Account/AccountCrud.php @@ -84,29 +84,6 @@ class AccountCrud implements AccountCrudInterface return new Account; } - /** - * @param array $types - * - * @return Collection - */ - public function getAccountsByType(array $types): Collection - { - /** @var Collection $result */ - $query = $this->user->accounts(); - if (count($types) > 0) { - $query->accountTypeIn($types); - } - - $result = $query->get(['accounts.*']); - $result = $result->sortBy( - function (Account $account) { - return strtolower($account->name); - } - ); - - return $result; - } - /** * @param array $types * diff --git a/app/Crud/Account/AccountCrudInterface.php b/app/Crud/Account/AccountCrudInterface.php index 8462b19e76..ec3087176f 100644 --- a/app/Crud/Account/AccountCrudInterface.php +++ b/app/Crud/Account/AccountCrudInterface.php @@ -35,13 +35,6 @@ interface AccountCrudInterface */ public function findByName(string $name, array $types): Account; - /** - * @param array $types - * - * @return Collection - */ - public function getAccountsByType(array $types): Collection; - /** * @param array $types * diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 4d0d115a04..d476c1250c 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -73,16 +73,16 @@ class AccountController extends Controller } /** - * @param AccountCrudInterface $crud - * @param Account $account + * @param ARI $repository + * @param Account $account * * @return View */ - public function delete(AccountCrudInterface $crud, Account $account) + public function delete(ARI $repository, Account $account) { $typeName = config('firefly.shortNamesByFullName.' . $account->accountType->type); $subTitle = trans('firefly.delete_' . $typeName . '_account', ['name' => $account->name]); - $accountList = ExpandedForm::makeSelectListWithEmpty($crud->getAccountsByType([$account->accountType->type])); + $accountList = ExpandedForm::makeSelectListWithEmpty($repository->getAccountsByType([$account->accountType->type])); unset($accountList[$account->id]); // put previous url in session @@ -94,8 +94,8 @@ class AccountController extends Controller } /** - * @param ARI $repository - * @param Account $account + * @param ARI $repository + * @param Account $account * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ @@ -158,19 +158,19 @@ class AccountController extends Controller } /** - * @param AccountCrudInterface $crud - * @param string $what + * @param ARI $repository + * @param string $what * * @return View */ - public function index(AccountCrudInterface $crud, string $what) + public function index(ARI $repository, string $what) { $what = $what ?? 'asset'; $subTitle = trans('firefly.' . $what . '_accounts'); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); $types = config('firefly.accountTypesByIdentifier.' . $what); - $accounts = $crud->getAccountsByType($types); + $accounts = $repository->getAccountsByType($types); /** @var Carbon $start */ $start = clone session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ @@ -195,13 +195,12 @@ class AccountController extends Controller /** * @param AccountTaskerInterface $tasker - * @param AccountCrudInterface $crud * @param ARI $repository * @param Account $account * * @return View */ - public function show(AccountTaskerInterface $tasker, AccountCrudInterface $crud, ARI $repository, Account $account) + public function show(AccountTaskerInterface $tasker, ARI $repository, Account $account) { // show journals from current period only: $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type); @@ -245,7 +244,7 @@ class AccountController extends Controller // only include asset accounts when this account is an asset: $assets = new Collection; if (in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEFAULT])) { - $assets = $crud->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); + $assets = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); } while ($end >= $start) { diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index aed7c69989..93d9a35261 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -16,12 +16,12 @@ namespace FireflyIII\Http\Controllers; use Amount; use Carbon\Carbon; use Config; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Requests\BudgetFormRequest; use FireflyIII\Models\AccountType; use FireflyIII\Models\Budget; use FireflyIII\Models\LimitRepetition; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; @@ -158,12 +158,13 @@ class BudgetController extends Controller } /** - * @param BudgetRepositoryInterface $repository - * @param AccountCrudInterface $crud + * @param BudgetRepositoryInterface $repository + * @param AccountRepositoryInterface $accountRepository * * @return View + * */ - public function index(BudgetRepositoryInterface $repository, AccountCrudInterface $crud) + public function index(BudgetRepositoryInterface $repository, AccountRepositoryInterface $accountRepository) { $repository->cleanupBudgets(); @@ -187,7 +188,7 @@ class BudgetController extends Controller $period = Navigation::periodShow($start, $range); $periodStart = $start->formatLocalized($this->monthAndDayFormat); $periodEnd = $end->formatLocalized($this->monthAndDayFormat); - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]); + $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]); $startAsString = $start->format('Y-m-d'); $endAsString = $end->format('Y-m-d'); diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index ce693de019..1a1fb3d787 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -14,10 +14,10 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; use Carbon\Carbon; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\CategoryFormRequest; use FireflyIII\Models\AccountType; use FireflyIII\Models\Category; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI; use FireflyIII\Support\CacheProperties; use Illuminate\Pagination\LengthAwarePaginator; @@ -159,13 +159,13 @@ class CategoryController extends Controller } /** - * @param CRI $repository - * @param AccountCrudInterface $crud - * @param Category $category + * @param CRI $repository + * @param AccountRepositoryInterface $accountRepository + * @param Category $category * * @return View */ - public function show(CRI $repository, AccountCrudInterface $crud, Category $category) + public function show(CRI $repository, AccountRepositoryInterface $accountRepository, Category $category) { $range = Preferences::get('viewRange', '1M')->data; /** @var Carbon $start */ @@ -210,7 +210,7 @@ class CategoryController extends Controller $categoryCollection = new Collection([$category]); - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); while ($end >= $start) { $end = Navigation::startOfPeriod($end, $range); $currentEnd = Navigation::endOfPeriod($end, $range); diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index e8877b2c6c..e1a18afd09 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers\Chart; use Carbon\Carbon; use Exception; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface; use FireflyIII\Http\Controllers\Controller; @@ -54,11 +53,11 @@ class AccountController extends Controller /** * Shows the balances for all the user's expense accounts. * - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse */ - public function expenseAccounts(AccountCrudInterface $crud) + public function expenseAccounts(AccountRepositoryInterface $repository) { $start = clone session('start', Carbon::now()->startOfMonth()); $end = clone session('end', Carbon::now()->endOfMonth()); @@ -70,7 +69,7 @@ class AccountController extends Controller if ($cache->has()) { return Response::json($cache->get()); } - $accounts = $crud->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]); + $accounts = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]); $start->subDay(); $ids = $accounts->pluck('id')->toArray(); @@ -103,12 +102,11 @@ class AccountController extends Controller /** * Shows the balances for all the user's frontpage accounts. * - * @param AccountCrudInterface $crud * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse */ - public function frontpage(AccountCrudInterface $crud, AccountRepositoryInterface $repository) + public function frontpage(AccountRepositoryInterface $repository) { $start = clone session('start', Carbon::now()->startOfMonth()); $end = clone session('end', Carbon::now()->endOfMonth()); @@ -124,7 +122,7 @@ class AccountController extends Controller return Response::json($cache->get()); } - $frontPage = Preferences::get('frontPageAccounts', $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()); + $frontPage = Preferences::get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()); $accounts = $repository->getAccountsById($frontPage->data); foreach ($accounts as $account) { diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index ab65675c37..98a8392ca4 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -15,11 +15,11 @@ namespace FireflyIII\Http\Controllers\Chart; use Carbon\Carbon; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\AccountType; use FireflyIII\Models\Category; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; @@ -52,13 +52,13 @@ class CategoryController extends Controller /** * Show an overview for a category for all time, per month/week/year. * - * @param CRI $repository - * @param AccountCrudInterface $crud - * @param Category $category + * @param CRI $repository + * @param AccountRepositoryInterface $accountRepository + * @param Category $category * * @return \Symfony\Component\HttpFoundation\Response */ - public function all(CRI $repository, AccountCrudInterface $crud, Category $category) + public function all(CRI $repository, AccountRepositoryInterface $accountRepository, Category $category) { $start = $repository->firstUseDate($category); $range = Preferences::get('viewRange', '1M')->data; @@ -67,7 +67,7 @@ class CategoryController extends Controller $end = new Carbon; $entries = new Collection; $cache = new CacheProperties; - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $cache->addProperty($start); $cache->addProperty($end); $cache->addProperty('all'); @@ -110,12 +110,12 @@ class CategoryController extends Controller } /** - * @param CRI $repository - * @param AccountCrudInterface $crud + * @param CRI $repository + * @param AccountRepositoryInterface $accountRepository * * @return \Illuminate\Http\JsonResponse */ - public function frontpage(CRI $repository, AccountCrudInterface $crud) + public function frontpage(CRI $repository, AccountRepositoryInterface $accountRepository) { $start = session('start', Carbon::now()->startOfMonth()); $end = session('end', Carbon::now()->endOfMonth()); @@ -129,7 +129,7 @@ class CategoryController extends Controller return Response::json($cache->get()); } $categories = $repository->getCategories(); - $accounts = $crud->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); + $accounts = $accountRepository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); $set = new Collection; /** @var Category $category */ foreach ($categories as $category) { @@ -256,9 +256,10 @@ class CategoryController extends Controller { $categoryCollection = new Collection([$category]); $cache = new CacheProperties; - /** @var AccountCrudInterface $crud */ - $crud = app(AccountCrudInterface::class); - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $cache->addProperty($start); $cache->addProperty($end); diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index 59d8cded47..d799d14c39 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -16,7 +16,6 @@ namespace FireflyIII\Http\Controllers; use Carbon\Carbon; use ExpandedForm; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Export\Processor; use FireflyIII\Http\Requests\ExportFormRequest; @@ -91,12 +90,12 @@ class ExportController extends Controller } /** - * @param AccountCrudInterface $crud - * @param EJRI $jobs + * @param AccountRepositoryInterface $repository + * @param EJRI $jobs * * @return View */ - public function index(AccountCrudInterface $crud, EJRI $jobs) + public function index(AccountRepositoryInterface $repository, EJRI $jobs) { // create new export job. $job = $jobs->create(); @@ -104,7 +103,7 @@ class ExportController extends Controller $jobs->cleanup(); // does the user have shared accounts? - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accountList = ExpandedForm::makeSelectList($accounts); $checked = array_keys($accountList); $formats = array_keys(config('firefly.export_formats')); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 63b2332792..8f8d40a535 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -14,7 +14,6 @@ namespace FireflyIII\Http\Controllers; use Artisan; use Carbon\Carbon; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\AccountType; use FireflyIII\Models\Tag; @@ -115,12 +114,11 @@ class HomeController extends Controller /** * @param ARI $repository - * @param AccountCrudInterface $crud * @param AccountTaskerInterface $tasker * * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View */ - public function index(ARI $repository, AccountCrudInterface $crud, AccountTaskerInterface $tasker) + public function index(ARI $repository, AccountTaskerInterface $tasker) { $types = config('firefly.accountTypesByIdentifier.asset'); @@ -135,7 +133,7 @@ class HomeController extends Controller $mainTitleIcon = 'fa-fire'; $transactions = []; $frontPage = Preferences::get( - 'frontPageAccounts', $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray() + 'frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray() ); /** @var Carbon $start */ $start = session('start', Carbon::now()->startOfMonth()); diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 5857040e44..39918cdbd8 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -14,9 +14,9 @@ namespace FireflyIII\Http\Controllers; use Amount; use Carbon\Carbon; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\AccountType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountTaskerInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface as CRI; @@ -97,13 +97,15 @@ class JsonController extends Controller } /** - * @param AccountTaskerInterface $accountTasker - * @param AccountCrudInterface $crud + * @param AccountTaskerInterface $accountTasker + * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse + * @internal param AccountCrudInterface $crud + * * @internal param ARI $accountRepository */ - public function boxIn(AccountTaskerInterface $accountTasker, AccountCrudInterface $crud) + public function boxIn(AccountTaskerInterface $accountTasker, AccountRepositoryInterface $repository) { $start = session('start', Carbon::now()->startOfMonth()); $end = session('end', Carbon::now()->endOfMonth()); @@ -116,8 +118,8 @@ class JsonController extends Controller if ($cache->has()) { return Response::json($cache->get()); } - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]); - $assets = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]); + $assets = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $amount = $accountTasker->amountInInPeriod($accounts, $assets, $start, $end); $data = ['box' => 'in', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; $cache->store($data); @@ -126,13 +128,12 @@ class JsonController extends Controller } /** - * @param AccountCrudInterface $crud - * @param AccountTaskerInterface $accountTasker + * @param AccountTaskerInterface $accountTasker + * @param AccountRepositoryInterface $repository * * @return \Symfony\Component\HttpFoundation\Response - * @internal param ARI $accountRepository */ - public function boxOut(AccountCrudInterface $crud, AccountTaskerInterface $accountTasker) + public function boxOut(AccountTaskerInterface $accountTasker, AccountRepositoryInterface $repository) { $start = session('start', Carbon::now()->startOfMonth()); $end = session('end', Carbon::now()->endOfMonth()); @@ -146,8 +147,8 @@ class JsonController extends Controller return Response::json($cache->get()); } - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]); - $assets = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]); + $assets = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $amount = $accountTasker->amountOutInPeriod($accounts, $assets, $start, $end); $data = ['box' => 'out', 'amount' => Amount::format($amount, false), 'amount_raw' => $amount]; @@ -187,13 +188,14 @@ class JsonController extends Controller /** * Returns a JSON list of all beneficiaries. * - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse + * */ - public function expenseAccounts(AccountCrudInterface $crud) + public function expenseAccounts(AccountRepositoryInterface $repository) { - $list = $crud->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]); + $list = $repository->getAccountsByType([AccountType::EXPENSE, AccountType::BENEFICIARY]); $return = []; foreach ($list as $entry) { $return[] = $entry->name; @@ -204,13 +206,14 @@ class JsonController extends Controller } /** - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\JsonResponse + * */ - public function revenueAccounts(AccountCrudInterface $crud) + public function revenueAccounts(AccountRepositoryInterface $repository) { - $list = $crud->getAccountsByType([AccountType::REVENUE]); + $list = $repository->getAccountsByType([AccountType::REVENUE]); $return = []; foreach ($list as $entry) { $return[] = $entry->name; diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index dc577b4291..59e79a74c7 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -15,10 +15,10 @@ namespace FireflyIII\Http\Controllers; use Amount; use Carbon\Carbon; use ExpandedForm; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\PiggyBankFormRequest; use FireflyIII\Models\AccountType; use FireflyIII\Models\PiggyBank; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use Illuminate\Support\Collection; use Input; @@ -88,13 +88,14 @@ class PiggyBankController extends Controller } /** - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return View + * */ - public function create(AccountCrudInterface $crud) + public function create(AccountRepositoryInterface $repository) { - $accounts = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); + $accounts = ExpandedForm::makeSelectList($repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); $subTitle = trans('firefly.new_piggy_bank'); $subTitleIcon = 'fa-plus'; @@ -144,15 +145,15 @@ class PiggyBankController extends Controller } /** - * @param AccountCrudInterface $crud - * @param PiggyBank $piggyBank + * @param AccountRepositoryInterface $repository + * @param PiggyBank $piggyBank * * @return View */ - public function edit(AccountCrudInterface $crud, PiggyBank $piggyBank) + public function edit(AccountRepositoryInterface $repository, PiggyBank $piggyBank) { - $accounts = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); + $accounts = ExpandedForm::makeSelectList($repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); $subTitle = trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); $subTitleIcon = 'fa-pencil'; $targetDate = null; diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 0c4b037d07..269eb9546b 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -12,9 +12,9 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\TokenFormRequest; use FireflyIII\Models\AccountType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Http\Request; use PragmaRX\Google2FA\Contracts\Google2FA; use Preferences; @@ -70,13 +70,13 @@ class PreferencesController extends Controller } /** - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return View */ - public function index(AccountCrudInterface $crud) + public function index(AccountRepositoryInterface $repository) { - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $viewRangePref = Preferences::get('viewRange', '1M'); $viewRange = $viewRangePref->data; $frontPageAccounts = Preferences::get('frontPageAccounts', []); diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 18b34b50c9..9834dab7c0 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -14,7 +14,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; use Carbon\Carbon; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Report\BalanceReportHelperInterface; use FireflyIII\Helpers\Report\BudgetReportHelperInterface; @@ -22,6 +21,7 @@ use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\Transaction; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; use FireflyIII\Repositories\Account\AccountTaskerInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; @@ -61,11 +61,11 @@ class ReportController extends Controller } /** - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return View */ - public function index(AccountCrudInterface $crud) + public function index(AccountRepositoryInterface $repository) { $this->createRepositories(); /** @var Carbon $start */ @@ -74,7 +74,7 @@ class ReportController extends Controller $customFiscalYear = Preferences::get('customFiscalYear', 0)->data; // does the user have shared accounts? - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); // get id's for quick links: $accountIds = []; /** @var Account $account */ diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.php index 5345b95041..0e07253ea7 100644 --- a/app/Http/Controllers/RuleGroupController.php +++ b/app/Http/Controllers/RuleGroupController.php @@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers; use Carbon\Carbon; use ExpandedForm; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\RuleGroupFormRequest; use FireflyIII\Http\Requests\SelectTransactionsRequest; use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions; @@ -179,15 +178,15 @@ class RuleGroupController extends Controller } /** - * @param AccountCrudInterface $crud - * @param RuleGroup $ruleGroup + * @param AccountRepositoryInterface $repository + * @param RuleGroup $ruleGroup * * @return View */ - public function selectTransactions(AccountCrudInterface $crud, RuleGroup $ruleGroup) + public function selectTransactions(AccountRepositoryInterface $repository, RuleGroup $ruleGroup) { // does the user have shared accounts? - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accountList = ExpandedForm::makeSelectList($accounts); $checkedAccounts = array_keys($accountList); $first = session('first')->format('Y-m-d'); diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index 8334b23668..55096119d9 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -20,6 +20,7 @@ use FireflyIII\Http\Requests\MassDeleteJournalRequest; use FireflyIII\Http\Requests\MassEditJournalRequest; use FireflyIII\Models\AccountType; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Preferences; @@ -107,9 +108,11 @@ class MassController extends Controller */ public function massEdit(Collection $journals) { - $subTitle = trans('firefly.mass_edit_journals'); - $crud = app('FireflyIII\Crud\Account\AccountCrudInterface'); - $accountList = ExpandedForm::makeSelectList($crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); + $subTitle = trans('firefly.mass_edit_journals'); + + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $accountList = ExpandedForm::makeSelectList($repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])); // skip transactions that have multiple destinations // or multiple sources: diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php index 29fbaa4e57..17f5994d39 100644 --- a/app/Http/Controllers/Transaction/SplitController.php +++ b/app/Http/Controllers/Transaction/SplitController.php @@ -24,6 +24,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Http\Request; use Illuminate\Support\Collection; use Log; @@ -61,17 +62,20 @@ class SplitController extends Controller $currencyRepository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface'); $budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); $piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface'); - $crud = app('FireflyIII\Crud\Account\AccountCrudInterface'); - $assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account'])); - $sessionData = session('journal-data', []); - $uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size'))); - $currencies = ExpandedForm::makeSelectList($currencyRepository->get()); - $budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); - $piggyBanks = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanksWithAmount()); - $subTitle = trans('form.add_new_' . $sessionData['what']); - $optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; - $subTitleIcon = 'fa-plus'; - $preFilled = [ + + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + + $assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccountsByType(['Default account', 'Asset account'])); + $sessionData = session('journal-data', []); + $uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size'))); + $currencies = ExpandedForm::makeSelectList($currencyRepository->get()); + $budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); + $piggyBanks = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanksWithAmount()); + $subTitle = trans('form.add_new_' . $sessionData['what']); + $optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; + $subTitleIcon = 'fa-plus'; + $preFilled = [ 'what' => $sessionData['what'] ?? 'withdrawal', 'journal_amount' => $sessionData['amount'] ?? 0, 'journal_source_account_id' => $sessionData['source_account_id'] ?? 0, @@ -100,15 +104,18 @@ class SplitController extends Controller { $currencyRepository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface'); $budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); - $crud = app('FireflyIII\Crud\Account\AccountCrudInterface'); - $uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size'))); - $currencies = ExpandedForm::makeSelectList($currencyRepository->get()); - $assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account'])); - $optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; - $budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); - $preFilled = $this->arrayFromJournal($request, $journal); - $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); - $subTitleIcon = 'fa-pencil'; + + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + + $uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size'))); + $currencies = ExpandedForm::makeSelectList($currencyRepository->get()); + $assetAccounts = ExpandedForm::makeSelectList($accountRepository->getAccountsByType(['Default account', 'Asset account'])); + $optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; + $budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); + $preFilled = $this->arrayFromJournal($request, $journal); + $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); + $subTitleIcon = 'fa-pencil'; Session::flash('gaEventCategory', 'transactions'); Session::flash('gaEventAction', 'edit-split-' . $preFilled['what']); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index aac0dccaae..ce6542586c 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -23,6 +23,7 @@ use FireflyIII\Http\Requests\JournalFormRequest; use FireflyIII\Models\AccountType; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Http\Request; use Preferences; @@ -150,10 +151,13 @@ class TransactionController extends Controller // code to get list data: $budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); $piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface'); - $crud = app('FireflyIII\Crud\Account\AccountCrudInterface'); - $assetAccounts = ExpandedForm::makeSelectList($crud->getAccountsByType(['Default account', 'Asset account'])); - $budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); - $piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks()); + + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + + $assetAccounts = ExpandedForm::makeSelectList($repository->getAccountsByType(['Default account', 'Asset account'])); + $budgetList = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); + $piggyBankList = ExpandedForm::makeSelectListWithEmpty($piggyRepository->getPiggyBanks()); // view related code $subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]); @@ -245,7 +249,7 @@ class TransactionController extends Controller $date = new Carbon($request->get('date')); if (count($ids) > 0) { $order = 0; - $ids = array_unique($ids); + $ids = array_unique($ids); foreach ($ids as $id) { $journal = $repository->find(intval($id)); if ($journal && $journal->date->format('Y-m-d') == $date->format('Y-m-d')) { diff --git a/app/Import/Mapper/AssetAccountIbans.php b/app/Import/Mapper/AssetAccountIbans.php index d45d558e37..e5ff5b8016 100644 --- a/app/Import/Mapper/AssetAccountIbans.php +++ b/app/Import/Mapper/AssetAccountIbans.php @@ -13,9 +13,9 @@ declare(strict_types = 1); namespace FireflyIII\Import\Mapper; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; /** * Class AssetAccounts @@ -30,11 +30,11 @@ class AssetAccountIbans implements MapperInterface */ public function getMap(): array { - /** @var AccountCrudInterface $crud */ - $crud = app(AccountCrudInterface::class); - $set = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); - $topList = []; - $list = []; + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $set = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $topList = []; + $list = []; /** @var Account $account */ foreach ($set as $account) { diff --git a/app/Import/Mapper/AssetAccounts.php b/app/Import/Mapper/AssetAccounts.php index fd8c9df410..dc6032dc7a 100644 --- a/app/Import/Mapper/AssetAccounts.php +++ b/app/Import/Mapper/AssetAccounts.php @@ -13,9 +13,9 @@ declare(strict_types = 1); namespace FireflyIII\Import\Mapper; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; /** * Class AssetAccounts @@ -30,10 +30,10 @@ class AssetAccounts implements MapperInterface */ public function getMap(): array { - /** @var AccountCrudInterface $crud */ - $crud = app(AccountCrudInterface::class); - $set = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); - $list = []; + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $set = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $list = []; /** @var Account $account */ foreach ($set as $account) { diff --git a/app/Import/Mapper/OpposingAccountIbans.php b/app/Import/Mapper/OpposingAccountIbans.php index 9e10c69ca9..dd2a3261ca 100644 --- a/app/Import/Mapper/OpposingAccountIbans.php +++ b/app/Import/Mapper/OpposingAccountIbans.php @@ -13,9 +13,9 @@ declare(strict_types = 1); namespace FireflyIII\Import\Mapper; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; /** * Class OpposingAccounts @@ -30,17 +30,17 @@ class OpposingAccountIbans implements MapperInterface */ public function getMap(): array { - /** @var AccountCrudInterface $crud */ - $crud = app(AccountCrudInterface::class); - $set = $crud->getAccountsByType( + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $set = $accountRepository->getAccountsByType( [ AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::REVENUE, ] ); - $topList = []; - $list = []; + $topList = []; + $list = []; /** @var Account $account */ foreach ($set as $account) { diff --git a/app/Import/Mapper/OpposingAccounts.php b/app/Import/Mapper/OpposingAccounts.php index 06e222ee39..8fbc20768e 100644 --- a/app/Import/Mapper/OpposingAccounts.php +++ b/app/Import/Mapper/OpposingAccounts.php @@ -13,9 +13,9 @@ declare(strict_types = 1); namespace FireflyIII\Import\Mapper; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; /** * Class OpposingAccounts @@ -30,16 +30,16 @@ class OpposingAccounts implements MapperInterface */ public function getMap(): array { - /** @var AccountCrudInterface $crud */ - $crud = app(AccountCrudInterface::class); - $set = $crud->getAccountsByType( + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $set = $accountRepository->getAccountsByType( [ AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::REVENUE, ] ); - $list = []; + $list = []; /** @var Account $account */ foreach ($set as $account) { diff --git a/app/Import/Setup/CsvSetup.php b/app/Import/Setup/CsvSetup.php index 67c4cd77fd..2bb8dca422 100644 --- a/app/Import/Setup/CsvSetup.php +++ b/app/Import/Setup/CsvSetup.php @@ -15,7 +15,6 @@ namespace FireflyIII\Import\Setup; use ExpandedForm; -use FireflyIII\Crud\Account\AccountCrud; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Import\Mapper\MapperInterface; use FireflyIII\Import\MapperPreProcess\PreProcessorInterface; @@ -75,9 +74,10 @@ class CsvSetup implements SetupInterface */ public function getConfigurationData(): array { - $crud = app('FireflyIII\Crud\Account\AccountCrudInterface'); - $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); - $delimiters = [ + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); + $delimiters = [ ',' => trans('form.csv_comma'), ';' => trans('form.csv_semicolon'), 'tab' => trans('form.csv_tab'), @@ -181,8 +181,8 @@ class CsvSetup implements SetupInterface /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class, [auth()->user()]); - $importId = $data['csv_import_account'] ?? 0; - $account = $repository->find(intval($importId)); + $importId = $data['csv_import_account'] ?? 0; + $account = $repository->find(intval($importId)); $hasHeaders = isset($data['has_headers']) && intval($data['has_headers']) === 1 ? true : false; $config = $this->job->configuration; diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 9b9c679103..d4f28480a9 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -202,6 +202,29 @@ class AccountRepository implements AccountRepositoryInterface return $result; } + /** + * @param array $types + * + * @return Collection + */ + public function getAccountsByType(array $types): Collection + { + /** @var Collection $result */ + $query = $this->user->accounts(); + if (count($types) > 0) { + $query->accountTypeIn($types); + } + + $result = $query->get(['accounts.*']); + $result = $result->sortBy( + function (Account $account) { + return strtolower($account->name); + } + ); + + return $result; + } + /** * Returns the date of the very first transaction in this account. * diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 837885cc49..831cbf3770 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -34,21 +34,6 @@ interface AccountRepositoryInterface */ public function count(array $types): int; - /** - * @param array $accountIds - * - * @return Collection - */ - public function getAccountsById(array $accountIds): Collection; - - /** - * @param string $name - * @param array $types - * - * @return Account - */ - public function findByName(string $name, array $types): Account; - /** * Moved here from account CRUD. * @@ -82,6 +67,28 @@ interface AccountRepositoryInterface */ public function findByIban(string $iban, array $types): Account; + /** + * @param string $name + * @param array $types + * + * @return Account + */ + public function findByName(string $name, array $types): Account; + + /** + * @param array $accountIds + * + * @return Collection + */ + public function getAccountsById(array $accountIds): Collection; + + /** + * @param array $types + * + * @return Collection + */ + public function getAccountsByType(array $types): Collection; + /** * Returns the date of the very first transaction in this account. * diff --git a/app/Repositories/Account/AccountTaskerInterface.php b/app/Repositories/Account/AccountTaskerInterface.php index 9bee71482e..61d3ebdbcc 100644 --- a/app/Repositories/Account/AccountTaskerInterface.php +++ b/app/Repositories/Account/AccountTaskerInterface.php @@ -62,6 +62,15 @@ interface AccountTaskerInterface */ public function expenseReport(Collection $accounts, Collection $excluded, Carbon $start, Carbon $end): Collection; + /** + * @param Carbon $start + * @param Carbon $end + * @param Collection $accounts + * + * @return AccountCollection + */ + public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection; + /** * Experimental getJournals method. * @@ -74,15 +83,6 @@ interface AccountTaskerInterface */ public function getJournalsInPeriod(Collection $accounts, array $types, Carbon $start, Carbon $end): Collection; - /** - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * - * @return AccountCollection - */ - public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection; - /** * @param Collection $accounts * @param Collection $excluded