mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-20 11:48:27 -06:00
Fix #853
This commit is contained in:
parent
c917d2b1c4
commit
ea1d543795
@ -20,6 +20,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ExecuteRuleOnExistingTransactions
|
* Class ExecuteRuleOnExistingTransactions
|
||||||
@ -128,18 +129,27 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue
|
|||||||
{
|
{
|
||||||
// Lookup all journals that match the parameters specified
|
// Lookup all journals that match the parameters specified
|
||||||
$transactions = $this->collectJournals();
|
$transactions = $this->collectJournals();
|
||||||
$processor = Processor::make($this->rule);
|
$processor = Processor::make($this->rule, true);
|
||||||
|
$hits = 0;
|
||||||
|
$misses = 0;
|
||||||
|
$total = 0;
|
||||||
// Execute the rules for each transaction
|
// Execute the rules for each transaction
|
||||||
foreach ($transactions as $transaction) {
|
foreach ($transactions as $transaction) {
|
||||||
|
$total++;
|
||||||
$processor->handleTransaction($transaction);
|
$result = $processor->handleTransaction($transaction);
|
||||||
|
if($result) {
|
||||||
|
$hits++;
|
||||||
|
}
|
||||||
|
if(!$result) {
|
||||||
|
$misses++;
|
||||||
|
}
|
||||||
|
Log::info(sprintf('Current progress: %d Transactions. Hits: %d, misses: %d', $total, $hits, $misses));
|
||||||
// Stop processing this group if the rule specifies 'stop_processing'
|
// Stop processing this group if the rule specifies 'stop_processing'
|
||||||
if ($processor->getRule()->stop_processing) {
|
if ($processor->getRule()->stop_processing) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log::info(sprintf('Total transactions: %d. Hits: %d, misses: %d', $total, $hits, $misses));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ final class Processor
|
|||||||
public $rule;
|
public $rule;
|
||||||
/** @var Collection */
|
/** @var Collection */
|
||||||
public $triggers;
|
public $triggers;
|
||||||
|
/** @var int */
|
||||||
protected $foundTriggers = 0;
|
protected $foundTriggers = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,9 +170,14 @@ final class Processor
|
|||||||
// get all triggers:
|
// get all triggers:
|
||||||
$triggered = $this->triggered();
|
$triggered = $this->triggered();
|
||||||
if ($triggered) {
|
if ($triggered) {
|
||||||
|
Log::debug('Rule is triggered, go to actions.');
|
||||||
if ($this->actions->count() > 0) {
|
if ($this->actions->count() > 0) {
|
||||||
|
Log::debug('Has more than zero actions.');
|
||||||
$this->actions();
|
$this->actions();
|
||||||
}
|
}
|
||||||
|
if ($this->actions->count() === 0) {
|
||||||
|
Log::info('Rule has no actions!');
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,25 @@ $(function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function testRuleTriggers(e) {
|
function testRuleTriggers(e) {
|
||||||
|
|
||||||
var obj = $(e.target);
|
var obj = $(e.target);
|
||||||
var ruleId = parseInt(obj.data('id'));
|
var ruleId = parseInt(obj.data('id'));
|
||||||
|
var icon = obj;
|
||||||
|
if(obj.prop("tagName") === 'A') {
|
||||||
|
icon = $('i', obj);
|
||||||
|
}
|
||||||
|
// change icon:
|
||||||
|
icon.addClass('fa-spinner fa-spin').removeClass('fa-flask');
|
||||||
|
|
||||||
|
var modal = $("#testTriggerModal");
|
||||||
|
// respond to modal:
|
||||||
|
modal.on('hide.bs.modal', function (e) {
|
||||||
|
disableRuleSpinners();
|
||||||
|
});
|
||||||
|
|
||||||
// Find a list of existing transactions that match these triggers
|
// Find a list of existing transactions that match these triggers
|
||||||
$.get('rules/test-rule/' + ruleId).done(function (data) {
|
$.get('rules/test-rule/' + ruleId).done(function (data) {
|
||||||
var modal = $("#testTriggerModal");
|
|
||||||
|
|
||||||
// Set title and body
|
// Set title and body
|
||||||
modal.find(".transactions-list").html(data.html);
|
modal.find(".transactions-list").html(data.html);
|
||||||
@ -66,11 +79,16 @@ function testRuleTriggers(e) {
|
|||||||
modal.modal();
|
modal.modal();
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
alert('Cannot get transactions for given triggers.');
|
alert('Cannot get transactions for given triggers.');
|
||||||
|
disableRuleSpinners();
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function disableRuleSpinners() {
|
||||||
|
$('i.test_rule_triggers').removeClass('fa-spin fa-spinner').addClass('fa-flask');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function sortStop(event, ui) {
|
function sortStop(event, ui) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** global: Modernizr */
|
/** global: Modernizr, askReadWarning */
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -17,4 +17,7 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
$('form.form-horizontal').on('submit', function () {
|
||||||
|
return confirm(askReadWarning);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -319,6 +319,8 @@ return [
|
|||||||
'rule_action_set_source_account' => 'Set source account to :action_value',
|
'rule_action_set_source_account' => 'Set source account to :action_value',
|
||||||
'rule_action_set_destination_account_choice' => 'Set destination account to...',
|
'rule_action_set_destination_account_choice' => 'Set destination account to...',
|
||||||
'rule_action_set_destination_account' => 'Set destination account to :action_value',
|
'rule_action_set_destination_account' => 'Set destination account to :action_value',
|
||||||
|
'rules_have_read_warning' => 'Have you read the warning?',
|
||||||
|
'apply_rule_warning' => 'Warning: running a rule(group) on a large selection of transactions could take ages, and it could time-out. If it does, the rule(group) will only be applied to an unknown subset of your transactions. This might leave your financial administration in tatters. Please be careful.',
|
||||||
|
|
||||||
// tags
|
// tags
|
||||||
'store_new_tag' => 'Store new tag',
|
'store_new_tag' => 'Store new tag',
|
||||||
|
@ -107,8 +107,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<div class="btn-group btn-group-xs test_buttons">
|
<div class="btn-group btn-group-xs test_buttons">
|
||||||
{# show which transactions would match #}
|
{# show which transactions would match #}
|
||||||
<a href="#" class="btn btn-default test_rule_triggers" data-id="{{ rule.id }}"
|
<a href="#" class="btn btn-default test_rule_triggers" data-id="{{ rule.id }}" title="{{ 'test_rule_triggers'|_ }}"><i data-id="{{ rule.id }}" class="test_rule_triggers fa fa-fw fa-flask"></i></a>
|
||||||
title="{{ 'test_rule_triggers'|_ }}"><i data-id="{{ rule.id }}" class="fa fa-fw fa-flask"></i></a>
|
|
||||||
|
|
||||||
{# actually execute rule #}
|
{# actually execute rule #}
|
||||||
<a href="{{ route('rules.select-transactions',rule.id) }}" class="btn btn-default"
|
<a href="{{ route('rules.select-transactions',rule.id) }}" class="btn btn-default"
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
<p>
|
<p>
|
||||||
{{ trans('firefly.apply_rule_group_selection_intro', {title: ruleGroup.title}) }}
|
{{ trans('firefly.apply_rule_group_selection_intro', {title: ruleGroup.title}) }}
|
||||||
</p>
|
</p>
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ 'apply_rule_warning'|_ }}
|
||||||
|
</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 col-md-8 col-sm-12 col-xs-12">
|
<div class="col-lg-6 col-md-8 col-sm-12 col-xs-12">
|
||||||
{{ ExpandedForm.date('start_date', first) }}
|
{{ ExpandedForm.date('start_date', first) }}
|
||||||
@ -41,6 +44,9 @@
|
|||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
var askReadWarning = "{{ trans('firefly.rules_have_read_warning')|escape('js') }}";
|
||||||
|
</script>
|
||||||
<script type="text/javascript" src="js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
|
||||||
<script type="text/javascript" src="js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
|
||||||
<script type="text/javascript" src="js/ff/rules/select-transactions.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/ff/rules/select-transactions.js?v={{ FF_VERSION }}"></script>
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
<p>
|
<p>
|
||||||
{{ trans('firefly.apply_rule_selection_intro', {title: rule.title}) }}
|
{{ trans('firefly.apply_rule_selection_intro', {title: rule.title}) }}
|
||||||
</p>
|
</p>
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ 'apply_rule_warning'|_ }}
|
||||||
|
</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 col-md-8 col-sm-12 col-xs-12">
|
<div class="col-lg-6 col-md-8 col-sm-12 col-xs-12">
|
||||||
{{ ExpandedForm.date('start_date', first) }}
|
{{ ExpandedForm.date('start_date', first) }}
|
||||||
@ -41,6 +44,9 @@
|
|||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
var askReadWarning = "{{ trans('firefly.rules_have_read_warning')|escape('js') }}";
|
||||||
|
</script>
|
||||||
<script type="text/javascript" src="js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
|
||||||
<script type="text/javascript" src="js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
|
||||||
<script type="text/javascript" src="js/ff/rules/select-transactions.js?v={{ FF_VERSION }}"></script>
|
<script type="text/javascript" src="js/ff/rules/select-transactions.js?v={{ FF_VERSION }}"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user