Jelajahi Sumber

ajustes gestao associados:filtros

Gustavo Zanatta 2 minggu lalu
induk
melakukan
81f37cd07f
2 mengubah file dengan 12 tambahan dan 2 penghapusan
  1. 1 1
      app/Http/Controllers/UserController.php
  2. 11 1
      app/Services/UserService.php

+ 1 - 1
app/Http/Controllers/UserController.php

@@ -70,7 +70,7 @@ class UserController extends Controller
 
     public function indexPaginated(Request $request): JsonResponse
     {
-        $filters = $request->only(['type', 'status', 'search', 'position_id', 'sector_id']);
+        $filters = $request->only(['type', 'status', 'search', 'position_id', 'sector_id', 'first_access']);
         $perPage = min((int) $request->get('per_page', 10), 100);
         $paginator = $this->service->getAllPaginated($filters, $perPage);
 

+ 11 - 1
app/Services/UserService.php

@@ -96,7 +96,12 @@ class UserService
             $query->where(function ($q) use ($term, $cpfTerm) {
                 $q->whereRaw('UNACCENT(LOWER(name)) LIKE UNACCENT(?)', [$term])
                     ->orWhereRaw('UNACCENT(LOWER(email)) LIKE UNACCENT(?)', [$term])
-                    ->orWhereRaw('UNACCENT(LOWER(COALESCE(registration, \'\'))) LIKE UNACCENT(?)', [$term]);
+                    ->orWhereRaw('UNACCENT(LOWER(COALESCE(registration, \'\'))) LIKE UNACCENT(?)', [$term])
+                    ->orWhereRaw("TO_CHAR(admission_date, 'DD/MM/YYYY') LIKE ?", [$term])
+                    ->orWhereRaw("TO_CHAR(expiry_date, 'DD/MM/YYYY') LIKE ?", [$term])
+                    ->orWhereHas('position', function ($p) use ($term) {
+                        $p->whereRaw('UNACCENT(LOWER(positions.name)) LIKE UNACCENT(?)', [$term]);
+                    });
 
                 if ($cpfTerm) {
                     $q->orWhere('cpf', 'LIKE', $cpfTerm);
@@ -104,6 +109,11 @@ class UserService
             });
         }
 
+        if (isset($filters['first_access']) && $filters['first_access'] !== '') {
+            $accessed = filter_var($filters['first_access'], FILTER_VALIDATE_BOOLEAN);
+            $accessed ? $query->whereHas('accessLogs') : $query->whereDoesntHave('accessLogs');
+        }
+
         return $query;
     }