diff --git a/app/Services/Admin/HR/LeaveRequestService.php b/app/Services/Admin/HR/LeaveRequestService.php index 49772d1..d17fcd0 100644 --- a/app/Services/Admin/HR/LeaveRequestService.php +++ b/app/Services/Admin/HR/LeaveRequestService.php @@ -12,10 +12,16 @@ class LeaveRequestService { + private function canViewAll(): bool + { + return auth()->user()->hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']); + } + public function getAll(array $filters = []): Collection { return LeaveRequest::select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at']) ->with(['employee.user.userProfile']) + ->when(! $this->canViewAll(), fn ($q) => $q->whereHas('employee', fn ($eq) => $eq->where('user_id', auth()->id()))) ->when($filters['status'] ?? null, function ($query, $status) { $query->where('status', $status); }) @@ -28,6 +34,7 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = return LeaveRequest::query() ->select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at']) ->with(['employee.user.userProfile']) + ->when(! $this->canViewAll(), fn ($q) => $q->whereHas('employee', fn ($eq) => $eq->where('user_id', auth()->id()))) ->when($search, fn ($q) => $q->whereHas('employee.user.userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%"))) ->when($filters['status'] ?? null, function ($query, $status) { $query->where('status', $status);