2016-12-23 07:02:45 +01:00
|
|
|
/*
|
|
|
|
* index.js
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
|
|
|
*/
|
2015-02-06 07:23:26 +01:00
|
|
|
|
2017-07-15 21:40:42 +02:00
|
|
|
/** global: accountFrontpageUri, token, billCount, accountExpenseUri, accountRevenueUri */
|
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";
|
2016-12-06 06:52:17 +01:00
|
|
|
lineChart(accountFrontpageUri, 'accounts-chart');
|
2016-11-22 19:10:38 +01:00
|
|
|
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();
|
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-09-27 08:45:27 +02:00
|
|
|
function getNetWorthBox() {
|
|
|
|
// box-net-worth
|
|
|
|
$.getJSON('json/box/net-worth').done(function(data) {
|
|
|
|
$('#box-net-worth').html(data.net_worth);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getAvailableBox() {
|
|
|
|
// box-left-to-spend
|
|
|
|
// box-left-per-day
|
|
|
|
$.getJSON('json/box/available').done(function(data) {
|
|
|
|
$('#box-left-to-spend').html(data.left);
|
|
|
|
$('#box-left-per-day').html(data.perDay);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getBillsBox() {
|
|
|
|
// box-bills-unpaid
|
|
|
|
// box-bills-paid
|
|
|
|
$.getJSON('json/box/bills').done(function(data) {
|
|
|
|
$('#box-bills-paid').html(data.paid);
|
|
|
|
$('#box-bills-unpaid').html(data.unpaid);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getBalanceBox() {
|
|
|
|
// box-balance-total
|
|
|
|
// box-balance-out
|
|
|
|
// box-balance-in
|
|
|
|
$.getJSON('json/box/balance').done(function(data) {
|
|
|
|
$('#box-balance-total').html(data.combined);
|
|
|
|
$('#box-balance-in').html(data.income);
|
|
|
|
$('#box-balance-out').html(data.expense);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-06 08:20:27 +01:00
|
|
|
function getBoxAmounts() {
|
2015-05-24 18:22:41 +02:00
|
|
|
"use strict";
|
2015-04-11 07:24:07 +02:00
|
|
|
var boxes = ['in', 'out', 'bills-unpaid', 'bills-paid'];
|
2015-05-24 18:22:41 +02:00
|
|
|
for (var x in boxes) {
|
2017-01-02 10:34:01 +01:00
|
|
|
if (!boxes.hasOwnProperty(x)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-06 08:20:27 +01:00
|
|
|
var box = boxes[x];
|
2016-02-04 07:30:12 +01:00
|
|
|
$.getJSON('json/box/' + box).done(putData).fail(failData);
|
2015-03-06 08:20:27 +01:00
|
|
|
}
|
2015-02-06 07:23:26 +01:00
|
|
|
}
|
2015-05-24 18:22:41 +02:00
|
|
|
|
|
|
|
function putData(data) {
|
|
|
|
"use strict";
|
|
|
|
$('#box-' + data.box).html(data.amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
function failData() {
|
|
|
|
"use strict";
|
|
|
|
}
|