diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index a57e76429e..b873c84e4b 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -221,7 +221,7 @@ class TagController extends Controller $subTitle = $tag->tag; $subTitleIcon = 'fa-tag'; /** @var Collection $journals */ - $journals = $tag->transactionjournals()->expanded()->get(TransactionJournal::QUERYFIELDS); + $journals = $tag->transactionjournals()->expanded()->get(TransactionJournal::queryFields()); $sum = $journals->sum( function (TransactionJournal $journal) { diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 9a88715ff5..91adf1e9a3 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -85,28 +85,6 @@ class TransactionJournal extends TransactionJournalSupport { use SoftDeletes, ValidatingTrait; - /** - * Fields which queries must load. - * ['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type'] - */ - const QUERYFIELDS - = [ - 'transaction_journals.*', - 'transaction_types.type AS transaction_type_type', // the other field is called "transaction_type_id" so this is pretty consistent. - 'transaction_currencies.code AS transaction_currency_code', - // all for destination: - //'destination.amount AS destination_amount', // is always positive - // DB::raw('SUM(`destination`.`amount`) as `destination_amount`'), - 'destination_account.id AS destination_account_id', - 'destination_account.name AS destination_account_name', - 'destination_acct_type.type AS destination_account_type', - // all for source: - 'source.amount AS source_amount', // is always negative - 'source_account.id AS source_account_id', - 'source_account.name AS source_account_name', - 'source_acct_type.type AS source_account_type', - - ]; /** @var array */ protected $dates = ['created_at', 'updated_at', 'date', 'deleted_at', 'interest_date', 'book_date', 'process_date']; /** @var array */ diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 2157e405aa..44d9bee43f 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -183,7 +183,7 @@ class AccountRepository implements AccountRepositoryInterface ->where('destination_account.id', $account->id) ->whereIn('source_account.id', $ids) ->after($start) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); return $journals; } @@ -273,7 +273,7 @@ class AccountRepository implements AccountRepositoryInterface ->where('source_account.id', $account->id) ->whereIn('destination_account.id', $ids) ->after($start) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); return $journals; } @@ -328,7 +328,7 @@ class AccountRepository implements AccountRepositoryInterface ->after($start) ->before($end); - $set = $query->get(TransactionJournal::QUERYFIELDS); + $set = $query->get(TransactionJournal::queryFields()); return $set; } diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index cc891e8b5e..fbae113952 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -319,7 +319,7 @@ class BillRepository implements BillRepositoryInterface ->orderBy('transaction_journals.order', 'ASC') ->orderBy('transaction_journals.id', 'DESC'); $count = $query->count(); - $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::QUERYFIELDS); + $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields()); $paginator = new LengthAwarePaginator($set, $count, $pageSize, $page); return $paginator; diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index e88606a49c..ef6606d34c 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -93,7 +93,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn ->before($end) ->after($start) ->where('source_account.id', $account->id) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); } /** @@ -191,7 +191,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn ->whereNull('budget_transaction_journal.id') ->before($end) ->after($start) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); } /** @@ -448,7 +448,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn ->expanded() ->where('transaction_types.type', TransactionType::WITHDRAWAL) ->whereIn('source_account.id', $ids) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); return $set; } @@ -545,7 +545,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn } - $set = $setQuery->get(TransactionJournal::QUERYFIELDS); + $set = $setQuery->get(TransactionJournal::queryFields()); $count = $countQuery->count(); @@ -623,7 +623,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn ->after($start); $count = $query->count(); - $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::QUERYFIELDS); + $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields()); $paginator = new LengthAwarePaginator($set, $count, $pageSize, $page); return $paginator; @@ -649,7 +649,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn ->whereNull('budget_transaction_journal.id') ->before($end) ->after($start) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); } /** diff --git a/app/Repositories/Category/SingleCategoryRepository.php b/app/Repositories/Category/SingleCategoryRepository.php index 127f212262..5f0ec5b771 100644 --- a/app/Repositories/Category/SingleCategoryRepository.php +++ b/app/Repositories/Category/SingleCategoryRepository.php @@ -157,7 +157,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate ->orderBy('transaction_journals.date', 'DESC') ->orderBy('transaction_journals.order', 'ASC') ->orderBy('transaction_journals.id', 'DESC') - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); } @@ -180,7 +180,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate ->expanded() ->whereIn('source_account.id', $ids) ->whereNotIn('destination_account.id', $ids) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); } /** @@ -203,7 +203,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate ->expanded() ->take($pageSize) ->offset($offset) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); } /** diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index cbb832a0f5..c539eee3bc 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -121,7 +121,7 @@ class JournalRepository implements JournalRepositoryInterface ->orderBy('date', 'DESC') ->orderBy('order', 'ASC') ->orderBy('id', 'DESC') - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); return $set; } @@ -153,7 +153,7 @@ class JournalRepository implements JournalRepositoryInterface $count = $query->count(); - $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::QUERYFIELDS); + $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields()); $journals = new LengthAwarePaginator($set, $count, $pageSize, $page); return $journals; diff --git a/app/Support/Binder/JournalList.php b/app/Support/Binder/JournalList.php index f673175db4..8c312f535f 100644 --- a/app/Support/Binder/JournalList.php +++ b/app/Support/Binder/JournalList.php @@ -37,7 +37,7 @@ class JournalList implements BinderInterface $object = TransactionJournal::whereIn('transaction_journals.id', $ids) ->expanded() ->where('transaction_journals.user_id', Auth::user()->id) - ->get(TransactionJournal::QUERYFIELDS); + ->get(TransactionJournal::queryFields()); if ($object->count() > 0) { return $object; diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index deb68245dd..b356271ccd 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -109,10 +109,10 @@ class Search implements SearchInterface $q->orWhere('transaction_journals.description', 'LIKE', '%' . e($word) . '%'); } } - )->get(TransactionJournal::QUERYFIELDS); + )->get(TransactionJournal::queryFields()); // encrypted - $all = Auth::user()->transactionjournals()->expanded()->where('transaction_journals.encrypted', 1)->get(TransactionJournal::QUERYFIELDS); + $all = Auth::user()->transactionjournals()->expanded()->where('transaction_journals.encrypted', 1)->get(TransactionJournal::queryFields()); $set = $all->filter( function (TransactionJournal $journal) use ($words) { foreach ($words as $word) {