Fix issue in multi year reports

This commit is contained in:
James Cole
2019-09-06 17:18:55 +02:00
parent 69af0c3d65
commit 1a583c771b
3 changed files with 52 additions and 7 deletions

View File

@@ -1125,4 +1125,41 @@ class GroupCollector implements GroupCollectorInterface
->orderBy('transaction_journals.description', 'DESC')
->orderBy('source.amount', 'DESC');
}
/**
* Either account can be set, but NOT both. This effectively excludes internal transfers.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function setXorAccounts(Collection $accounts): GroupCollectorInterface
{
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$this->query->where(
static function (EloquentBuilder $q1) use ($accountIds) {
// sourceAccount is in the set, and destination is NOT.
$q1->where(
static function (EloquentBuilder $q2) use ($accountIds) {
$q2->whereIn('source.account_id', $accountIds);
$q2->whereNotIn('destination.account_id', $accountIds);
}
);
// destination is in the set, and source is NOT
$q1->orWhere(
static function (EloquentBuilder $q3) use ($accountIds) {
$q3->whereNotIn('source.account_id', $accountIds);
$q3->whereIn('destination.account_id', $accountIds);
}
);
}
);
app('log')->debug(sprintf('GroupCollector: setXorAccounts: %s', implode(', ', $accountIds)));
}
return $this;
}
}

View File

@@ -121,6 +121,15 @@ interface GroupCollectorInterface
*/
public function setAccounts(Collection $accounts): GroupCollectorInterface;
/**
* Either account can be set, but NOT both. This effectively excludes internal transfers.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function setXorAccounts(Collection $accounts): GroupCollectorInterface;
/**
* Collect transactions after a specific date.
*