mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
Convert raw XORs to a construct compatible with Laravel's query builder
This commit is contained in:
@@ -23,6 +23,7 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -368,9 +369,22 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
if ($accounts->count() > 0) {
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
$set = join(', ', $accountIds);
|
||||
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
|
||||
|
||||
$query->where(
|
||||
// source.account_id in accountIds XOR destination.account_id in accountIds
|
||||
function (Builder $sourceXorDestinationQuery) use ($accountIds) {
|
||||
$sourceXorDestinationQuery->where(
|
||||
function (Builder $inSourceButNotDestinationQuery) use ($accountIds) {
|
||||
$inSourceButNotDestinationQuery->whereIn('source.account_id', $accountIds)
|
||||
->whereNotIn('destination.account_id', $accountIds);
|
||||
}
|
||||
)->orWhere(
|
||||
function (Builder $inDestinationButNotSourceQuery) use ($accountIds) {
|
||||
$inDestinationButNotSourceQuery->whereIn('destination.account_id', $accountIds)
|
||||
->whereNotIn('source.account_id', $accountIds);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
if ($budgets->count() > 0) {
|
||||
$budgetIds = $budgets->pluck('id')->toArray();
|
||||
@@ -445,9 +459,22 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
|
||||
$set = join(', ', $accountIds);
|
||||
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
|
||||
$query->where(
|
||||
// source.account_id in accountIds XOR destination.account_id in accountIds
|
||||
function (Builder $sourceXorDestinationQuery) use ($accountIds) {
|
||||
$sourceXorDestinationQuery->where(
|
||||
function (Builder $inSourceButNotDestinationQuery) use ($accountIds) {
|
||||
$inSourceButNotDestinationQuery->whereIn('source.account_id', $accountIds)
|
||||
->whereNotIn('destination.account_id', $accountIds);
|
||||
}
|
||||
)->orWhere(
|
||||
function (Builder $inDestinationButNotSourceQuery) use ($accountIds) {
|
||||
$inDestinationButNotSourceQuery->whereIn('destination.account_id', $accountIds)
|
||||
->whereNotIn('source.account_id', $accountIds);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
$ids = $query->get(['transaction_journals.id'])->pluck('id')->toArray();
|
||||
$sum = '0';
|
||||
|
||||
Reference in New Issue
Block a user