diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index 91cd99c644..f4384d6d12 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -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); diff --git a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php index c3ca7d946c..3eeb6eb5f9 100644 --- a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php +++ b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php @@ -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); } /** diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php index 1f44b5c6f5..3438bbc37d 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php @@ -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. * diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php index dba4e144a8..c6b76bd38a 100644 --- a/app/lib/FireflyIII/Form/Form.php +++ b/app/lib/FireflyIII/Form/Form.php @@ -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; } diff --git a/app/views/form/amount.blade.php b/app/views/form/amount.blade.php index 3de0fcd955..e1c99a4c05 100644 --- a/app/views/form/amount.blade.php +++ b/app/views/form/amount.blade.php @@ -3,16 +3,17 @@
-
{{Form::input('number', $name, $value, $options)}} + {{Form::input('hidden','amount_currency_id',$defaultCurrency->id)}} @include('form.feedback')
diff --git a/app/views/layouts/default.blade.php b/app/views/layouts/default.blade.php index 17595c0643..fe1bbafe6e 100644 --- a/app/views/layouts/default.blade.php +++ b/app/views/layouts/default.blade.php @@ -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') diff --git a/app/views/transactions/edit.blade.php b/app/views/transactions/edit.blade.php index 0b60dd357e..0996995257 100644 --- a/app/views/transactions/edit.blade.php +++ b/app/views/transactions/edit.blade.php @@ -36,7 +36,7 @@ @endif - {{Form::ffAmount('amount',$data['amount'])}} + {{Form::ffAmount('amount',$data['amount'],['currency' => $journal->transactionCurrency])}} {{Form::ffDate('date',$data['date'])}} diff --git a/public/assets/javascript/firefly/firefly.js b/public/assets/javascript/firefly/firefly.js new file mode 100644 index 0000000000..6f2f799abf --- /dev/null +++ b/public/assets/javascript/firefly/firefly.js @@ -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; +} \ No newline at end of file