mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix split query.
This commit is contained in:
parent
0db9852769
commit
d870e0f42e
@ -354,6 +354,9 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
|
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
$query->whereNull('source.deleted_at');
|
||||||
|
$query->whereNull('destination.deleted_at');
|
||||||
|
$query->where('transaction_journals.completed', 1);
|
||||||
|
|
||||||
if ($end >= $start) {
|
if ($end >= $start) {
|
||||||
$query->before($end)->after($start);
|
$query->before($end)->after($start);
|
||||||
@ -362,16 +365,27 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
$accountIds = $accounts->pluck('id')->toArray();
|
$accountIds = $accounts->pluck('id')->toArray();
|
||||||
$set = join(', ', $accountIds);
|
$set = join(', ', $accountIds);
|
||||||
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
|
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
|
||||||
|
|
||||||
}
|
}
|
||||||
if ($budgets->count() > 0) {
|
if ($budgets->count() > 0) {
|
||||||
$budgetIds = $budgets->pluck('id')->toArray();
|
$budgetIds = $budgets->pluck('id')->toArray();
|
||||||
$query->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
$query->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id');
|
||||||
$query->whereIn('budget_transaction_journal.budget_id', $budgetIds);
|
$query->whereIn('budget_transaction_journal.budget_id', $budgetIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// that should do it:
|
// that should do it:
|
||||||
$first = strval($query->sum('source.amount'));
|
$ids = $query->distinct()->get(['transaction_journals.id'])->pluck('id')->toArray();
|
||||||
|
$first = '0';
|
||||||
|
if (count($ids) > 0) {
|
||||||
|
$first = strval(
|
||||||
|
$this->user->transactions()
|
||||||
|
->whereIn('transaction_journal_id', $ids)
|
||||||
|
->where('amount', '<', '0')
|
||||||
|
->whereNull('transactions.deleted_at')
|
||||||
|
->sum('amount')
|
||||||
|
);
|
||||||
|
}
|
||||||
// then collection transactions (harder)
|
// then collection transactions (harder)
|
||||||
$query = $this->user->transactions()
|
$query = $this->user->transactions()
|
||||||
->where('transactions.amount', '<', 0)
|
->where('transactions.amount', '<', 0)
|
||||||
@ -419,7 +433,10 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
->whereNull('budget_transaction_journal.id')
|
->whereNull('budget_transaction_journal.id')
|
||||||
->whereNull('budget_transaction.id')
|
->whereNull('budget_transaction.id')
|
||||||
->before($end)
|
->before($end)
|
||||||
->after($start);
|
->after($start)
|
||||||
|
->whereNull('source.deleted_at')
|
||||||
|
->whereNull('destination.deleted_at')
|
||||||
|
->where('transaction_journals.completed', 1);
|
||||||
|
|
||||||
if ($accounts->count() > 0) {
|
if ($accounts->count() > 0) {
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
$accountIds = $accounts->pluck('id')->toArray();
|
||||||
@ -427,7 +444,17 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
$set = join(', ', $accountIds);
|
$set = join(', ', $accountIds);
|
||||||
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
|
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
|
||||||
}
|
}
|
||||||
$sum = strval($query->sum('source.amount'));
|
$ids = $query->get(['transaction_journals.id'])->pluck('id')->toArray();
|
||||||
|
$sum = '0';
|
||||||
|
if (count($ids) > 0) {
|
||||||
|
$sum = strval(
|
||||||
|
$this->user->transactions()
|
||||||
|
->whereIn('transaction_journal_id', $ids)
|
||||||
|
->where('amount', '<', '0')
|
||||||
|
->whereNull('transactions.deleted_at')
|
||||||
|
->sum('amount')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user