Skip to content

Firefly III: a personal finances manager

Fix query.

James Colea985e0928288
diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php
index e97e4ec370..0b7b8a65cd 100644
--- a/app/Helpers/Report/ReportQuery.php
+++ b/app/Helpers/Report/ReportQuery.php
@@ -191,14 +191,14 @@ class ReportQuery implements ReportQueryInterface
{
return Auth::user()->transactionjournals()
- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
- ->transactionTypes([TransactionType::WITHDRAWAL])
- ->where('transactions.account_id', $account->id)
- ->before($end)
- ->after($start)
- ->where('budget_transaction_journal.budget_id', $budget->id)
- ->get(['transaction_journals.*'])->sum('amount');
+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
+ ->transactionTypes([TransactionType::WITHDRAWAL])
+ ->where('transactions.account_id', $account->id)
+ ->before($end)
+ ->after($start)
+ ->where('budget_transaction_journal.budget_id', $budget->id)
+ ->get(['transaction_journals.*'])->sum('amount');
}
/**
@@ -288,7 +288,6 @@ class ReportQuery implements ReportQueryInterface
// OR is a transfer from NOT a shared account to a shared account.
-
$query->where(
function (Builder $query) {
$query->where(
@@ -367,28 +366,20 @@ class ReportQuery implements ReportQueryInterface
$query = $this->queryJournalsWithTransactions($start, $end);
+ // withdrawals from any account are an expense.
+ // transfers away, to an account not in the list, are an expense.
$query->where(
- function (Builder $query) {
+ function (Builder $query) use ($ids) {
$query->where(
- function (Builder $q) { // only get withdrawals from any account:
+ function (Builder $q) {
$q->where('transaction_types.type', TransactionType::WITHDRAWAL);
- //$q->where('acm_from.data', '!=', '"sharedAsset"');
}
);
$query->orWhere(
- function (Builder $q) { // and transfers from a shared account to a not-shared account.
+ function (Builder $q) use ($ids) {
$q->where('transaction_types.type', TransactionType::TRANSFER);
- $q->where('acm_to.data', '=', '"sharedAsset"');
- $q->where('acm_from.data', '!=', '"sharedAsset"');
- }
- );
- // OR transfers from a NOT shared account to a shared account.
- $query->orWhere(
- function (Builder $q) { // and transfers from a shared account to a not-shared account.
- $q->where('transaction_types.type', TransactionType::TRANSFER);
- $q->where('acm_to.data', '!=', '"sharedAsset"');
- $q->where('acm_from.data', '=', '"sharedAsset"');
+ $q->whereNotIn('ac_to.id', $ids);
}
);
}