mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix for #1760
This commit is contained in:
parent
d624f20107
commit
329b34f7d1
@ -29,6 +29,7 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||||
use FireflyIII\Generator\Report\Support;
|
use FireflyIII\Generator\Report\Support;
|
||||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||||
|
use FireflyIII\Helpers\Filter\DoubleTransactionFilter;
|
||||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
|
||||||
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
|
||||||
@ -216,9 +217,9 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
->setTags($this->tags)->withOpposingAccount();
|
->setTags($this->tags)->withOpposingAccount();
|
||||||
$collector->removeFilter(TransferFilter::class);
|
$collector->removeFilter(TransferFilter::class);
|
||||||
|
|
||||||
$collector->addFilter(OpposingAccountFilter::class);
|
$collector->addFilter(OpposingAccountFilter::class);
|
||||||
$collector->addFilter(PositiveAmountFilter::class);
|
$collector->addFilter(PositiveAmountFilter::class);
|
||||||
|
$collector->addFilter(DoubleTransactionFilter::class);
|
||||||
|
|
||||||
$transactions = $collector->getTransactions();
|
$transactions = $collector->getTransactions();
|
||||||
$this->expenses = $transactions;
|
$this->expenses = $transactions;
|
||||||
|
@ -28,6 +28,7 @@ use Carbon\Carbon;
|
|||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Filter\CountAttachmentsFilter;
|
use FireflyIII\Helpers\Filter\CountAttachmentsFilter;
|
||||||
|
use FireflyIII\Helpers\Filter\DoubleTransactionFilter;
|
||||||
use FireflyIII\Helpers\Filter\FilterInterface;
|
use FireflyIII\Helpers\Filter\FilterInterface;
|
||||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||||
@ -53,26 +54,14 @@ use Log;
|
|||||||
/**
|
/**
|
||||||
* Class TransactionCollector
|
* Class TransactionCollector
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class TransactionCollector implements TransactionCollectorInterface
|
class TransactionCollector implements TransactionCollectorInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
if ('testing' === env('APP_ENV')) {
|
|
||||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $accountIds = [];
|
private $accountIds = [];
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $count = 0;
|
private $count = 0;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $fields
|
private $fields
|
||||||
= [
|
= [
|
||||||
@ -139,6 +128,16 @@ class TransactionCollector implements TransactionCollectorInterface
|
|||||||
/** @var User */
|
/** @var User */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if ('testing' === env('APP_ENV')) {
|
||||||
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filter
|
* @param string $filter
|
||||||
*
|
*
|
||||||
@ -253,6 +252,30 @@ class TransactionCollector implements TransactionCollectorInterface
|
|||||||
return $this->count;
|
return $this->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LengthAwarePaginator
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function getPaginatedTransactions(): LengthAwarePaginator
|
||||||
|
{
|
||||||
|
if (true === $this->run) {
|
||||||
|
throw new FireflyException('Cannot getPaginatedTransactions after run in TransactionCollector.');
|
||||||
|
}
|
||||||
|
$this->count();
|
||||||
|
$set = $this->getTransactions();
|
||||||
|
$journals = new LengthAwarePaginator($set, $this->count, $this->limit, $this->page);
|
||||||
|
|
||||||
|
return $journals;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return EloquentBuilder
|
||||||
|
*/
|
||||||
|
public function getQuery(): EloquentBuilder
|
||||||
|
{
|
||||||
|
return $this->query;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
@ -309,30 +332,6 @@ class TransactionCollector implements TransactionCollectorInterface
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return LengthAwarePaginator
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
public function getPaginatedTransactions(): LengthAwarePaginator
|
|
||||||
{
|
|
||||||
if (true === $this->run) {
|
|
||||||
throw new FireflyException('Cannot getPaginatedTransactions after run in TransactionCollector.');
|
|
||||||
}
|
|
||||||
$this->count();
|
|
||||||
$set = $this->getTransactions();
|
|
||||||
$journals = new LengthAwarePaginator($set, $this->count, $this->limit, $this->page);
|
|
||||||
|
|
||||||
return $journals;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return EloquentBuilder
|
|
||||||
*/
|
|
||||||
public function getQuery(): EloquentBuilder
|
|
||||||
{
|
|
||||||
return $this->query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TransactionCollectorInterface
|
* @return TransactionCollectorInterface
|
||||||
*/
|
*/
|
||||||
@ -784,14 +783,15 @@ class TransactionCollector implements TransactionCollectorInterface
|
|||||||
{
|
{
|
||||||
// create all possible filters:
|
// create all possible filters:
|
||||||
$filters = [
|
$filters = [
|
||||||
InternalTransferFilter::class => new InternalTransferFilter($this->accountIds),
|
InternalTransferFilter::class => new InternalTransferFilter($this->accountIds),
|
||||||
OpposingAccountFilter::class => new OpposingAccountFilter($this->accountIds),
|
OpposingAccountFilter::class => new OpposingAccountFilter($this->accountIds),
|
||||||
TransferFilter::class => new TransferFilter,
|
TransferFilter::class => new TransferFilter,
|
||||||
PositiveAmountFilter::class => new PositiveAmountFilter,
|
PositiveAmountFilter::class => new PositiveAmountFilter,
|
||||||
NegativeAmountFilter::class => new NegativeAmountFilter,
|
NegativeAmountFilter::class => new NegativeAmountFilter,
|
||||||
SplitIndicatorFilter::class => new SplitIndicatorFilter,
|
SplitIndicatorFilter::class => new SplitIndicatorFilter,
|
||||||
CountAttachmentsFilter::class => new CountAttachmentsFilter,
|
CountAttachmentsFilter::class => new CountAttachmentsFilter,
|
||||||
TransactionViewFilter::class => new TransactionViewFilter,
|
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) {
|
foreach ($this->filters as $enabled) {
|
||||||
|
60
app/Helpers/Filter/DoubleTransactionFilter.php
Normal file
60
app/Helpers/Filter/DoubleTransactionFilter.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* DoubleTransactionFilter.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Helpers\Filter;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Used when the final collection contains double transactions, which can happen when viewing the tag report.
|
||||||
|
* Class DoubleTransactionFilter
|
||||||
|
*/
|
||||||
|
class DoubleTransactionFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the filter.
|
||||||
|
*
|
||||||
|
* @param Collection $set
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function filter(Collection $set): Collection
|
||||||
|
{
|
||||||
|
$count = [];
|
||||||
|
$result = new Collection;
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
foreach ($set as $transaction) {
|
||||||
|
$id = (int)$transaction->id;
|
||||||
|
$count[$id] = isset($count[$id]) ? $count[$id] + 1 : 1;
|
||||||
|
if (1 === $count[$id]) {
|
||||||
|
$result->push($transaction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user