authorizeAbility($request, 'reports.view'); $organization = $this->organization($request); $branchScope = app(OrganizationResolver::class)->branchScope($this->member($request)); $branchId = $request->input('branch_id') ? (int) $request->input('branch_id') : $branchScope; $from = Carbon::parse($request->input('from', now()->subDays(30)->toDateString()))->startOfDay(); $to = Carbon::parse($request->input('to', now()->toDateString()))->endOfDay(); $owner = $this->ownerRef($request); $data = match ($type) { 'tickets' => $reports->ticketsReport($owner, $organization->id, $from, $to, $branchId), 'wait_times' => $reports->waitTimesReport($owner, $organization->id, $from, $to, $branchId), 'counters' => $reports->countersReport($owner, $organization->id, $from, $to, $branchId), 'appointments' => $reports->appointmentsReport($owner, $organization->id, $from, $to, $branchId), 'feedback' => $reports->feedbackReport($owner, $organization->id, $from, $to, $branchId), 'service_sessions' => $reports->serviceSessionsReport($owner, $organization->id, $from, $to, $branchId), default => abort(404), }; return response()->json(['data' => $data, 'from' => $from->toDateString(), 'to' => $to->toDateString()]); } }