close #265 Fixed: Dashboard 'Last 12 months' does not work, 'Custom Range' partially broken

This commit is contained in:
cuneytsenturk 2018-11-05 13:29:55 +03:00
parent 2da5ad838c
commit 9988d49f46
2 changed files with 33 additions and 3 deletions

View File

@ -126,6 +126,7 @@ class Dashboard extends Controller
$start = Date::parse(request('start', $this->today->startOfYear()->format('Y-m-d'))); $start = Date::parse(request('start', $this->today->startOfYear()->format('Y-m-d')));
$end = Date::parse(request('end', $this->today->endOfYear()->format('Y-m-d'))); $end = Date::parse(request('end', $this->today->endOfYear()->format('Y-m-d')));
$period = request('period', 'month'); $period = request('period', 'month');
$range = request('range', 'custom');
$start_month = $start->month; $start_month = $start->month;
$end_month = $end->month; $end_month = $end->month;
@ -135,6 +136,11 @@ class Dashboard extends Controller
$s = clone $start; $s = clone $start;
if ($range == 'last_12_months') {
$end_month = 12;
$start_month = 1;
}
for ($j = $end_month; $j >= $start_month; $j--) { for ($j = $end_month; $j >= $start_month; $j--) {
$labels[$end_month - $j] = $s->format('M Y'); $labels[$end_month - $j] = $s->format('M Y');

View File

@ -266,11 +266,13 @@
$('#cashflow-range').on('apply.daterangepicker', function(ev, picker) { $('#cashflow-range').on('apply.daterangepicker', function(ev, picker) {
var period = $('#period').val(); var period = $('#period').val();
range = getRange(picker);
$.ajax({ $.ajax({
url: '{{ url("common/dashboard/cashflow") }}', url: '{{ url("common/dashboard/cashflow") }}',
type: 'get', type: 'get',
dataType: 'html', dataType: 'html',
data: 'period=' + period + '&start=' + picker.startDate.format('YYYY-MM-DD') + '&end=' + picker.endDate.format('YYYY-MM-DD'), data: 'period=' + period + '&start=' + picker.startDate.format('YYYY-MM-DD') + '&end=' + picker.endDate.format('YYYY-MM-DD') + '&range=' + range,
success: function(data) { success: function(data) {
$('#cashflow').html(data); $('#cashflow').html(data);
} }
@ -282,11 +284,13 @@
$('#period').val('month'); $('#period').val('month');
range = getRange(picker);
$.ajax({ $.ajax({
url: '{{ url("common/dashboard/cashflow") }}', url: '{{ url("common/dashboard/cashflow") }}',
type: 'get', type: 'get',
dataType: 'html', dataType: 'html',
data: 'period=month&start=' + picker.startDate.format('YYYY-MM-DD') + '&end=' + picker.endDate.format('YYYY-MM-DD'), data: 'period=month&start=' + picker.startDate.format('YYYY-MM-DD') + '&end=' + picker.endDate.format('YYYY-MM-DD') + '&range=' + range,
success: function(data) { success: function(data) {
$('#cashflow').html(data); $('#cashflow').html(data);
} }
@ -298,16 +302,36 @@
$('#period').val('quarter'); $('#period').val('quarter');
range = getRange(picker);
$.ajax({ $.ajax({
url: '{{ url("common/dashboard/cashflow") }}', url: '{{ url("common/dashboard/cashflow") }}',
type: 'get', type: 'get',
dataType: 'html', dataType: 'html',
data: 'period=quarter&start=' + picker.startDate.format('YYYY-MM-DD') + '&end=' + picker.endDate.format('YYYY-MM-DD'), data: 'period=quarter&start=' + picker.startDate.format('YYYY-MM-DD') + '&end=' + picker.endDate.format('YYYY-MM-DD') + '&range=' + range,
success: function(data) { success: function(data) {
$('#cashflow').html(data); $('#cashflow').html(data);
} }
}); });
}); });
}); });
function getRange(picker) {
ranges = {
'{{ trans("reports.this_year") }}': 'this_year',
'{{ trans("reports.previous_year") }}': 'previous_year',
'{{ trans("reports.this_quarter") }}': 'this_quarter',
'{{ trans("reports.previous_quarter") }}': 'previous_quarter',
'{{ trans("reports.last_12_months") }}': 'last_12_months'
};
range = 'custom';
if (ranges[picker.chosenLabel] != undefined) {
range = ranges[picker.chosenLabel];
}
return range;
}
</script> </script>
@endpush @endpush