mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various small changes.
This commit is contained in:
parent
978e3e615c
commit
8fb6c1a0c8
@ -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
|
||||
*
|
||||
|
@ -162,9 +162,12 @@ class SingleController extends Controller
|
||||
*/
|
||||
public function delete(TransactionJournal $journal)
|
||||
{
|
||||
// Covered by another controller's tests
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($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)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($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)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$count = $journal->transactions()->count();
|
||||
|
||||
@ -313,22 +320,20 @@ class SingleController extends Controller
|
||||
Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)])));
|
||||
Preferences::mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($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)
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($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
|
||||
// @codeCoverageIgnoreStart
|
||||
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
Session::flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
}
|
||||
// flash messages
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
Session::flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
event(new UpdatedTransactionJournal($journal));
|
||||
// update, get events by date and sort DESC
|
||||
@ -366,15 +373,13 @@ class SingleController extends Controller
|
||||
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['description'])])));
|
||||
Preferences::mark();
|
||||
|
||||
// if wishes to split:
|
||||
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (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'));
|
||||
|
@ -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
|
||||
// @codeCoverageIgnoreStart
|
||||
if (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();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (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'));
|
||||
|
@ -102,7 +102,7 @@ function currencySelect(e) {
|
||||
$('#' + spanId).text(symbol);
|
||||
|
||||
// close the menu (hack hack)
|
||||
$('#' + menuID).click();
|
||||
$('#' + menuID).dropdown('toggle');
|
||||
|
||||
|
||||
return false;
|
||||
|
@ -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});
|
||||
|
@ -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',
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
4
resources/views/javascript/accounts.twig
Normal file
4
resources/views/javascript/accounts.twig
Normal file
@ -0,0 +1,4 @@
|
||||
var accountInfo = [];
|
||||
{% for id, account in accounts %}
|
||||
accountInfo[{{ id }}] = {preferredCurrency: {{ account.preferredCurrency}}};
|
||||
{% endfor %}
|
@ -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']);
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user