Skip to content

Firefly III: a personal finances manager

Various code to fix checkboxes.

James Cole56bc79d64e6d
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index ad44631ba9..225e52b89a 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -184,7 +184,9 @@ class AccountController extends Controller
$currency = $default;
}
- $preFilled = [
+ // code to handle active-checkboxes
+ $hasOldInput = null !== $request->old('_token');
+ $preFilled = [
'accountNumber' => $repository->getMetaValue($account, 'accountNumber'),
'accountRole' => $repository->getMetaValue($account, 'accountRole'),
'ccType' => $repository->getMetaValue($account, 'ccType'),
@@ -195,7 +197,7 @@ class AccountController extends Controller
'virtualBalance' => $account->virtual_balance,
'currency_id' => $currency->id,
'notes' => '',
- 'active' => $account->active,
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
];
/** @var Note $note */
$note = $this->repository->getNote($account);
@@ -203,7 +205,6 @@ class AccountController extends Controller
$preFilled['notes'] = $note->text;
}
-
$request->session()->flash('preFilled', $preFilled);
return view('accounts.edit', compact('account', 'currency', 'subTitle', 'subTitleIcon', 'what', 'roles', 'preFilled'));
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index bbb5a96234..b0ae134570 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -161,10 +161,13 @@ class BillController extends Controller
$bill->amount_max = round($bill->amount_max, $currency->decimal_places);
$defaultCurrency = app('amount')->getDefaultCurrency();
+ // code to handle active-checkboxes
+ $hasOldInput = null !== $request->old('_token');
+
$preFilled = [
'notes' => $this->billRepository->getNoteText($bill),
'transaction_currency_id' => $bill->transaction_currency_id,
- 'active' => $bill->active,
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $bill->active,
];
$request->session()->flash('preFilled', $preFilled);
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index e8c5f00b19..df6f0d8954 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -216,11 +216,18 @@ class BudgetController extends Controller
{
$subTitle = trans('firefly.edit_budget', ['name' => $budget->name]);
+ // code to handle active-checkboxes
+ $hasOldInput = null !== $request->old('_token');
+ $preFilled = [
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active,
+ ];
+
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('budgets.edit.fromUpdate')) {
$this->rememberPreviousUri('budgets.edit.uri');
}
$request->session()->forget('budgets.edit.fromUpdate');
+ $request->session()->flash('preFilled', $preFilled);
return view('budgets.edit', compact('budget', 'subTitle'));
}
diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php
index 7ce8d77675..4088c85cd3 100644
--- a/app/Http/Controllers/Recurring/EditController.php
+++ b/app/Http/Controllers/Recurring/EditController.php
@@ -106,13 +106,17 @@ class EditController extends Controller
$repetitionEnd = 'times';
}
- // flash some data:
- $preFilled = [
+ // code to handle active-checkboxes
+ $hasOldInput = null !== $request->old('_token');
+ $preFilled = [
'transaction_type' => strtolower($recurrence->transactionType->type),
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $recurrence->active,
+ 'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : $recurrence->apply_rules,
+
];
$request->flash('preFilled', $preFilled);
- return view('recurring.edit', compact('recurrence', 'array','budgets', 'preFilled', 'currentRepetitionType', 'repetitionEnd', 'repetitionEnds'));
+ return view('recurring.edit', compact('recurrence', 'array', 'budgets', 'preFilled', 'currentRepetitionType', 'repetitionEnd', 'repetitionEnds'));
}
diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php
index 4838a5cc93..3c44641bd1 100644
--- a/app/Http/Controllers/RuleController.php
+++ b/app/Http/Controllers/RuleController.php
@@ -229,6 +229,14 @@ class RuleController extends Controller
$actionCount = \count($oldActions);
}
+ $hasOldInput = null !== $request->old('_token');
+ $preFilled = [
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $rule->active,
+ 'stop_processing' => $hasOldInput ? (bool)$request->old('stop_processing') : $rule->stop_processing,
+ 'strict' => $hasOldInput ? (bool)$request->old('strict') : $rule->strict,
+
+ ];
+
// get rule trigger for update / store-journal:
$primaryTrigger = $this->ruleRepos->getPrimaryTrigger($rule);
$subTitle = trans('firefly.edit_rule', ['title' => $rule->title]);
@@ -239,6 +247,8 @@ class RuleController extends Controller
}
session()->forget('rules.edit.fromUpdate');
+ $request->session()->flash('preFilled', $preFilled);
+
return view('rules.rule.edit', compact('rule', 'subTitle', 'primaryTrigger', 'oldTriggers', 'oldActions', 'triggerCount', 'actionCount'));
}
diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.php
index 360f73eb82..27d3005ee5 100644
--- a/app/Http/Controllers/RuleGroupController.php
+++ b/app/Http/Controllers/RuleGroupController.php
@@ -121,16 +121,18 @@ class RuleGroupController extends Controller
}
/**
+ * @param Request $request
* @param RuleGroup $ruleGroup
*
- * @return View
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
- public function edit(RuleGroup $ruleGroup)
+ public function edit(Request $request, RuleGroup $ruleGroup)
{
$subTitle = trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
- $preFilled = [
- 'active' => $ruleGroup->active,
+ $hasOldInput = null !== $request->old('_token');
+ $preFilled = [
+ 'active' => $hasOldInput ? (bool)$request->old('active') : $ruleGroup->active,
];
diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.php
index 19c0f47ccb..454e01af3d 100644
--- a/app/Http/Requests/RecurrenceFormRequest.php
+++ b/app/Http/Requests/RecurrenceFormRequest.php
@@ -151,7 +151,6 @@ class RecurrenceFormRequest extends Request
'destination_account_name' => 'between:1,255|nullable',
// foreign amount data:
- 'foreign_currency_id' => 'exists:transaction_currencies,id',
'foreign_amount' => 'nullable|more:0',
// optional fields:
@@ -159,6 +158,9 @@ class RecurrenceFormRequest extends Request
'category' => 'between:1,255|nullable',
'tags' => 'between:1,255|nullable',
];
+ if ($this->integer('foreign_currency_id') > 0) {
+ $rules['foreign_currency_id'] = 'exists:transaction_currencies,id';
+ }
// if ends after X repetitions, set another rule
if ($this->string('repetition_end') === 'times') {
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 3a0897258c..b58d60de6d 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -42,6 +42,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property string $name
* @property string $iban
* @property AccountType $accountType
+ * @property bool $active
*/
class Account extends Model
{
diff --git a/app/Models/Budget.php b/app/Models/Budget.php
index c4bd59d5c8..503495b411 100644
--- a/app/Models/Budget.php
+++ b/app/Models/Budget.php
@@ -33,6 +33,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* Class Budget.
* @property int $id
* @property string $name
+ * @property bool $active
*/
class Budget extends Model
{
diff --git a/app/Models/Rule.php b/app/Models/Rule.php
index 7f38e31824..c3c4acd811 100644
--- a/app/Models/Rule.php
+++ b/app/Models/Rule.php
@@ -33,6 +33,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property bool $stop_processing
* @property int $id
* @property \Illuminate\Support\Collection $ruleTriggers
+ * @property bool $active
+ * @property bool $strict
*/
class Rule extends Model
{
diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php
index a25c51b383..a8a3e91453 100644
--- a/app/Support/ExpandedForm.php
+++ b/app/Support/ExpandedForm.php
@@ -247,6 +247,33 @@ class ExpandedForm
return $res;
}
+ /**
+ * @param string $name
+ * @param null $value
+ * @param array $options
+ *
+ * @return string
+ * @throws \Throwable
+ */
+ public function currencyListEmpty(string $name, $value = null, array $options = []): string
+ {
+ /** @var CurrencyRepositoryInterface $currencyRepos */
+ $currencyRepos = app(CurrencyRepositoryInterface::class);
+
+ // get all currencies:
+ $list = $currencyRepos->get();
+ $array = [
+ 0 => trans('firefly.no_currency')
+ ];
+ /** @var TransactionCurrency $currency */
+ foreach ($list as $currency) {
+ $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
+ }
+ $res = $this->select($name, $array, $value, $options);
+
+ return $res;
+ }
+
/**
* @param string $name
* @param null $value
diff --git a/config/twigbridge.php b/config/twigbridge.php
index c5c5dc98f0..484eafd88a 100644
--- a/config/twigbridge.php
+++ b/config/twigbridge.php
@@ -189,7 +189,7 @@ return [
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password', 'nonSelectableBalance', 'nonSelectableAmount',
'number', 'assetAccountList','amountNoCurrency','currencyList','ruleGroupList','assetAccountCheckList','ruleGroupListWithEmpty',
- 'piggyBankList'
+ 'piggyBankList','currencyListEmpty'
],
],
'Form' => [
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index ab8d62b08e..b0a617e9b0 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -1230,6 +1230,7 @@ return [
'create_new_recurrence' => 'Create new recurring transaction',
'help_first_date' => 'Indicate the first expected recurrence. This must be in the future.',
'help_first_date_no_past' => 'Indicate the first expected recurrence. Firefly III will not create transactions in the past.',
+ 'no_currency' => '(no currency)',
'mandatory_for_recurring' => 'Mandatory recurrence information',
'mandatory_for_transaction' => 'Mandatory transaction information',
'optional_for_recurring' => 'Optional recurrence information',
diff --git a/resources/views/accounts/edit.twig b/resources/views/accounts/edit.twig
index feaba02711..827f0f4cc9 100644
--- a/resources/views/accounts/edit.twig
+++ b/resources/views/accounts/edit.twig
@@ -48,7 +48,9 @@
{% endif %}
{{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
- {{ ExpandedForm.checkbox('active','1', preFilled.active) }}
+
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
</div>
</div>
diff --git a/resources/views/bills/create.twig b/resources/views/bills/create.twig
index dd3fb10ab1..5e5508d02c 100644
--- a/resources/views/bills/create.twig
+++ b/resources/views/bills/create.twig
@@ -35,7 +35,8 @@
{{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
{{ ExpandedForm.integer('skip',0) }}
- {{ ExpandedForm.checkbox('active',1, true) }}
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
</div>
</div>
diff --git a/resources/views/bills/edit.twig b/resources/views/bills/edit.twig
index 6302b36198..e45f891c5b 100644
--- a/resources/views/bills/edit.twig
+++ b/resources/views/bills/edit.twig
@@ -37,7 +37,8 @@
{{ ExpandedForm.textarea('notes',null,{helpText: trans('firefly.field_supports_markdown')}) }}
{{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
{{ ExpandedForm.integer('skip') }}
- {{ ExpandedForm.checkbox('active',1) }}
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
</div>
</div>
diff --git a/resources/views/budgets/edit.twig b/resources/views/budgets/edit.twig
index eeaf34244e..4c2f03c6be 100644
--- a/resources/views/budgets/edit.twig
+++ b/resources/views/budgets/edit.twig
@@ -14,7 +14,8 @@
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
</div>
<div class="box-body">
- {{ ExpandedForm.checkbox('active') }}
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
{{ ExpandedForm.text('name') }}
</div>
</div>
diff --git a/resources/views/recurring/create.twig b/resources/views/recurring/create.twig
index 44c8e40e7d..d9f4e3572f 100644
--- a/resources/views/recurring/create.twig
+++ b/resources/views/recurring/create.twig
@@ -47,7 +47,8 @@
<div class="box-body">
{{ ExpandedForm.textarea('recurring_description') }}
- {{ ExpandedForm.checkbox('active',1) }}
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
{{ ExpandedForm.checkbox('apply_rules',1) }}
</div>
@@ -109,7 +110,7 @@
</div>
<div class="box-body">
{# transaction information (optional) #}
- {{ ExpandedForm.currencyList('foreign_currency_id', defaultCurrency.id) }}
+ {{ ExpandedForm.currencyListEmpty('foreign_currency_id', 0) }}
{{ ExpandedForm.amountNoCurrency('foreign_amount', []) }}
{# BUDGET ONLY WHEN CREATING A WITHDRAWAL #}
diff --git a/resources/views/recurring/edit.twig b/resources/views/recurring/edit.twig
index 93b8932417..a1f3c15876 100644
--- a/resources/views/recurring/edit.twig
+++ b/resources/views/recurring/edit.twig
@@ -47,9 +47,10 @@
<div class="box-body">
{{ ExpandedForm.textarea('recurring_description',array.description) }}
- {{ ExpandedForm.checkbox('active',1, array.active) }}
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
- {{ ExpandedForm.checkbox('apply_rules',1, array.apply_rules) }}
+ {{ ExpandedForm.checkbox('apply_rules',1) }}
</div>
</div>
</div>
@@ -108,7 +109,7 @@
</div>
<div class="box-body">
{# transaction information (optional) #}
- {{ ExpandedForm.currencyList('foreign_currency_id', array.transactions[0].foreign_currency_id) }}
+ {{ ExpandedForm.currencyListEmpty('foreign_currency_id', array.transactions[0].foreign_currency_id) }}
{{ ExpandedForm.amountNoCurrency('foreign_amount', array.transactions[0].foreign_amount) }}
{# BUDGET ONLY WHEN CREATING A WITHDRAWAL #}
diff --git a/resources/views/rules/rule-group/edit.twig b/resources/views/rules/rule-group/edit.twig
index 8ef2671a6b..78b4b672bc 100644
--- a/resources/views/rules/rule-group/edit.twig
+++ b/resources/views/rules/rule-group/edit.twig
@@ -14,7 +14,9 @@
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
</div>
<div class="box-body">
- {{ ExpandedForm.checkbox('active') }}
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1) }}
+
{{ ExpandedForm.text('title') }}
</div>
</div>
diff --git a/resources/views/rules/rule/edit.twig b/resources/views/rules/rule/edit.twig
index dad8d5871c..d5a4100306 100644
--- a/resources/views/rules/rule/edit.twig
+++ b/resources/views/rules/rule/edit.twig
@@ -17,7 +17,10 @@
{{ ExpandedForm.text('title') }}
{{ ExpandedForm.ruleGroupList('rule_group_id', ruleGroup.id) }}
{{ ExpandedForm.select('trigger',allJournalTriggers(), primaryTrigger) }}
- {{ ExpandedForm.checkbox('active',1,rule.active, {helpText: trans('firefly.rule_help_active')}) }}
+
+ {# only correct way to do active checkbox #}
+ {{ ExpandedForm.checkbox('active', 1, null, {helpText: trans('firefly.rule_help_active')}) }}
+
{{ ExpandedForm.checkbox('stop_processing',1,rule.stop_processing, {helpText: trans('firefly.rule_help_stop_processing')}) }}
{{ ExpandedForm.checkbox('strict',1,rule.strict, {helpText: trans('firefly.rule_help_strict')}) }}
</div>