This commit is contained in:
James Cole 2018-05-29 07:25:04 +02:00
parent 5b4967acb9
commit 3de36901b8
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
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;
}
);
}
}

View File

@ -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'));
}
/**

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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:

View File

@ -1,7 +1,7 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
{{ Breadcrumbs.render(Route.getCurrentRoute.getName, journals) }}
{{ Breadcrumbs.render(Route.getCurrentRoute.getName, transactions) }}
{% endblock %}
{% block content %}
@ -29,90 +29,91 @@
<th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.category') }}</th>
<th class="col-lg-2 col-md-2 col-sm-2">{{ trans('list.budget') }}</th>
</tr>
{% for journal in journals %}
{% for transaction in transactions %}
<tr>
<td>
{# LINK TO EDIT FORM #}
<a href="{{ route('transactions.edit', journal.journal_id) }}" class="btn btn-xs btn-default"><i
<a href="{{ route('transactions.edit', transaction.journal_id) }}" class="btn btn-xs btn-default"><i
class="fa fa-fw fa-pencil"></i></a>
<input type="hidden" name="journals[]" value="{{ journal.journal_id }}"/>
<input type="hidden" name="journals[]" value="{{ transaction.journal_id }}"/>
</td>
<td>
{# DESCRIPTION #}
<input class="form-control input-sm" autocomplete="off"
placeholder="{{ journal.description }}" name="description[{{ journal.journal_id }}]"
type="text" value="{{ journal.description }}">
placeholder="{{ transaction.description }}" name="description[{{ transaction.journal_id }}]"
type="text" value="{{ transaction.description }}">
</td>
{# AMOUNT #}
<td>
<div class="input-group input-group-sm">
<span class="input-group-addon">{{ journal.currency_symbol }}</span>
<input name="amount[{{ journal.journal_id }}]" class="form-control" autocomplete="off"
step="any" type="number" value="{{ journal.amount }}">
<input type="hidden" name="transaction_currency_id[{{ journal.journal_id }}]"
value="{{ journal.currency_id }}">
<span class="input-group-addon">{{ transaction.currency_symbol }}</span>
<input name="amount[{{ transaction.journal_id }}]" class="form-control" autocomplete="off"
step="any" type="number" value="{{ transaction.amount }}">
<input type="hidden" name="transaction_currency_id[{{ transaction.journal_id }}]"
value="{{ transaction.currency_id }}">
</div>
{% if journal.foreign_amount %}
{% if transaction.foreign_amount %}
{# insert foreign data #}
<div class="input-group input-group-sm">
<span class="input-group-addon">{{ journal.foreign_currency.symbol }}</span>
<input name="foreign_amount[{{ journal.journal_id }}]" class="form-control" autocomplete="off"
step="any" type="number" value="{{ journal.foreign_amount }}">
<input type="hidden" name="foreign_currency_id[{{ journal.journal_id }}]" value="{{ journal.foreign_currency.id }}">
<span class="input-group-addon">{{ transaction.foreign_currency_symbol }}</span>
<input name="foreign_amount[{{ transaction.journal_id }}]" class="form-control" autocomplete="off"
step="any" type="number" value="{{ transaction.foreign_amount }}">
<input type="hidden" name="foreign_currency_id[{{ transaction.journal_id }}]" value="{{ transaction.foreign_currency_id }}">
</div>
{% endif %}
</td>
<td>
{# DATE #}
<input class="form-control input-sm" autocomplete="off"
name="date[{{ journal.journal_id }}]" type="date" value="{{ journal.date.format('Y-m-d') }}">
name="date[{{ transaction.journal_id }}]" type="date" value="{{ transaction.date }}">
</td>
<td>
{# SOURCE ACCOUNT ID FOR TRANSFER OR WITHDRAWAL #}
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Withdrawal' %}
<select class="form-control input-sm" name="source_account_id[{{ journal.journal_id }}]">
{% if transaction.type == 'Transfer' or transaction.type == 'Withdrawal' %}
<select class="form-control input-sm" name="source_account_id[{{ transaction.journal_id }}]">
{% for account in accounts %}
<option value="{{ account.id }}"{% if account.id==journal.source_account_id %} selected="selected"{% endif %}
label="{{ account.name }}">{{ account.name }}</option>
<!-- {{ transaction.type }}: {{ transaction.source_name }} -->
<option value="{{ account.id }}"{% if account.id == transaction.source_id %} selected{% endif %} label="{{ account.name }}">{{ account.name }}</option>
{% endfor %}
</select>
{% else %}
{# SOURCE ACCOUNT NAME FOR DEPOSIT #}
<input class="form-control input-sm" placeholder="{{ journal.source_account_name }}" autocomplete="off"
name="source_account_name[{{ journal.journal_id }}]" type="text" value="{{ journal.source_account_name }}">
<input class="form-control input-sm" placeholder="{% if transaction.source_type != 'Cash account' %}{{ transaction.source_name }}{% endif %}" autocomplete="off"
name="source_account_name[{{ transaction.journal_id }}]" type="text" value="{% if transaction.source_type != 'Cash account' %}{{ transaction.source_name }}{% endif %}">
{% endif %}
</td>
<td>
{% if journal.transaction_type_type == 'Transfer' or journal.transaction_type_type == 'Deposit' %}
{% if transaction.type == 'Transfer' or transaction.type == 'Deposit' %}
{# DESTINATION ACCOUNT NAME FOR TRANSFER AND DEPOSIT #}
<select class="form-control input-sm" name="destination_account_id[{{ journal.journal_id }}]">
<select class="form-control input-sm" name="destination_account_id[{{ transaction.journal_id }}]">
{% for account in accounts %}
<option value="{{ account.id }}"{% if account.id==journal.destination_account_id %} selected="selected"{% endif %}
<option value="{{ account.id }}"{% if account.id == transaction.destination_id %} selected="selected"{% endif %}
label="{{ account.name }}">{{ account.name }}</option>
{% endfor %}
</select>
{% else %}
{# DESTINATION ACCOUNT NAME FOR EXPENSE #}
<input class="form-control input-sm" placeholder="{{ journal.destination_account_name }}"
name="destination_account_name[{{ journal.journal_id }}]" type="text" autocomplete="off"
value="{{ journal.destination_account_name }}">
<input class="form-control input-sm" placeholder="{% if transaction.destination_type != 'Cash account' %}{{ transaction.destination_name }}{% endif %}"
name="destination_account_name[{{ transaction.journal_id }}]" type="text" autocomplete="off"
value="{% if transaction.destination_type != 'Cash account' %}{{ transaction.destination_name }}{% endif %}">
{% endif %}
</td>
{# category #}
<td>
<input class="form-control input-sm" placeholder="{{ journal.categories[0].name }}" autocomplete="off"
name="category[{{ journal.journal_id }}]" type="text" value="{{ journal.categories[0].name }}">
<input class="form-control input-sm" placeholder="{{ transaction.category_name }}" autocomplete="off"
name="category[{{ transaction.journal_id }}]" type="text" value="{{ transaction.category_name }}">
</td>
{# budget #}
<td>
{% if journal.transaction_type_type == 'Withdrawal' %}
<select class="form-control input-sm" name="budget_id[{{ journal.journal_id }}]">
{% if transaction.type == 'Withdrawal' %}
<select class="form-control input-sm" name="budget_id[{{ transaction.journal_id }}]">
<option value="0" label="({{ 'no_budget'|_ }})"
{% if journal.budgets.count == 0 %}selected="selected"{% endif %}
{% if transaction.budget_id == 0 %}selected="selected"{% endif %}
>({{ 'no_budget'|_ }})
</option>
{% for budget in budgets %}
<option value="{{ budget.id }}"{% if budget.id==journal.budgets[0].id %} selected="selected"{% endif %}
<option value="{{ budget.id }}"{% if budget.id == transaction.budget_id %} selected="selected"{% endif %}
label="{{ budget.name }}">{{ budget.name }}</option>
{% endfor %}
</select>