diff --git a/app/assets/javascripts/budgets-default.js b/app/assets/javascripts/budgets-default.js new file mode 100644 index 0000000000..84ef7a1402 --- /dev/null +++ b/app/assets/javascripts/budgets-default.js @@ -0,0 +1,14 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it +// gets included (e.g. say you have require_tree . then the code will appear after all the directories +// but before any files alphabetically greater than 'application.js' +// +// The available directives right now are require, require_directory, and require_tree +// +//= require_tree highcharts +//= require firefly/budgets/default diff --git a/app/assets/javascripts/budgets-limit.js b/app/assets/javascripts/budgets-limit.js new file mode 100644 index 0000000000..03b84cc11f --- /dev/null +++ b/app/assets/javascripts/budgets-limit.js @@ -0,0 +1,14 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it +// gets included (e.g. say you have require_tree . then the code will appear after all the directories +// but before any files alphabetically greater than 'application.js' +// +// The available directives right now are require, require_directory, and require_tree +// +//= require_tree highcharts +//= require firefly/budgets/limit diff --git a/app/assets/javascripts/budgets-nolimit.js b/app/assets/javascripts/budgets-nolimit.js new file mode 100644 index 0000000000..54f42944fe --- /dev/null +++ b/app/assets/javascripts/budgets-nolimit.js @@ -0,0 +1,14 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it +// gets included (e.g. say you have require_tree . then the code will appear after all the directories +// but before any files alphabetically greater than 'application.js' +// +// The available directives right now are require, require_directory, and require_tree +// +//= require_tree highcharts +//= require firefly/budgets/nolimit diff --git a/app/assets/javascripts/budgets-session.js b/app/assets/javascripts/budgets-session.js new file mode 100644 index 0000000000..c8798ad459 --- /dev/null +++ b/app/assets/javascripts/budgets-session.js @@ -0,0 +1,14 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it +// gets included (e.g. say you have require_tree . then the code will appear after all the directories +// but before any files alphabetically greater than 'application.js' +// +// The available directives right now are require, require_directory, and require_tree +// +//= require_tree highcharts +//= require firefly/budgets/session diff --git a/app/assets/javascripts/firefly/budgets/default.js b/app/assets/javascripts/firefly/budgets/default.js new file mode 100644 index 0000000000..88b7b82e44 --- /dev/null +++ b/app/assets/javascripts/firefly/budgets/default.js @@ -0,0 +1,109 @@ +$(function () { + if ($('#chart').length == 1) { + var budgetId = $('#instr').data('budget'); + var URL = 'chart/budget/' + budgetId + '/default'; + + // go do something with this URL. + $.getJSON(URL).success(function (data) { + var options = { + chart: { + renderTo: 'chart', + }, + + series: data.series, + title: { + text: data.chart_title + }, + tooltip: { + shared: true, + crosshairs: false, + formatter: function () { + var str = '' + this.points[0].key + '
'; + for (x in this.points) { + var point = this.points[x]; + var colour = point.point.pointAttr[''].fill; + if (x == 0) { + str += '' + point.series.name + ': € ' + Highcharts.numberFormat(point.y, 2) + '
'; + } + if (x == 1) { + str += '' + point.series.name + ': ' + Highcharts.numberFormat(point.y, 1) + '%
'; + } + } + return str; + } + }, + + + yAxis: [ + { // Primary yAxis + title: { + 'text': 'Amount (EUR)', + style: { + color: Highcharts.getOptions().colors[0] + } + }, + labels: { + format: '€ {value}', + style: { + color: Highcharts.getOptions().colors[0] + } + } + }, + { // Secondary yAxis + title: { + 'text': 'Percentage', + style: { + color: Highcharts.getOptions().colors[1] + } + }, + labels: { + format: '{value}%', + style: { + color: Highcharts.getOptions().colors[1] + } + }, + opposite: true + } + ], + subtitle: { + text: data.subtitle, + useHTML: true + }, + + xAxis: { + type: 'category', + labels: { + rotation: -45, + style: { + fontSize: '12px', + fontFamily: 'Verdana, sans-serif' + } + } + }, + plotOptions: { + line: { + shadow: true + }, + series: { + cursor: 'pointer', + negativeColor: '#FF0000', + threshold: 0, + lineWidth: 1, + marker: { + radius: 2 + }, + } + }, + credits: { + enabled: false + } + }; + $('#chart').highcharts(options); + + + }); + + } + + +}); \ No newline at end of file diff --git a/app/assets/javascripts/firefly/budgets/limit.js b/app/assets/javascripts/firefly/budgets/limit.js new file mode 100644 index 0000000000..be1876ba01 --- /dev/null +++ b/app/assets/javascripts/firefly/budgets/limit.js @@ -0,0 +1,103 @@ +$(function () { + if ($('#chart').length == 1) { + var envelopeId = $('#instr').data('envelope'); + var URL = 'chart/budget/envelope/' + envelopeId; + // go do something with this URL. + $.getJSON(URL).success(function (data) { + var options = { + chart: { + renderTo: 'chart', + }, + + series: data.series, + title: { + text: data.chart_title + }, + yAxis: [ + { // Primary yAxis + title: { + text: 'Expense (€)', + style: { + color: Highcharts.getOptions().colors[0] + } + }, + labels: { + format: '€ {value}', + style: { + color: Highcharts.getOptions().colors[0] + } + } + }, + { // Secondary yAxis + title: { + text: 'Left (€)', + style: { + color: Highcharts.getOptions().colors[1] + } + }, + labels: { + format: '€ {value}', + style: { + color: Highcharts.getOptions().colors[1] + } + }, + opposite: true + } + ], + subtitle: { + text: data.subtitle, + useHTML: true + }, + + tooltip: { + shared: true, + crosshairs: false, + formatter: function () { + var str = '' + Highcharts.dateFormat("%A, %e %B", this.x) + '
'; + for (x in this.points) { + var point = this.points[x]; + var colour = point.point.pointAttr[''].fill; + str += '' + point.series.name + ': € ' + Highcharts.numberFormat(point.y, 2) + '
'; + } + return str; + } + }, + + xAxis: { + floor: 0, + type: 'datetime', + dateTimeLabelFormats: { + day: '%e %b', + year: '%b' + }, + title: { + text: 'Date' + } + }, + plotOptions: { + line: { + shadow: true + }, + series: { + cursor: 'pointer', + negativeColor: '#FF0000', + threshold: 0, + lineWidth: 1, + marker: { + radius: 2 + }, + } + }, + credits: { + enabled: false + } + }; + $('#chart').highcharts(options); + + + }); + + } + + +}); \ No newline at end of file diff --git a/app/assets/javascripts/firefly/budgets.js b/app/assets/javascripts/firefly/budgets/nolimit.js similarity index 73% rename from app/assets/javascripts/firefly/budgets.js rename to app/assets/javascripts/firefly/budgets/nolimit.js index 26bac723e7..77aa8dde33 100644 --- a/app/assets/javascripts/firefly/budgets.js +++ b/app/assets/javascripts/firefly/budgets/nolimit.js @@ -3,22 +3,21 @@ $(function () { chartType = $('#instr').data('type'); - - if(chartType == 'envelope') { + if (chartType == 'envelope') { var envelopeId = $('#instr').data('envelope'); var URL = 'chart/budget/envelope/' + envelopeId; } - if(chartType == 'no_envelope') { + if (chartType == 'no_envelope') { var budgetId = $('#instr').data('budget'); - var URL = 'chart/budget/'+budgetId+'/no_envelope'; - } - if(chartType == 'session') { - var budgetId = $('#instr').data('budget'); - var URL = 'chart/budget/'+budgetId+'/session'; + var URL = 'chart/budget/' + budgetId + '/no_envelope'; } - if(chartType == 'default') { + if (chartType == 'session') { var budgetId = $('#instr').data('budget'); - var URL = 'chart/budget/'+budgetId+'/default'; + var URL = 'chart/budget/' + budgetId + '/session'; + } + if (chartType == 'default') { + var budgetId = $('#instr').data('budget'); + var URL = 'chart/budget/' + budgetId + '/default'; } // go do something with this URL. @@ -32,25 +31,31 @@ $(function () { title: { text: data.chart_title }, - yAxis: [{ // Primary yAxis + yAxis: { // Primary yAxis + title: { + text: 'Amount (€)', + style: { + color: Highcharts.getOptions().colors[1] + } + }, labels: { format: '€ {value}', style: { color: Highcharts.getOptions().colors[1] } } - }, { // Secondary yAxis - title: { - style: { - color: Highcharts.getOptions().colors[0] - } - }, - opposite: true - }], + }, subtitle: { text: data.subtitle, useHTML: true }, + tooltip: { + crosshairs: false, + formatter: function () { + var str = Highcharts.dateFormat("%A, %e %B", this.x) + ': € ' + Highcharts.numberFormat(this.y, 2); + return str; + } + }, xAxis: { floor: 0, @@ -84,7 +89,6 @@ $(function () { $('#chart').highcharts(options); - }); } diff --git a/app/assets/javascripts/firefly/budgets/session.js b/app/assets/javascripts/firefly/budgets/session.js new file mode 100644 index 0000000000..a4dd8aeec1 --- /dev/null +++ b/app/assets/javascripts/firefly/budgets/session.js @@ -0,0 +1,93 @@ +$(function () { + if ($('#chart').length == 1) { + var budgetId = $('#instr').data('budget'); + var URL = 'chart/budget/' + budgetId + '/session'; + + // go do something with this URL. + $.getJSON(URL).success(function (data) { + var options = { + chart: { + renderTo: 'chart', + }, + + series: data.series, + title: { + text: data.chart_title + }, + yAxis: [ + { // Primary yAxis + title: { + text: 'Spent (€)', + style: { + color: Highcharts.getOptions().colors[0] + } + }, + labels: { + format: '€ {value}', + style: { + color: Highcharts.getOptions().colors[0] + } + } + }, + { // Secondary yAxis + title: { + text: 'Left in envelope (€)', + style: { + color: Highcharts.getOptions().colors[1] + } + }, + labels: { + format: '€ {value}', + style: { + color: Highcharts.getOptions().colors[1] + } + }, + opposite: true + } + ], + tooltip: { + valuePrefix: '€ ' + }, + subtitle: { + text: data.subtitle, + useHTML: true + }, + + xAxis: { + floor: 0, + type: 'datetime', + dateTimeLabelFormats: { + day: '%e %b', + year: '%b' + }, + title: { + text: 'Date' + } + }, + plotOptions: { + line: { + shadow: true + }, + series: { + cursor: 'pointer', + negativeColor: '#FF0000', + threshold: 0, + lineWidth: 1, + marker: { + radius: 2 + }, + } + }, + credits: { + enabled: false + } + }; + $('#chart').highcharts(options); + + + }); + + } + + +}); \ No newline at end of file diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php index e93f9ef288..32f2d9494d 100644 --- a/app/controllers/ChartController.php +++ b/app/controllers/ChartController.php @@ -52,15 +52,16 @@ class ChartController extends BaseController )->sum('amount'); - $pct = round(($spentInRep / $limit->amount) * 100,2); - $expense[] = [$rep->startdate->timestamp * 1000, floatval($spentInRep)]; - $left[] = [$rep->startdate->timestamp * 1000, $pct]; + $pct = round(($spentInRep / $limit->amount) * 100, 2); + $name = $rep->periodShow(); + $expense[] = [$name, floatval($spentInRep)]; + $left[] = [$name, $pct]; } } $return = [ 'chart_title' => 'Overview for budget ' . $budget->name, - 'subtitle' => 'Between something something', + 'subtitle' => 'All envelopes', 'series' => [ [ 'type' => 'column', @@ -70,12 +71,13 @@ class ChartController extends BaseController [ 'type' => 'line', 'yAxis' => 1, - 'name' => 'Spent pct for envelope', + 'name' => 'Spent percentage for envelope', 'data' => $left ] ] ]; + return Response::json($return); } @@ -108,7 +110,8 @@ class ChartController extends BaseController $return = [ 'chart_title' => 'Overview for budget ' . $budget->name, - 'subtitle' => 'Between ' . $rep->startdate->format('d M Y') . ' and ' . $rep->startdate->format('d M Y'), + 'subtitle' => + 'Between ' . $rep->startdate->format('M jS, Y') . ' and ' . $rep->enddate->format('M jS, Y'), 'series' => [ [ 'type' => 'column', @@ -224,7 +227,7 @@ class ChartController extends BaseController $start = clone Session::get('start'); $repetitionSeries[] = [ 'type' => 'column', - 'name' => 'Something something expenses', + 'name' => 'Expenses per day', 'data' => $expense ]; @@ -259,8 +262,7 @@ class ChartController extends BaseController 'type' => 'spline', 'id' => 'rep-' . $repetition->id, 'yAxis' => 1, - 'name' => 'Serie ' . $repetition->startdate->format('Y-m-d') . ' to ' . - $repetition->enddate->format('Y-m-d') . '.', + 'name' => 'Envelope in ' . $repetition->periodShow(), 'data' => [] ]; $current = clone $repetition->startdate; @@ -299,7 +301,10 @@ class ChartController extends BaseController $return = [ 'chart_title' => 'Overview for budget ' . $budget->name, - 'subtitle' => 'Between Bla bla bla', + 'subtitle' => + 'Between ' . Session::get('start')->format('M jS, Y') . ' and ' . Session::get('end')->format( + 'M jS, Y' + ), 'series' => $repetitionSeries ]; diff --git a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php index e7f4c29242..ec211dcffc 100644 --- a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php +++ b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php @@ -42,7 +42,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface { $set = \Auth::user()->budgets()->with( ['limits' => function ($q) { - $q->orderBy('limits.startdate', 'ASC'); + $q->orderBy('limits.startdate', 'DESC'); }, 'limits.limitrepetitions' => function ($q) { $q->orderBy('limit_repetitions.startdate', 'ASC'); }] diff --git a/app/views/budgets/show.blade.php b/app/views/budgets/show.blade.php index 52f14a4d26..d9a6f05661 100644 --- a/app/views/budgets/show.blade.php +++ b/app/views/budgets/show.blade.php @@ -45,25 +45,15 @@
-
+
@if(isset($filters[0]) && is_object($filters[0]) && get_class($filters[0]) == 'Limit')
@elseif(isset($filters[0]) && $filters[0] == 'no_envelope')
-

- A chart showing the date-range of all the not-enveloped stuff, and their amount. -

@elseif($useSessionDates == true)
-

- Date range of session, show chart with all expenses in bars - find all limit repetitions, add them as individual lines and make them go down. - same as the first but bigger range (potentially). -

@else
-

(For each visible repetition, a sum of the expense as a bar. A line shows - the percentage spent for each rep.)

@endif @@ -110,5 +100,14 @@ @stop @section('scripts') - +@if(isset($filters[0]) && is_object($filters[0]) && get_class($filters[0]) == 'Limit') + +@elseif(isset($filters[0]) && $filters[0] == 'no_envelope') + +@elseif($useSessionDates == true) + +@else + +@endif + @stop \ No newline at end of file