James Cole 2023-07-18 06:30:45 +02:00
parent e435ff8b1c
commit a45a050e7d
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
4 changed files with 52 additions and 2 deletions

View File

@ -33,6 +33,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
trait CollectorProperties
{
public const TEST = 'Test';
private bool $expandGroupSearch;
private array $fields;
private bool $hasAccountInfo;
private bool $hasBillInformation;

View File

@ -76,6 +76,7 @@ class GroupCollector implements GroupCollectorInterface
$this->hasNotesInformation = false;
$this->hasJoinedTagTables = false;
$this->hasJoinedAttTables = false;
$this->expandGroupSearch = false;
$this->hasJoinedMetaTables = false;
$this->integerFields = [
'transaction_group_id',
@ -454,6 +455,14 @@ class GroupCollector implements GroupCollectorInterface
return $this;
}
/**
* @return bool
*/
public function getExpandGroupSearch(): bool
{
return $this->expandGroupSearch;
}
/**
* Return the transaction journals without group information. Is useful in some instances.
*
@ -480,10 +489,16 @@ class GroupCollector implements GroupCollectorInterface
* Return the groups.
*
* @return Collection
* @throws FireflyException
*/
public function getGroups(): Collection
{
if ($this->expandGroupSearch) {
// get group ID's for the query:
$groupIds = $this->getCollectedGroupIds();
// add to query:
$this->query->orWhereIn('transaction_journals.transaction_group_id', $groupIds);
}
$result = $this->query->get($this->fields);
// now to parse this into an array.
@ -505,6 +520,14 @@ class GroupCollector implements GroupCollectorInterface
return $collection;
}
/**
* @return array
*/
private function getCollectedGroupIds(): array
{
return $this->query->get(['transaction_journals.transaction_group_id'])->pluck('transaction_group_id')->toArray();
}
/**
* @param Collection $collection
*
@ -516,7 +539,7 @@ class GroupCollector implements GroupCollectorInterface
$groups = [];
/** @var TransactionJournal $augumentedJournal */
foreach ($collection as $augumentedJournal) {
$groupId = $augumentedJournal->transaction_group_id;
$groupId = (int)$augumentedJournal->transaction_group_id;
if (!array_key_exists($groupId, $groups)) {
// make new array
@ -871,6 +894,14 @@ class GroupCollector implements GroupCollectorInterface
return $this;
}
/**
* @param bool $expandGroupSearch
*/
public function setExpandGroupSearch(bool $expandGroupSearch): void
{
$this->expandGroupSearch = $expandGroupSearch;
}
/**
* @inheritDoc
*/

View File

@ -583,6 +583,11 @@ interface GroupCollectorInterface
*/
public function foreignAmountMore(string $amount): GroupCollectorInterface;
/**
* @return bool
*/
public function getExpandGroupSearch(): bool;
/**
* Return the transaction journals without group information. Is useful in some instances.
*
@ -1072,6 +1077,11 @@ interface GroupCollectorInterface
*/
public function setDestinationAccounts(Collection $accounts): GroupCollectorInterface;
/**
* @param bool $expandGroupSearch
*/
public function setExpandGroupSearch(bool $expandGroupSearch);
/**
* Look for specific external ID's.
*
@ -1502,4 +1512,6 @@ interface GroupCollectorInterface
* @return GroupCollectorInterface
*/
public function yearIsNot(string $year): GroupCollectorInterface;
}

View File

@ -131,6 +131,12 @@ class ShowController extends Controller
->setLimit($pageSize)
->setPage($page)->withAccountInformation()->withCategoryInformation()
->setRange($start, $end);
// this search will not include transaction groups where this asset account (or liability)
// is just part of ONE of the journals. To force this:
$collector->setExpandGroupSearch(true);
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));