diff --git a/app/Http/Controllers/Common/Dashboard.php b/app/Http/Controllers/Common/Dashboard.php index 50ec8bbcb..0091cf9fe 100644 --- a/app/Http/Controllers/Common/Dashboard.php +++ b/app/Http/Controllers/Common/Dashboard.php @@ -126,6 +126,7 @@ class Dashboard extends Controller $start = Date::parse(request('start', $this->today->startOfYear()->format('Y-m-d'))); $end = Date::parse(request('end', $this->today->endOfYear()->format('Y-m-d'))); $period = request('period', 'month'); + $range = request('range', 'custom'); $start_month = $start->month; $end_month = $end->month; @@ -135,6 +136,11 @@ class Dashboard extends Controller $s = clone $start; + if ($range == 'last_12_months') { + $end_month = 12; + $start_month = 1; + } + for ($j = $end_month; $j >= $start_month; $j--) { $labels[$end_month - $j] = $s->format('M Y'); diff --git a/resources/views/common/dashboard/index.blade.php b/resources/views/common/dashboard/index.blade.php index 749692874..a7c221d87 100644 --- a/resources/views/common/dashboard/index.blade.php +++ b/resources/views/common/dashboard/index.blade.php @@ -266,11 +266,13 @@ $('#cashflow-range').on('apply.daterangepicker', function(ev, picker) { var period = $('#period').val(); + range = getRange(picker); + $.ajax({ url: '{{ url("common/dashboard/cashflow") }}', type: 'get', 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) { $('#cashflow').html(data); } @@ -282,11 +284,13 @@ $('#period').val('month'); + range = getRange(picker); + $.ajax({ url: '{{ url("common/dashboard/cashflow") }}', type: 'get', 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) { $('#cashflow').html(data); } @@ -298,16 +302,36 @@ $('#period').val('quarter'); + range = getRange(picker); + $.ajax({ url: '{{ url("common/dashboard/cashflow") }}', type: 'get', 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) { $('#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; + } @endpush \ No newline at end of file