This commit is contained in:
James Cole 2017-09-03 10:39:05 +02:00
parent b9f6119c68
commit 816b291ed3
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
9 changed files with 433 additions and 25 deletions

View File

@ -286,7 +286,7 @@ class RuleRepository implements RuleRepositoryInterface
$ruleTrigger->active = 1;
$ruleTrigger->stop_processing = $values['stopProcessing'];
$ruleTrigger->trigger_type = $values['action'];
$ruleTrigger->trigger_value = $values['value'];
$ruleTrigger->trigger_value = is_null($values['value']) ? '' : $values['value'];
$ruleTrigger->save();
return $ruleTrigger;

View File

@ -0,0 +1,65 @@
<?php
/**
* HasAnyBudget.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasAnyBudget
*
* @package FireflyIII\Rules\Triggers
*/
final class HasAnyBudget extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->budgets()->count();
if ($count > 0) {
Log::debug(sprintf('RuleTrigger HasAnyBudget for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasAnyBudget for journal #%d: count is %d, return false.', $journal->id, $count));
return false;
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* HasAnyCategory.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasAnyCategory
*
* @package FireflyIII\Rules\Triggers
*/
final class HasAnyCategory extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->categories()->count();
if ($count > 0) {
Log::debug(sprintf('RuleTrigger HasAnyCategory for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasAnyCategory for journal #%d: count is %d, return false.', $journal->id, $count));
return false;
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* HasAnyTag.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasAnyTag
*
* @package FireflyIII\Rules\Triggers
*/
final class HasAnyTag extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->tags()->count();
if ($count > 0) {
Log::debug(sprintf('RuleTrigger HasAnyTag for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasAnyTag for journal #%d: count is %d, return false.', $journal->id, $count));
return false;
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* HasNoBudget.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasNoBudget
*
* @package FireflyIII\Rules\Triggers
*/
final class HasNoBudget extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->budgets()->count();
if ($count === 0) {
Log::debug(sprintf('RuleTrigger HasNoBudget for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasNoBudget for journal #%d: count is %d, return false.', $journal->id, $count));
return false;
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* HasNoCategory.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasNoCategory
*
* @package FireflyIII\Rules\Triggers
*/
final class HasNoCategory extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->categories()->count();
if ($count === 0) {
Log::debug(sprintf('RuleTrigger HasNoCategory for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasNoCategory for journal #%d: count is %d, return false.', $journal->id, $count));
return false;
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* HasNoTag.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\TransactionJournal;
use Log;
/**
* Class HasNoTag
*
* @package FireflyIII\Rules\Triggers
*/
final class HasNoTag extends AbstractTrigger implements TriggerInterface
{
/**
* A trigger is said to "match anything", or match any given transaction,
* when the trigger value is very vague or has no restrictions. Easy examples
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
* has an amount of more than zero! Other examples are all the "Description"-triggers
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
*
* If the user tries to create such a trigger, this method MUST return true so Firefly III
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
* (even if it will still include 99.9% of the users transactions), this method MUST return
* false.
*
* @param null $value
*
* @return bool
*/
public static function willMatchEverything($value = null)
{
return false;
}
/**
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$count = $journal->tags()->count();
if ($count === 0) {
Log::debug(sprintf('RuleTrigger HasNoTag for journal #%d: count is %d, return true.', $journal->id, $count));
return true;
}
Log::debug(sprintf('RuleTrigger HasNoTag for journal #%d: count is %d, return false.', $journal->id, $count));
return false;
}
}

View File

@ -229,6 +229,7 @@ function updateTriggerInput(selectList) {
var parent = selectList.parent().parent();
// the text input we're looking for:
var input = parent.find('input[name^="rule-trigger-value["]');
input.prop('disabled', false);
switch (selectList.val()) {
case 'from_account_starts':
case 'from_account_ends':
@ -259,6 +260,15 @@ function updateTriggerInput(selectList) {
case 'description_is':
createAutoComplete(input, 'json/transaction-journals/all');
break;
case 'has_no_category':
case 'has_any_category':
case 'has_no_budget':
case 'has_any_budget':
case 'has_no_tag':
case 'has_any_tag':
input.prop('disabled', true);
input.typeahead('destroy');
break;
default:
input.typeahead('destroy');
break;

View File

@ -239,52 +239,60 @@ return [
// actions and triggers
'rule_trigger_user_action' => 'User action is ":trigger_value"',
'rule_trigger_from_account_starts' => 'Source account starts with ":trigger_value"',
'rule_trigger_from_account_ends' => 'Source account ends with ":trigger_value"',
'rule_trigger_from_account_is' => 'Source account is ":trigger_value"',
'rule_trigger_from_account_contains' => 'Source account contains ":trigger_value"',
'rule_trigger_to_account_starts' => 'Destination account starts with ":trigger_value"',
'rule_trigger_to_account_ends' => 'Destination account ends with ":trigger_value"',
'rule_trigger_to_account_is' => 'Destination account is ":trigger_value"',
'rule_trigger_to_account_contains' => 'Destination account contains ":trigger_value"',
'rule_trigger_transaction_type' => 'Transaction is of type ":trigger_value"',
'rule_trigger_category_is' => 'Category is ":trigger_value"',
'rule_trigger_amount_less' => 'Amount is less than :trigger_value',
'rule_trigger_amount_exactly' => 'Amount is :trigger_value',
'rule_trigger_amount_more' => 'Amount is more than :trigger_value',
'rule_trigger_description_starts' => 'Description starts with ":trigger_value"',
'rule_trigger_description_ends' => 'Description ends with ":trigger_value"',
'rule_trigger_description_contains' => 'Description contains ":trigger_value"',
'rule_trigger_description_is' => 'Description is ":trigger_value"',
'rule_trigger_from_account_starts_choice' => 'Source account starts with..',
'rule_trigger_from_account_starts' => 'Source account starts with ":trigger_value"',
'rule_trigger_from_account_ends_choice' => 'Source account ends with..',
'rule_trigger_from_account_ends' => 'Source account ends with ":trigger_value"',
'rule_trigger_from_account_is_choice' => 'Source account is..',
'rule_trigger_from_account_is' => 'Source account is ":trigger_value"',
'rule_trigger_from_account_contains_choice' => 'Source account contains..',
'rule_trigger_from_account_contains' => 'Source account contains ":trigger_value"',
'rule_trigger_to_account_starts_choice' => 'Destination account starts with..',
'rule_trigger_to_account_starts' => 'Destination account starts with ":trigger_value"',
'rule_trigger_to_account_ends_choice' => 'Destination account ends with..',
'rule_trigger_to_account_ends' => 'Destination account ends with ":trigger_value"',
'rule_trigger_to_account_is_choice' => 'Destination account is..',
'rule_trigger_to_account_is' => 'Destination account is ":trigger_value"',
'rule_trigger_to_account_contains_choice' => 'Destination account contains..',
'rule_trigger_to_account_contains' => 'Destination account contains ":trigger_value"',
'rule_trigger_transaction_type_choice' => 'Transaction is of type..',
'rule_trigger_amount_less_choice' => 'Amount is less than..',
'rule_trigger_amount_exactly_choice' => 'Amount is..',
'rule_trigger_amount_more_choice' => 'Amount is more than..',
'rule_trigger_description_starts_choice' => 'Description starts with..',
'rule_trigger_description_ends_choice' => 'Description ends with..',
'rule_trigger_description_contains_choice' => 'Description contains..',
'rule_trigger_description_is_choice' => 'Description is..',
'rule_trigger_transaction_type' => 'Transaction is of type ":trigger_value"',
'rule_trigger_category_is_choice' => 'Category is..',
'rule_trigger_category_is' => 'Category is ":trigger_value"',
'rule_trigger_amount_less_choice' => 'Amount is less than..',
'rule_trigger_amount_less' => 'Amount is less than :trigger_value',
'rule_trigger_amount_exactly_choice' => 'Amount is..',
'rule_trigger_amount_exactly' => 'Amount is :trigger_value',
'rule_trigger_amount_more_choice' => 'Amount is more than..',
'rule_trigger_amount_more' => 'Amount is more than :trigger_value',
'rule_trigger_description_starts_choice' => 'Description starts with..',
'rule_trigger_description_starts' => 'Description starts with ":trigger_value"',
'rule_trigger_description_ends_choice' => 'Description ends with..',
'rule_trigger_description_ends' => 'Description ends with ":trigger_value"',
'rule_trigger_description_contains_choice' => 'Description contains..',
'rule_trigger_description_contains' => 'Description contains ":trigger_value"',
'rule_trigger_description_is_choice' => 'Description is..',
'rule_trigger_description_is' => 'Description is ":trigger_value"',
'rule_trigger_budget_is_choice' => 'Budget is..',
'rule_trigger_budget_is' => 'Budget is ":trigger_value"',
'rule_trigger_tag_is_choice' => '(A) tag is..',
'rule_trigger_tag_is' => 'A tag is ":trigger_value"',
'rule_trigger_has_attachments_choice' => 'Has at least this many attachments',
'rule_trigger_has_attachments' => 'Has at least :trigger_value attachment(s)',
'rule_trigger_store_journal' => 'When a transaction is created',
'rule_trigger_update_journal' => 'When a transaction is updated',
'rule_trigger_has_no_category_choice' => 'Has no category',
'rule_trigger_has_no_category' => 'Transaction has no category',
'rule_trigger_has_any_category_choice' => 'Has a (any) category',
'rule_trigger_has_any_category' => 'Transaction has a (any) category',
'rule_trigger_has_no_budget_choice' => 'Has no budget',
'rule_trigger_has_no_budget' => 'Transaction has no budget',
'rule_trigger_has_any_budget_choice' => 'Has a (any) budget',
'rule_trigger_has_any_budget' => 'Transaction has a (any) budget',
'rule_trigger_has_no_tag_choice' => 'Has no tag(s)',
'rule_trigger_has_no_tag' => 'Transaction has no tag(s)',
'rule_trigger_has_any_tag_choice' => 'Has one or more (any) tags',
'rule_trigger_has_any_tag' => 'Transaction has one or more (any) tags',
'rule_action_set_category' => 'Set category to ":action_value"',
'rule_action_clear_category' => 'Clear category',
'rule_action_set_budget' => 'Set budget to ":action_value"',