mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Big refactor to remove the deprecated transaction collector.
This commit is contained in:
@@ -130,23 +130,15 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transaction journals without group information. Is useful in some instances.
|
||||
* Same as getGroups but everything is in a paginator.
|
||||
*
|
||||
* @return array
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getExtractedJournals(): array
|
||||
public function getPaginatedGroups(): LengthAwarePaginator
|
||||
{
|
||||
$selection = $this->getGroups();
|
||||
$return = [];
|
||||
/** @var array $group */
|
||||
foreach ($selection as $group) {
|
||||
foreach ($group['transactions'] as $journalId => $journal) {
|
||||
$journal['group_title'] = $group['title'];
|
||||
$return[$journalId] = $journal;
|
||||
}
|
||||
}
|
||||
$set = $this->getGroups();
|
||||
|
||||
return $return;
|
||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,18 +322,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getGroups but everything is in a paginator.
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginatedGroups(): LengthAwarePaginator
|
||||
{
|
||||
$set = $this->getGroups();
|
||||
|
||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define which accounts can be part of the source and destination transactions.
|
||||
*
|
||||
@@ -554,7 +534,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
$this->query->where('transaction_journals.date', '>=', $startStr);
|
||||
$this->query->where('transaction_journals.date', '<=', $endStr);
|
||||
app('log')->debug(sprintf('TransactionCollector range is now %s - %s (inclusive)', $startStr, $endStr));
|
||||
app('log')->debug(sprintf('GroupCollector range is now %s - %s (inclusive)', $startStr, $endStr));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -642,7 +622,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
private function startQuery(): void
|
||||
{
|
||||
app('log')->debug('TransactionCollector::startQuery');
|
||||
app('log')->debug('GroupCollector::startQuery');
|
||||
$this->query = $this->user
|
||||
->transactionGroups()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||
@@ -778,4 +758,76 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a budget..
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutBudget(): GroupCollectorInterface
|
||||
{
|
||||
$this->withBudgetInformation();
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q) {
|
||||
$q->whereNull('budget_transaction_journal.budget_id');
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a category.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): GroupCollectorInterface
|
||||
{
|
||||
$this->withCategoryInformation();
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q) {
|
||||
$q->whereNull('category_transaction_journal.category_id');
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sum of all journals.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSum(): string
|
||||
{
|
||||
$journals = $this->getExtractedJournals();
|
||||
$sum = '0';
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = (string)$journal['amount'];
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transaction journals without group information. Is useful in some instances.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtractedJournals(): array
|
||||
{
|
||||
$selection = $this->getGroups();
|
||||
$return = [];
|
||||
/** @var array $group */
|
||||
foreach ($selection as $group) {
|
||||
foreach ($group['transactions'] as $journalId => $journal) {
|
||||
$journal['group_title'] = $group['title'];
|
||||
$return[$journalId] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,13 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function getExtractedJournals(): array;
|
||||
|
||||
/**
|
||||
* Return the sum of all journals.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSum(): string;
|
||||
|
||||
/**
|
||||
* Return the groups.
|
||||
*
|
||||
@@ -170,6 +177,20 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a budget.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutBudget(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a category.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit the search to one specific transaction group.
|
||||
*
|
||||
|
||||
@@ -458,7 +458,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
public function setBudgets(Collection $budgets): TransactionCollectorInterface
|
||||
{
|
||||
$budgetIds = $budgets->pluck('id')->toArray();
|
||||
if (0 !== \count($budgetIds)) {
|
||||
if (0 !== count($budgetIds)) {
|
||||
$this->joinBudgetTables();
|
||||
Log::debug('Journal collector will filter for budgets', $budgetIds);
|
||||
|
||||
@@ -481,7 +481,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
public function setCategories(Collection $categories): TransactionCollectorInterface
|
||||
{
|
||||
$categoryIds = $categories->pluck('id')->toArray();
|
||||
if (0 !== \count($categoryIds)) {
|
||||
if (0 !== count($categoryIds)) {
|
||||
$this->joinCategoryTables();
|
||||
|
||||
$this->query->where(
|
||||
@@ -721,7 +721,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
*/
|
||||
public function setTypes(array $types): TransactionCollectorInterface
|
||||
{
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
Log::debug('Set query collector types', $types);
|
||||
$this->query->whereIn('transaction_types.type', $types);
|
||||
}
|
||||
@@ -849,7 +849,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
TransactionViewFilter::class => new TransactionViewFilter,
|
||||
DoubleTransactionFilter::class => new DoubleTransactionFilter,
|
||||
];
|
||||
Log::debug(sprintf('Will run %d filters on the set.', \count($this->filters)));
|
||||
Log::debug(sprintf('Will run %d filters on the set.', count($this->filters)));
|
||||
foreach ($this->filters as $enabled) {
|
||||
if (isset($filters[$enabled])) {
|
||||
Log::debug(sprintf('Before filter %s: %d', $enabled, $set->count()));
|
||||
|
||||
Reference in New Issue
Block a user