Files
firefly-iii/public/js/ff/index.js

132 lines
3.6 KiB
JavaScript
Raw Normal View History

/*
* index.js
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:43:13 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2015-02-06 07:23:26 +01:00
2017-11-25 08:54:52 +01:00
/** global: accountFrontpageUri, today, piggyInfoUri, token, billCount, accountExpenseUri, accountRevenueUri */
$(function () {
"use strict";
// do chart JS stuff.
drawChart();
2015-07-11 10:01:13 +02:00
});
2015-02-06 07:23:26 +01:00
function drawChart() {
2015-05-24 20:48:31 +02:00
"use strict";
2017-11-22 21:12:27 +01:00
if (today >= 0) {
2017-11-17 19:31:48 +01:00
lineChartWithDay(accountFrontpageUri, 'accounts-chart', today);
} else {
lineChart(accountFrontpageUri, 'accounts-chart');
}
if (billCount > 0) {
pieChart('chart/bill/frontpage', 'bills-chart');
}
2016-11-16 20:35:25 +01:00
stackedColumnChart('chart/budget/frontpage', 'budgets-chart');
columnChart('chart/category/frontpage', 'categories-chart');
2016-12-06 06:52:17 +01:00
columnChart(accountExpenseUri, 'expense-accounts-chart');
columnChart(accountRevenueUri, '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() {
$.getJSON(piggyInfoUri).done(function (data) {
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
2017-10-22 18:15:12 +02:00
$.getJSON('json/box/available').done(function (data) {
2017-09-27 08:45:27 +02:00
$('#box-left-to-spend').html(data.left);
$('#box-left-per-day').html(data.perDay);
});
}
/**
*
*/
function getBillsBox() {
// box-bills-unpaid
// box-bills-paid
2017-10-22 18:15:12 +02:00
$.getJSON('json/box/bills').done(function (data) {
2017-09-27 08:45:27 +02:00
$('#box-bills-paid').html(data.paid);
$('#box-bills-unpaid').html(data.unpaid);
});
}
/**
*
*/
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.
for (x in data.sums) {
$('#box-balance-sums').html(data.sums[x]);
$('#box-balance-list').html(data.incomes[x] + ' / ' + data.expenses[x]);
}
return;
}
// do not use "sums", only use list.
$('#box-balance-progress').remove();
var expense, string, sum, income, current;
var count = 0;
for (x in data.sums) {
if (count > 1) {
return;
}
current = $('#box-balance-list').html();
sum = data.sums[x];
expense = data.expenses[x];
income = data.incomes[x];
string = income + ' / ' + expense + ': ' + sum;
$('#box-balance-list').html(current + '<span title="' + string + '">' + string + '</span>' + '<br>');
count++;
}
return;
2017-09-27 08:45:27 +02:00
});
2015-05-24 18:22:41 +02:00
}