From 725f5b711002dc88e9e0b1fe723389bdfdf70f97 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 30 Jan 2015 18:22:55 +0100 Subject: [PATCH] Creating and editing an account now allows the opening balance to be set in a certain currency. Issue #37 --- app/lib/FireflyIII/Database/Account/Account.php | 5 +++-- app/lib/FireflyIII/Form/Form.php | 2 +- app/views/accounts/edit.blade.php | 2 +- app/views/form/balance.blade.php | 7 ++++--- public/assets/javascript/firefly/firefly.js | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php index 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.php index 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.php index 547068fae8..45737070a9 100644 --- a/app/views/accounts/edit.blade.php +++ b/app/views/accounts/edit.blade.php @@ -26,7 +26,7 @@
{{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'))}} @endif diff --git a/app/views/form/balance.blade.php b/app/views/form/balance.blade.php index 3de0fcd955..ba7f2c5d06 100644 --- a/app/views/form/balance.blade.php +++ b/app/views/form/balance.blade.php @@ -3,16 +3,17 @@
-
{{Form::input('number', $name, $value, $options)}} + {{Form::input('hidden','balance_currency_id',$defaultCurrency->id)}} @include('form.feedback')
diff --git a/public/assets/javascript/firefly/firefly.js b/public/assets/javascript/firefly/firefly.js index 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();