diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index bad619e64a..7fed6c5cf0 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -297,23 +297,8 @@ class AccountController extends Controller */ public function store(AccountFormRequest $request, ARI $repository) { - $accountData = [ - 'name' => trim($request->input('name')), - 'accountType' => $request->input('what'), - 'virtualBalance' => round($request->input('virtualBalance'), 2), - 'virtualBalanceCurrency' => intval($request->input('amount_currency_id_virtualBalance')), - 'active' => true, - 'user' => auth()->user()->id, - 'iban' => trim($request->input('iban')), - 'accountNumber' => trim($request->input('accountNumber')), - 'accountRole' => $request->input('accountRole'), - 'openingBalance' => round($request->input('openingBalance'), 2), - 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), - 'openingBalanceCurrency' => intval($request->input('amount_currency_id_openingBalance')), - - ]; - - $account = $repository->store($accountData); + $data = $request->getAccountData(); + $account = $repository->store($data); Session::flash('success', strval(trans('firefly.stored_new_account', ['name' => $account->name]))); Preferences::mark(); @@ -345,22 +330,8 @@ class AccountController extends Controller */ public function update(AccountFormRequest $request, ARI $repository, Account $account) { - - $accountData = [ - 'name' => $request->input('name'), - 'active' => $request->input('active'), - 'user' => auth()->user()->id, - 'iban' => $request->input('iban'), - 'accountNumber' => $request->input('accountNumber'), - 'accountRole' => $request->input('accountRole'), - 'virtualBalance' => round($request->input('virtualBalance'), 2), - 'openingBalance' => round($request->input('openingBalance'), 2), - 'openingBalanceDate' => new Carbon((string)$request->input('openingBalanceDate')), - 'openingBalanceCurrency' => intval($request->input('amount_currency_id_openingBalance')), - 'ccType' => $request->input('ccType'), - 'ccMonthlyPaymentDate' => $request->input('ccMonthlyPaymentDate'), - ]; - $repository->update($account, $accountData); + $data = $request->getAccountData(); + $repository->update($account, $data); Session::flash('success', strval(trans('firefly.updated_account', ['name' => $account->name]))); Preferences::mark(); diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index 3bad8d5ec6..1264cbc3c7 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -13,6 +13,7 @@ declare(strict_types = 1); namespace FireflyIII\Http\Requests; +use Carbon\Carbon; use FireflyIII\Models\Account; use Input; @@ -33,6 +34,29 @@ class AccountFormRequest extends Request return auth()->check(); } + /** + * @return array + */ + public function getAccountDate(): array + { + return [ + 'name' => trim($this->input('name')), + 'active' => intval($this->input('active')) === 1, + 'accountType' => $this->input('what'), + 'virtualBalance' => round($this->input('virtualBalance'), 2), + 'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')), + 'user' => auth()->user()->id, + 'iban' => trim($this->input('iban')), + 'accountNumber' => trim($this->input('accountNumber')), + 'accountRole' => $this->input('accountRole'), + 'openingBalance' => round($this->input('openingBalance'), 2), + 'openingBalanceDate' => new Carbon((string)$this->input('openingBalanceDate')), + 'openingBalanceCurrency' => intval($this->input('amount_currency_id_openingBalance')), + 'ccType' => $this->input('ccType'), + 'ccMonthlyPaymentDate' => $this->input('ccMonthlyPaymentDate'), + ]; + } + /** * @return array */ diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twig index 0541560806..cc48551a42 100644 --- a/resources/views/accounts/create.twig +++ b/resources/views/accounts/create.twig @@ -7,6 +7,7 @@
+