2016-12-23 07:02:45 +01:00
|
|
|
/*
|
|
|
|
* index.js
|
2020-02-16 13:59:41 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* 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.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:43:38 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* 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/>.
|
2016-12-23 07:02:45 +01:00
|
|
|
*/
|
2015-02-06 07:23:26 +01:00
|
|
|
|
2017-01-02 10:34:01 +01:00
|
|
|
|
2015-06-27 12:21:04 +02:00
|
|
|
$(function () {
|
|
|
|
"use strict";
|
2015-08-01 07:22:48 +02:00
|
|
|
// do chart JS stuff.
|
|
|
|
drawChart();
|
2015-07-11 10:01:13 +02:00
|
|
|
|
2015-06-27 12:21:04 +02:00
|
|
|
});
|
2015-02-06 07:23:26 +01:00
|
|
|
|
2024-12-24 06:34:12 +01:00
|
|
|
|
2015-02-06 07:23:26 +01:00
|
|
|
function drawChart() {
|
2015-05-24 20:48:31 +02:00
|
|
|
"use strict";
|
2022-04-12 18:19:30 +02:00
|
|
|
lineChart(accountFrontpageUrl, 'accounts-chart');
|
2017-11-17 19:31:48 +01:00
|
|
|
|
2016-11-22 19:10:38 +01:00
|
|
|
if (billCount > 0) {
|
2018-08-28 05:21:23 +02:00
|
|
|
multiCurrencyPieChart('chart/bill/frontpage', 'bills-chart');
|
2016-11-22 19:10:38 +01:00
|
|
|
}
|
2016-11-16 20:35:25 +01:00
|
|
|
stackedColumnChart('chart/budget/frontpage', 'budgets-chart');
|
|
|
|
columnChart('chart/category/frontpage', 'categories-chart');
|
2022-04-12 18:19:30 +02:00
|
|
|
columnChart(accountExpenseUrl, 'expense-accounts-chart');
|
|
|
|
columnChart(accountRevenueUrl, 'revenue-accounts-chart');
|
2017-10-22 18:15:12 +02:00
|
|
|
getPiggyBanks();
|
2025-02-15 19:19:23 +01:00
|
|
|
console.log('Get all boxes');
|
2024-12-24 06:34:12 +01:00
|
|
|
getAllBoxes();
|
2015-05-16 09:57:31 +02:00
|
|
|
|
2024-12-24 06:34:12 +01:00
|
|
|
function getAllBoxes() {
|
|
|
|
// get summary.
|
|
|
|
$.getJSON('api/v1/summary/basic?start=' + sessionStart + '&end=' + sessionEnd).done(function (data) {
|
|
|
|
var key;
|
2015-03-06 08:20:27 +01:00
|
|
|
|
2024-12-24 06:34:12 +01:00
|
|
|
// balance.
|
|
|
|
var balance_top = [];
|
|
|
|
var balance_bottom = [];
|
2017-10-22 18:15:12 +02:00
|
|
|
|
2024-12-24 06:34:12 +01:00
|
|
|
// bills
|
|
|
|
var unpaid = [];
|
|
|
|
var paid = [];
|
2017-09-27 08:45:27 +02:00
|
|
|
|
2024-12-24 06:34:12 +01:00
|
|
|
// left to spend.
|
|
|
|
var left_to_spend_top = [];
|
|
|
|
var left_to_spend_bottom = [];
|
2017-09-27 08:45:27 +02:00
|
|
|
|
2024-12-24 06:34:12 +01:00
|
|
|
// net worth
|
|
|
|
var net_worth = [];
|
2025-02-15 19:19:23 +01:00
|
|
|
var keepGreen = false;
|
2024-12-24 06:34:12 +01:00
|
|
|
|
|
|
|
for (key in data) {
|
|
|
|
// balance
|
|
|
|
if (key.substring(0, 11) === 'balance-in-') {
|
|
|
|
balance_top.push(data[key].value_parsed);
|
|
|
|
balance_bottom.push(data[key].sub_title);
|
|
|
|
}
|
|
|
|
|
|
|
|
// bills
|
|
|
|
if (key.substring(0, 16) === 'bills-unpaid-in-') {
|
2020-08-06 18:34:10 +02:00
|
|
|
unpaid.push(data[key].value_parsed);
|
|
|
|
}
|
2024-12-24 06:34:12 +01:00
|
|
|
if (key.substring(0, 14) === 'bills-paid-in-') {
|
2020-08-06 18:34:10 +02:00
|
|
|
paid.push(data[key].value_parsed);
|
|
|
|
}
|
2024-12-24 06:34:12 +01:00
|
|
|
|
|
|
|
// left to spend
|
|
|
|
if (key.substring(0, 17) === 'left-to-spend-in-') {
|
2025-04-07 19:44:22 +02:00
|
|
|
if(true === data[key].no_available_budgets) {
|
|
|
|
left_to_spend_top.push('---');
|
|
|
|
left_to_spend_bottom.push('---');
|
2025-02-15 19:19:23 +01:00
|
|
|
keepGreen = true;
|
2024-12-24 06:34:12 +01:00
|
|
|
}
|
2025-04-07 19:44:22 +02:00
|
|
|
if(false === data[key].no_available_budgets) {
|
|
|
|
left_to_spend_top.push(data[key].value_parsed);
|
|
|
|
left_to_spend_bottom.push(data[key].sub_title);
|
|
|
|
if (parseFloat(data[key].monetary_value) > 0) {
|
|
|
|
keepGreen = true;
|
|
|
|
}
|
|
|
|
}
|
2024-12-24 06:34:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// net worth
|
|
|
|
if (key.substring(0, 13) === 'net-worth-in-') {
|
|
|
|
net_worth.push(data[key].value_parsed);
|
|
|
|
}
|
2020-08-06 18:34:10 +02:00
|
|
|
}
|
2025-02-15 19:19:23 +01:00
|
|
|
if(!keepGreen) {
|
|
|
|
$('#box-left-to-spend-box').removeClass('bg-green-gradient').addClass('bg-red-gradient')
|
|
|
|
}
|
2024-12-24 06:34:12 +01:00
|
|
|
|
|
|
|
// balance
|
|
|
|
$('#box-balance-sums').html(balance_top.join(', '));
|
|
|
|
$('#box-balance-list').html(balance_bottom.join(', '));
|
|
|
|
|
|
|
|
// bills
|
|
|
|
$('#box-bills-unpaid').html(unpaid.join(', '));
|
|
|
|
$('#box-bills-paid').html(paid.join(', '));
|
|
|
|
|
|
|
|
// left to spend
|
|
|
|
$('#box-left-to-spend').html(left_to_spend_top.join(', '));
|
|
|
|
$('#box-left-per-day').html(left_to_spend_bottom.join(', '));
|
|
|
|
|
|
|
|
// net worth
|
|
|
|
$('#box-net-worth').html(net_worth.join(', '));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//getBoxAmounts();
|
2017-09-27 08:45:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2024-12-24 06:34:12 +01:00
|
|
|
function getPiggyBanks() {
|
|
|
|
$.getJSON(piggyInfoUrl).done(function (data) {
|
|
|
|
if (data.html.length > 0) {
|
|
|
|
$('#piggy_bank_overview').html(data.html);
|
2018-03-10 06:49:03 +01:00
|
|
|
}
|
2017-09-27 08:45:27 +02:00
|
|
|
});
|
2024-12-24 06:34:12 +01:00
|
|
|
}
|