diff --git a/app/Crud/Account/AccountCrud.php b/app/Crud/Account/AccountCrud.php index e128d7a93c..1e83d004f4 100644 --- a/app/Crud/Account/AccountCrud.php +++ b/app/Crud/Account/AccountCrud.php @@ -84,33 +84,6 @@ class AccountCrud implements AccountCrudInterface return new Account; } - /** - * @param array $types - * - * @return Collection - */ - public function getActiveAccountsByType(array $types): Collection - { - /** @var Collection $result */ - $query = $this->user->accounts()->with( - ['accountmeta' => function (HasMany $query) { - $query->where('name', 'accountRole'); - }] - ); - if (count($types) > 0) { - $query->accountTypeIn($types); - } - $query->where('active', 1); - $result = $query->get(['accounts.*']); - $result = $result->sortBy( - function (Account $account) { - return strtolower($account->name); - } - ); - - return $result; - } - /** * @param array $data * @@ -132,18 +105,6 @@ class AccountCrud implements AccountCrudInterface } - /** - * @param $account - * @param $name - * @param $value - * - * @return AccountMeta - */ - public function storeMeta(Account $account, string $name, $value): AccountMeta - { - return AccountMeta::create(['name' => $name, 'data' => $value, 'account_id' => $account->id,]); - } - /** * @param Account $account * @param array $data diff --git a/app/Crud/Account/AccountCrudInterface.php b/app/Crud/Account/AccountCrudInterface.php index ec3087176f..6dfcd6e713 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 getActiveAccountsByType(array $types): Collection; - /** * @param array $data * @@ -49,15 +42,6 @@ interface AccountCrudInterface */ public function store(array $data) : Account; - /** - * @param $account - * @param $name - * @param $value - * - * @return AccountMeta - */ - public function storeMeta(Account $account, string $name, $value): AccountMeta; - /** * @param Account $account * @param array $data diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index ce6542586c..98ce9f9317 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers; use Carbon\Carbon; use ExpandedForm; -use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Events\TransactionJournalStored; use FireflyIII\Events\TransactionJournalUpdated; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; @@ -63,20 +62,20 @@ class TransactionController extends Controller */ public function create(string $what = TransactionType::DEPOSIT) { - /** @var AccountCrudInterface $crud */ - $crud = app(AccountCrudInterface::class); - $budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); - $piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface'); - $what = strtolower($what); - $uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size'))); - $assetAccounts = ExpandedForm::makeSelectList($crud->getActiveAccountsByType(['Default account', 'Asset account'])); - $budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); - $piggyBanks = $piggyRepository->getPiggyBanksWithAmount(); - $piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks); - $preFilled = Session::has('preFilled') ? session('preFilled') : []; - $subTitle = trans('form.add_new_' . $what); - $subTitleIcon = 'fa-plus'; - $optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; + /** @var AccountRepositoryInterface $accountRepository */ + $accountRepository = app(AccountRepositoryInterface::class); + $budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + $piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface'); + $what = strtolower($what); + $uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size'))); + $assetAccounts = ExpandedForm::makeSelectList($accountRepository->getActiveAccountsByType(['Default account', 'Asset account'])); + $budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets()); + $piggyBanks = $piggyRepository->getPiggyBanksWithAmount(); + $piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks); + $preFilled = Session::has('preFilled') ? session('preFilled') : []; + $subTitle = trans('form.add_new_' . $what); + $subTitleIcon = 'fa-plus'; + $optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; Session::put('preFilled', $preFilled); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index d4f28480a9..afed9ef68d 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -225,6 +225,33 @@ class AccountRepository implements AccountRepositoryInterface return $result; } + /** + * @param array $types + * + * @return Collection + */ + public function getActiveAccountsByType(array $types): Collection + { + /** @var Collection $result */ + $query = $this->user->accounts()->with( + ['accountmeta' => function (HasMany $query) { + $query->where('name', 'accountRole'); + }] + ); + if (count($types) > 0) { + $query->accountTypeIn($types); + } + $query->where('active', 1); + $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 831cbf3770..21d8c7a163 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -89,6 +89,13 @@ interface AccountRepositoryInterface */ public function getAccountsByType(array $types): Collection; + /** + * @param array $types + * + * @return Collection + */ + public function getActiveAccountsByType(array $types): Collection; + /** * Returns the date of the very first transaction in this account. *