Make sure rules work.

This commit is contained in:
James Cole
2018-12-21 09:01:21 +01:00
parent a8ff77addd
commit a7e1a51476
10 changed files with 54 additions and 47 deletions

View File

@@ -218,7 +218,7 @@ class TransactionController extends Controller
$collector->addFilter(PositiveAmountFilter::class); $collector->addFilter(PositiveAmountFilter::class);
} }
if (!($transactionType === TransactionType::WITHDRAWAL)) { if (!($transactionType === TransactionType::WITHDRAWAL)) {
$collector->addFilter(NegativeAmountFilter::class); $collector->addFilter(NegativeAmountFilter::class); // @codeCoverageIgnore
} }
$transactions = $collector->getTransactions(); $transactions = $collector->getTransactions();

View File

@@ -69,10 +69,10 @@ class AttachmentRequest extends Request
{ {
$models = implode( $models = implode(
',', [ ',', [
Bill::class, str_replace('FireflyIII\\Models\\', '', Bill::class),
ImportJob::class, str_replace('FireflyIII\\Models\\', '', ImportJob::class),
TransactionJournal::class, str_replace('FireflyIII\\Models\\', '', TransactionJournal::class),
ImportJob::class, str_replace('FireflyIII\\Models\\', '', ImportJob::class),
] ]
); );
$model = $this->string('model'); $model = $this->string('model');

View File

@@ -66,6 +66,15 @@ class TransactionRequest extends Request
'bill_id' => $this->integer('bill_id'), 'bill_id' => $this->integer('bill_id'),
'bill_name' => $this->string('bill_name'), 'bill_name' => $this->string('bill_name'),
'tags' => explode(',', $this->string('tags')), 'tags' => explode(',', $this->string('tags')),
'notes' => $this->string('notes'),
'sepa-cc' => $this->string('sepa_cc'),
'sepa-ct-op' => $this->string('sepa_ct_op'),
'sepa-ct-id' => $this->string('sepa_ct_id'),
'sepa-db' => $this->string('sepa_db'),
'sepa-country' => $this->string('sepa_country'),
'sepa-ep' => $this->string('sepa_ep'),
'sepa-ci' => $this->string('sepa_ci'),
'sepa-batch-id' => $this->string('sepa_batch_id'),
'interest_date' => $this->date('interest_date'), 'interest_date' => $this->date('interest_date'),
'book_date' => $this->date('book_date'), 'book_date' => $this->date('book_date'),
'process_date' => $this->date('process_date'), 'process_date' => $this->date('process_date'),
@@ -73,22 +82,10 @@ class TransactionRequest extends Request
'payment_date' => $this->date('payment_date'), 'payment_date' => $this->date('payment_date'),
'invoice_date' => $this->date('invoice_date'), 'invoice_date' => $this->date('invoice_date'),
'internal_reference' => $this->string('internal_reference'), 'internal_reference' => $this->string('internal_reference'),
'notes' => $this->string('notes'),
'original-source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'transactions' => $this->getTransactionData(),
// SEPA fields:
'sepa-cc' => $this->string('sepa_cc'),
'sepa-ct-op' => $this->string('sepa_ct_op'),
'sepa-db' => $this->string('sepa_db'),
'sepa-country' => $this->string('sepa_country'),
'sepa-ep' => $this->string('sepa_ep'),
'sepa-ci' => $this->string('sepa_ci'),
'sepa-batch-id' => $this->string('sepa_batch_id'),
// others:
'bunq_payment_id' => $this->string('bunq_payment_id'), 'bunq_payment_id' => $this->string('bunq_payment_id'),
'external_id' => $this->string('external_id'), 'external_id' => $this->string('external_id'),
'original-source' => sprintf('ff3-v%s|api-v%s', config('firefly.version'), config('firefly.api_version')),
'transactions' => $this->getTransactionData(),
]; ];
return $data; return $data;
@@ -104,7 +101,7 @@ class TransactionRequest extends Request
{ {
$rules = [ $rules = [
// basic fields for journal: // basic fields for journal:
'type' => 'required|in:withdrawal,deposit,transfer', 'type' => 'required|in:withdrawal,deposit,transfer,opening-balance,reconciliation',
'description' => 'between:1,255', 'description' => 'between:1,255',
'date' => 'required|date', 'date' => 'required|date',
'piggy_bank_id' => ['numeric', 'nullable', 'mustExist:piggy_banks,id', new BelongsUser], 'piggy_bank_id' => ['numeric', 'nullable', 'mustExist:piggy_banks,id', new BelongsUser],
@@ -114,15 +111,6 @@ class TransactionRequest extends Request
'tags' => 'between:1,255', 'tags' => 'between:1,255',
// then, custom fields for journal // then, custom fields for journal
'interest_date' => 'date|nullable',
'book_date' => 'date|nullable',
'process_date' => 'date|nullable',
'due_date' => 'date|nullable',
'payment_date' => 'date|nullable',
'invoice_date' => 'date|nullable',
'internal_reference' => 'min:1,max:255|nullable',
'bunq_payment_id' => 'min:1,max:255|nullable',
'external_id' => 'min:1,max:255|nullable',
'notes' => 'min:1,max:50000|nullable', 'notes' => 'min:1,max:50000|nullable',
// SEPA fields: // SEPA fields:
@@ -135,6 +123,17 @@ class TransactionRequest extends Request
'sepa_ci' => 'min:1,max:255|nullable', 'sepa_ci' => 'min:1,max:255|nullable',
'sepa_batch_id' => 'min:1,max:255|nullable', 'sepa_batch_id' => 'min:1,max:255|nullable',
// dates
'interest_date' => 'date|nullable',
'book_date' => 'date|nullable',
'process_date' => 'date|nullable',
'due_date' => 'date|nullable',
'payment_date' => 'date|nullable',
'invoice_date' => 'date|nullable',
'internal_reference' => 'min:1,max:255|nullable',
'bunq_payment_id' => 'min:1,max:255|nullable',
'external_id' => 'min:1,max:255|nullable',
// transaction rules (in array for splits): // transaction rules (in array for splits):
'transactions.*.amount' => 'required|numeric|more:0', 'transactions.*.amount' => 'required|numeric|more:0',
'transactions.*.description' => 'nullable|between:1,255', 'transactions.*.description' => 'nullable|between:1,255',

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Requests; namespace FireflyIII\Http\Requests;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Rules\IsBoolean;
/** /**
* Class RuleGroupFormRequest. * Class RuleGroupFormRequest.
@@ -47,9 +48,15 @@ class RuleGroupFormRequest extends Request
*/ */
public function getRuleGroupData(): array public function getRuleGroupData(): array
{ {
$active = true;
if (null !== $this->get('active')) {
$active = $this->boolean('active');
}
return [ return [
'title' => $this->string('title'), 'title' => $this->string('title'),
'description' => $this->string('description'), 'description' => $this->string('description'),
'active' => $active,
]; ];
} }
@@ -72,6 +79,7 @@ class RuleGroupFormRequest extends Request
return [ return [
'title' => $titleRule, 'title' => $titleRule,
'description' => 'between:1,5000|nullable', 'description' => 'between:1,5000|nullable',
'active' => [new IsBoolean],
]; ];
} }
} }

View File

@@ -424,7 +424,7 @@ class RuleRepository implements RuleRepositoryInterface
$stopProcessing = $action['stop_processing'] ?? false; $stopProcessing = $action['stop_processing'] ?? false;
$actionValues = [ $actionValues = [
'action' => $action['name'], 'action' => $action['type'],
'value' => $value, 'value' => $value,
'stop_processing' => $stopProcessing, 'stop_processing' => $stopProcessing,
'order' => $order, 'order' => $order,
@@ -460,7 +460,7 @@ class RuleRepository implements RuleRepositoryInterface
$stopProcessing = $trigger['stop_processing'] ?? false; $stopProcessing = $trigger['stop_processing'] ?? false;
$triggerValues = [ $triggerValues = [
'action' => $trigger['name'], 'action' => $trigger['type'],
'value' => $value, 'value' => $value,
'stop_processing' => $stopProcessing, 'stop_processing' => $stopProcessing,
'order' => $order, 'order' => $order,

View File

@@ -268,7 +268,7 @@ trait RequestInformation
if (\is_array($data)) { if (\is_array($data)) {
foreach ($data as $index => $triggerInfo) { foreach ($data as $index => $triggerInfo) {
$triggers[] = [ $triggers[] = [
'type' => $triggerInfo['name'] ?? '', 'type' => $triggerInfo['type'] ?? '',
'value' => $triggerInfo['value'] ?? '', 'value' => $triggerInfo['value'] ?? '',
'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'), 'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'),
]; ];

View File

@@ -54,13 +54,13 @@ trait RuleManagement
'active' => true, 'active' => true,
'triggers' => [ 'triggers' => [
[ [
'name' => 'description_is', 'type' => 'description_is',
'value' => (string)trans('firefly.default_rule_trigger_description'), 'value' => (string)trans('firefly.default_rule_trigger_description'),
'stop_processing' => false, 'stop_processing' => false,
], ],
[ [
'name' => 'from_account_is', 'type' => 'from_account_is',
'value' => (string)trans('firefly.default_rule_trigger_from_account'), 'value' => (string)trans('firefly.default_rule_trigger_from_account'),
'stop_processing' => false, 'stop_processing' => false,
@@ -69,12 +69,12 @@ trait RuleManagement
], ],
'actions' => [ 'actions' => [
[ [
'name' => 'prepend_description', 'type' => 'prepend_description',
'value' => (string)trans('firefly.default_rule_action_prepend'), 'value' => (string)trans('firefly.default_rule_action_prepend'),
'stop_processing' => false, 'stop_processing' => false,
], ],
[ [
'name' => 'set_category', 'type' => 'set_category',
'value' => (string)trans('firefly.default_rule_action_set_category'), 'value' => (string)trans('firefly.default_rule_action_set_category'),
'stop_processing' => false, 'stop_processing' => false,
], ],
@@ -102,7 +102,7 @@ trait RuleManagement
$triggers[] = view( $triggers[] = view(
'rules.partials.action', 'rules.partials.action',
[ [
'oldAction' => $oldAction['name'], 'oldAction' => $oldAction['type'],
'oldValue' => $oldAction['value'], 'oldValue' => $oldAction['value'],
'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'), 'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'),
'count' => $index + 1, 'count' => $index + 1,
@@ -135,7 +135,7 @@ trait RuleManagement
$triggers[] = view( $triggers[] = view(
'rules.partials.trigger', 'rules.partials.trigger',
[ [
'oldTrigger' => $oldTrigger['name'], 'oldTrigger' => $oldTrigger['type'],
'oldValue' => $oldTrigger['value'], 'oldValue' => $oldTrigger['value'],
'oldChecked' => 1 === (int)($oldTrigger['stop_processing'] ?? '0'), 'oldChecked' => 1 === (int)($oldTrigger['stop_processing'] ?? '0'),
'count' => $index + 1, 'count' => $index + 1,

View File

@@ -162,7 +162,7 @@ function onAddNewAction() {
"use strict"; "use strict";
console.log('Now in onAddNewAction()'); console.log('Now in onAddNewAction()');
var selectQuery = 'select[name^="actions["][name$="][name]"]'; var selectQuery = 'select[name^="actions["][name$="][type]"]';
var selectResult = $(selectQuery); var selectResult = $(selectQuery);
console.log('Select query is "' + selectQuery + '" and the result length is ' + selectResult.length); console.log('Select query is "' + selectQuery + '" and the result length is ' + selectResult.length);
@@ -190,7 +190,7 @@ function onAddNewTrigger() {
"use strict"; "use strict";
console.log('Now in onAddNewTrigger()'); console.log('Now in onAddNewTrigger()');
var selectQuery = 'select[name^="triggers["][name$="][name]"]'; var selectQuery = 'select[name^="triggers["][name$="][type]"]';
var selectResult = $(selectQuery); var selectResult = $(selectQuery);
console.log('Select query is "' + selectQuery + '" and the result length is ' + selectResult.length); console.log('Select query is "' + selectQuery + '" and the result length is ' + selectResult.length);

View File

@@ -4,9 +4,9 @@
</td> </td>
<td style="width:30%;"> <td style="width:30%;">
{# todo error when invalid name. #} {# todo error when invalid name. #}
<select name="actions[{{ count }}][name]" class="form-control"> <select name="actions[{{ count }}][type]" class="form-control">
{% for key,name in allRuleActions() %} {% for key,type in allRuleActions() %}
<option value="{{ key }}" label="{{ name }}" {% if key == oldAction %} selected{% endif %}>{{ name }}</option> <option value="{{ key }}" label="{{ type }}" {% if key == oldAction %} selected{% endif %}>{{ type }}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>

View File

@@ -3,13 +3,13 @@
<a href="#" class="btn btn-danger btn-sm remove-trigger"><i class="fa fa-trash"></i></a> <a href="#" class="btn btn-danger btn-sm remove-trigger"><i class="fa fa-trash"></i></a>
</td> </td>
<td style="width:30%;"> <td style="width:30%;">
<select name="triggers[{{ count }}][name]" class="form-control"> <select name="triggers[{{ count }}][type]" class="form-control">
{% for key,name in allRuleTriggers() %} {% for key,type in allRuleTriggers() %}
<option value="{{ key }}" label="{{ name }}" <option value="{{ key }}" label="{{ type }}"
{% if key == oldTrigger %} {% if key == oldTrigger %}
selected selected
{% endif %} {% endif %}
>{{ name }}</option> >{{ type }}</option>
{% endfor %} {% endfor %}
</select> </select>
</td> </td>