mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Moved getAccountsById
This commit is contained in:
parent
717c1d080e
commit
e8a095e543
@ -84,30 +84,6 @@ class AccountCrud implements AccountCrudInterface
|
||||
return new Account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsById(array $accountIds): Collection
|
||||
{
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (count($accountIds) > 0) {
|
||||
$query->whereIn('accounts.id', $accountIds);
|
||||
}
|
||||
|
||||
$result = $query->get(['accounts.*']);
|
||||
$result = $result->sortBy(
|
||||
function (Account $account) {
|
||||
return strtolower($account->name);
|
||||
}
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
|
@ -35,13 +35,6 @@ interface AccountCrudInterface
|
||||
*/
|
||||
public function findByName(string $name, array $types): Account;
|
||||
|
||||
/**
|
||||
* @param array $accountIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsById(array $accountIds): Collection;
|
||||
|
||||
/**
|
||||
* @param array $types
|
||||
*
|
||||
|
@ -21,6 +21,7 @@ use FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@ -102,11 +103,12 @@ class AccountController extends Controller
|
||||
/**
|
||||
* Shows the balances for all the user's frontpage accounts.
|
||||
*
|
||||
* @param AccountCrudInterface $crud
|
||||
* @param AccountCrudInterface $crud
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function frontpage(AccountCrudInterface $crud)
|
||||
public function frontpage(AccountCrudInterface $crud, AccountRepositoryInterface $repository)
|
||||
{
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
@ -123,7 +125,7 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
$frontPage = Preferences::get('frontPageAccounts', $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray());
|
||||
$accounts = $crud->getAccountsById($frontPage->data);
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$balances = [];
|
||||
|
@ -22,6 +22,7 @@ use FireflyIII\Export\Processor;
|
||||
use FireflyIII\Http\Requests\ExportFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface as EJRI;
|
||||
use Preferences;
|
||||
use Response;
|
||||
@ -116,20 +117,20 @@ class ExportController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ExportFormRequest $request
|
||||
* @param AccountCrudInterface $crud
|
||||
*
|
||||
* @param EJRI $jobs
|
||||
* @param ExportFormRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param EJRI $jobs
|
||||
*
|
||||
* @return string
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @internal param AccountCrudInterface $crud
|
||||
*
|
||||
*/
|
||||
public function postIndex(ExportFormRequest $request, AccountCrudInterface $crud, EJRI $jobs)
|
||||
public function postIndex(ExportFormRequest $request, AccountRepositoryInterface $repository, EJRI $jobs)
|
||||
{
|
||||
set_time_limit(0);
|
||||
$job = $jobs->findByKey($request->get('job'));
|
||||
$settings = [
|
||||
'accounts' => $crud->getAccountsById($request->get('accounts')),
|
||||
'accounts' => $repository->getAccountsById($request->get('accounts')),
|
||||
'startDate' => new Carbon($request->get('export_start_range')),
|
||||
'endDate' => new Carbon($request->get('export_end_range')),
|
||||
'exportFormat' => $request->get('exportFormat'),
|
||||
|
@ -142,7 +142,7 @@ class HomeController extends Controller
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$showTour = Preferences::get('tour', true)->data;
|
||||
$accounts = $crud->getAccountsById($frontPage->data);
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
||||
|
@ -21,6 +21,7 @@ use FireflyIII\Http\Requests\SelectTransactionsRequest;
|
||||
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use Input;
|
||||
use Preferences;
|
||||
@ -146,16 +147,16 @@ class RuleGroupController extends Controller
|
||||
/**
|
||||
* Execute the given rulegroup on a set of existing transactions
|
||||
*
|
||||
* @param SelectTransactionsRequest $request
|
||||
* @param AccountCrudInterface $crud
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param SelectTransactionsRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function execute(SelectTransactionsRequest $request, AccountCrudInterface $crud, RuleGroup $ruleGroup)
|
||||
public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
// Get parameters specified by the user
|
||||
$accounts = $crud->getAccountsById($request->get('accounts'));
|
||||
$accounts = $repository->getAccountsById($request->get('accounts'));
|
||||
$startDate = new Carbon($request->get('start_date'));
|
||||
$endDate = new Carbon($request->get('end_date'));
|
||||
|
||||
|
@ -178,6 +178,30 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return new Account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAccountsById(array $accountIds): Collection
|
||||
{
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (count($accountIds) > 0) {
|
||||
$query->whereIn('accounts.id', $accountIds);
|
||||
}
|
||||
|
||||
$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.
|
||||
*
|
||||
|
@ -15,6 +15,7 @@ namespace FireflyIII\Repositories\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface AccountRepositoryInterface
|
||||
@ -33,6 +34,13 @@ 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
|
||||
|
Loading…
Reference in New Issue
Block a user