From 72906a7afd8656ca606d437f738b11a7ccf259f3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 May 2015 13:52:33 +0200 Subject: [PATCH] Experimental chart [skip ci] --- .../Controllers/GoogleChartController.php | 41 ++++++++++++------- public/js/index.js | 3 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.php index ffb8a5439e..3920745488 100644 --- a/app/Http/Controllers/GoogleChartController.php +++ b/app/Http/Controllers/GoogleChartController.php @@ -149,6 +149,7 @@ class GoogleChartController extends Controller { $chart->addColumn('Budget', 'string'); $chart->addColumn('Left', 'number'); + $chart->addColumn('Spent', 'number'); $chart->addColumn('Overspent', 'number'); $budgets = $repository->getBudgets(); @@ -160,31 +161,41 @@ class GoogleChartController extends Controller $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); if ($repetitions->count() == 0) { $expenses = $repository->sumBudgetExpensesInPeriod($budget, $start, $end); - $allEntries->push([$budget->name, 0, $expenses]); + $allEntries->push([$budget->name, 0, 0, $expenses]); continue; } /** @var LimitRepetition $repetition */ foreach ($repetitions as $repetition) { - $expenses = $repository->sumBudgetExpensesInPeriod($budget, $repetition->startdate, $repetition->enddate); - $allEntries->push([$budget->name . ' (' . $repetition->startdate->format('j M Y') . ')', floatval($repetition->amount), $expenses]); + $expenses = $repository->sumBudgetExpensesInPeriod($budget, $repetition->startdate, $repetition->enddate); + $left = $expenses > floatval($repetition->amount) ? 0 : (floatval($repetition->amount)); + $spent = $expenses > floatval($repetition->amount) ? 0 : $expenses; + $overspent = $expenses > floatval($repetition->amount) ? $expenses - floatval($repetition->amount) : 0; + $allEntries->push( + [$budget->name . ' (' . $repetition->startdate->format('j M Y') . ')', + $left, + $spent, + $overspent + ] + ); } } $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); - $allEntries->push(['(no budget)', 0, $noBudgetExpenses]); + $allEntries->push(['(no budget)', 0, 0, $noBudgetExpenses]); foreach ($allEntries as $entry) { - if ($entry[2] > 0) { - $left = $entry[1] - $entry[2]; - if ($left > 0) { - $chart->addRow($entry[0], $left, null); - } else { - if ($left < 0) { - $chart->addRow($entry[0], null, $left); - } - } - - } + $chart->addRow($entry[0], $entry[1], $entry[2], $entry[3]); +// if ($entry[2] > 0) { +// $left = $entry[1] - $entry[2]; +// if ($left > 0) { +// $chart->addRow($entry[0], $left, null); +// } else { +// if ($left < 0) { +// $chart->addRow($entry[0], null, $left); +// } +// } +// +// } } $chart->generate(); diff --git a/public/js/index.js b/public/js/index.js index 6663b8a7d3..1af5c9199e 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -3,7 +3,8 @@ google.setOnLoadCallback(drawChart); function drawChart() { googleLineChart('chart/home/account', 'accounts-chart'); - googleColumnChart('chart/home/budgets', 'budgets-chart'); + //googleColumnChart('chart/home/budgets', 'budgets-chart'); + googleStackedColumnChart('chart/home/budgets', 'budgets-chart'); googleColumnChart('chart/home/categories', 'categories-chart'); googlePieChart('chart/home/bills', 'bills-chart'); getBoxAmounts();