Skip to content

Firefly III: a personal finances manager

Merge branch 'develop' into adminlte4

James Cole87961685804d
diff --cc resources/assets/v2/pages/dashboard/accounts.js
index a590fb4036,0000000000..6c043d9586
mode 100644,000000..100644
--- a/resources/assets/v2/pages/dashboard/accounts.js
+++ b/resources/assets/v2/pages/dashboard/accounts.js
@@@ -1,176 -1,0 +1,191 @@@
+/*
+ * accounts.js
+ * Copyright (c) 2023 [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 ApexCharts from "apexcharts";
+import {getVariable} from "../../store/get-variable.js";
+import Dashboard from "../../api/v2/chart/account/dashboard.js";
+import formatLocal from "../../util/format.js";
+import {format} from "date-fns";
+import formatMoney from "../../util/format-money.js";
+import Get from "../../api/v1/accounts/get.js";
+
+// this is very ugly, but I have no better ideas at the moment to save the currency info
+// for each series.
+window.currencies = [];
+
+export default () => ({
+ loading: false,
+ loadingAccounts: false,
+ accountList: [],
++ autoConvert: false,
+ chart: null,
++ switchConversion() {
++ this.autoConvert = !this.autoConvert;
++ this.loadChart();
++ },
+ loadChart() {
+ if (this.loading) {
+ return;
+ }
+ // load chart data
+ this.loading = true;
+ const dashboard = new Dashboard();
+ dashboard.dashboard(new Date(window.store.get('start')), new Date(window.store.get('end')), null).then((response) => {
+
+ // chart options (may need to be centralized later on)
+ window.currencies = [];
+ let options = {
+ legend: {show: false},
+ chart: {
+ height: 400,
+ toolbar: {tools: {zoom: false, download: false, pan: false}}, type: 'line'
+ }, series: [],
+ settings: [],
+ xaxis: {
+ categories: [], labels: {
+ formatter: function (value) {
+ if (undefined === value) {
+ return '';
+ }
+ const date = new Date(value);
+ if (date instanceof Date && !isNaN(date)) {
+ return formatLocal(date, 'PP');
+ }
+ console.error('Could not parse "' + value + '", return "".');
+ return ':(';
+ }
+ }
+ }, yaxis: {
+ labels: {
+ formatter: function (value, index) {
+ if (undefined === value) {
+ return value;
+ }
+ if (undefined === index) {
+ return value;
+ }
+ if (typeof index === 'object') {
+ index = index.seriesIndex;
+ }
+ //console.log(index);
+ let currencyCode = window.currencies[index] ?? 'EUR';
+ return formatMoney(value, currencyCode);
+ }
+ }
+ },
+ };
+ // render data:
+ for (let i = 0; i < response.data.length; i++) {
+ if (response.data.hasOwnProperty(i)) {
+ let current = response.data[i];
+ let entry = [];
- window.currencies.push(current.currency_code);
- for (const [ii, value] of Object.entries(current.entries)) {
++ let collection = [];
++ // use the "native" currency code and use the "converted_entries" as array
++ if (this.autoConvert) {
++ window.currencies.push(current.native_code);
++ collection = current.converted_entries;
++ }
++ if (!this.autoConvert) {
++ window.currencies.push(current.currency_code);
++ collection = current.entries;
++ }
++
++ for (const [ii, value] of Object.entries(collection)) {
+ entry.push({x: format(new Date(ii), 'yyyy-MM-dd'), y: parseFloat(value)});
+ }
+ options.series.push({name: current.label, data: entry});
+ }
+ }
+ if (null !== this.chart) {
+ // chart already in place, refresh:
+ this.chart.updateOptions(options);
+ }
+ if (null === this.chart) {
+ this.chart = new ApexCharts(document.querySelector("#account-chart"), options);
+ this.chart.render();
+ }
+ this.loading = false;
+ });
+ }, loadAccounts() {
+ if (this.loadingAccounts) {
+ return;
+ }
+ this.loadingAccounts = true;
+ const max = 10;
+ Promise.all([getVariable('frontpageAccounts'),]).then((values) => {
+ for (let i = 0; i < values[0].length; i++) {
+ if (values[0].hasOwnProperty(i)) {
+ let accountId = values[0][i];
+ // grab account info for box:
+ (new Get).get(accountId, new Date(window.store.get('end'))).then((response) => {
+ let current = response.data.data;
+ this.accountList[i] = {
+ name: current.attributes.name,
+ id: current.id,
+ balance: formatMoney(current.attributes.current_balance, current.attributes.currency_code),
+ groups: [],
+ };
+
+ // get groups for account:
+ (new Get).transactions(current.id, 1).then((response) => {
+ for (let ii = 0; ii < response.data.data.length; ii++) {
+ if (ii >= max) {
+ break;
+ }
+ let current = response.data.data[ii];
+ let group = {
+ title: null === current.attributes.group_title ? '' : current.attributes.group_title,
+ id: current.id,
+ transactions: [],
+ };
+ for (let iii = 0; iii < current.attributes.transactions.length; iii++) {
+ let currentTransaction = current.attributes.transactions[iii];
+ group.transactions.push({
+ description: currentTransaction.description,
+ id: current.id,
+ amount: formatMoney(currentTransaction.amount, currentTransaction.currency_code),
+ });
+ }
+ this.accountList[i].groups.push(group);
+ }
+ // will become false after the FIRST account is loaded.
+ this.loadingAccounts = false;
+ });
+ }).then(() => {
+ console.log(this.accountList);
+ });
+ }
+ }
+
+ });
+ },
+
+ init() {
+ console.log('init');
+ Promise.all([getVariable('viewRange'),]).then((values) => {
+ this.loadChart();
+ this.loadAccounts();
+ });
+ window.store.observe('end', () => {
+ this.loadChart();
+ this.loadAccounts();
+ });
+ },
+});
diff --cc resources/views/v2/index.blade.php
index ef112cfbe7,0000000000..9f09889ac4
mode 100644,000000..100644
--- a/resources/views/v2/index.blade.php
+++ b/resources/views/v2/index.blade.php
@@@ -1,129 -1,0 +1,141 @@@
+@extends('layout.v2')
+@section('vite')
+ @vite(['resources/assets/v2/sass/app.scss', 'resources/assets/v2/dashboard.js'])
+@endsection
+@section('content')
+
+ <div class="app-content">
+ <!--begin::Container-->
+ <div class="container-fluid">
+ @include('partials.dashboard.boxes')
+ <!-- row with account data -->
+ <div class="row">
+ <div class="col-xl-8 col-lg-12 col-sm-12 col-xs-12">
+ <div class="row mb-2">
+ <div class="col">
+
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title"><a href="{{ route('accounts.index',['asset']) }}"
+ title="{{ __('firefly.yourAccounts') }}">{{ __('firefly.yourAccounts') }}</a>
+ </h3>
+ </div>
+ <div class="card-body">
+ <div id="account-chart"></div>
++ <p x-data="accounts">
++ <template x-if="autoConvert">
++ <button type="button" @click="switchConversion" class="btn btn-info btm-sm">
++ Disable auto-convert
++ </button>
++ </template>
++ <template x-if="!autoConvert">
++ <button type="button" @click="switchConversion" class="btn btn-info btm-sm">
++ Enable auto-convert
++ </button>
++ </template>
++ </p>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ <div class="row mb-2">
+ <div class="col">
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title"><a href="{{ route('accounts.index',['asset']) }}"
+ title="{{ __('firefly.yourAccounts') }}">budget</a>
+ </h3>
+ </div>
+ <div class="card-body">
+ <div id="budget-chart"></div>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ <div class="row mb-2">
+ <div class="col">
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title"><a href="{{ route('accounts.index',['asset']) }}"
+ title="{{ __('firefly.yourAccounts') }}">cat</a>
+ </h3>
+ </div>
+ <div class="card-body">
+ <div id="category-chart"></div>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ </div>
+ <div class="col-xl-4 col-lg-12 col-sm-12 col-xs-12">
+ <div class="row" x-data="accounts">
+ <template x-for="account in accountList">
+ <div class="col-12 mb-2">
+ <div class="card">
+ <div class="card-header">
+ <h3 class="card-title">
+ <a :href="'{{ route('accounts.show','') }}/' + account.id"
+ x-text="account.name"></a>
+
+ <span class="small text-muted">(<span
+ x-text="account.balance"></span>)</span>
+ </h3>
+ </div>
+ <div class="card-body p-0">
+ <table class="table table-sm">
+ <tbody>
+ <template x-for="group in account.groups">
+ <tr>
+ <td>
+ <template x-if="group.title">
+ <span><a
+ :href="'{{route('transactions.show', '') }}/' + group.id"
+ x-text="group.title"></a><br/></span>
+ </template>
+ <template x-for="transaction in group.transactions">
+ <span>
+ <template x-if="group.title">
+ <span>-
+ <span
+ x-text="transaction.description"></span><br>
+ </span>
+ </template>
+ <template x-if="!group.title">
+ <span><a
+ :href="'{{route('transactions.show', '') }}/' + group.id"
+ x-text="transaction.description"></a><br>
+ </span>
+ </template>
+ </span>
+ </template>
+ </td>
+ <td style="width:30%;" class="text-end">
+ <template x-if="group.title">
+ <span><br/></span>
+ </template>
+ <template x-for="transaction in group.transactions">
+ <span>
+ <span x-text="transaction.amount"></span><br>
+ </span>
+ </template>
+ </td>
+ </tr>
+ </template>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ </template>
+ </div>
+ </div>
+
+ </div>
+ </div>
+
+ </div>
+
+@endsection