mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Moved more stuff to the journal collector.
This commit is contained in:
@@ -210,76 +210,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function journalsInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$return = new Collection;
|
||||
$accountIds = [];
|
||||
// expand the number of grabbed fields:
|
||||
$fields = TransactionJournal::queryFields();
|
||||
$fields[] = 'source.account_id';
|
||||
if ($accounts->count() > 0) {
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
// first get all journals for all budget(s):
|
||||
$journalQuery = $this->user->transactionJournals()
|
||||
->expanded()
|
||||
->sortCorrectly()
|
||||
->before($end)
|
||||
->after($start)
|
||||
->leftJoin(
|
||||
'transactions as source',
|
||||
function (JoinClause $join) {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', '0');
|
||||
}
|
||||
)
|
||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->whereIn('budget_transaction_journal.budget_id', $budgets->pluck('id')->toArray());
|
||||
// add account id's, if relevant:
|
||||
if (count($accountIds) > 0) {
|
||||
$journalQuery->whereIn('source.account_id', $accountIds);
|
||||
}
|
||||
// get them:
|
||||
$journals = $journalQuery->get(TransactionJournal::queryFields());
|
||||
|
||||
// then get transactions themselves.
|
||||
$transactionQuery = $this->user->transactionJournals()
|
||||
->expanded()
|
||||
->before($end)
|
||||
->sortCorrectly()
|
||||
->after($start)
|
||||
->leftJoin('transactions as related', 'related.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budget_transaction', 'budget_transaction.transaction_id', '=', 'related.id')
|
||||
->leftJoin(
|
||||
'transactions as source',
|
||||
function (JoinClause $join) {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', '0');
|
||||
}
|
||||
)
|
||||
->groupBy(['source.account_id'])
|
||||
->whereIn('budget_transaction.budget_id', $budgets->pluck('id')->toArray());
|
||||
|
||||
if (count($accountIds) > 0) {
|
||||
$transactionQuery->whereIn('source.account_id', $accountIds);
|
||||
}
|
||||
|
||||
$transactions = $transactionQuery->get($fields);
|
||||
|
||||
// return complete set:
|
||||
$return = $return->merge($transactions);
|
||||
$return = $return->merge($journals);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
|
@@ -89,16 +89,6 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function getInactiveBudgets(): Collection;
|
||||
|
||||
/**
|
||||
* @param Collection $budgets
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function journalsInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
|
Reference in New Issue
Block a user