Skip to content

Firefly III: a personal finances manager

Move to object held user object.

James Cole745e0aa52560
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index 8096a7f166..0e2b58d244 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -2,7 +2,6 @@
namespace FireflyIII\Repositories\Account;
-use Auth;
use Carbon\Carbon;
use Config;
use DB;
@@ -52,7 +51,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function countAccounts(array $types): int
{
- $count = Auth::user()->accounts()->accountTypeIn($types)->count();
+ $count = $this->user->accounts()->accountTypeIn($types)->count();
return $count;
}
@@ -84,7 +83,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function find(int $accountId): Account
{
- return Auth::user()->accounts()->findOrNew($accountId);
+ return $this->user->accounts()->findOrNew($accountId);
}
/**
@@ -107,7 +106,7 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccounts(array $types): Collection
{
/** @var Collection $result */
- $result = Auth::user()->accounts()->with(
+ $result = $this->user->accounts()->with(
['accountmeta' => function (HasMany $query) {
$query->where('name', 'accountRole');
}]
@@ -135,22 +134,22 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getCreditCards(Carbon $date): Collection
{
- $set = Auth::user()->accounts()
- ->hasMetaValue('accountRole', 'ccAsset')
- ->hasMetaValue('ccType', 'monthlyFull')
- ->leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->whereNull('transactions.deleted_at')
- ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
- ->groupBy('accounts.id')
- ->get(
- [
- 'accounts.*',
- 'ccType.data as ccType',
- 'accountRole.data as accountRole',
- DB::Raw('SUM(`transactions`.`amount`) AS `balance`'),
- ]
- );
+ $set = $this->user->accounts()
+ ->hasMetaValue('accountRole', 'ccAsset')
+ ->hasMetaValue('ccType', 'monthlyFull')
+ ->leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ ->whereNull('transactions.deleted_at')
+ ->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
+ ->groupBy('accounts.id')
+ ->get(
+ [
+ 'accounts.*',
+ 'ccType.data as ccType',
+ 'accountRole.data as accountRole',
+ DB::Raw('SUM(`transactions`.`amount`) AS `balance`'),
+ ]
+ );
return $set;
}
@@ -178,7 +177,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getFrontpageAccounts(Preference $preference): Collection
{
- $query = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account']);
+ $query = $this->user->accounts()->accountTypeIn(['Default account', 'Asset account']);
if (count($preference->data) > 0) {
$query->whereIn('accounts.id', $preference->data);
@@ -202,20 +201,20 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection
{
- $set = Auth::user()
- ->transactionjournals()
- ->with(['transactions'])
- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
- ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id')
- ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->before($end)
- ->after($start)
- ->orderBy('transaction_journals.date', 'DESC')
- ->orderBy('transaction_journals.order', 'ASC')
- ->orderBy('transaction_journals.id', 'DESC')
- ->take(10)
- ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
+ $set = $this->user
+ ->transactionjournals()
+ ->with(['transactions'])
+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
+ ->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transaction_journals.transaction_currency_id')
+ ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
+ ->before($end)
+ ->after($start)
+ ->orderBy('transaction_journals.date', 'DESC')
+ ->orderBy('transaction_journals.order', 'ASC')
+ ->orderBy('transaction_journals.id', 'DESC')
+ ->take(10)
+ ->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
return $set;
}
@@ -229,14 +228,14 @@ class AccountRepository implements AccountRepositoryInterface
public function getJournals(Account $account, $page): LengthAwarePaginator
{
$offset = ($page - 1) * 50;
- $query = Auth::user()
- ->transactionJournals()
- ->withRelevantData()
- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transactions.account_id', $account->id)
- ->orderBy('transaction_journals.date', 'DESC')
- ->orderBy('transaction_journals.order', 'ASC')
- ->orderBy('transaction_journals.id', 'DESC');
+ $query = $this->user
+ ->transactionJournals()
+ ->withRelevantData()
+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->where('transactions.account_id', $account->id)
+ ->orderBy('transaction_journals.date', 'DESC')
+ ->orderBy('transaction_journals.order', 'ASC')
+ ->orderBy('transaction_journals.id', 'DESC');
$count = $query->count();
$set = $query->take(50)->offset($offset)->get(['transaction_journals.*']);
@@ -262,7 +261,7 @@ class AccountRepository implements AccountRepositoryInterface
$ids = array_unique($ids);
if (count($ids) > 0) {
- $accounts = Auth::user()->accounts()->whereIn('id', $ids)->where('accounts.active', 1)->get();
+ $accounts = $this->user->accounts()->whereIn('id', $ids)->where('accounts.active', 1)->get();
}
bcscale(2);
@@ -296,12 +295,12 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getSavingsAccounts(): Collection
{
- $accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')
- ->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
- ->where('account_meta.name', 'accountRole')
- ->where('accounts.active', 1)
- ->where('account_meta.data', '"savingAsset"')
- ->get(['accounts.*']);
+ $accounts = $this->user->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')
+ ->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
+ ->where('account_meta.name', 'accountRole')
+ ->where('accounts.active', 1)
+ ->where('account_meta.data', '"savingAsset"')
+ ->get(['accounts.*']);
$start = clone Session::get('start', new Carbon);
$end = clone Session::get('end', new Carbon);
@@ -426,7 +425,7 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function sumOfEverything(): string
{
- return strval(Auth::user()->transactions()->sum('amount'));
+ return strval($this->user->transactions()->sum('amount'));
}
/**