Moved getAccountsByType

This commit is contained in:
James Cole 2016-10-10 07:49:39 +02:00
parent e8a095e543
commit de6f838413
25 changed files with 215 additions and 202 deletions

View File

@ -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
*

View File

@ -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
*

View File

@ -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) {

View File

@ -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');

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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'));

View File

@ -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());

View File

@ -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;

View File

@ -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;

View File

@ -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', []);

View File

@ -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 */

View File

@ -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');

View File

@ -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:

View File

@ -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']);

View File

@ -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')) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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