This commit is contained in:
James Cole
2018-05-29 07:25:04 +02:00
parent 5b4967acb9
commit 3de36901b8
9 changed files with 146 additions and 50 deletions

View File

@@ -32,6 +32,7 @@ use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\SplitIndicatorFilter;
use FireflyIII\Helpers\Filter\TransactionViewFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
@@ -768,6 +769,7 @@ class JournalCollector implements JournalCollectorInterface
NegativeAmountFilter::class => new NegativeAmountFilter,
SplitIndicatorFilter::class => new SplitIndicatorFilter,
CountAttachmentsFilter::class => new CountAttachmentsFilter,
TransactionViewFilter::class => new TransactionViewFilter,
];
Log::debug(sprintf('Will run %d filters on the set.', \count($this->filters)));
foreach ($this->filters as $enabled) {

View File

@@ -0,0 +1,80 @@
<?php
/**
* TransactionViewFilter.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 FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
use Log;
/**
* Class TransactionViewFilter.
*
* This filter removes the entry with a negative amount when it's a withdrawal
* And the positive amount when it's a deposit or transfer
*
* This is used in the mass-edit routine.
*
*/
class TransactionViewFilter implements FilterInterface
{
/**
* @param Collection $set
*
* @return Collection
*/
public function filter(Collection $set): Collection
{
return $set->filter(
function (Transaction $transaction) {
// remove if amount is less than zero and type is withdrawal.
if ($transaction->transaction_type_type === TransactionType::WITHDRAWAL && 1 === bccomp($transaction->transaction_amount, '0')) {
Log::debug(
sprintf(
'Filtered #%d because amount is %f and type is %s.', $transaction->id, $transaction->transaction_amount,
$transaction->transaction_type_type
)
);
return null;
}
if ($transaction->transaction_type_type === TransactionType::DEPOSIT && -1 === bccomp($transaction->transaction_amount, '0')) {
Log::debug(
sprintf(
'Filtered #%d because amount is %f and type is %s.', $transaction->id, $transaction->transaction_amount,
$transaction->transaction_type_type
)
);
return null;
}
Log::debug(
sprintf('#%d: amount is %f and type is %s.', $transaction->id, $transaction->transaction_amount, $transaction->transaction_type_type)
);
return $transaction;
}
);
}
}