mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
Use other method of collecting query fields. #142
This commit is contained in:
parent
94a79876ce
commit
9baadd3793
@ -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) {
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user