mirror of
https://gitlab.com/DanLegoff/mgap.git
synced 2026-11-16 14:22:37 +00:00
69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Usuario;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Inertia\Inertia;
|
|
|
|
class DashboardAccesosController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$usuariosPorTipo = Usuario::select('tipo_usuario_id', DB::raw('count(*) as total'))
|
|
->groupBy('tipo_usuario_id')
|
|
->with('tipoUsuario')
|
|
->get()
|
|
->map(fn ($item) => [
|
|
'tipo' => $item->tipoUsuario?->nombre ?? 'Sin tipo',
|
|
'total' => $item->total,
|
|
]);
|
|
|
|
$usuariosPorArea = DB::table('area_usuario')
|
|
->join('areas', 'areas.id', '=', 'area_usuario.area_id')
|
|
->select('areas.nombre as area', DB::raw('count(distinct area_usuario.usuario_id) as total'))
|
|
->groupBy('areas.nombre')
|
|
->orderByDesc('total')
|
|
->limit(12)
|
|
->get();
|
|
|
|
$rolesDistribucion = DB::table('rol_usuario')
|
|
->join('roles', 'roles.id', '=', 'rol_usuario.rol_id')
|
|
->select('roles.nombre as rol', DB::raw('count(distinct rol_usuario.usuario_id) as total'))
|
|
->groupBy('roles.nombre')
|
|
->orderByDesc('total')
|
|
->get();
|
|
|
|
$permisosPorPerfil = DB::table('permiso_perfil')
|
|
->join('perfiles', 'perfiles.id', '=', 'permiso_perfil.perfil_id')
|
|
->select('perfiles.nombre as perfil', DB::raw('count(*) as total'))
|
|
->groupBy('perfiles.nombre')
|
|
->orderByDesc('total')
|
|
->get();
|
|
|
|
$perfilesPorRol = DB::table('perfil_rol')
|
|
->join('roles', 'roles.id', '=', 'perfil_rol.rol_id')
|
|
->select('roles.nombre as rol', DB::raw('count(distinct perfil_rol.perfil_id) as total'))
|
|
->groupBy('roles.nombre')
|
|
->orderByDesc('total')
|
|
->limit(12)
|
|
->get();
|
|
|
|
$usuariosActivos = Usuario::where('activo', true)->count();
|
|
$usuariosInactivos = Usuario::where('activo', false)->count();
|
|
|
|
$totalUsuarios = Usuario::count();
|
|
|
|
return Inertia::render('Dashboards/Accesos', [
|
|
'usuariosPorTipo' => $usuariosPorTipo,
|
|
'usuariosPorArea' => $usuariosPorArea,
|
|
'rolesDistribucion' => $rolesDistribucion,
|
|
'permisosPorPerfil' => $permisosPorPerfil,
|
|
'perfilesPorRol' => $perfilesPorRol,
|
|
'usuariosActivos' => $usuariosActivos,
|
|
'usuariosInactivos' => $usuariosInactivos,
|
|
'totalUsuarios' => $totalUsuarios,
|
|
]);
|
|
}
|
|
}
|