Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Creating and editing an account now allows the opening balance to be set in a certain currency. Issue #37
James Cole725f5b711002
diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.phpindex 9894dda5c3..7562946ac8 100644--- a/app/lib/FireflyIII/Database/Account/Account.php+++ b/app/lib/FireflyIII/Database/Account/Account.php@@ -105,10 +105,11 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');$type = $typeRepository->findByWhat('opening');- $currency = \Amount::getDefaultCurrency();+ $currency = $journals->getJournalCurrencyById(intval($data['balance_currency_id']));+ //$currency = \Amount::getDefaultCurrency();$opening = ['transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'amount' => $balance, 'from' => $fromAccount,- 'completed' => 0, 'currency' => 'EUR', 'what' => 'opening', 'to' => $toAccount, 'date' => $date,+ 'completed' => 0, 'what' => 'opening', 'to' => $toAccount, 'date' => $date,'description' => 'Opening balance for new account ' . $account->name,];$validation = $journals->validate($opening);diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.phpindex c6b76bd38a..59a28f7828 100644--- a/app/lib/FireflyIII/Form/Form.php+++ b/app/lib/FireflyIII/Form/Form.php@@ -140,7 +140,7 @@ class Form$classes = self::getHolderClasses($name);$value = self::fillFieldValue($name, $value);$options['step'] = 'any';- $defaultCurrency = \Amount::getDefaultCurrency();+ $defaultCurrency = isset($options['currency']) ? $options['currency'] : \Amount::getDefaultCurrency();$currencies = \TransactionCurrency::orderBy('code','ASC')->get();$html = \View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();return $html;diff --git a/app/views/accounts/edit.blade.php b/app/views/accounts/edit.blade.phpindex 547068fae8..45737070a9 100644--- a/app/views/accounts/edit.blade.php+++ b/app/views/accounts/edit.blade.php@@ -26,7 +26,7 @@<div class="panel-body">{{Form::ffCheckbox('active','1')}}@if($account->accounttype->type == 'Default account' || $account->accounttype->type == 'Asset account')- {{Form::ffBalance('openingBalance')}}+ {{Form::ffBalance('openingBalance',null, ['currency' => $openingBalance->transactionCurrency])}}{{Form::ffDate('openingBalanceDate')}}{{Form::ffSelect('account_role',Config::get('firefly.accountRoles'))}}@endifdiff --git a/app/views/form/balance.blade.php b/app/views/form/balance.blade.phpindex 3de0fcd955..ba7f2c5d06 100644--- a/app/views/form/balance.blade.php+++ b/app/views/form/balance.blade.php@@ -3,16 +3,17 @@<div class="col-sm-8"><div class="input-group"><div class="input-group-btn">- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">- {{$defaultCurrency->symbol}} <span class="caret"></span>+ <button type="button" class="btn btn-default dropdown-toggle balanceCurrencyDropdown" data-toggle="dropdown" aria-expanded="false">+ <span id="balanceCurrentSymbol">{{$defaultCurrency->symbol}}</span> <span class="caret"></span></button><ul class="dropdown-menu" role="menu">@foreach($currencies as $currency)- <li><a href="#">{{{$currency->name}}}</a></li>+ <li><a href="#" class="currencySelect" data-id="{{{$currency->id}}}" data-field="balance" data-currency="{{{$currency->code}}}" data-symbol="{{{$currency->symbol}}}">{{{$currency->name}}}</a></li>@endforeach</ul></div>{{Form::input('number', $name, $value, $options)}}+ {{Form::input('hidden','balance_currency_id',$defaultCurrency->id)}}@include('form.feedback')</div></div>diff --git a/public/assets/javascript/firefly/firefly.js b/public/assets/javascript/firefly/firefly.jsindex 6f2f799abf..871eb221b4 100644--- a/public/assets/javascript/firefly/firefly.js+++ b/public/assets/javascript/firefly/firefly.js@@ -10,11 +10,11 @@ function currencySelect(e) {var code = target.data('code');var id = target.data('id');var fieldType = target.data('field');- var menu = $('.' + fieldType + 'currencyDropdown');+ var menu = $('.' + fieldType + 'CurrencyDropdown');var symbolHolder = $('#' + fieldType + 'CurrentSymbol');symbolHolder.text(symbol);- $('input[name="amount_currency_id"]').val(id);+ $('input[name="' + fieldType + '_currency_id"]').val(id);// close dropdown (hack hack)menu.click();