Sort and cleanup code.

This commit is contained in:
James Cole
2022-09-25 15:31:58 +02:00
parent 3c33ea959e
commit 6eaed9829b
7 changed files with 614 additions and 623 deletions

View File

@@ -34,6 +34,26 @@ use Illuminate\Support\Collection;
trait AccountCollection
{
/**
* 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;
}
/**
* These accounts must not be destination accounts.
*
@@ -72,26 +92,6 @@ 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.
*
@@ -115,29 +115,6 @@ 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.
*
@@ -180,6 +157,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;
}
/**
* Define which accounts can be part of the source and destination transactions.
*