mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-29 12:14:34 -06:00
Experimental query. [skip ci]
This commit is contained in:
parent
4870945af2
commit
e64b40d58b
@ -13,6 +13,7 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@ -323,8 +324,25 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
if ($accounts->count() > 0) {
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
$query->leftJoin('transactions as t', 't.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$query->whereIn('t.account_id', $accountIds);
|
||||
$query->leftJoin(
|
||||
'transactions as source', function (JoinClause $join) {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('amount', '<', 0);
|
||||
}
|
||||
);
|
||||
$query->leftJoin(
|
||||
'transactions as destination', function (JoinClause $join) {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('amount', '>', 0);
|
||||
}
|
||||
);
|
||||
|
||||
// XOR. must be either.
|
||||
$query->where(
|
||||
function (Builder $query) use ($accountIds) {
|
||||
$query->whereIn('source.account_id', $accountIds, 'xor')
|
||||
->whereIn('destination.account_id', $accountIds, 'xor');
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
// that should do it:
|
||||
$complete = $query->get(TransactionJournal::queryFields());
|
||||
|
Loading…
Reference in New Issue
Block a user