diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 7ad7b4a0d1..493adf003d 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -13,6 +13,7 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; +use Amount; use Carbon\Carbon; use ExpandedForm; use FireflyIII\Exceptions\FireflyException; @@ -25,6 +26,7 @@ use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; use FireflyIII\Repositories\Account\AccountTaskerInterface; +use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; use Input; @@ -68,9 +70,18 @@ class AccountController extends Controller */ public function create(string $what = 'asset') { - $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); - $subTitle = trans('firefly.make_new_' . $what . '_account'); - Session::flash('preFilled', []); + /** @var CurrencyRepositoryInterface $repository */ + $repository = app(CurrencyRepositoryInterface::class); + $currencies = ExpandedForm::makeSelectList($repository->get()); + $defaultCurrency = Amount::getDefaultCurrency(); + $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); + $subTitle = trans('firefly.make_new_' . $what . '_account'); + Session::flash( + 'preFilled', + [ + 'currency_id' => $defaultCurrency->id, + ] + ); // put previous url in session if not redirect from store (not "create another"). if (session('accounts.create.fromStore') !== true) { @@ -80,7 +91,7 @@ class AccountController extends Controller Session::flash('gaEventCategory', 'accounts'); Session::flash('gaEventAction', 'create-' . $what); - return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle')); + return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencies')); } @@ -137,6 +148,9 @@ class AccountController extends Controller $what = config('firefly.shortNamesByFullName')[$account->accountType->type]; $subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); + /** @var CurrencyRepositoryInterface $repository */ + $repository = app(CurrencyRepositoryInterface::class); + $currencies = ExpandedForm::makeSelectList($repository->get()); // put previous url in session if not redirect from store (not "return_to_edit"). if (session('accounts.edit.fromUpdate') !== true) { @@ -160,12 +174,13 @@ class AccountController extends Controller 'openingBalanceDate' => $openingBalanceDate, 'openingBalance' => $openingBalanceAmount, 'virtualBalance' => $account->virtual_balance, + 'currency_id' => $account->getMeta('currency_id'), ]; Session::flash('preFilled', $preFilled); Session::flash('gaEventCategory', 'accounts'); Session::flash('gaEventAction', 'edit-' . $what); - return view('accounts.edit', compact('account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what')); + return view('accounts.edit', compact('currencies', 'account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what')); } /** diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index b40e21785f..95cf746044 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -42,6 +42,7 @@ class AccountFormRequest extends Request 'name' => trim($this->input('name')), 'active' => intval($this->input('active')) === 1, 'accountType' => $this->input('what'), + 'currency_id' => intval($this->input('currency_id')), 'virtualBalance' => round($this->input('virtualBalance'), 2), 'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')), 'iban' => trim($this->input('iban')), @@ -80,6 +81,7 @@ class AccountFormRequest extends Request 'iban' => 'iban', 'virtualBalance' => 'numeric', 'openingBalanceDate' => 'date', + 'currency_id' => 'exists:transaction_currencies,id', 'accountNumber' => 'between:1,255|uniqueAccountNumberForUser', 'accountRole' => 'in:' . $accountRoles, 'active' => 'boolean', diff --git a/app/Models/Account.php b/app/Models/Account.php index efecd2fa28..db6f7dffae 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -169,7 +169,7 @@ class Account extends Model { foreach ($this->accountMeta as $meta) { if ($meta->name == $fieldName) { - return $meta->data; + return strval($meta->data); } } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index e9c21082e2..aeb1535a31 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -41,7 +41,7 @@ class AccountRepository implements AccountRepositoryInterface /** @var User */ private $user; /** @var array */ - private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber']; + private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber','currency_id']; /** * AttachmentRepository constructor. diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twig index b068c909c4..f4f560fd5b 100644 --- a/resources/views/accounts/create.twig +++ b/resources/views/accounts/create.twig @@ -17,6 +17,10 @@