date filter on dashboard will work fiscal year based akaunting/software#78
This commit is contained in:
@@ -50,6 +50,13 @@ class Dashboards extends Controller
|
||||
*/
|
||||
public function show($dashboard_id = null)
|
||||
{
|
||||
$date_picker_shortcuts = $this->getDatePickerShortcuts();
|
||||
|
||||
if (!request()->has('start_date')) {
|
||||
request()->merge(['start_date' => $date_picker_shortcuts[trans('reports.this_year')]['start']]);
|
||||
request()->merge(['end_date' => $date_picker_shortcuts[trans('reports.this_year')]['end']]);
|
||||
}
|
||||
|
||||
$dashboard_id = $dashboard_id ?? session('dashboard_id');
|
||||
|
||||
try {
|
||||
@@ -72,9 +79,7 @@ class Dashboards extends Controller
|
||||
return Widgets::canShow($widget->class);
|
||||
});
|
||||
|
||||
$financial_start = $this->getFinancialStart()->format('Y-m-d');
|
||||
|
||||
return view('common.dashboards.show', compact('dashboard', 'widgets', 'financial_start'));
|
||||
return view('common.dashboards.show', compact('dashboard', 'widgets', 'date_picker_shortcuts'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -136,6 +136,46 @@ trait DateTime
|
||||
return $quarters;
|
||||
}
|
||||
|
||||
public function getDatePickerShortcuts()
|
||||
{
|
||||
$today = new Date();
|
||||
$financial_year = $this->getFinancialYear();
|
||||
$financial_quarters = $this->getFinancialQuarters();
|
||||
|
||||
foreach ($financial_quarters as $quarter) {
|
||||
if ($today->lessThan($quarter->getStartDate()) || $today->greaterThan($quarter->getEndDate())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this_quarter = $quarter;
|
||||
}
|
||||
|
||||
$date_picker_shortcuts = [
|
||||
trans('reports.this_year') => [
|
||||
'start' => $financial_year->getStartDate()->format('Y-m-d'),
|
||||
'end' => $financial_year->getEndDate()->format('Y-m-d'),
|
||||
],
|
||||
trans('reports.previous_year') => [
|
||||
'start' => $financial_year->getStartDate()->copy()->subYear()->format('Y-m-d'),
|
||||
'end' => $financial_year->getEndDate()->copy()->subYear()->format('Y-m-d'),
|
||||
],
|
||||
trans('reports.this_quarter') => [
|
||||
'start' => $this_quarter->getStartDate()->format('Y-m-d'),
|
||||
'end' => $this_quarter->getEndDate()->format('Y-m-d'),
|
||||
],
|
||||
trans('reports.previous_quarter') => [
|
||||
'start' => $this_quarter->getStartDate()->copy()->subQuarter()->format('Y-m-d'),
|
||||
'end' => $this_quarter->getEndDate()->copy()->subQuarter()->format('Y-m-d'),
|
||||
],
|
||||
trans('reports.last_12_months') => [
|
||||
'start' => $today->copy()->subYear()->startOfDay()->format('Y-m-d'),
|
||||
'end' => $today->copy()->subDay()->endOfDay()->format('Y-m-d'),
|
||||
],
|
||||
];
|
||||
|
||||
return $date_picker_shortcuts;
|
||||
}
|
||||
|
||||
public function getMonthlyDateFormat($year = null)
|
||||
{
|
||||
$format = 'M';
|
||||
|
||||
Reference in New Issue
Block a user