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
|
|
|
|
|
|
|
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');
|
2015-05-16 09:57:31 +02:00
|
|
|
|
2017-09-27 08:45:27 +02:00
|
|
|
// get balance box:
|
|
|
|
getBalanceBox();
|
|
|
|
getBillsBox();
|
|
|
|
getAvailableBox();
|
|
|
|
getNetWorthBox();
|
2017-10-22 18:15:12 +02:00
|
|
|
getPiggyBanks();
|
2015-05-16 09:57:31 +02:00
|
|
|
|
2017-09-27 08:45:27 +02:00
|
|
|
//getBoxAmounts();
|
2015-03-06 08:20:27 +01:00
|
|
|
}
|
|
|
|
|
2017-10-22 18:15:12 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getPiggyBanks() {
|
2022-04-12 18:19:30 +02:00
|
|
|
$.getJSON(piggyInfoUrl).done(function (data) {
|
2017-10-22 18:15:12 +02:00
|
|
|
if (data.html.length > 0) {
|
|
|
|
$('#piggy_bank_overview').html(data.html);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-27 08:45:27 +02:00
|
|
|
function getNetWorthBox() {
|
|
|
|
// box-net-worth
|
2017-10-22 18:15:12 +02:00
|
|
|
$.getJSON('json/box/net-worth').done(function (data) {
|
2018-01-13 18:40:28 +01:00
|
|
|
$('#box-net-worth').html(data.net_worths.join(', '));
|
2017-09-27 08:45:27 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getAvailableBox() {
|
|
|
|
// box-left-to-spend
|
|
|
|
// box-left-per-day
|
2020-02-01 06:19:12 +01:00
|
|
|
// * 0) If the user has available amount this period and has overspent: overspent box.
|
|
|
|
// * 1) If the user has available amount this period and has NOT overspent: left to spend box.
|
|
|
|
// * 2) if the user has no available amount set this period: spent per day
|
2017-10-22 18:15:12 +02:00
|
|
|
$.getJSON('json/box/available').done(function (data) {
|
2020-02-01 06:19:12 +01:00
|
|
|
$('#box-left-to-spend-text').text(data.title);
|
|
|
|
if (0 === data.display) {
|
2018-03-25 10:17:07 +02:00
|
|
|
$('#box-left-to-spend-box').removeClass('bg-green-gradient').addClass('bg-red-gradient');
|
2020-02-01 06:19:12 +01:00
|
|
|
$('#box-left-to-spend').html(data.left_to_spend);
|
|
|
|
$('#box-left-per-day').html(data.left_per_day);
|
|
|
|
}
|
2020-08-06 18:34:10 +02:00
|
|
|
if (1 === data.display) {
|
2020-02-01 06:19:12 +01:00
|
|
|
$('#box-left-to-spend').html(data.left_to_spend);
|
|
|
|
$('#box-left-per-day').html(data.left_per_day);
|
|
|
|
}
|
2020-08-06 18:34:10 +02:00
|
|
|
if (2 === data.display) {
|
2020-02-01 06:19:12 +01:00
|
|
|
$('#box-left-to-spend').html(data.spent_total);
|
|
|
|
$('#box-left-per-day').html(data.spent_per_day);
|
2018-03-25 10:17:07 +02:00
|
|
|
}
|
2017-09-27 08:45:27 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getBillsBox() {
|
|
|
|
// box-bills-unpaid
|
|
|
|
// box-bills-paid
|
2020-08-06 18:34:10 +02:00
|
|
|
|
|
|
|
// get summary.
|
|
|
|
|
|
|
|
$.getJSON('api/v1/summary/basic?start=' + sessionStart + '&end=' + sessionEnd).done(function (data) {
|
|
|
|
var key;
|
|
|
|
var unpaid = [];
|
|
|
|
var paid = [];
|
|
|
|
for (key in data) {
|
|
|
|
//console.log(key);
|
|
|
|
if (key.substr(0, 16) === 'bills-unpaid-in-') {
|
|
|
|
// only when less than 3.
|
|
|
|
if (unpaid.length < 3) {
|
|
|
|
unpaid.push(data[key].value_parsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (key.substr(0, 14) === 'bills-paid-in-') {
|
|
|
|
// only when less than 5.
|
|
|
|
if (paid.length < 3) {
|
|
|
|
paid.push(data[key].value_parsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#box-bills-unpaid').html(unpaid.join(', '));
|
|
|
|
$('#box-bills-paid').html(paid.join(', '));
|
2017-09-27 08:45:27 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getBalanceBox() {
|
2018-03-10 06:49:03 +01:00
|
|
|
// box-balance-sums
|
|
|
|
// box-balance-list
|
2017-10-22 18:15:12 +02:00
|
|
|
$.getJSON('json/box/balance').done(function (data) {
|
2018-03-10 06:49:03 +01:00
|
|
|
if (data.size === 1) {
|
|
|
|
// show balance in "sums", show single entry in list.
|
2020-10-04 07:25:30 +02:00
|
|
|
for (var x in data.sums) {
|
2018-03-10 06:49:03 +01:00
|
|
|
$('#box-balance-sums').html(data.sums[x]);
|
2019-08-11 07:29:05 +02:00
|
|
|
$('#box-balance-list').html(data.incomes[x] + ' + ' + data.expenses[x]);
|
2018-03-10 06:49:03 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// do not use "sums", only use list.
|
|
|
|
$('#box-balance-progress').remove();
|
|
|
|
var expense, string, sum, income, current;
|
2019-07-20 22:32:32 +02:00
|
|
|
|
|
|
|
// first loop, echo only "preferred".
|
|
|
|
for (x in data.sums) {
|
|
|
|
current = $('#box-balance-list').html();
|
|
|
|
sum = data.sums[x];
|
|
|
|
expense = data.expenses[x];
|
|
|
|
income = data.incomes[x];
|
2019-08-11 07:29:05 +02:00
|
|
|
string = income + ' + ' + expense + ': ' + sum;
|
2019-07-20 22:32:32 +02:00
|
|
|
if (data.preferred == x) {
|
|
|
|
$('#box-balance-list').html(current + '<span title="' + string + '">' + string + '</span>' + '<br>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// then list the others (only 1 space)
|
|
|
|
|
2018-03-10 06:49:03 +01:00
|
|
|
var count = 0;
|
|
|
|
for (x in data.sums) {
|
2019-07-20 22:32:32 +02:00
|
|
|
if (count > 2) {
|
2018-03-10 06:49:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
current = $('#box-balance-list').html();
|
|
|
|
sum = data.sums[x];
|
|
|
|
expense = data.expenses[x];
|
|
|
|
income = data.incomes[x];
|
2019-08-11 07:29:05 +02:00
|
|
|
string = income + ' + ' + expense + ': ' + sum;
|
2019-07-20 22:32:32 +02:00
|
|
|
if (data.preferred != x) {
|
|
|
|
$('#box-balance-list').html(current + '<span title="' + string + '">' + string + '</span>' + '<br>');
|
|
|
|
}
|
2018-03-10 06:49:03 +01:00
|
|
|
count++;
|
2019-07-20 22:32:32 +02:00
|
|
|
|
2018-03-10 06:49:03 +01:00
|
|
|
}
|
2017-09-27 08:45:27 +02:00
|
|
|
});
|
2015-05-24 18:22:41 +02:00
|
|
|
}
|