Expand search with negated search options

This commit is contained in:
James Cole
2022-09-25 15:31:07 +02:00
parent 80a732b32b
commit 3c33ea959e
8 changed files with 1570 additions and 108 deletions

View File

@@ -72,6 +72,26 @@ trait AccountCollection
return $this;
}
/**
* These accounts must not be included.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function excludeAccounts(Collection $accounts): GroupCollectorInterface
{
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$this->query->whereNotIn('source.account_id', $accountIds);
$this->query->whereNotIn('destination.account_id', $accountIds);
app('log')->debug(sprintf('GroupCollector: excludeAccounts: %s', implode(', ', $accountIds)));
}
return $this;
}
/**
* Define which accounts can be part of the source and destination transactions.
*
@@ -95,6 +115,29 @@ trait AccountCollection
return $this;
}
/**
* Define which accounts can NOT be part of the source and destination transactions.
*
* @param Collection $accounts
*
* @return GroupCollectorInterface
*/
public function setNotAccounts(Collection $accounts): GroupCollectorInterface
{
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$this->query->where(
static function (EloquentBuilder $query) use ($accountIds) {
$query->whereNotIn('source.account_id', $accountIds);
$query->whereNotIn('destination.account_id', $accountIds);
}
);
//app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
}
return $this;
}
/**
* Both source AND destination must be in this list of accounts.
*