mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* RuleFormRequest.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -66,17 +67,48 @@ class RuleFormRequest extends FormRequest
|
||||
if (is_array($triggerData)) {
|
||||
foreach ($triggerData as $trigger) {
|
||||
$stopProcessing = $trigger['stop_processing'] ?? '0';
|
||||
$return[] = [
|
||||
$current = [
|
||||
'type' => $trigger['type'] ?? 'invalid',
|
||||
'value' => $trigger['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)$stopProcessing,
|
||||
];
|
||||
$current = self::replaceAmountTrigger($current);
|
||||
|
||||
$return[] = $current;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function replaceAmountTrigger(array $array): array
|
||||
{
|
||||
// do some sneaky search and replace.
|
||||
$amountFields = [
|
||||
'amount_is',
|
||||
'amount',
|
||||
'amount_exactly',
|
||||
'amount_less',
|
||||
'amount_max',
|
||||
'amount_more',
|
||||
'amount_min',
|
||||
'foreign_amount_is',
|
||||
'foreign_amount',
|
||||
'foreign_amount_less',
|
||||
'foreign_amount_max',
|
||||
'foreign_amount_more',
|
||||
'foreign_amount_min',
|
||||
];
|
||||
if (in_array($array['type'], $amountFields, true) && '0' === $array['value']) {
|
||||
$array['value'] = '0.00';
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -27,6 +27,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Helpers\Help\HelpInterface;
|
||||
use FireflyIII\Http\Requests\RuleFormRequest;
|
||||
use FireflyIII\Http\Requests\TestRuleFormRequest;
|
||||
use FireflyIII\Support\Binder\AccountList;
|
||||
use FireflyIII\User;
|
||||
@@ -70,14 +71,15 @@ trait RequestInformation
|
||||
$data = $request->get('triggers');
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $triggerInfo) {
|
||||
$triggers[] = [
|
||||
$current = [
|
||||
'type' => $triggerInfo['type'] ?? '',
|
||||
'value' => $triggerInfo['value'] ?? '',
|
||||
'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'),
|
||||
];
|
||||
$current = RuleFormRequest::replaceAmountTrigger($current);
|
||||
$triggers[] = $current;
|
||||
}
|
||||
}
|
||||
|
||||
return $triggers;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user