Report remembers budgets and categories.

This commit is contained in:
James Cole
2015-12-16 16:19:15 +01:00
parent 32e92c2a16
commit 3fe57b7983
3 changed files with 72 additions and 8 deletions

View File

@@ -183,9 +183,13 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
$name = $entry['name']; $name = $entry['name'];
$spent = $entry['spent']; $spent = $entry['spent'];
$earned = $entry['earned']; $earned = $entry['earned'];
if (array_sum(array_values($spent)) != 0) {
$data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)]; $data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
}
if (array_sum(array_values($earned)) != 0) {
$data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)]; $data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
} }
}
$data['count'] = count($data['datasets']); $data['count'] = count($data['datasets']);
return $data; return $data;

View File

@@ -23,13 +23,39 @@ function drawChart() {
// draw budget chart based on selected budgets: // draw budget chart based on selected budgets:
$('.budget-checkbox').on('change', updateBudgetChart); $('.budget-checkbox').on('change', updateBudgetChart);
selectBudgetsByCookie();
updateBudgetChart(); updateBudgetChart();
// draw category chart based on selected budgets: // draw category chart based on selected budgets:
$('.category-checkbox').on('change', updateCategoryChart); $('.category-checkbox').on('change', updateCategoryChart);
selectCategoriesByCookie();
updateCategoryChart(); updateCategoryChart();
} }
function selectBudgetsByCookie() {
"use strict";
var cookie = readCookie('multi-year-budgets');
if (cookie !== null) {
var cookieArray = cookie.split(',');
for (var x in cookieArray) {
var budgetId = cookieArray[x];
$('.budget-checkbox[value="' + budgetId + '"').prop('checked', true);
}
}
}
function selectCategoriesByCookie() {
"use strict";
var cookie = readCookie('multi-year-categories');
if (cookie !== null) {
var cookieArray = cookie.split(',');
for (var x in cookieArray) {
var categoryId = cookieArray[x];
$('.category-checkbox[value="' + categoryId + '"').prop('checked', true);
}
}
}
function updateBudgetChart() { function updateBudgetChart() {
"use strict"; "use strict";
console.log('will update budget chart.'); console.log('will update budget chart.');
@@ -54,6 +80,7 @@ function updateBudgetChart() {
// draw chart. Redraw when exists? Not sure if we support that. // draw chart. Redraw when exists? Not sure if we support that.
columnChart('chart/budget/multi-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds + '/' + budgetIds, 'budgets-chart'); columnChart('chart/budget/multi-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds + '/' + budgetIds, 'budgets-chart');
createCookie('multi-year-budgets', budgets, 365);
} else { } else {
// hide canvas, show message: // hide canvas, show message:
$('#budgets-chart-message').show(); $('#budgets-chart-message').show();
@@ -87,6 +114,7 @@ function updateCategoryChart() {
// draw chart. Redraw when exists? Not sure if we support that. // draw chart. Redraw when exists? Not sure if we support that.
columnChart('chart/category/multi-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds + '/' + categoryIds, 'categories-chart'); columnChart('chart/category/multi-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds + '/' + categoryIds, 'categories-chart');
createCookie('multi-year-categories', categories, 365);
} else { } else {
// hide canvas, show message: // hide canvas, show message:
$('#categories-chart-message').show(); $('#categories-chart-message').show();
@@ -94,3 +122,34 @@ function updateCategoryChart() {
} }
} }
function createCookie(name, value, days) {
"use strict";
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
}
function readCookie(name) {
"use strict";
var nameEQ = encodeURIComponent(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}

View File

@@ -119,3 +119,4 @@ function readCookie(name) {
} }
return null; return null;
} }