This commit is contained in:
James Cole 2017-09-25 09:28:16 +02:00
parent c917d2b1c4
commit ea1d543795
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
8 changed files with 59 additions and 10 deletions

View File

@ -20,6 +20,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
use Log;
/**
* Class ExecuteRuleOnExistingTransactions
@ -128,18 +129,27 @@ class ExecuteRuleOnExistingTransactions extends Job implements ShouldQueue
{
// Lookup all journals that match the parameters specified
$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
foreach ($transactions as $transaction) {
$processor->handleTransaction($transaction);
$total++;
$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'
if ($processor->getRule()->stop_processing) {
break;
}
}
Log::info(sprintf('Total transactions: %d. Hits: %d, misses: %d', $total, $hits, $misses));
}

View File

@ -40,7 +40,7 @@ final class Processor
public $rule;
/** @var Collection */
public $triggers;
/** @var int */
protected $foundTriggers = 0;
/**
@ -170,9 +170,14 @@ final class Processor
// get all triggers:
$triggered = $this->triggered();
if ($triggered) {
Log::debug('Rule is triggered, go to actions.');
if ($this->actions->count() > 0) {
Log::debug('Has more than zero actions.');
$this->actions();
}
if ($this->actions->count() === 0) {
Log::info('Rule has no actions!');
}
return true;
}

View File

@ -44,12 +44,25 @@ $(function () {
);
function testRuleTriggers(e) {
var obj = $(e.target);
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
$.get('rules/test-rule/' + ruleId).done(function (data) {
var modal = $("#testTriggerModal");
// Set title and body
modal.find(".transactions-list").html(data.html);
@ -66,11 +79,16 @@ function testRuleTriggers(e) {
modal.modal();
}).fail(function () {
alert('Cannot get transactions for given triggers.');
disableRuleSpinners();
});
return false;
}
function disableRuleSpinners() {
$('i.test_rule_triggers').removeClass('fa-spin fa-spinner').addClass('fa-flask');
}
function sortStop(event, ui) {
"use strict";

View File

@ -6,7 +6,7 @@
* See the LICENSE file for details.
*/
/** global: Modernizr */
/** global: Modernizr, askReadWarning */
$(document).ready(function () {
"use strict";
@ -17,4 +17,7 @@ $(document).ready(function () {
}
);
}
$('form.form-horizontal').on('submit', function () {
return confirm(askReadWarning);
});
});

View File

@ -319,6 +319,8 @@ return [
'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' => '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
'store_new_tag' => 'Store new tag',

View File

@ -107,8 +107,7 @@
<td>
<div class="btn-group btn-group-xs test_buttons">
{# show which transactions would match #}
<a href="#" class="btn btn-default test_rule_triggers" data-id="{{ rule.id }}"
title="{{ 'test_rule_triggers'|_ }}"><i data-id="{{ rule.id }}" class="fa fa-fw fa-flask"></i></a>
<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>
{# actually execute rule #}
<a href="{{ route('rules.select-transactions',rule.id) }}" class="btn btn-default"

View File

@ -21,6 +21,9 @@
<p>
{{ trans('firefly.apply_rule_group_selection_intro', {title: ruleGroup.title}) }}
</p>
<p class="text-danger">
{{ 'apply_rule_warning'|_ }}
</p>
<div class="row">
<div class="col-lg-6 col-md-8 col-sm-12 col-xs-12">
{{ ExpandedForm.date('start_date', first) }}
@ -41,6 +44,9 @@
</form>
{% endblock %}
{% 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/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/ff/rules/select-transactions.js?v={{ FF_VERSION }}"></script>

View File

@ -21,6 +21,9 @@
<p>
{{ trans('firefly.apply_rule_selection_intro', {title: rule.title}) }}
</p>
<p class="text-danger">
{{ 'apply_rule_warning'|_ }}
</p>
<div class="row">
<div class="col-lg-6 col-md-8 col-sm-12 col-xs-12">
{{ ExpandedForm.date('start_date', first) }}
@ -41,6 +44,9 @@
</form>
{% endblock %}
{% 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/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/ff/rules/select-transactions.js?v={{ FF_VERSION }}"></script>