mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 11:08:28 +00:00
Expand native amount things.
This commit is contained in:
@@ -26,6 +26,7 @@ $(function () {
|
||||
|
||||
});
|
||||
|
||||
|
||||
function drawChart() {
|
||||
"use strict";
|
||||
lineChart(accountFrontpageUrl, 'accounts-chart');
|
||||
@@ -37,13 +38,77 @@ function drawChart() {
|
||||
columnChart('chart/category/frontpage', 'categories-chart');
|
||||
columnChart(accountExpenseUrl, 'expense-accounts-chart');
|
||||
columnChart(accountRevenueUrl, 'revenue-accounts-chart');
|
||||
|
||||
// get balance box:
|
||||
getBalanceBox();
|
||||
getBillsBox();
|
||||
getAvailableBox();
|
||||
getNetWorthBox();
|
||||
getPiggyBanks();
|
||||
getAllBoxes();
|
||||
|
||||
function getAllBoxes() {
|
||||
// get summary.
|
||||
$.getJSON('api/v1/summary/basic?start=' + sessionStart + '&end=' + sessionEnd).done(function (data) {
|
||||
var key;
|
||||
|
||||
// balance.
|
||||
var balance_top = [];
|
||||
var balance_bottom = [];
|
||||
|
||||
// bills
|
||||
var unpaid = [];
|
||||
var paid = [];
|
||||
|
||||
// left to spend.
|
||||
var left_to_spend_top = [];
|
||||
var left_to_spend_bottom = [];
|
||||
|
||||
// net worth
|
||||
var net_worth = [];
|
||||
|
||||
|
||||
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-') {
|
||||
unpaid.push(data[key].value_parsed);
|
||||
}
|
||||
if (key.substring(0, 14) === 'bills-paid-in-') {
|
||||
paid.push(data[key].value_parsed);
|
||||
}
|
||||
|
||||
// left to spend
|
||||
if (key.substring(0, 17) === 'left-to-spend-in-') {
|
||||
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) {
|
||||
$('#box-left-to-spend-box').removeClass('bg-green-gradient').addClass('bg-red-gradient');
|
||||
}
|
||||
}
|
||||
|
||||
// net worth
|
||||
if (key.substring(0, 13) === 'net-worth-in-') {
|
||||
net_worth.push(data[key].value_parsed);
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
@@ -58,121 +123,3 @@ function getPiggyBanks() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getNetWorthBox() {
|
||||
// box-net-worth
|
||||
$.getJSON('json/box/net-worth').done(function (data) {
|
||||
$('#box-net-worth').html(data.net_worths.join(', '));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getAvailableBox() {
|
||||
// box-left-to-spend
|
||||
// box-left-per-day
|
||||
// * 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
|
||||
$.getJSON('json/box/available').done(function (data) {
|
||||
$('#box-left-to-spend-text').text(data.title);
|
||||
if (0 === data.display) {
|
||||
$('#box-left-to-spend-box').removeClass('bg-green-gradient').addClass('bg-red-gradient');
|
||||
$('#box-left-to-spend').html(data.left_to_spend);
|
||||
$('#box-left-per-day').html(data.left_per_day);
|
||||
}
|
||||
if (1 === data.display) {
|
||||
$('#box-left-to-spend').html(data.left_to_spend);
|
||||
$('#box-left-per-day').html(data.left_per_day);
|
||||
}
|
||||
if (2 === data.display) {
|
||||
$('#box-left-to-spend').html(data.spent_total);
|
||||
$('#box-left-per-day').html(data.spent_per_day);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getBillsBox() {
|
||||
// box-bills-unpaid
|
||||
// box-bills-paid
|
||||
|
||||
// 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(', '));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getBalanceBox() {
|
||||
// box-balance-sums
|
||||
// box-balance-list
|
||||
$.getJSON('json/box/balance').done(function (data) {
|
||||
if (data.size === 1) {
|
||||
// show balance in "sums", show single entry in list.
|
||||
for (var 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;
|
||||
|
||||
// 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];
|
||||
string = income + ' + ' + expense + ': ' + sum;
|
||||
if (data.preferred == x) {
|
||||
$('#box-balance-list').html(current + '<span title="' + string + '">' + string + '</span>' + '<br>');
|
||||
}
|
||||
}
|
||||
// then list the others (only 1 space)
|
||||
|
||||
var count = 0;
|
||||
for (x in data.sums) {
|
||||
if (count > 2) {
|
||||
return;
|
||||
}
|
||||
current = $('#box-balance-list').html();
|
||||
sum = data.sums[x];
|
||||
expense = data.expenses[x];
|
||||
income = data.incomes[x];
|
||||
string = income + ' + ' + expense + ': ' + sum;
|
||||
if (data.preferred != x) {
|
||||
$('#box-balance-list').html(current + '<span title="' + string + '">' + string + '</span>' + '<br>');
|
||||
}
|
||||
count++;
|
||||
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user