Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand dashboard view
James Cole87be478dd88f
diff --git a/app/Support/Binder/EitherConfigKey.php b/app/Support/Binder/EitherConfigKey.phpindex 719f98d481..a5a8494c76 100644--- a/app/Support/Binder/EitherConfigKey.php+++ b/app/Support/Binder/EitherConfigKey.php@@ -34,6 +34,10 @@ class EitherConfigKey{public static array $static= [+ // currency conversion+ 'cer.enabled',++ // firefly iii settings'firefly.version','firefly.api_version','firefly.default_location',diff --git a/resources/assets/v2/api/v1/configuration/get.js b/resources/assets/v2/api/v1/configuration/get.jsnew file mode 100644index 0000000000..6289f405fe--- /dev/null+++ b/resources/assets/v2/api/v1/configuration/get.js@@ -0,0 +1,27 @@+/*+ * basic.js+ * Copyright (c) 2021 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++import {api} from "../../../boot/axios";++export default class Get {+ getByName(name) {+ return api.get('/api/v1/configuration/' + name);+ }+}diff --git a/resources/assets/v2/pages/dashboard/accounts.js b/resources/assets/v2/pages/dashboard/accounts.jsindex aa0983092d..179c49f965 100644--- a/resources/assets/v2/pages/dashboard/accounts.js+++ b/resources/assets/v2/pages/dashboard/accounts.js@@ -27,6 +27,7 @@ import {Chart} from 'chart.js';import {getDefaultChartSettings} from "../../support/default-chart-settings.js";import {getColors} from "../../support/get-colors.js";import {getCacheKey} from "../../support/get-cache-key.js";+import {getConfiguration} from "../../store/get-configuration.js";// this is very ugly, but I have no better ideas at the moment to save the currency info// for each series.@@ -40,6 +41,7 @@ export default () => ({loadingAccounts: false,accountList: [],autoConversion: false,+ autoConversionAvailable: false,chartOptions: null,switchAutoConversion() {this.autoConversion = !this.autoConversion;@@ -215,8 +217,16 @@ export default () => ({for (let iii = 0; iii < current.attributes.transactions.length; iii++) {let currentTransaction = current.attributes.transactions[iii];//console.log(currentTransaction);- const nativeAmountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.native_amount) * -1 : parseFloat(currentTransaction.native_amount);- const amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount);+ let nativeAmountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.native_amount) * -1 : parseFloat(currentTransaction.native_amount);+ let amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount);++ // if transfer and source is this account, multiply again+ if('transfer' === currentTransaction.type && parseInt(currentTransaction.source_id) === accountId) { //+ console.log('transfer', parseInt(currentTransaction.source_id), accountId);+ nativeAmountRaw = nativeAmountRaw * -1;+ amountRaw = amountRaw * -1;+ }+group.transactions.push({description: currentTransaction.description,id: current.id,@@ -259,9 +269,12 @@ export default () => ({init() {// console.log('accounts init');- Promise.all([getVariable('viewRange', '1M'), getVariable('autoConversion', false), getVariable('language', 'en_US')]).then((values) => {+ Promise.all([getVariable('viewRange', '1M'), getVariable('autoConversion', false), getVariable('language', 'en_US'),+ getConfiguration('cer.enabled', false)+ ]).then((values) => {//console.log('accounts after promises');- this.autoConversion = values[1];+ this.autoConversion = values[1] && values[3];+ this.autoConversionAvailable = values[3];afterPromises = true;// main dashboard chart:diff --git a/resources/assets/v2/store/get-configuration.js b/resources/assets/v2/store/get-configuration.jsnew file mode 100644index 0000000000..814f906c81--- /dev/null+++ b/resources/assets/v2/store/get-configuration.js@@ -0,0 +1,45 @@+/*+ * get-configuration.js+ * Copyright (c) 2024 [email protected].+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see https://www.gnu.org/licenses/.+ */++import Get from "../api/v1/configuration/get.js";+import {parseResponse} from "./get-variable.js";++export function getConfiguration(name, defaultValue = null) {+ const validCache = window.store.get('cacheValid');+ // currently unused, window.X can be used by the blade template+ // to make things available quicker than if the store has to grab it through the API.+ // then again, it's not that slow.+ if (validCache && window.hasOwnProperty(name)) {+ // console.log('Get from window');+ return Promise.resolve(window[name]);+ }+ // load from store2, if it's present.+ const fromStore = window.store.get(name);+ if (validCache && typeof fromStore !== 'undefined') {+ return Promise.resolve(fromStore);+ }+ let getter = (new Get);+ return getter.getByName(name).then((response) => {+ // console.log('Get "' + name + '" from API');+ return Promise.resolve(parseResponse(name, response));+ }).catch(() => {+ return defaultValue;+ });+}diff --git a/resources/assets/v2/store/get-variable.js b/resources/assets/v2/store/get-variable.jsindex e9ba25a721..56d506de46 100644--- a/resources/assets/v2/store/get-variable.js+++ b/resources/assets/v2/store/get-variable.js@@ -52,7 +52,7 @@ export function getVariable(name, defaultValue = null) {});}-function parseResponse(name, response) {+export function parseResponse(name, response) {let value = response.data.data.attributes.data;window.store.set(name, value);// console.log('Store "' + name + '" in localStorage');diff --git a/resources/views/v2/partials/dashboard/account-chart.blade.php b/resources/views/v2/partials/dashboard/account-chart.blade.phpindex 4e94a5276c..40a4fc9db1 100644--- a/resources/views/v2/partials/dashboard/account-chart.blade.php+++ b/resources/views/v2/partials/dashboard/account-chart.blade.php@@ -9,22 +9,24 @@<div class="card-body p-0" style="position: relative;height:400px;"><canvas id="account-chart"></canvas></div>- <div class="card-footer text-end">- <template x-if="autoConversion">- <button type="button" @click="switchAutoConversion"- class="btn btn-outline-info btm-sm">+ <template x-if="autoConversionAvailable">+ <div class="card-footer text-end">+ <template x-if="autoConversion">+ <button type="button" @click="switchAutoConversion"+ class="btn btn-outline-info btm-sm"><spanclass="fa-solid fa-comments-dollar"></span> {{ __('firefly.disable_auto_convert') }}- </button>- </template>- <template x-if="!autoConversion">- <button type="button" @click="switchAutoConversion"- class="btn btn-outline-info btm-sm">+ </button>+ </template>+ <template x-if="!autoConversion">+ <button type="button" @click="switchAutoConversion"+ class="btn btn-outline-info btm-sm"><spanclass="fa-solid fa-comments-dollar"></span> {{ __('firefly.enable_auto_convert') }}- </button>- </template>- </div>+ </button>+ </template>+ </div>+ </template></div></div>diff --git a/resources/views/v2/partials/dashboard/boxes.blade.php b/resources/views/v2/partials/dashboard/boxes.blade.phpindex 5600c968b6..14a602c84e 100644--- a/resources/views/v2/partials/dashboard/boxes.blade.php+++ b/resources/views/v2/partials/dashboard/boxes.blade.php@@ -63,7 +63,7 @@<template x-if="!loading && billBox.unpaid.length > 0"><p><a href="{{ route('bills.index') }}">{{ __('firefly.bills_to_pay') }}</a></p></template>- <template x-if="0 === billBox.unpaid.length">+ <template x-if="0 === billBox.unpaid.length && !loading"><p>No subscriptions are waiting to be paid</p></template></div>diff --git a/resources/views/v2/partials/elements/amount.blade.php b/resources/views/v2/partials/elements/amount.blade.phpindex b4e5bca831..d8329abf62 100644--- a/resources/views/v2/partials/elements/amount.blade.php+++ b/resources/views/v2/partials/elements/amount.blade.php@@ -23,14 +23,35 @@<template x-if="!autoConversion"><span><template x-if="{{ $amount }}_raw < 0">- <span class="text-danger">- <span x-text="{{ $amount }}"></span>- </span>++ <span>+ <template x-if="'transfer' === {{ $type }}">+ <span class="text-primary">+ <span x-text="{{ $native }}"></span>+ </span>+ </template>+ <template x-if="'transfer' !== {{ $type }}">+ <span class="text-danger">+ <span x-text="{{ $native }}"></span>+ </span>+ </template>+ </span>++</template><template x-if="{{ $amount }}_raw >= 0">- <span class="text-success">- <span x-text="{{ $amount }}"></span>- </span>+ <span>+ <template x-if="'transfer' === {{ $type }}">+ <span class="text-primary">+ <span x-text="{{ $native }}"></span>+ </span>+ </template>+ <template x-if="'transfer' !== {{ $type }}">+ <span class="text-success">+ <span x-text="{{ $native }}"></span>+ </span>+ </template>+ </span></template></span></template>