user(); $now = Carbon::now(); $yearPeriod = $yearPeriodRetriever->selected(); $absences = Vacation::query() ->with(["user", "vacationRequest"]) ->whereDate("date", $now) ->approved() ->get(); if ($user->can("listAll", VacationRequest::class)) { $vacationRequests = $yearPeriod->vacationRequests() ->states(VacationRequestStatesRetriever::waitingForUserActionStates($user)) ->latest("updated_at") ->limit(3) ->get(); } else { $vacationRequests = $user->vacationRequests() ->whereBelongsTo($yearPeriod) ->latest("updated_at") ->limit(3) ->get(); } $holidays = $yearPeriod ->holidays() ->whereDate("date", ">=", $now) ->orderBy("date") ->limit(3) ->get(); $limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod); $used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod); $pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod); $other = $vacationStatsRetriever->getOtherApprovedVacationDays($user, $yearPeriod); $remaining = $limit - $used - $pending; return inertia("Dashboard", [ "absences" => AbsenceResource::collection($absences), "vacationRequests" => VacationRequestResource::collection($vacationRequests), "holidays" => HolidayResource::collection($holidays), "stats" => [ "limit" => $limit, "remaining" => $remaining, "used" => $used, "pending" => $pending, "other" => $other, ], "can" => [ "listAllVacationRequests" => $user->can("listAll", VacationRequest::class), ], ]); } }