mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some javascript clean up
This commit is contained in:
parent
8dc56bcee0
commit
490733bdd1
@ -25,7 +25,9 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
@ -69,6 +71,7 @@ class UpgradeDatabase extends Command
|
|||||||
$this->migrateRepetitions();
|
$this->migrateRepetitions();
|
||||||
$this->repairPiggyBanks();
|
$this->repairPiggyBanks();
|
||||||
$this->updateAccountCurrencies();
|
$this->updateAccountCurrencies();
|
||||||
|
$this->updateJournalCurrencies();
|
||||||
$this->info('Firefly III database is up to date.');
|
$this->info('Firefly III database is up to date.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,4 +255,49 @@ class UpgradeDatabase extends Command
|
|||||||
$identifier++;
|
$identifier++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes sure that withdrawals, deposits and transfers have
|
||||||
|
* a currency setting matching their respective accounts
|
||||||
|
*/
|
||||||
|
private function updateJournalCurrencies()
|
||||||
|
{
|
||||||
|
$types = [
|
||||||
|
TransactionType::WITHDRAWAL => '<',
|
||||||
|
TransactionType::DEPOSIT => '>',
|
||||||
|
];
|
||||||
|
$repository = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
|
foreach ($types as $type => $operator) {
|
||||||
|
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->leftJoin(
|
||||||
|
'transactions', function (JoinClause $join) use ($operator) {
|
||||||
|
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', $operator, '0');
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||||
|
->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id')
|
||||||
|
->where('transaction_types.type', $type)
|
||||||
|
->where('account_meta.name', 'currency_id')
|
||||||
|
->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data'))
|
||||||
|
->get(
|
||||||
|
['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']
|
||||||
|
);
|
||||||
|
/** @var TransactionJournal $journal */
|
||||||
|
foreach ($set as $journal) {
|
||||||
|
$expectedCurrency = $repository->find(intval($journal->expected_currency_id));
|
||||||
|
$this->line(
|
||||||
|
sprintf(
|
||||||
|
'%s #%d uses %s but should use %s. It has been updated to do so, please verify the amounts.', $type, $journal->id,
|
||||||
|
$journal->transactionCurrency->code, $expectedCurrency->code
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$journal->setMeta('foreign_amount', $journal->transaction_amount);
|
||||||
|
$journal->setMeta('foreign_currency_id', $journal->transaction_currency_id);
|
||||||
|
$journal->transaction_currency_id = $expectedCurrency->id;
|
||||||
|
$journal->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,6 +249,8 @@ class AccountController extends Controller
|
|||||||
if ($account->accountType->type === AccountType::INITIAL_BALANCE) {
|
if ($account->accountType->type === AccountType::INITIAL_BALANCE) {
|
||||||
return $this->redirectToOriginalAccount($account);
|
return $this->redirectToOriginalAccount($account);
|
||||||
}
|
}
|
||||||
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||||
@ -257,6 +259,7 @@ class AccountController extends Controller
|
|||||||
$start = null;
|
$start = null;
|
||||||
$end = null;
|
$end = null;
|
||||||
$periods = new Collection;
|
$periods = new Collection;
|
||||||
|
$currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
|
||||||
|
|
||||||
// prep for "all" view.
|
// prep for "all" view.
|
||||||
if ($moment === 'all') {
|
if ($moment === 'all') {
|
||||||
@ -323,7 +326,7 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'accounts.show', compact('account', 'moment', 'accountType', 'periods', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri')
|
'accounts.show', compact('account','currency', 'moment', 'accountType', 'periods', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
configAccounting(currencySymbol);
|
||||||
|
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRF-Token': $('meta[name="_token"]').attr('content')
|
'X-CSRF-Token': $('meta[name="_token"]').attr('content')
|
||||||
@ -108,10 +110,12 @@ function currencySelect(e) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function configAccounting(customCurrency) {
|
||||||
|
|
||||||
// Settings object that controls default parameters for library methods:
|
// Settings object that controls default parameters for library methods:
|
||||||
accounting.settings = {
|
accounting.settings = {
|
||||||
currency: {
|
currency: {
|
||||||
symbol: currencySymbol, // default currency symbol is '$'
|
symbol: customCurrency, // default currency symbol is '$'
|
||||||
format: accountingConfig, // controls output: %s = symbol, %v = value/number (can be object: see below)
|
format: accountingConfig, // controls output: %s = symbol, %v = value/number (can be object: see below)
|
||||||
decimal: mon_decimal_point, // decimal point separator
|
decimal: mon_decimal_point, // decimal point separator
|
||||||
thousand: mon_thousands_sep, // thousands separator
|
thousand: mon_thousands_sep, // thousands separator
|
||||||
@ -123,7 +127,7 @@ accounting.settings = {
|
|||||||
decimal: "."
|
decimal: "."
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function listLengthInitial() {
|
function listLengthInitial() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -26,7 +26,6 @@ $(document).ready(function () {
|
|||||||
updateNativeCurrency();
|
updateNativeCurrency();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// when user changes source account or destination, native currency may be different.
|
// when user changes source account or destination, native currency may be different.
|
||||||
$('select[name="source_account_id"]').on('change', updateNativeCurrency);
|
$('select[name="source_account_id"]').on('change', updateNativeCurrency);
|
||||||
$('select[name="destination_account_id"]').on('change', updateNativeCurrency);
|
$('select[name="destination_account_id"]').on('change', updateNativeCurrency);
|
||||||
@ -101,85 +100,83 @@ function updateForm() {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
$('input[name="what"]').val(what);
|
$('input[name="what"]').val(what);
|
||||||
|
|
||||||
|
var destName = $('#ffInput_destination_account_name');
|
||||||
|
var srcName = $('#ffInput_source_account_name');
|
||||||
|
|
||||||
switch (what) {
|
switch (what) {
|
||||||
case 'withdrawal':
|
case 'withdrawal':
|
||||||
// show source_id and dest_name
|
// show source_id and dest_name
|
||||||
$('#source_account_id_holder').show();
|
document.getElementById('source_account_id_holder').style.display = 'block';
|
||||||
$('#destination_account_name_holder').show();
|
document.getElementById('destination_account_name_holder').style.display = 'block';
|
||||||
|
|
||||||
// hide others:
|
// hide others:
|
||||||
$('#source_account_name_holder').hide();
|
document.getElementById('source_account_name_holder').style.display = 'none';
|
||||||
$('#destination_account_id_holder').hide();
|
document.getElementById('destination_account_id_holder').style.display = 'none';
|
||||||
|
document.getElementById('budget_id_holder').style.display = 'block';
|
||||||
//
|
|
||||||
$('#budget_id_holder').show();
|
|
||||||
|
|
||||||
// hide piggy bank:
|
// hide piggy bank:
|
||||||
$('#piggy_bank_id_holder').hide();
|
document.getElementById('piggy_bank_id_holder').style.display = 'none';
|
||||||
|
|
||||||
// copy destination account name to
|
// copy destination account name to source account name:
|
||||||
// source account name:
|
if (destName.val().length > 0) {
|
||||||
if ($('#ffInput_destination_account_name').val().length > 0) {
|
srcName.val(destName.val());
|
||||||
$('#ffInput_source_account_name').val($('#ffInput_destination_account_name').val());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// exchange / foreign currencies:
|
// exchange / foreign currencies:
|
||||||
// hide explanation, hide source and destination amounts:
|
// hide explanation, hide source and destination amounts, show normal amount
|
||||||
$('#exchange_rate_instruction_holder').hide();
|
document.getElementById('exchange_rate_instruction_holder').style.display = 'none';
|
||||||
$('#source_amount_holder').hide();
|
document.getElementById('source_amount_holder').style.display = 'none';
|
||||||
$('#destination_amount_holder').hide();
|
document.getElementById('destination_amount_holder').style.display = 'none';
|
||||||
// show normal amount:
|
document.getElementById('amount_holder').style.display = 'block';
|
||||||
$('#amount_holder').show();
|
|
||||||
break;
|
break;
|
||||||
case 'deposit':
|
case 'deposit':
|
||||||
// show source_name and dest_id:
|
// show source_name and dest_id:
|
||||||
$('#source_account_name_holder').show();
|
document.getElementById('source_account_name_holder').style.display = 'block';
|
||||||
$('#destination_account_id_holder').show();
|
document.getElementById('destination_account_id_holder').style.display = 'block';
|
||||||
|
|
||||||
// hide others:
|
// hide others:
|
||||||
$('#source_account_id_holder').hide();
|
document.getElementById('source_account_id_holder').style.display = 'none';
|
||||||
$('#destination_account_name_holder').hide();
|
document.getElementById('destination_account_name_holder').style.display = 'none';
|
||||||
|
|
||||||
// hide budget
|
// hide budget
|
||||||
$('#budget_id_holder').hide();
|
document.getElementById('budget_id_holder').style.display = 'none';
|
||||||
|
|
||||||
// hide piggy bank
|
// hide piggy bank
|
||||||
$('#piggy_bank_id_holder').hide();
|
document.getElementById('piggy_bank_id_holder').style.display = 'none';
|
||||||
|
|
||||||
if ($('#ffInput_source_account_name').val().length > 0) {
|
// copy name
|
||||||
$('#ffInput_destination_account_name').val($('#ffInput_source_account_name').val());
|
if (srcName.val().length > 0) {
|
||||||
|
destName.val(srcName.val());
|
||||||
}
|
}
|
||||||
|
|
||||||
// exchange / foreign currencies:
|
// exchange / foreign currencies:
|
||||||
// hide explanation, hide source and destination amounts:
|
// hide explanation, hide source and destination amounts, show amount
|
||||||
$('#exchange_rate_instruction_holder').hide();
|
document.getElementById('exchange_rate_instruction_holder').style.display = 'none';
|
||||||
$('#source_amount_holder').hide();
|
document.getElementById('source_amount_holder').style.display = 'none';
|
||||||
$('#destination_amount_holder').hide();
|
document.getElementById('destination_amount_holder').style.display = 'none';
|
||||||
// show normal amount:
|
document.getElementById('amount_holder').style.display = 'block';
|
||||||
$('#amount_holder').show();
|
|
||||||
break;
|
break;
|
||||||
case 'transfer':
|
case 'transfer':
|
||||||
// show source_id and dest_id:
|
// show source_id and dest_id:
|
||||||
$('#source_account_id_holder').show();
|
document.getElementById('source_account_id_holder').style.display = 'block';
|
||||||
$('#destination_account_id_holder').show();
|
document.getElementById('destination_account_id_holder').style.display = 'block';
|
||||||
|
|
||||||
// hide others:
|
// hide others:
|
||||||
$('#source_account_name_holder').hide();
|
document.getElementById('source_account_name_holder').style.display = 'none';
|
||||||
$('#destination_account_name_holder').hide();
|
document.getElementById('destination_account_name_holder').style.display = 'none';
|
||||||
|
|
||||||
// hide budget
|
// hide budget
|
||||||
$('#budget_id_holder').hide();
|
document.getElementById('budget_id_holder').style.display = 'none';
|
||||||
|
|
||||||
|
// optional piggies
|
||||||
|
var showPiggies = 'block';
|
||||||
if (piggiesLength === 0) {
|
if (piggiesLength === 0) {
|
||||||
$('#piggy_bank_id_holder').hide();
|
showPiggies = 'none';
|
||||||
} else {
|
|
||||||
$('#piggy_bank_id_holder').show();
|
|
||||||
}
|
}
|
||||||
break;
|
document.getElementById('piggy_bank_id_holder').style.display = showPiggies;
|
||||||
default:
|
|
||||||
// no action.
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// update the amount thing:
|
|
||||||
updateNativeCurrency();
|
updateNativeCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ function updateInitialPage() {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$('#source_amount_holder').hide();
|
||||||
|
$('#destination_amount_holder').hide();
|
||||||
|
|
||||||
|
|
||||||
if (journalData.native_currency.id === journalData.currency.id) {
|
if (journalData.native_currency.id === journalData.currency.id) {
|
||||||
|
@ -140,6 +140,7 @@
|
|||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
currencySymbol = "{{ currency.symbol }}";
|
||||||
var accountID = {{ account.id }};
|
var accountID = {{ account.id }};
|
||||||
// uri's for charts:
|
// uri's for charts:
|
||||||
var chartUri = '{{ chartUri }}';
|
var chartUri = '{{ chartUri }}';
|
||||||
@ -155,9 +156,15 @@
|
|||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
{# overrule currency symbol for charts: #}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/lib/Chart.bundle.min.js"></script>
|
<script type="text/javascript" src="js/lib/Chart.bundle.min.js"></script>
|
||||||
<script type="text/javascript" src="js/ff/charts.defaults.js"></script>
|
<script type="text/javascript" src="js/ff/charts.defaults.js"></script>
|
||||||
<script type="text/javascript" src="js/ff/charts.js"></script>
|
<script type="text/javascript" src="js/ff/charts.js"></script>
|
||||||
|
|
||||||
<script src="js/lib/jquery-ui.min.js" type="text/javascript"></script>
|
<script src="js/lib/jquery-ui.min.js" type="text/javascript"></script>
|
||||||
<script src="js/lib/jquery.color-2.1.2.min.js" type="text/javascript"></script>
|
<script src="js/lib/jquery.color-2.1.2.min.js" type="text/javascript"></script>
|
||||||
<script src="js/ff/accounts/show.js" type="text/javascript"></script>
|
<script src="js/ff/accounts/show.js" type="text/javascript"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user