query( Employee::query() ->whereNotNull('birth_date') ->whereIn('id', $this->upcomingBirthdayEmployeeIds()), ) ->columns([ TextColumn::make('full_name') ->label(__('hr.fields.employee')), TextColumn::make('birth_date') ->label(__('hr.fields.birthday')) ->date() ->formatStateUsing(fn (Employee $record): string => $record->birth_date?->format('M d') ?? '—'), TextColumn::make('department.name') ->label(__('hr.fields.department')), ]) ->paginated(false); } /** * @return array */ private function upcomingBirthdayEmployeeIds(): array { return Employee::query() ->whereNotNull('birth_date') ->get() ->filter(function (Employee $employee): bool { if ($employee->birth_date === null) { return false; } $birthday = $employee->birth_date->copy()->year(now()->year); if ($birthday->lt(now()->startOfDay())) { $birthday = $birthday->addYear(); } return $birthday->lte(now()->addDays(30)); }) ->sortBy(function (Employee $employee): int { $birthday = $employee->birth_date->copy()->year(now()->year); if ($birthday->lt(now()->startOfDay())) { $birthday = $birthday->addYear(); } return $birthday->dayOfYear; }) ->pluck('id') ->all(); } /** * @return Builder|null */ protected function getTableQuery(): ?Builder { return null; } }