diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 633b8804b8..d11ca96249 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -69,12 +69,13 @@ class AccountController extends Controller public function create(Request $request, string $what = 'asset') { /** @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'); - $roles = []; + $repository = app(CurrencyRepositoryInterface::class); + $allCurrencies = $repository->get(); + $currencySelectList = ExpandedForm::makeSelectList($allCurrencies); + $defaultCurrency = Amount::getDefaultCurrency(); + $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); + $subTitle = trans('firefly.make_new_' . $what . '_account'); + $roles = []; foreach (config('firefly.accountRoles') as $role) { $roles[$role] = strval(trans('firefly.account_role_' . $role)); } @@ -91,7 +92,7 @@ class AccountController extends Controller $request->session()->flash('gaEventCategory', 'accounts'); $request->session()->flash('gaEventAction', 'create-' . $what); - return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencies', 'roles')); + return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencySelectList','allCurrencies', 'roles')); } @@ -193,8 +194,8 @@ class AccountController extends Controller return view( 'accounts.edit', compact( - 'allCurrencies', 'currencySelectList', 'account', 'currency', 'subTitle', 'subTitleIcon', 'openingBalance', 'what', 'roles' - ) + 'allCurrencies', 'currencySelectList', 'account', 'currency', 'subTitle', 'subTitleIcon', 'openingBalance', 'what', 'roles' + ) ); } @@ -337,7 +338,6 @@ class AccountController extends Controller { $data = $request->getAccountData(); $account = $repository->store($data); - $request->session()->flash('success', strval(trans('firefly.stored_new_account', ['name' => $account->name]))); Preferences::mark(); diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index 1433e65f48..90b8eb760d 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -43,14 +43,12 @@ class AccountFormRequest extends Request 'accountType' => $this->string('what'), 'currency_id' => $this->integer('currency_id'), 'virtualBalance' => $this->float('virtualBalance'), - 'virtualBalanceCurrency' => $this->integer('amount_currency_id_virtualBalance'), 'iban' => $this->string('iban'), 'BIC' => $this->string('BIC'), 'accountNumber' => $this->string('accountNumber'), 'accountRole' => $this->string('accountRole'), 'openingBalance' => $this->float('openingBalance'), 'openingBalanceDate' => $this->date('openingBalanceDate'), - 'openingBalanceCurrency' => $this->integer('amount_currency_id_openingBalance'), 'ccType' => $this->string('ccType'), 'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'), ]; diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 52d32d47f5..5d25d31fcc 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -455,6 +455,7 @@ class AccountRepository implements AccountRepositoryInterface { $amount = $data['openingBalance']; $name = $data['name']; + $currencyId = $data['currency_id']; $opposing = $this->storeOpposingAccount($name); $transactionType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first(); /** @var TransactionJournal $journal */ @@ -462,7 +463,7 @@ class AccountRepository implements AccountRepositoryInterface [ 'user_id' => $this->user->id, 'transaction_type_id' => $transactionType->id, - 'transaction_currency_id' => $data['openingBalanceCurrency'], + 'transaction_currency_id' => $currencyId, 'description' => 'Initial balance for "' . $account->name . '"', 'completed' => true, 'date' => $data['openingBalanceDate'], @@ -530,9 +531,7 @@ class AccountRepository implements AccountRepositoryInterface } // opening balance data? update it! if (!is_null($openingBalance->id)) { - Log::debug('Opening balance journal found, update journal.'); - $this->updateOpeningBalanceJournal($account, $openingBalance, $data); return true; diff --git a/public/js/ff/accounts/create.js b/public/js/ff/accounts/create.js index 675a5fe730..228a2bfb4a 100644 --- a/public/js/ff/accounts/create.js +++ b/public/js/ff/accounts/create.js @@ -6,7 +6,7 @@ * See the LICENSE file for details. */ -/** global: Modernizr */ +/** global: Modernizr, currencies */ $(document).ready(function () { "use strict"; @@ -17,4 +17,14 @@ $(document).ready(function () { } ); } + // on change currency drop down list: + $('#ffInput_currency_id').change(updateCurrencyItems); + updateCurrencyItems(); + }); + +function updateCurrencyItems() { + var value = $('#ffInput_currency_id').val(); + var symbol = currencies[value]; + $('.non-selectable-currency-symbol').text(symbol); +} diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twig index 28f2407b81..1747c1a20b 100644 --- a/resources/views/accounts/create.twig +++ b/resources/views/accounts/create.twig @@ -19,7 +19,7 @@ {{ ExpandedForm.text('name') }} {% if what == 'asset' %} {# Not really mandatory but OK #} - {{ ExpandedForm.select('currency_id', currencies, null, {helpText:'account_default_currency'|_}) }} + {{ ExpandedForm.select('currency_id', currencySelectList, null, {helpText:'account_default_currency'|_}) }} {% endif %} @@ -39,10 +39,10 @@ {% if what == 'asset' %} - {{ ExpandedForm.balance('openingBalance') }} + {{ ExpandedForm.nonSelectableBalance('openingBalance') }} {{ ExpandedForm.date('openingBalanceDate') }} {{ ExpandedForm.select('accountRole', roles,null,{'helpText' : 'asset_account_role_help'|_}) }} - {{ ExpandedForm.balance('virtualBalance') }} + {{ ExpandedForm.nonSelectableBalance('virtualBalance') }} {% endif %} @@ -70,6 +70,13 @@ {% block scripts %} + {# JS currency list for update thing #} + {% endblock %}