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;
|
use RuleManagement, ModelInformation;
|
||||||
|
|
||||||
/** @var RuleRepositoryInterface Rule repository */
|
private RuleRepositoryInterface $ruleRepos;
|
||||||
private $ruleRepos;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RuleController constructor.
|
* RuleController constructor.
|
||||||
@@ -76,8 +75,8 @@ class CreateController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Create a new rule. It will be stored under the given $ruleGroup.
|
* Create a new rule. It will be stored under the given $ruleGroup.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param RuleGroup $ruleGroup
|
* @param RuleGroup|null $ruleGroup
|
||||||
*
|
*
|
||||||
* @return Factory|View
|
* @return Factory|View
|
||||||
*/
|
*/
|
||||||
@@ -290,45 +289,4 @@ class CreateController extends Controller
|
|||||||
|
|
||||||
return $redirect;
|
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);
|
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||||
/** @noinspection NullPointerExceptionInspection */
|
/** @noinspection NullPointerExceptionInspection */
|
||||||
$liabilityTypes = [
|
$liabilityTypes = [
|
||||||
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
$debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
||||||
$loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
$loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
||||||
$mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
$mortgage->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
||||||
];
|
];
|
||||||
asort($liabilityTypes);
|
asort($liabilityTypes);
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ trait ModelInformation
|
|||||||
{
|
{
|
||||||
$roles = [];
|
$roles = [];
|
||||||
foreach (config('firefly.accountRoles') as $role) {
|
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;
|
return $roles;
|
||||||
@@ -122,8 +122,8 @@ trait ModelInformation
|
|||||||
$triggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];
|
$triggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];
|
||||||
$values = [
|
$values = [
|
||||||
$bill->transactionCurrency()->first()->name,
|
$bill->transactionCurrency()->first()->name,
|
||||||
round((float)$bill->amount_min, 12),
|
round((float) $bill->amount_min, 12),
|
||||||
round((float)$bill->amount_max, 12),
|
round((float) $bill->amount_max, 12),
|
||||||
$bill->name,
|
$bill->name,
|
||||||
];
|
];
|
||||||
foreach ($triggers as $index => $trigger) {
|
foreach ($triggers as $index => $trigger) {
|
||||||
@@ -160,10 +160,21 @@ trait ModelInformation
|
|||||||
*/
|
*/
|
||||||
private function getTriggersForJournal(TransactionJournal $journal): array
|
private function getTriggersForJournal(TransactionJournal $journal): array
|
||||||
{
|
{
|
||||||
$result = [];
|
// TODO duplicated code.
|
||||||
$triggers = [];
|
$operators = config('firefly.search.operators');
|
||||||
$values = [];
|
$triggers = [];
|
||||||
$index = 0;
|
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
|
// amount, description, category, budget, tags, source, destination, notes, currency type
|
||||||
//,type
|
//,type
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
@@ -174,66 +185,65 @@ trait ModelInformation
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
// type
|
// type
|
||||||
$triggers[$index] = 'transaction_type';
|
$journalTriggers[$index] = 'transaction_type';
|
||||||
$values[$index] = $journal->transactionType->type;
|
$values[$index] = $journal->transactionType->type;
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
// currency
|
// currency
|
||||||
$triggers[$index] = 'currency_is';
|
$journalTriggers[$index] = 'currency_is';
|
||||||
$values[$index] = sprintf('%s (%s)', $journal->transactionCurrency->name, $journal->transactionCurrency->code);
|
$values[$index] = sprintf('%s (%s)', $journal->transactionCurrency->name, $journal->transactionCurrency->code);
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
// amount_exactly:
|
// amount_exactly:
|
||||||
$triggers[$index] = 'amount_exactly';
|
$journalTriggers[$index] = 'amount_exactly';
|
||||||
$values[$index] = $destination->amount;
|
$values[$index] = $destination->amount;
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
// description_is:
|
// description_is:
|
||||||
$triggers[$index] = 'description_is';
|
$journalTriggers[$index] = 'description_is';
|
||||||
$values[$index] = $journal->description;
|
$values[$index] = $journal->description;
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
// from_account_is
|
// from_account_is
|
||||||
$triggers[$index] = 'from_account_is';
|
$journalTriggers[$index] = 'source_account_is';
|
||||||
$values[$index] = $source->account->name;
|
$values[$index] = $source->account->name;
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
// to_account_is
|
// to_account_is
|
||||||
$triggers[$index] = 'to_account_is';
|
$journalTriggers[$index] = 'destination_account_is';
|
||||||
$values[$index] = $destination->account->name;
|
$values[$index] = $destination->account->name;
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
// category (if)
|
// category (if)
|
||||||
$category = $journal->categories()->first();
|
$category = $journal->categories()->first();
|
||||||
if (null !== $category) {
|
if (null !== $category) {
|
||||||
$triggers[$index] = 'category_is';
|
$journalTriggers[$index] = 'category_is';
|
||||||
$values[$index] = $category->name;
|
$values[$index] = $category->name;
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
// budget (if)
|
// budget (if)
|
||||||
$budget = $journal->budgets()->first();
|
$budget = $journal->budgets()->first();
|
||||||
if (null !== $budget) {
|
if (null !== $budget) {
|
||||||
$triggers[$index] = 'budget_is';
|
$journalTriggers[$index] = 'budget_is';
|
||||||
$values[$index] = $budget->name;
|
$values[$index] = $budget->name;
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
// tags (if)
|
// tags (if)
|
||||||
$tags = $journal->tags()->get();
|
$tags = $journal->tags()->get();
|
||||||
/** @var Tag $tag */
|
/** @var Tag $tag */
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$triggers[$index] = 'tag_is';
|
$journalTriggers[$index] = 'tag_is';
|
||||||
$values[$index] = $tag->tag;
|
$values[$index] = $tag->tag;
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
// notes (if)
|
// notes (if)
|
||||||
$notes = $journal->notes()->first();
|
$notes = $journal->notes()->first();
|
||||||
if (null !== $notes) {
|
if (null !== $notes) {
|
||||||
$triggers[$index] = 'notes_are';
|
$journalTriggers[$index] = 'notes_are';
|
||||||
$values[$index] = $notes->text;
|
$values[$index] = $notes->text;
|
||||||
$index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($triggers as $index => $trigger) {
|
foreach ($journalTriggers as $index => $trigger) {
|
||||||
try {
|
try {
|
||||||
$string = view(
|
$string = view(
|
||||||
'rules.partials.trigger',
|
'rules.partials.trigger',
|
||||||
@@ -242,6 +252,7 @@ trait ModelInformation
|
|||||||
'oldValue' => $values[$index],
|
'oldValue' => $values[$index],
|
||||||
'oldChecked' => false,
|
'oldChecked' => false,
|
||||||
'count' => $index + 1,
|
'count' => $index + 1,
|
||||||
|
'triggers' => $triggers,
|
||||||
]
|
]
|
||||||
)->render();
|
)->render();
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
|
@@ -36,6 +36,46 @@ use Throwable;
|
|||||||
*/
|
*/
|
||||||
trait RuleManagement
|
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_ends' => ['alias' => false, 'needs_context' => true,],
|
||||||
'description_contains' => ['alias' => false, 'needs_context' => true,],
|
'description_contains' => ['alias' => false, 'needs_context' => true,],
|
||||||
'description_is' => ['alias' => false, 'needs_context' => true,],
|
'description_is' => ['alias' => false, 'needs_context' => true,],
|
||||||
|
|
||||||
'currency_is' => ['alias' => false, 'needs_context' => true,],
|
'currency_is' => ['alias' => false, 'needs_context' => true,],
|
||||||
'foreign_currency_is' => ['alias' => false, 'needs_context' => true,],
|
'foreign_currency_is' => ['alias' => false, 'needs_context' => true,],
|
||||||
|
|
||||||
'has_attachments' => ['alias' => false, 'needs_context' => false,],
|
'has_attachments' => ['alias' => false, 'needs_context' => false,],
|
||||||
'has_no_category' => ['alias' => false, 'needs_context' => false,],
|
'has_no_category' => ['alias' => false, 'needs_context' => false,],
|
||||||
'has_any_category' => ['alias' => false, 'needs_context' => false,],
|
'has_any_category' => ['alias' => false, 'needs_context' => false,],
|
||||||
|
@@ -15,9 +15,12 @@
|
|||||||
{{ 'actions'|_}} <span class="caret"></span>
|
{{ 'actions'|_}} <span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<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.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><a href="{{ route('transactions.delete', [transactionGroup.id]) }}"><i class="fa fa-trash"></i> {{ 'delete'|_ }}</a></li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
|
|
||||||
|
{# convert to different type #}
|
||||||
{% if groupArray.transactions[0].type != 'withdrawal' %}
|
{% 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>
|
<li><a href="{{ route('transactions.convert.index', ['withdrawal', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_withdrawal'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -29,6 +32,8 @@
|
|||||||
{% if groupArray.transactions[0].type != 'transfer' %}
|
{% 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>
|
<li><a href="{{ route('transactions.convert.index', ['transfer', transactionGroup.id]) }}"><i class="fa fa-exchange"></i> {{ 'convert_to_transfer'|_ }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# clone #}
|
||||||
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
{% if groupArray.transactions[0].type != 'opening balance' and groupArray.transactions[0].type != 'reconciliation' %}
|
||||||
<!-- since 5.1.0 -->
|
<!-- since 5.1.0 -->
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
@@ -182,7 +187,33 @@
|
|||||||
{{ 'actions'|_}} <span class="caret"></span>
|
{{ 'actions'|_}} <span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<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><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('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>
|
<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>
|
</ul>
|
||||||
|
Reference in New Issue
Block a user