Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Various small changes.
James Cole8fb6c1a0c86c
diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.phpindex 042fd32217..c86a3feb55 100644--- a/app/Http/Controllers/JavascriptController.php+++ b/app/Http/Controllers/JavascriptController.php@@ -13,6 +13,10 @@ namespace FireflyIII\Http\Controllers;use Amount;use FireflyIII\Exceptions\FireflyException;+use FireflyIII\Models\Account;+use FireflyIII\Models\AccountType;+use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use Illuminate\Http\Request;use Navigation;use Preferences;@@ -26,6 +30,33 @@ use Session;class JavascriptController extends Controller{+ /**+ *+ */+ public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)+ {+ $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);+ $preference = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'));+ $default = $currencyRepository->findByCode($preference->data);++ $data = ['accounts' => [],];+++ /** @var Account $account */+ foreach ($accounts as $account) {+ $accountId = $account->id;+ $currency = intval($account->getMeta('currency_id'));+ $currency = $currency === 0 ? $default->id : $currency;+ $entry = ['preferredCurrency' => $currency];+ $data['accounts'][$accountId] = $entry;+ }+++ return response()+ ->view('javascript.accounts', $data, 200)+ ->header('Content-Type', 'text/javascript');+ }+/*** @param Request $request*diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.phpindex 830c32eb78..d895f776f1 100644--- a/app/Http/Controllers/Transaction/SingleController.php+++ b/app/Http/Controllers/Transaction/SingleController.php@@ -162,9 +162,12 @@ class SingleController extends Controller*/public function delete(TransactionJournal $journal){+ // Covered by another controller's tests+ // @codeCoverageIgnoreStartif ($this->isOpeningBalance($journal)) {return $this->redirectToAccount($journal);}+ // @codeCoverageIgnoreEnd$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);$subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]);@@ -187,9 +190,11 @@ class SingleController extends Controller*/public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal){+ // @codeCoverageIgnoreStartif ($this->isOpeningBalance($transactionJournal)) {return $this->redirectToAccount($transactionJournal);}+ // @codeCoverageIgnoreEnd$type = TransactionJournal::transactionTypeStr($transactionJournal);Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));@@ -207,9 +212,11 @@ class SingleController extends Controller*/public function edit(TransactionJournal $journal){+ // @codeCoverageIgnoreStartif ($this->isOpeningBalance($journal)) {return $this->redirectToAccount($journal);}+ // @codeCoverageIgnoreEnd$count = $journal->transactions()->count();@@ -313,22 +320,20 @@ class SingleController extends ControllerSession::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)])));Preferences::mark();+ // @codeCoverageIgnoreStartif ($createAnother === true) {- // set value so create routine will not overwrite URL:Session::put('transactions.create.fromStore', true);return redirect(route('transactions.create', [$request->input('what')]))->withInput();}if ($doSplit === true) {- // redirect to edit screen:return redirect(route('transactions.split.edit', [$journal->id]));}+ // @codeCoverageIgnoreEnd- // redirect to previous URL.return redirect($this->getPreviousUri('transactions.create.uri'));-}/**@@ -340,9 +345,11 @@ class SingleController extends Controller*/public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal){+ // @codeCoverageIgnoreStartif ($this->isOpeningBalance($journal)) {return $this->redirectToAccount($journal);}+ // @codeCoverageIgnoreEnd$data = $request->getJournalData();$journal = $repository->update($journal, $data);@@ -350,14 +357,14 @@ class SingleController extends Controller$files = $request->hasFile('attachments') ? $request->file('attachments') : null;$this->attachments->saveAttachmentsForModel($journal, $files);- // flash errors+ // @codeCoverageIgnoreStartif (count($this->attachments->getErrors()->get('attachments')) > 0) {Session::flash('error', $this->attachments->getErrors()->get('attachments'));}- // flash messagesif (count($this->attachments->getMessages()->get('attachments')) > 0) {Session::flash('info', $this->attachments->getMessages()->get('attachments'));}+ // @codeCoverageIgnoreEndevent(new UpdatedTransactionJournal($journal));// update, get events by date and sort DESC@@ -366,15 +373,13 @@ class SingleController extends ControllerSession::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['description'])])));Preferences::mark();- // if wishes to split:--+ // @codeCoverageIgnoreStartif (intval($request->get('return_to_edit')) === 1) {- // set value so edit routine will not overwrite URL:Session::put('transactions.edit.fromUpdate', true);return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);}+ // @codeCoverageIgnoreEnd// redirect to previous URL.return redirect($this->getPreviousUri('transactions.edit.uri'));diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.phpindex e667cb5f1b..b1c75d150a 100644--- a/app/Http/Controllers/Transaction/SplitController.php+++ b/app/Http/Controllers/Transaction/SplitController.php@@ -141,25 +141,27 @@ class SplitController extends Controller$files = $request->hasFile('attachments') ? $request->file('attachments') : null;// save attachments:$this->attachments->saveAttachmentsForModel($journal, $files);-event(new UpdatedTransactionJournal($journal));- // update, get events by date and sort DESC// flash messages+ // @codeCoverageIgnoreStartif (count($this->attachments->getMessages()->get('attachments')) > 0) {Session::flash('info', $this->attachments->getMessages()->get('attachments'));}+ // @codeCoverageIgnoreEnd$type = strtolower(TransactionJournal::transactionTypeStr($journal));Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])])));Preferences::mark();+ // @codeCoverageIgnoreStartif (intval($request->get('return_to_edit')) === 1) {// set value so edit routine will not overwrite URL:Session::put('transactions.edit-split.fromUpdate', true);return redirect(route('transactions.split.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);}+ // @codeCoverageIgnoreEnd// redirect to previous URL.return redirect($this->getPreviousUri('transactions.edit-split.uri'));diff --git a/public/js/ff/firefly.js b/public/js/ff/firefly.jsindex 4f33376896..4c11b51065 100644--- a/public/js/ff/firefly.js+++ b/public/js/ff/firefly.js@@ -102,7 +102,7 @@ function currencySelect(e) {$('#' + spanId).text(symbol);// close the menu (hack hack)- $('#' + menuID).click();+ $('#' + menuID).dropdown('toggle');return false;diff --git a/public/js/ff/transactions/single/create.js b/public/js/ff/transactions/single/create.jsindex 7cf2796417..203962b24c 100644--- a/public/js/ff/transactions/single/create.js+++ b/public/js/ff/transactions/single/create.js@@ -6,19 +6,16 @@* See the LICENSE file for details.*/-/** global: what,Modernizr, title, breadcrumbs, middleCrumbName, button, piggiesLength, txt, doSwitch, middleCrumbUrl */+/** global: what,Modernizr, title, breadcrumbs, middleCrumbName, button, piggiesLength, txt, middleCrumbUrl */$(document).ready(function () {"use strict";- // respond to switch buttons when- // creating stuff:- if (doSwitch == true) {- updateButtons();- updateForm();- updateLayout();- updateDescription();- }+ // respond to switch buttons+ updateButtons();+ updateForm();+ updateLayout();+ updateDescription();if (!Modernizr.inputtypes.date) {$('input[type="date"]').datepicker(@@ -28,11 +25,27 @@ $(document).ready(function () {);}+ // update currency+ $('select[name="source_account_id"]').on('change', updateCurrency)+// get JSON things:getJSONautocomplete();-});++function updateCurrency() {+ // get value:+ var accountId = $('select[name="source_account_id"]').val();+ console.log('account id is ' + accountId);+ var currencyPreference = accountInfo[accountId].preferredCurrency;+ console.log('currency pref is ' + currencyPreference);++ $('.currency-option[data-id="' + currencyPreference + '"]').click();+ $('[data-toggle="dropdown"]').parent().removeClass('open');+ $('select[name="source_account_id"]').focus();++}+function updateDescription() {$.getJSON('json/transaction-journals/' + what).done(function (data) {$('input[name="description"]').typeahead('destroy').typeahead({source: data});diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 5406586eb2..70abb28daf 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -559,6 +559,7 @@ return ['select_more_than_one_tag' => 'Please select more than one tag','from_to' => 'From :start to :end','from_to_breadcrumb' => 'from :start to :end',+ 'account_default_currency' => 'If you select another currency, new transactions from this account will have this currency pre-selected.',// categories:'new_category' => 'New category',diff --git a/resources/views/accounts/create.twig b/resources/views/accounts/create.twigindex 2063b86e79..28f2407b81 100644--- a/resources/views/accounts/create.twig+++ b/resources/views/accounts/create.twig@@ -19,7 +19,7 @@{{ ExpandedForm.text('name') }}{% if what == 'asset' %}{# Not really mandatory but OK #}- {{ ExpandedForm.select('currency_id', currencies) }}+ {{ ExpandedForm.select('currency_id', currencies, null, {helpText:'account_default_currency'|_}) }}{% endif %}</div></div>diff --git a/resources/views/index.twig b/resources/views/index.twigindex 07450afebb..2a62729913 100644--- a/resources/views/index.twig+++ b/resources/views/index.twig@@ -12,7 +12,7 @@<div class="row"><div class="col-lg-8 col-md-12 col-sm-12">- <!-- ACCOUNTS -->+ {# ACCOUNTS #}<div class="box box-primary"><div class="box-header with-border"><h3 class="box-title">{{ 'yourAccounts'|_ }}</h3>@@ -22,7 +22,7 @@</div></div>- <!-- BUDGETS -->+ {# BUDGETS #}<div class="box"><div class="box-header with-border"><h3 class="box-title">{{ 'budgetsAndSpending'|_ }}</h3>diff --git a/resources/views/javascript/accounts.twig b/resources/views/javascript/accounts.twignew file mode 100644index 0000000000..61fb09f610--- /dev/null+++ b/resources/views/javascript/accounts.twig@@ -0,0 +1,4 @@+var accountInfo = [];+{% for id, account in accounts %}+ accountInfo[{{ id }}] = {preferredCurrency: {{ account.preferredCurrency}}};+{% endfor %}diff --git a/routes/web.php b/routes/web.phpindex 1abb383b16..201351db87 100755--- a/routes/web.php+++ b/routes/web.php@@ -414,6 +414,7 @@ Route::group(Route::group(['middleware' => 'user-full-auth', 'prefix' => 'javascript', 'as' => 'javascript.'], function () {Route::get('variables', ['uses' => 'JavascriptController@variables', 'as' => 'variables']);+ Route::get('accounts', ['uses' => 'JavascriptController@accounts', 'as' => 'accounts']);});