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:
@@ -84,30 +84,6 @@ class AccountCrud implements AccountCrudInterface
|
|||||||
return new Account;
|
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
|
* @param array $types
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,13 +35,6 @@ interface AccountCrudInterface
|
|||||||
*/
|
*/
|
||||||
public function findByName(string $name, array $types): Account;
|
public function findByName(string $name, array $types): Account;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $accountIds
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAccountsById(array $accountIds): Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $types
|
* @param array $types
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use FireflyIII\Generator\Chart\Account\AccountChartGeneratorInterface;
|
|||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -103,10 +104,11 @@ class AccountController extends Controller
|
|||||||
* Shows the balances for all the user's frontpage accounts.
|
* Shows the balances for all the user's frontpage accounts.
|
||||||
*
|
*
|
||||||
* @param AccountCrudInterface $crud
|
* @param AccountCrudInterface $crud
|
||||||
|
* @param AccountRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function frontpage(AccountCrudInterface $crud)
|
public function frontpage(AccountCrudInterface $crud, AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
$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());
|
$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) {
|
foreach ($accounts as $account) {
|
||||||
$balances = [];
|
$balances = [];
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use FireflyIII\Export\Processor;
|
|||||||
use FireflyIII\Http\Requests\ExportFormRequest;
|
use FireflyIII\Http\Requests\ExportFormRequest;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\ExportJob;
|
use FireflyIII\Models\ExportJob;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface as EJRI;
|
use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface as EJRI;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Response;
|
use Response;
|
||||||
@@ -117,19 +118,19 @@ class ExportController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ExportFormRequest $request
|
* @param ExportFormRequest $request
|
||||||
* @param AccountCrudInterface $crud
|
* @param AccountRepositoryInterface $repository
|
||||||
*
|
|
||||||
* @param EJRI $jobs
|
* @param EJRI $jobs
|
||||||
*
|
*
|
||||||
* @return string
|
* @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);
|
set_time_limit(0);
|
||||||
$job = $jobs->findByKey($request->get('job'));
|
$job = $jobs->findByKey($request->get('job'));
|
||||||
$settings = [
|
$settings = [
|
||||||
'accounts' => $crud->getAccountsById($request->get('accounts')),
|
'accounts' => $repository->getAccountsById($request->get('accounts')),
|
||||||
'startDate' => new Carbon($request->get('export_start_range')),
|
'startDate' => new Carbon($request->get('export_start_range')),
|
||||||
'endDate' => new Carbon($request->get('export_end_range')),
|
'endDate' => new Carbon($request->get('export_end_range')),
|
||||||
'exportFormat' => $request->get('exportFormat'),
|
'exportFormat' => $request->get('exportFormat'),
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class HomeController extends Controller
|
|||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = session('end', Carbon::now()->endOfMonth());
|
$end = session('end', Carbon::now()->endOfMonth());
|
||||||
$showTour = Preferences::get('tour', true)->data;
|
$showTour = Preferences::get('tour', true)->data;
|
||||||
$accounts = $crud->getAccountsById($frontPage->data);
|
$accounts = $repository->getAccountsById($frontPage->data);
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use FireflyIII\Http\Requests\SelectTransactionsRequest;
|
|||||||
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
|
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||||
use Input;
|
use Input;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
@@ -147,15 +148,15 @@ class RuleGroupController extends Controller
|
|||||||
* Execute the given rulegroup on a set of existing transactions
|
* Execute the given rulegroup on a set of existing transactions
|
||||||
*
|
*
|
||||||
* @param SelectTransactionsRequest $request
|
* @param SelectTransactionsRequest $request
|
||||||
* @param AccountCrudInterface $crud
|
* @param AccountRepositoryInterface $repository
|
||||||
* @param RuleGroup $ruleGroup
|
* @param RuleGroup $ruleGroup
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @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
|
// 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'));
|
$startDate = new Carbon($request->get('start_date'));
|
||||||
$endDate = new Carbon($request->get('end_date'));
|
$endDate = new Carbon($request->get('end_date'));
|
||||||
|
|
||||||
|
|||||||
@@ -178,6 +178,30 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return new Account;
|
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.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace FireflyIII\Repositories\Account;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface AccountRepositoryInterface
|
* Interface AccountRepositoryInterface
|
||||||
@@ -33,6 +34,13 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function count(array $types): int;
|
public function count(array $types): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $accountIds
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAccountsById(array $accountIds): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
|||||||
Reference in New Issue
Block a user