mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix #3735
This commit is contained in:
@@ -49,8 +49,7 @@ class CreateController extends Controller
|
||||
{
|
||||
use RuleManagement, ModelInformation;
|
||||
|
||||
/** @var RuleRepositoryInterface Rule repository */
|
||||
private $ruleRepos;
|
||||
private RuleRepositoryInterface $ruleRepos;
|
||||
|
||||
/**
|
||||
* RuleController constructor.
|
||||
@@ -76,8 +75,8 @@ class CreateController extends Controller
|
||||
/**
|
||||
* Create a new rule. It will be stored under the given $ruleGroup.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param Request $request
|
||||
* @param RuleGroup|null $ruleGroup
|
||||
*
|
||||
* @return Factory|View
|
||||
*/
|
||||
@@ -290,45 +289,4 @@ class CreateController extends Controller
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submittedOperators
|
||||
* @return array
|
||||
*/
|
||||
private function parseFromOperators(array $submittedOperators): array
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$renderedEntries = [];
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$index = 0;
|
||||
foreach ($submittedOperators as $operator) {
|
||||
try {
|
||||
$renderedEntries[] = view(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($operator['type']),
|
||||
'oldValue' => $operator['value'],
|
||||
'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $renderedEntries;
|
||||
}
|
||||
}
|
||||
|
@@ -86,9 +86,9 @@ trait ModelInformation
|
||||
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$liabilityTypes = [
|
||||
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
||||
$loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
||||
$mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
||||
$debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
||||
$loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
||||
$mortgage->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
||||
];
|
||||
asort($liabilityTypes);
|
||||
|
||||
@@ -103,7 +103,7 @@ trait ModelInformation
|
||||
{
|
||||
$roles = [];
|
||||
foreach (config('firefly.accountRoles') as $role) {
|
||||
$roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role));
|
||||
$roles[$role] = (string) trans(sprintf('firefly.account_role_%s', $role));
|
||||
}
|
||||
|
||||
return $roles;
|
||||
@@ -122,8 +122,8 @@ trait ModelInformation
|
||||
$triggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];
|
||||
$values = [
|
||||
$bill->transactionCurrency()->first()->name,
|
||||
round((float)$bill->amount_min, 12),
|
||||
round((float)$bill->amount_max, 12),
|
||||
round((float) $bill->amount_min, 12),
|
||||
round((float) $bill->amount_max, 12),
|
||||
$bill->name,
|
||||
];
|
||||
foreach ($triggers as $index => $trigger) {
|
||||
@@ -160,10 +160,21 @@ trait ModelInformation
|
||||
*/
|
||||
private function getTriggersForJournal(TransactionJournal $journal): array
|
||||
{
|
||||
$result = [];
|
||||
$triggers = [];
|
||||
$values = [];
|
||||
$index = 0;
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$result = [];
|
||||
$journalTriggers = [];
|
||||
$values = [];
|
||||
$index = 0;
|
||||
// amount, description, category, budget, tags, source, destination, notes, currency type
|
||||
//,type
|
||||
/** @var Transaction $source */
|
||||
@@ -174,66 +185,65 @@ trait ModelInformation
|
||||
return $result;
|
||||
}
|
||||
// type
|
||||
$triggers[$index] = 'transaction_type';
|
||||
$values[$index] = $journal->transactionType->type;
|
||||
$journalTriggers[$index] = 'transaction_type';
|
||||
$values[$index] = $journal->transactionType->type;
|
||||
$index++;
|
||||
|
||||
// currency
|
||||
$triggers[$index] = 'currency_is';
|
||||
$values[$index] = sprintf('%s (%s)', $journal->transactionCurrency->name, $journal->transactionCurrency->code);
|
||||
$journalTriggers[$index] = 'currency_is';
|
||||
$values[$index] = sprintf('%s (%s)', $journal->transactionCurrency->name, $journal->transactionCurrency->code);
|
||||
$index++;
|
||||
|
||||
// amount_exactly:
|
||||
$triggers[$index] = 'amount_exactly';
|
||||
$values[$index] = $destination->amount;
|
||||
$journalTriggers[$index] = 'amount_exactly';
|
||||
$values[$index] = $destination->amount;
|
||||
$index++;
|
||||
|
||||
// description_is:
|
||||
$triggers[$index] = 'description_is';
|
||||
$values[$index] = $journal->description;
|
||||
$journalTriggers[$index] = 'description_is';
|
||||
$values[$index] = $journal->description;
|
||||
$index++;
|
||||
|
||||
// from_account_is
|
||||
$triggers[$index] = 'from_account_is';
|
||||
$values[$index] = $source->account->name;
|
||||
$journalTriggers[$index] = 'source_account_is';
|
||||
$values[$index] = $source->account->name;
|
||||
$index++;
|
||||
|
||||
// to_account_is
|
||||
$triggers[$index] = 'to_account_is';
|
||||
$values[$index] = $destination->account->name;
|
||||
$journalTriggers[$index] = 'destination_account_is';
|
||||
$values[$index] = $destination->account->name;
|
||||
$index++;
|
||||
|
||||
// category (if)
|
||||
$category = $journal->categories()->first();
|
||||
if (null !== $category) {
|
||||
$triggers[$index] = 'category_is';
|
||||
$values[$index] = $category->name;
|
||||
$journalTriggers[$index] = 'category_is';
|
||||
$values[$index] = $category->name;
|
||||
$index++;
|
||||
}
|
||||
// budget (if)
|
||||
$budget = $journal->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
$triggers[$index] = 'budget_is';
|
||||
$values[$index] = $budget->name;
|
||||
$journalTriggers[$index] = 'budget_is';
|
||||
$values[$index] = $budget->name;
|
||||
$index++;
|
||||
}
|
||||
// tags (if)
|
||||
$tags = $journal->tags()->get();
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$triggers[$index] = 'tag_is';
|
||||
$values[$index] = $tag->tag;
|
||||
$journalTriggers[$index] = 'tag_is';
|
||||
$values[$index] = $tag->tag;
|
||||
$index++;
|
||||
}
|
||||
// notes (if)
|
||||
$notes = $journal->notes()->first();
|
||||
if (null !== $notes) {
|
||||
$triggers[$index] = 'notes_are';
|
||||
$values[$index] = $notes->text;
|
||||
$index++;
|
||||
$journalTriggers[$index] = 'notes_are';
|
||||
$values[$index] = $notes->text;
|
||||
}
|
||||
|
||||
foreach ($triggers as $index => $trigger) {
|
||||
foreach ($journalTriggers as $index => $trigger) {
|
||||
try {
|
||||
$string = view(
|
||||
'rules.partials.trigger',
|
||||
@@ -242,6 +252,7 @@ trait ModelInformation
|
||||
'oldValue' => $values[$index],
|
||||
'oldChecked' => false,
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@@ -36,6 +36,46 @@ use Throwable;
|
||||
*/
|
||||
trait RuleManagement
|
||||
{
|
||||
/**
|
||||
* @param array $submittedOperators
|
||||
* @return array
|
||||
*/
|
||||
protected function parseFromOperators(array $submittedOperators): array
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$renderedEntries = [];
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$index = 0;
|
||||
foreach ($submittedOperators as $operator) {
|
||||
try {
|
||||
$renderedEntries[] = view(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($operator['type']),
|
||||
'oldValue' => $operator['value'],
|
||||
'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -455,8 +455,10 @@ return [
|
||||
'description_ends' => ['alias' => false, 'needs_context' => true,],
|
||||
'description_contains' => ['alias' => false, 'needs_context' => true,],
|
||||
'description_is' => ['alias' => false, 'needs_context' => true,],
|
||||
|
||||
'currency_is' => ['alias' => false, 'needs_context' => true,],
|
||||
'foreign_currency_is' => ['alias' => false, 'needs_context' => true,],
|
||||
|
||||
'has_attachments' => ['alias' => false, 'needs_context' => false,],
|
||||
'has_no_category' => ['alias' => false, 'needs_context' => false,],
|
||||
'has_any_category' => ['alias' => false, 'needs_context' => false,],
|
||||
|
@@ -15,9 +15,12 @@
|
||||
{{ 'actions'|_}} <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{# edit + delete #}
|
||||
<li><a href="{{ route('transactions.edit', [transactionGroup.id]) }}"><i class="fa fa-pencil"></i> {{ 'edit'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><i class="fa fa-trash"></i> {{ 'delete'|_ }}</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
|
||||
{# convert to different type #}
|
||||
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
||||
<li><a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_withdrawal'|_ }}</a></li>
|
||||
{% endif %}
|
||||
@@ -29,6 +32,8 @@
|
||||
{% if groupArray.transactions[0].type != 'transfer' %}
|
||||
<li><a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_transfer'|_ }}</a></li>
|
||||
{% endif %}
|
||||
|
||||
{# clone #}
|
||||
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
||||
<!-- since 5.1.0 -->
|
||||
<li role="separator" class="divider"></li>
|
||||
@@ -182,7 +187,33 @@
|
||||
{{ 'actions'|_}} <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
{# edit + delete #}
|
||||
<li><a href="{{ route('transactions.edit', [transactionGroup.id]) }}"><i class="fa fa-pencil"></i> {{ 'edit'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><i class="fa fa-trash"></i> {{ 'delete'|_ }}</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
|
||||
{# convert to different type #}
|
||||
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
||||
<li><a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_withdrawal'|_ }}</a></li>
|
||||
{% endif %}
|
||||
|
||||
{% if groupArray.transactions[0].type != 'deposit' %}
|
||||
<li><a href="{{ route('transactions.convert.index', ['deposit', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_deposit'|_ }}</a></li>
|
||||
{% endif %}
|
||||
|
||||
{% if groupArray.transactions[0].type != 'transfer' %}
|
||||
<li><a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_transfer'|_ }}</a></li>
|
||||
{% endif %}
|
||||
|
||||
{# clone #}
|
||||
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
||||
<!-- since 5.1.0 -->
|
||||
<li role="separator" class="divider"></li>
|
||||
<li><a href="{{ route('transactions.clone', [transactionGroup.id]) }}" id="clone_button"><i class="fa fa-copy"></i> {{ 'clone'|_ }}</a></li>
|
||||
{% endif %}
|
||||
|
||||
<li><a href="#" class="link-modal" data-journal="{{ journal.transaction_journal_id }}"><i class="fa fa-fw fa-link"></i>{{ 'link_transaction'|_ }}</a></li>
|
||||
<li role="separator" class="divider"></li>
|
||||
<li><a href="{{ route('rules.create-from-journal', [journal.transaction_journal_id]) }}"><i class="fa fa-fw fa-random"></i>{{ 'create_rule_from_transaction'|_ }}</a></li>
|
||||
<li><a href="{{ route('recurring.create-from-journal', [journal.transaction_journal_id]) }}"><i class="fa fa-fw fa-paint-brush"></i>{{ 'create_recurring_from_transaction'|_ }}</a></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user