Creating and editing an account now allows the opening balance to be set in a certain currency. Issue #37

This commit is contained in:
James Cole 2015-01-30 18:22:55 +01:00
parent 5a890c5c3a
commit 725f5b7110
5 changed files with 11 additions and 9 deletions

View File

@ -105,10 +105,11 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
/** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */ /** @var \FireflyIII\Database\TransactionType\TransactionType $typeRepository */
$typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType'); $typeRepository = \App::make('FireflyIII\Database\TransactionType\TransactionType');
$type = $typeRepository->findByWhat('opening'); $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, $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,]; 'description' => 'Opening balance for new account ' . $account->name,];
$validation = $journals->validate($opening); $validation = $journals->validate($opening);

View File

@ -140,7 +140,7 @@ class Form
$classes = self::getHolderClasses($name); $classes = self::getHolderClasses($name);
$value = self::fillFieldValue($name, $value); $value = self::fillFieldValue($name, $value);
$options['step'] = 'any'; $options['step'] = 'any';
$defaultCurrency = \Amount::getDefaultCurrency(); $defaultCurrency = isset($options['currency']) ? $options['currency'] : \Amount::getDefaultCurrency();
$currencies = \TransactionCurrency::orderBy('code','ASC')->get(); $currencies = \TransactionCurrency::orderBy('code','ASC')->get();
$html = \View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); $html = \View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
return $html; return $html;

View File

@ -26,7 +26,7 @@
<div class="panel-body"> <div class="panel-body">
{{Form::ffCheckbox('active','1')}} {{Form::ffCheckbox('active','1')}}
@if($account->accounttype->type == 'Default account' || $account->accounttype->type == 'Asset account') @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::ffDate('openingBalanceDate')}}
{{Form::ffSelect('account_role',Config::get('firefly.accountRoles'))}} {{Form::ffSelect('account_role',Config::get('firefly.accountRoles'))}}
@endif @endif

View File

@ -3,16 +3,17 @@
<div class="col-sm-8"> <div class="col-sm-8">
<div class="input-group"> <div class="input-group">
<div class="input-group-btn"> <div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <button type="button" class="btn btn-default dropdown-toggle balanceCurrencyDropdown" data-toggle="dropdown" aria-expanded="false">
{{$defaultCurrency->symbol}} <span class="caret"></span> <span id="balanceCurrentSymbol">{{$defaultCurrency->symbol}}</span> <span class="caret"></span>
</button> </button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
@foreach($currencies as $currency) @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 @endforeach
</ul> </ul>
</div> </div>
{{Form::input('number', $name, $value, $options)}} {{Form::input('number', $name, $value, $options)}}
{{Form::input('hidden','balance_currency_id',$defaultCurrency->id)}}
@include('form.feedback') @include('form.feedback')
</div> </div>
</div> </div>

View File

@ -10,11 +10,11 @@ function currencySelect(e) {
var code = target.data('code'); var code = target.data('code');
var id = target.data('id'); var id = target.data('id');
var fieldType = target.data('field'); var fieldType = target.data('field');
var menu = $('.' + fieldType + 'currencyDropdown'); var menu = $('.' + fieldType + 'CurrencyDropdown');
var symbolHolder = $('#' + fieldType + 'CurrentSymbol'); var symbolHolder = $('#' + fieldType + 'CurrentSymbol');
symbolHolder.text(symbol); symbolHolder.text(symbol);
$('input[name="amount_currency_id"]').val(id); $('input[name="' + fieldType + '_currency_id"]').val(id);
// close dropdown (hack hack) // close dropdown (hack hack)
menu.click(); menu.click();