diff --git a/app/Http/Controllers/Budget/CreateController.php b/app/Http/Controllers/Budget/CreateController.php index 0cb2a9c201..b4b203e2a4 100644 --- a/app/Http/Controllers/Budget/CreateController.php +++ b/app/Http/Controllers/Budget/CreateController.php @@ -89,7 +89,7 @@ class CreateController extends Controller $preFilled = [ 'auto_budget_period' => $hasOldInput ? (bool)$request->old('auto_budget_period') : 'monthly', - 'transaction_currency_id' => $hasOldInput ? (int)$request->old('transaction_currency_id') : $currency->id, + 'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id, ]; $request->session()->flash('preFilled', $preFilled); diff --git a/app/Http/Controllers/Budget/EditController.php b/app/Http/Controllers/Budget/EditController.php index 536f827c73..b150d5eb9f 100644 --- a/app/Http/Controllers/Budget/EditController.php +++ b/app/Http/Controllers/Budget/EditController.php @@ -24,9 +24,9 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; -use FireflyIII\Models\AutoBudget; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\BudgetFormUpdateRequest; +use FireflyIII\Models\AutoBudget; use FireflyIII\Models\Budget; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use Illuminate\Http\RedirectResponse; @@ -72,8 +72,9 @@ class EditController extends Controller { $subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]); $autoBudget = $this->repository->getAutoBudget($budget); - // auto budget options - $autoBudgetOptions = [ + + // auto budget types + $autoBudgetTypes = [ 0 => (string)trans('firefly.auto_budget_none'), AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'), AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'), @@ -89,15 +90,13 @@ class EditController extends Controller // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); + $currency = app('amount')->getDefaultCurrency(); $preFilled = [ - 'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active, + 'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active, + 'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id, ]; if($autoBudget) { $preFilled['auto_budget_amount'] = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount; - //'auto_budget_option' => $request->, - //'transaction_currency_id' => 'required|exists:transaction_currencies,id', - //'auto_budget_amount' => $request->old('auto_budget_amount'), - //'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly', } // put previous url in session if not redirect from store (not "return_to_edit"). @@ -107,7 +106,7 @@ class EditController extends Controller $request->session()->forget('budgets.edit.fromUpdate'); $request->session()->flash('preFilled', $preFilled); - return view('budgets.edit', compact('budget', 'subTitle', 'autoBudgetOptions', 'autoBudgetPeriods', 'autoBudget')); + return view('budgets.edit', compact('budget', 'subTitle', 'autoBudgetTypes', 'autoBudgetPeriods', 'autoBudget')); } /** diff --git a/app/Http/Requests/BudgetFormUpdateRequest.php b/app/Http/Requests/BudgetFormUpdateRequest.php index d9c54cfb5f..02ce9bebd4 100644 --- a/app/Http/Requests/BudgetFormUpdateRequest.php +++ b/app/Http/Requests/BudgetFormUpdateRequest.php @@ -51,8 +51,8 @@ class BudgetFormUpdateRequest extends Request return [ 'name' => $this->string('name'), 'active' => $this->boolean('active'), - 'auto_budget_option' => $this->integer('auto_budget_option'), - 'transaction_currency_id' => $this->integer('transaction_currency_id'), + 'auto_budget_type' => $this->integer('auto_budget_type'), + 'transaction_currency_id' => $this->integer('auto_budget_currency_id'), 'auto_budget_amount' => $this->string('auto_budget_amount'), 'auto_budget_period' => $this->string('auto_budget_period'), ]; @@ -78,7 +78,7 @@ class BudgetFormUpdateRequest extends Request 'name' => $nameRule, 'active' => 'numeric|between:0,1', 'auto_budget_option' => 'numeric|between:0,2', - 'transaction_currency_id' => 'required|exists:transaction_currencies,id', + 'auto_budget_currency_id' => 'required|exists:transaction_currencies,id', 'auto_budget_amount' => 'min:0|max:1000000000', 'auto_budget_period' => 'in:daily,weekly,monthly,quarterly,half_year,yearly', ]; diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 6820074bfd..ab32906687 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -348,7 +348,6 @@ class BudgetRepository implements BudgetRepositoryInterface if ('none' === $autoBudgetType) { $autoBudgetType = 0; } - if (0 !== $autoBudgetType) { $autoBudget = $this->getAutoBudget($budget); if (null === $autoBudget) { diff --git a/resources/views/v1/budgets/edit.twig b/resources/views/v1/budgets/edit.twig index 4b64626a92..659cf3b419 100644 --- a/resources/views/v1/budgets/edit.twig +++ b/resources/views/v1/budgets/edit.twig @@ -28,8 +28,8 @@

{{ 'optionalFields'|_ }}

- {{ ExpandedForm.select('auto_budget_option', autoBudgetOptions, autoBudget.auto_budget_type) }} - {{ CurrencyForm.currencyList('transaction_currency_id', autoBudget.transaction_currency_id) }} + {{ ExpandedForm.select('auto_budget_type', autoBudgetTypes, autoBudget.auto_budget_type) }} + {{ CurrencyForm.currencyList('auto_budget_currency_id', autoBudget.transaction_currency_id) }} {{ ExpandedForm.amountNoCurrency('auto_budget_amount', preFilled.auto_budget_amount) }} {{ ExpandedForm.select('auto_budget_period', autoBudgetPeriods, autoBudget.period) }}