mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
It is now possible to select a different currency if desired (issue #37).
This commit is contained in:
parent
7752329b94
commit
5a890c5c3a
@ -242,8 +242,9 @@ class TransactionController extends BaseController
|
||||
public function store($what)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
|
||||
$transactionType = $this->_repository->getJournalType($what);
|
||||
$transactionCurrency = $this->_repository->getJournalCurrency('EUR');
|
||||
$transactionCurrency = $this->_repository->getJournalCurrencyById(intval($data['amount_currency_id']));
|
||||
$data['transaction_type_id'] = $transactionType->id;
|
||||
$data['transaction_currency_id'] = $transactionCurrency->id;
|
||||
$data['completed'] = 0;
|
||||
@ -289,10 +290,9 @@ class TransactionController extends BaseController
|
||||
public function update(TransactionJournal $journal)
|
||||
{
|
||||
$data = Input::except('_token');
|
||||
$data['currency'] = 'EUR';
|
||||
$data['what'] = strtolower($journal->transactionType->type);
|
||||
$data['transaction_type_id'] = $journal->transaction_type_id;
|
||||
$data['transaction_currency_id'] = $journal->transaction_currency_id;
|
||||
$data['transaction_currency_id'] = intval($data['amount_currency_id']);
|
||||
$data['completed'] = 1;
|
||||
$messages = $this->_repository->validate($data);
|
||||
|
||||
|
@ -94,14 +94,12 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
|
||||
* Returns an object with id $id.
|
||||
*
|
||||
* @param int $objectId
|
||||
* @throws NotImplementedException
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return \Eloquent
|
||||
*/
|
||||
public function find($objectId)
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
return \TransactionCurrency::find($objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,7 +102,7 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
||||
public function update(Eloquent $model, array $data)
|
||||
{
|
||||
$journalType = $this->getJournalType($data['what']);
|
||||
$currency = $this->getJournalCurrency($data['currency']);
|
||||
$currency = $this->getJournalCurrencyById($data['transaction_currency_id']);
|
||||
$model->description = $data['description'];
|
||||
$model->date = $data['date'];
|
||||
|
||||
@ -304,6 +304,19 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
||||
return $currencyRepository->findByCode($currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currencyId
|
||||
*
|
||||
* @return null|\TransactionCurrency
|
||||
*/
|
||||
public function getJournalCurrencyById($currencyId)
|
||||
{
|
||||
/** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencyRepository */
|
||||
$currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
|
||||
|
||||
return $currencyRepository->find($currencyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
*
|
||||
|
@ -30,8 +30,8 @@ class Form
|
||||
$value = self::fillFieldValue($name, $value);
|
||||
$options['step'] = 'any';
|
||||
$options['min'] = '0.01';
|
||||
$defaultCurrency = \Amount::getDefaultCurrency();
|
||||
$currencies = \TransactionCurrency::where('name', '!=', $defaultCurrency->name)->get();
|
||||
$defaultCurrency = isset($options['currency']) ? $options['currency'] : \Amount::getDefaultCurrency();
|
||||
$currencies = \TransactionCurrency::orderBy('code','ASC')->get();
|
||||
$html = \View::make('form.amount', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
@ -141,7 +141,7 @@ class Form
|
||||
$value = self::fillFieldValue($name, $value);
|
||||
$options['step'] = 'any';
|
||||
$defaultCurrency = \Amount::getDefaultCurrency();
|
||||
$currencies = \TransactionCurrency::where('name', '!=', $defaultCurrency->name)->get();
|
||||
$currencies = \TransactionCurrency::orderBy('code','ASC')->get();
|
||||
$html = \View::make('form.balance', compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
|
||||
return $html;
|
||||
}
|
||||
|
@ -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 amountCurrencyDropdown" data-toggle="dropdown" aria-expanded="false">
|
||||
<span id="amountCurrentSymbol">{{$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="amount" data-currency="{{{$currency->code}}}" data-symbol="{{{$currency->symbol}}}">{{{$currency->name}}}</a></li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
{{Form::input('number', $name, $value, $options)}}
|
||||
{{Form::input('hidden','amount_currency_id',$defaultCurrency->id)}}
|
||||
@include('form.feedback')
|
||||
</div>
|
||||
</div>
|
||||
|
@ -91,6 +91,7 @@
|
||||
{{HTML::script('assets/javascript/metisMenu/jquery.metisMenu.min.js')}}
|
||||
{{HTML::script('assets/javascript/sb-admin/sb-admin-2.js')}}
|
||||
{{HTML::script('assets/javascript/firefly/help.js')}}
|
||||
{{HTML::script('assets/javascript/firefly/firefly.js')}}
|
||||
@yield('scripts')
|
||||
</body>
|
||||
</html>
|
||||
|
@ -36,7 +36,7 @@
|
||||
@endif
|
||||
|
||||
<!-- ALWAYS SHOW AMOUNT -->
|
||||
{{Form::ffAmount('amount',$data['amount'])}}
|
||||
{{Form::ffAmount('amount',$data['amount'],['currency' => $journal->transactionCurrency])}}
|
||||
|
||||
<!-- ALWAYS SHOW DATE -->
|
||||
{{Form::ffDate('date',$data['date'])}}
|
||||
|
24
public/assets/javascript/firefly/firefly.js
Normal file
24
public/assets/javascript/firefly/firefly.js
Normal file
@ -0,0 +1,24 @@
|
||||
$(function () {
|
||||
|
||||
$('.currencySelect').click(currencySelect)
|
||||
|
||||
});
|
||||
|
||||
function currencySelect(e) {
|
||||
var target = $(e.target);
|
||||
var symbol = target.data('symbol');
|
||||
var code = target.data('code');
|
||||
var id = target.data('id');
|
||||
var fieldType = target.data('field');
|
||||
var menu = $('.' + fieldType + 'currencyDropdown');
|
||||
|
||||
var symbolHolder = $('#' + fieldType + 'CurrentSymbol');
|
||||
symbolHolder.text(symbol);
|
||||
$('input[name="amount_currency_id"]').val(id);
|
||||
|
||||
// close dropdown (hack hack)
|
||||
menu.click();
|
||||
|
||||
|
||||
return false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user