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)
|
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');
|
$dashboard_id = $dashboard_id ?? session('dashboard_id');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -72,9 +79,7 @@ class Dashboards extends Controller
|
|||||||
return Widgets::canShow($widget->class);
|
return Widgets::canShow($widget->class);
|
||||||
});
|
});
|
||||||
|
|
||||||
$financial_start = $this->getFinancialStart()->format('Y-m-d');
|
return view('common.dashboards.show', compact('dashboard', 'widgets', 'date_picker_shortcuts'));
|
||||||
|
|
||||||
return view('common.dashboards.show', compact('dashboard', 'widgets', 'financial_start'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,6 +136,46 @@ trait DateTime
|
|||||||
return $quarters;
|
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)
|
public function getMonthlyDateFormat($year = null)
|
||||||
{
|
{
|
||||||
$format = 'M';
|
$format = 'M';
|
||||||
|
@ -81,18 +81,15 @@
|
|||||||
value-format="yyyy-MM-dd"
|
value-format="yyyy-MM-dd"
|
||||||
@change="onChangeFilterDate"
|
@change="onChangeFilterDate"
|
||||||
range-separator=">>"
|
range-separator=">>"
|
||||||
start-placeholder="{{ trans('general.start_date')}}"
|
start-placeholder="{{ $date_picker_shortcuts[trans("reports.this_year")]["start"] }}"
|
||||||
end-placeholder="{{ trans('general.end_date')}}"
|
end-placeholder="{{ $date_picker_shortcuts[trans("reports.this_year")]["end"] }}"
|
||||||
:picker-options="{
|
:picker-options="{
|
||||||
shortcuts: [
|
shortcuts: [
|
||||||
{
|
{
|
||||||
text: '{{ trans("reports.this_year") }}',
|
text: '{{ trans("reports.this_year") }}',
|
||||||
onClick(picker) {
|
onClick(picker) {
|
||||||
const end = new Date('{{ $financial_start }}');
|
const start = new Date('{{ $date_picker_shortcuts[trans("reports.this_year")]["start"] }}');
|
||||||
const start = new Date('{{ $financial_start }}');
|
const end = new Date('{{ $date_picker_shortcuts[trans("reports.this_year")]["end"] }}');
|
||||||
|
|
||||||
end.setFullYear(start.getFullYear() + 1);
|
|
||||||
end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
|
|
||||||
|
|
||||||
picker.$emit('pick', [start, end]);
|
picker.$emit('pick', [start, end]);
|
||||||
}
|
}
|
||||||
@ -100,13 +97,8 @@
|
|||||||
{
|
{
|
||||||
text: '{{ trans("reports.previous_year") }}',
|
text: '{{ trans("reports.previous_year") }}',
|
||||||
onClick(picker) {
|
onClick(picker) {
|
||||||
const end = new Date('{{ $financial_start }}');
|
const start = new Date('{{ $date_picker_shortcuts[trans("reports.previous_year")]["start"] }}');
|
||||||
const start = new Date('{{ $financial_start }}');
|
const end = new Date('{{ $date_picker_shortcuts[trans("reports.previous_year")]["end"] }}');
|
||||||
|
|
||||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
|
|
||||||
|
|
||||||
end.setFullYear(start.getFullYear() + 1);
|
|
||||||
end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
|
|
||||||
|
|
||||||
picker.$emit('pick', [start, end]);
|
picker.$emit('pick', [start, end]);
|
||||||
}
|
}
|
||||||
@ -114,10 +106,8 @@
|
|||||||
{
|
{
|
||||||
text: '{{ trans("reports.this_quarter") }}',
|
text: '{{ trans("reports.this_quarter") }}',
|
||||||
onClick(picker) {
|
onClick(picker) {
|
||||||
const now = new Date();
|
const start = new Date('{{ $date_picker_shortcuts[trans("reports.this_quarter")]["start"] }}');
|
||||||
const quarter = Math.floor((now.getMonth() / 3));
|
const end = new Date('{{ $date_picker_shortcuts[trans("reports.this_quarter")]["end"] }}');
|
||||||
const start = new Date(now.getFullYear(), quarter * 3, 1);
|
|
||||||
const end = new Date(start.getFullYear(), start.getMonth() + 3, 0);
|
|
||||||
|
|
||||||
picker.$emit('pick', [start, end]);
|
picker.$emit('pick', [start, end]);
|
||||||
}
|
}
|
||||||
@ -125,13 +115,8 @@
|
|||||||
{
|
{
|
||||||
text: '{{ trans("reports.previous_quarter") }}',
|
text: '{{ trans("reports.previous_quarter") }}',
|
||||||
onClick(picker) {
|
onClick(picker) {
|
||||||
const now = new Date();
|
const start = new Date('{{ $date_picker_shortcuts[trans("reports.previous_quarter")]["start"] }}');
|
||||||
const quarter = Math.floor((now.getMonth() / 3));
|
const end = new Date('{{ $date_picker_shortcuts[trans("reports.previous_quarter")]["end"] }}');
|
||||||
const start = new Date(now.getFullYear(), quarter * 3, 1);
|
|
||||||
const end = new Date(start.getFullYear(), start.getMonth() + 3, 0);
|
|
||||||
|
|
||||||
start.setMonth(start.getMonth() - 3);
|
|
||||||
end.setMonth(end.getMonth() - 3);
|
|
||||||
|
|
||||||
picker.$emit('pick', [start, end]);
|
picker.$emit('pick', [start, end]);
|
||||||
}
|
}
|
||||||
@ -139,10 +124,8 @@
|
|||||||
{
|
{
|
||||||
text: '{{ trans("reports.last_12_months") }}',
|
text: '{{ trans("reports.last_12_months") }}',
|
||||||
onClick(picker) {
|
onClick(picker) {
|
||||||
const end = new Date();
|
const start = new Date('{{ $date_picker_shortcuts[trans("reports.last_12_months")]["start"] }}');
|
||||||
const start = new Date();
|
const end = new Date('{{ $date_picker_shortcuts[trans("reports.last_12_months")]["end"] }}');
|
||||||
|
|
||||||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
|
|
||||||
|
|
||||||
picker.$emit('pick', [start, end]);
|
picker.$emit('pick', [start, end]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user