mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #1425
This commit is contained in:
@@ -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) {
|
||||
|
||||
80
app/Helpers/Filter/TransactionViewFilter.php
Normal file
80
app/Helpers/Filter/TransactionViewFilter.php
Normal 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;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
|
||||
use FireflyIII\Helpers\Filter\TransactionViewFilter;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\MassDeleteJournalRequest;
|
||||
use FireflyIII\Http\Requests\MassEditJournalRequest;
|
||||
@@ -145,22 +146,24 @@ class MassController extends Controller
|
||||
$collector->setUser(auth()->user());
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setJournals($journals);
|
||||
$collector->addFilter(NegativeAmountFilter::class);
|
||||
$transactions = $collector->getJournals();
|
||||
$collector->addFilter(TransactionViewFilter::class);
|
||||
$collection = $collector->getJournals();
|
||||
|
||||
// add some filters:
|
||||
|
||||
|
||||
// transform to array
|
||||
$journals = $transactions->map(
|
||||
$transactions = $collection->map(
|
||||
function (Transaction $transaction) use ($transformer) {
|
||||
$result = $transformer->transform($transaction);
|
||||
|
||||
return $result;
|
||||
$transaction= $transformer->transform($transaction);
|
||||
// make sure amount is positive:
|
||||
$transaction['amount'] = app('steam')->positive((string)$transaction['amount']);
|
||||
$transaction['foreign_amount'] = app('steam')->positive((string)$transaction['foreign_amount']);
|
||||
return $transaction;
|
||||
}
|
||||
);
|
||||
|
||||
return view('transactions.mass.edit', compact('journals', 'subTitle', 'accounts', 'budgets'));
|
||||
return view('transactions.mass.edit', compact('transactions', 'subTitle', 'accounts', 'budgets'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,11 +27,6 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
* Class Transaction.
|
||||
@@ -49,12 +44,14 @@ use FireflyIII\Models\Account;
|
||||
* @property string $account_iban
|
||||
* @property string $account_number
|
||||
* @property string $account_bic
|
||||
* @property string $account_type
|
||||
* @property string $account_currency_code
|
||||
* @property int $opposing_account_id
|
||||
* @property string $opposing_account_name
|
||||
* @property string $opposing_account_iban
|
||||
* @property string $opposing_account_number
|
||||
* @property string $opposing_account_bic
|
||||
* @property string $opposing_account_type
|
||||
* @property string $opposing_currency_code
|
||||
* @property int $transaction_budget_id
|
||||
* @property string $transaction_budget_name
|
||||
|
||||
@@ -99,9 +99,9 @@ trait TransactionServiceTrait
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return Account
|
||||
* @return Account|null
|
||||
*/
|
||||
public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): Account
|
||||
public function findAccount(?string $expectedType, ?int $accountId, ?string $accountName): ?Account
|
||||
{
|
||||
$accountId = (int)$accountId;
|
||||
$accountName = (string)$accountName;
|
||||
|
||||
@@ -57,7 +57,7 @@ class JournalUpdateService
|
||||
$service = app(TransactionUpdateService::class);
|
||||
$service->setUser($journal->user);
|
||||
|
||||
// create transactions
|
||||
// create transactions:
|
||||
/** @var TransactionFactory $factory */
|
||||
$factory = app(TransactionFactory::class);
|
||||
$factory->setUser($journal->user);
|
||||
@@ -105,6 +105,12 @@ class JournalUpdateService
|
||||
// connect tags:
|
||||
$this->connectTags($journal, $data);
|
||||
|
||||
// remove category from journal:
|
||||
$journal->categories()->sync([]);
|
||||
|
||||
// remove budgets from journal:
|
||||
$journal->budgets()->sync([]);
|
||||
|
||||
// update or create custom fields:
|
||||
// store date meta fields (if present):
|
||||
$this->storeMeta($journal, $data, 'interest_date');
|
||||
@@ -162,6 +168,8 @@ class JournalUpdateService
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$service->updateCategory($transaction, $category);
|
||||
}
|
||||
// make journal empty:
|
||||
$journal->categories()->sync([]);
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
|
||||
use FireflyIII\User;
|
||||
|
||||
@@ -31,6 +31,7 @@ use FireflyIII\Models\TransactionType;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Log;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
@@ -214,6 +215,7 @@ class TransactionTransformer extends TransformerAbstract
|
||||
// switch on type for consistency
|
||||
switch ($transaction->transaction_type_type) {
|
||||
case TransactionType::WITHDRAWAL:
|
||||
Log::debug(sprintf('%d is a withdrawal', $transaction->journal_id));
|
||||
$data['source_id'] = $transaction->account_id;
|
||||
$data['source_name'] = $transaction->account_name;
|
||||
$data['source_iban'] = $transaction->account_iban;
|
||||
@@ -222,6 +224,8 @@ class TransactionTransformer extends TransformerAbstract
|
||||
$data['destination_name'] = $transaction->opposing_account_name;
|
||||
$data['destination_iban'] = $transaction->opposing_account_iban;
|
||||
$data['destination_type'] = $transaction->opposing_account_type;
|
||||
Log::debug(sprintf('source_id / account_id is %d', $transaction->account_id));
|
||||
Log::debug(sprintf('source_name / account_name is "%s"', $transaction->account_name));
|
||||
break;
|
||||
case TransactionType::DEPOSIT:
|
||||
case TransactionType::TRANSFER:
|
||||
|
||||
Reference in New Issue
Block a user