Skip to content

Firefly III: a personal finances manager

Replace budget chart.

James Coleebbe2aca464a
diff --git a/public/v1/js/ff/accounts/index.js b/public/v1/js/ff/accounts/index.js
deleted file mode 100644
index 23b45dc244..0000000000
--- a/public/v1/js/ff/accounts/index.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * index.js
- * Copyright (c) 2020 [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/>.
- */
-
-var fixObjectHelper = function (e, tr) {
- "use strict";
- var $originals = tr.children();
- var $helper = tr.clone();
- $helper.children().each(function (index) {
- // Set helper cell sizes to match the original sizes
- $(this).width($originals.eq(index).width());
- });
- return $helper;
-};
-
-$(function () {
- "use strict";
- console.log('Here we are, loaded.');
- // table may have multiple tbody's.
- $('#sortable-table').find('tbody').sortable(
- {
- helper: fixObjectHelper,
- stop: stopSorting,
- items: 'tr.sortable-object',
- handle: '.object-handle',
- start: function (event, ui) {
- // Build a placeholder cell that spans all the cells in the row
- var cellCount = 0;
- $('td, th', ui.helper).each(function () {
- // For each TD or TH try and get it's colspan attribute, and add that or 1 to the total
- var colspan = 1;
- var colspanAttr = $(this).attr('colspan');
- if (colspanAttr > 1) {
- colspan = colspanAttr;
- }
- cellCount += colspan;
- });
-
- // Add the placeholder UI - note that this is the item's content, so TD rather than TR
- ui.placeholder.html('<td colspan="' + cellCount + '">&nbsp;</td>');
- }
- }
- );
-});
-
-
-function stopSorting() {
- "use strict";
- $.each($('#sortable-table>tbody>tr.sortable-object'), function (i, v) {
- var holder = $(v);
- var position = parseInt(holder.data('position'));
- var originalOrder = parseInt(holder.data('order'));
- var id = holder.data('id');
- var newOrder;
-
- if (position === i) {
- // not changed, position is what it should be.
- return;
- }
-
- if (position < i) {
- // position is less.
- console.log('Account #' + id + ' has moved down from position ' + originalOrder + ' to ' + (i + 1));
- }
- if (position > i) {
- console.log('Account #' + id + ' has moved up from position ' + originalOrder + ' to ' + (i + 1));
- }
- // update position:
- holder.data('position', i);
- newOrder = i + 1;
-
- // post new position via API!
- //$.post('api/v1/accounts/' + id, {order: newOrder, _token: token});
- $.ajax({
- url: 'api/v1/accounts/' + id,
- data: JSON.stringify({order: newOrder}),
- type: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
- },
- });
- });
-
-}
diff --git a/public/v1/js/ff/accounts/show.js b/public/v1/js/ff/accounts/show.js
index 4653e71104..67e7c2428a 100644
--- a/public/v1/js/ff/accounts/show.js
+++ b/public/v1/js/ff/accounts/show.js
@@ -18,17 +18,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-var fixHelper = function (e, tr) {
- "use strict";
- var $originals = tr.children();
- var $helper = tr.clone();
- $helper.children().each(function (index) {
- // Set helper cell sizes to match the original sizes
- $(this).width($originals.eq(index).width());
- });
- return $helper;
-};
-
$(function () {
"use strict";
//lineChart(chartUrl, 'overview-chart');
@@ -38,69 +27,4 @@ $(function () {
multiCurrencyPieChart(expenseCategoryUrl, 'account-cat-out');
multiCurrencyPieChart(expenseBudgetUrl, 'account-budget-out');
}
-
- // sortable!
- if (typeof $(".sortable-table tbody").sortable !== "undefined") {
- $(".sortable-table tbody").sortable(
- {
- helper: fixHelper,
- items: 'tr:not(.ignore)',
- stop: sortStop,
- handle: '.handle',
- start: function (event, ui) {
- // Build a placeholder cell that spans all the cells in the row
- var cellCount = 0;
- $('td, th', ui.helper).each(function () {
- // For each TD or TH try and get it's colspan attribute, and add that or 1 to the total
- var colspan = 1;
- var colspanAttr = $(this).attr('colspan');
- if (colspanAttr > 1) {
- colspan = colspanAttr;
- }
- cellCount += colspan;
- });
-
- // Add the placeholder UI - note that this is the item's content, so TD rather than TR
- ui.placeholder.html('<td colspan="' + cellCount + '">&nbsp;</td>');
- }
- }
- );
- }
-
});
-
-function sortStop(event, ui) {
- "use strict";
- var current = $(ui.item);
- var thisDate = current.data('date');
- var originalBG = current.css('backgroundColor');
-
-
- if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {
- // animate something with color:
- current.animate({backgroundColor: "#d9534f"}, 200, function () {
- $(this).animate({backgroundColor: originalBG}, 200);
- return undefined;
- });
-
- return false;
- }
-
- // do update
- var list = $('tr[data-date="' + thisDate + '"]');
- var submit = [];
- $.each(list, function (i, v) {
- var row = $(v);
- var id = row.data('id');
- submit.push(id);
- });
-
- // do extra animation when done?
- $.post('transactions/reorder', {items: submit, date: thisDate});
-
- current.animate({backgroundColor: "#5cb85c"}, 200, function () {
- $(this).animate({backgroundColor: originalBG}, 200);
- return undefined;
- });
- return undefined;
-}
diff --git a/public/v1/js/ff/index.js b/public/v1/js/ff/index.js
index 7b00a4bb1b..32571b6a54 100644
--- a/public/v1/js/ff/index.js
+++ b/public/v1/js/ff/index.js
@@ -34,7 +34,7 @@ function drawChart() {
if (billCount > 0) {
multiCurrencyPieChart('chart/bill/frontpage', 'bills-chart');
}
- stackedColumnChart('chart/budget/frontpage', 'budgets-two-chart');
+ // stackedColumnChart('chart/budget/frontpage', 'budgets-two-chart');
columnChart('chart/category/frontpage', 'categories-chart');
columnChart(accountExpenseUrl, 'expense-accounts-chart');
columnChart(accountRevenueUrl, 'revenue-accounts-chart');
diff --git a/resources/assets/v3/js/pages/dashboard/dashboard.js b/resources/assets/v3/js/pages/dashboard/dashboard.js
index 36bb242058..499b73e38a 100644
--- a/resources/assets/v3/js/pages/dashboard/dashboard.js
+++ b/resources/assets/v3/js/pages/dashboard/dashboard.js
@@ -51,15 +51,15 @@ let index = function () {
true,
);
- // drawMultiCurrencyChart(
- // "stacked-column",
- // "api/v1/chart/budget/overview?start=" +
- // format(start, "yyyy-LL-dd") +
- // "&end=" +
- // format(end, "yyyy-LL-dd"),
- // "budgets-chart",
- // value, false
- // );
+ drawMultiCurrencyChart(
+ "stacked-column",
+ "api/v1/chart/budget/overview?start=" +
+ format(start, "yyyy-LL-dd") +
+ "&end=" +
+ format(end, "yyyy-LL-dd"),
+ "budgets-chart",
+ value, false
+ );
});
},
loadPiggyBanks() {
diff --git a/resources/assets/v3/js/shared/draw-chart.js b/resources/assets/v3/js/shared/draw-chart.js
index 80ec6dd014..053d0bacf9 100644
--- a/resources/assets/v3/js/shared/draw-chart.js
+++ b/resources/assets/v3/js/shared/draw-chart.js
@@ -100,96 +100,101 @@ function drawMultiCurrencyStackedColumnChart(url, holder, anonymous) {
// make custom options set.
let options = structuredClone(defaultChartOptions);
let datasets = {};
-
+ console.log('All data is', all);
// loop all collected data.
for (let i = 0; i < all.length; i++) {
if (Object.hasOwn(all, i)) {
let current = all[i];
+ let label = formatLabel(current.label + " (" + current.currency_code + ")", 20);
+
+ // if there is NOTHING in this budget, skip it.
+ if (0 === parseFloat(current.entries.budgeted) && 0 === parseFloat(current.entries.spent) && 0 === parseFloat(current.entries.left) && 0 === parseFloat(current.entries.overspent)) {
+ console.log('SKIP', current.entries);
+ continue;
+ }
+
// add the name as a label
- data.labels.push(formatLabel(current.label, 20));
+ data.labels.push(label);
+ let labelIndex = data.labels.length - 1;
- // there are four possible data sets for this chart
- // TODO this is very much hard coded.
+ /*
+ ok dus je hebt al zes labels voor alle zes de budget/currency combinaties
+ dus je moet nu vier datasets maken. Die elk 6 entries hebben.
+ */
let keys = ["budgeted", "spent", "left", "overspent"];
for (let i in keys) {
let key = keys[i] + current.currency_code;
if (!Object.hasOwn(datasets, key)) {
datasets[key] = {
- label:
- i18next.t("firefly." + keys[i]) +
- " (" +
- current.currency_code +
- ")",
- currency_code: current.currency_code,
+ label: key,
data: [],
+ currency_code: current.currency_code,
yAxisID: "y" + current.currency_code,
};
+ // make sure that data set is all zeroes when we start:
+ for (let j = 0; j < all.length; j++) {
+ datasets[key].data.push(0);
+ }
+ }
+ let multiplier = 1;
+ if ("spent" === keys[i]) {
+ multiplier = -1;
+ }
+ // then set the current value:
+ //if(0 === parseFloat(current.entries[keys[i]])) {
+ // console.log('Budget "'+current.label+'" has no amount for "'+keys[i]+'" in '+current.currency_code+' so we skip it.', current.entries[keys[i]]);
+ //console.log('EMPTY What to choose from ['+i+'] (label "'+label+'" is index: '+labelIndex+') (i: '+i+', keys[i]: '+keys[i]+')?', current.entries[keys[i]]);
+ //}
+ if (0 !== parseFloat(current.entries[keys[i]])) {
+ console.log('Budget "' + current.label + '" has amount for "' + keys[i] + '" in ' + current.currency_code + ' so we skip it.', current.entries[keys[i]]);
+ // console.log('What to choose from ['+i+'] (label "'+label+'" is index: '+labelIndex+') (i: '+i+', keys[i]: '+keys[i]+')?', current.entries[keys[i]]);
+ datasets[key].data[labelIndex] = parseFloat(current.entries[keys[i]]) * multiplier;
}
}
+ if (parseFloat(current.entries.spent) * -1 < parseFloat(current.entries.budgeted)) {
+ // user has not overspent.
+ let key = "budgeted" + current.currency_code;
+ datasets[key].data[labelIndex] = 0;// parseFloat(current.entries.budgeted);
- // for the first and all other datasets, create a new dataset object.
- // add the data to the dataset.
+ key = "spent" + current.currency_code;
+ datasets[key].data[labelIndex] = parseFloat(current.entries.spent) * -1
- // add spent and left to the dataset, if they exist.
- // console.log('current', current);
- if (
- parseFloat(current.entries.spent) * -1 <
- parseFloat(current.entries.budgeted)
- ) {
+ key = "left" + current.currency_code;
+ datasets[key].data[labelIndex] = parseFloat(current.entries.left);
+
+ key = "overspent" + current.currency_code;
+ datasets[key].data[labelIndex] = 0;
+ }
+ if (parseFloat(current.entries.spent) * -1 >= parseFloat(current.entries.budgeted) && 0 !== parseFloat(current.entries.budgeted)) {
+ // user has overspent!
let key = "budgeted" + current.currency_code;
- datasets[key].data.push(0);
+ datasets[key].data[labelIndex] = parseFloat(current.entries.budgeted);
- // user has not overspent.
key = "spent" + current.currency_code;
- let value = parseFloat(current.entries.spent) * -1;
- datasets[key].data.push(value);
+ datasets[key].data[labelIndex] = 0;
key = "left" + current.currency_code;
- value = parseFloat(current.entries.left);
- datasets[key].data.push(value);
+ datasets[key].data[labelIndex] = 0;
key = "overspent" + current.currency_code;
- datasets[key].data.push(0);
+ datasets[key].data[labelIndex] = parseFloat(current.entries.overspent);
}
- if (
- parseFloat(current.entries.spent) * -1 >=
- parseFloat(current.entries.budgeted)
- ) {
+
+ if (parseFloat(current.entries.spent) * -1 >= parseFloat(current.entries.budgeted) && 0 === parseFloat(current.entries.budgeted)) {
+ // user has no budget set.
let key = "budgeted" + current.currency_code;
- datasets[key].data.push(0);
+ datasets[key].data[labelIndex] = 0;
- // user has overspent.
key = "spent" + current.currency_code;
- let value = parseFloat(current.entries.spent) * -1;
- datasets[key].data.push(value);
+ datasets[key].data[labelIndex] = parseFloat(current.entries.spent) * -1;
key = "left" + current.currency_code;
- datasets[key].data.push(0);
+ datasets[key].data[labelIndex] = 0;
key = "overspent" + current.currency_code;
- value = parseFloat(current.entries.overspent);
- datasets[key].data.push(value);
+ datasets[key].data[labelIndex] = 0;
}
- // console.log('Current entries:')
- // console.log(current.entries);
- //
- //
- // for (let j in current.entries) {
- // // j = "spent" or earned or whatever.
- // let key = j + current.currency_code;
- // if (Object.hasOwn(datasets, key)) {
- // let value = parseFloat(current.entries[j]);
- // if(value < 0) {
- // value = value * -1;
- // }
- // datasets[key].data.push(value);
- // }
- // }
- // console.log('All generatred datasets.')
- // console.log(datasets);
- // add it to the dataset collection.
- //data.datasets.push(dataset);
- data.datasets = Object.values(datasets);
+
// if there is no axis yet for this currency, create one.
let currencyCode = current.currency_code;
@@ -213,14 +218,127 @@ function drawMultiCurrencyStackedColumnChart(url, holder, anonymous) {
},
};
}
+
}
}
+
+
+ // loop all collected data.
+ for (let i = 0; i < all.length; i++) {
+ if (Object.hasOwn(all, i)) {
+ // let current = all[i];
+ // let label = formatLabel(current.label + " (" + current.currency_code + ")", 20);
+ // console.log('Now processing "' + label + '"');
+ // // add the name as a label
+ // data.labels.push(label);
+
+
+ // wil je dan niet eerst de labels + currencies maken in objectjes.
+
+ // each data set is per budget (so per label):
+ // if (!Object.hasOwn(datasets, label)) {
+ // datasets[label] = {
+ // label: label,
+ // currency_code: current.currency_code,
+ // budget_name: current.label,
+ // data: [],
+ // yAxisID: "y" + current.currency_code,
+ // };
+ // }
+
+ // there must be 4 data sets with a length of X budgets * currencies.
+
+
+ // there are four possible data sets for this chart
+ // // TODO this is very much hard coded.
+ // let keys = ["budgeted", "spent", "left", "overspent"];
+ // for (let i in keys) {
+ // let key = keys[i] + current.currency_code;
+ // if (!Object.hasOwn(datasets, key)) {
+ // datasets[key] = {
+ // label: i18next.t("firefly." + keys[i]) + " (" + current.currency_code + ")",
+ // currency_code: current.currency_code,
+ // budget_name: current.label,
+ // data: [],
+ // yAxisID: "y" + current.currency_code,
+ // };
+ // }
+ // }
+
+ // for the first and all other datasets, create a new dataset object.
+ // add the data to the dataset.
+
+ // // add spent and left to the dataset, if they exist.
+ // // console.log('current', current);
+ // if (parseFloat(current.entries.spent) * -1 < parseFloat(current.entries.budgeted)) {
+ // let key = "budgeted" + current.currency_code;
+ // datasets[label].data.push(0);
+ //
+ // // user has not overspent.
+ // key = "spent" + current.currency_code;
+ // let value = parseFloat(current.entries.spent) * -1;
+ // datasets[label].data.push(value);
+ //
+ // key = "left" + current.currency_code;
+ // value = parseFloat(current.entries.left);
+ // datasets[label].data.push(value);
+ //
+ // key = "overspent" + current.currency_code;
+ // datasets[label].data.push(0);
+ // }
+ // if (parseFloat(current.entries.spent) * -1 >= parseFloat(current.entries.budgeted)) {
+ // let key = "budgeted" + current.currency_code;
+ // datasets[label].data.push(0);
+ //
+ // // user has overspent.
+ // key = "spent" + current.currency_code;
+ // let value = parseFloat(current.entries.spent) * -1;
+ // datasets[label].data.push(value);
+ //
+ // key = "left" + current.currency_code;
+ // datasets[label].data.push(0);
+ //
+ // key = "overspent" + current.currency_code;
+ // value = parseFloat(current.entries.overspent);
+ // datasets[label].data.push(value);
+ // }
+ // console.log('Current entries:')
+ // console.log(current.entries);
+ //
+ //
+ // for (let j in current.entries) {
+ // // j = "spent" or earned or whatever.
+ // let key = j + current.currency_code;
+ // if (Object.hasOwn(datasets, key)) {
+ // let value = parseFloat(current.entries[j]);
+ // if(value < 0) {
+ // value = value * -1;
+ // }
+ // datasets[key].data.push(value);
+ // }
+ // }
+ // console.log('All generatred datasets.')
+ // console.log(datasets);
+ // add it to the dataset collection.
+ //data.datasets.push(dataset);
+
+
+ }
+ }
+ console.log('All labels are', data.labels);
+ console.log('All datasets are', datasets);
+ console.log('All scales are', axes);
+ // do a proper conversion so its in the right order?
+
+
+ data.datasets = Object.values(datasets);
+ console.log('Final datasets are', data.datasets);
// remove the standard y-axis, do not need it.
delete options.scales.y;
options.scales.x.stacked = true;
// options.scales.y.stacked = true;
// add the new axes.
- options.scales = { ...options.scales, ...axes };
+ options.scales = {...options.scales, ...axes};
// console.log(options);
// console.log(data);
@@ -379,7 +497,7 @@ function drawMultiCurrencyLineChart(url, holder, anonymous, drawTodayMarker) {
delete options.scales.y;
// options.scales.y.stacked = true;
// add the new axes.
- options.scales = { ...options.scales, ...axes };
+ options.scales = {...options.scales, ...axes};
// add a callback for the label.
options.plugins.tooltip.callbacks.label = function (tooltipItem) {
@@ -502,7 +620,7 @@ function drawSingleCurrencyLineChart(url, holder, anonymous) {
return label + ": " + string;
};
- let options = { ...defaultChartOptions };
+ let options = {...defaultChartOptions};
options.scales.y.ticks.callback = yAxisCallback;
options.plugins.tooltip.callbacks.label = labelCallback;
@@ -551,7 +669,7 @@ function isSameDay(d1, d2) {
);
}
-function formatLabel(str, maxwidth) {
+function formatLabel(str, maxWidth) {
let sections = [];
str = String(str);
let words = str.split(" ");
@@ -561,7 +679,7 @@ function formatLabel(str, maxwidth) {
if (temp.length > 0) {
let concat = temp + " " + item;
- if (concat.length > maxwidth) {
+ if (concat.length > maxWidth) {
sections.push(temp);
temp = "";
} else {
@@ -580,12 +698,12 @@ function formatLabel(str, maxwidth) {
return;
}
- if (item.length < maxwidth) {
+ if (item.length < maxWidth) {
temp = item;
} else {
sections.push(item);
}
});
- return sections;
+ return sections.join('X'); // temp value "X"
}
diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php
index 5c9f7e0ea9..117661b6be 100644
--- a/resources/views/index.blade.php
+++ b/resources/views/index.blade.php
@@ -32,14 +32,14 @@
</div>
</div>
<div class="card-body">
- <!--
<div>
<canvas id="budgets-chart" class="wide-chart" height="400" width="100%"></canvas>
</div>
- -->
+ <!--
<div>
<canvas id="budgets-two-chart" class="wide-chart" height="400" width="100%"></canvas>
</div>
+ -->
</div>
<div class="card-footer text-end">
<a href="{{ route('budgets.index') }}" class="btn btn-primary btn-sm">