From 03207775af11aa93afd382c411df4e88e42f9492 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 18 Apr 2026 14:08:14 -0500 Subject: [PATCH] up --- app/Http/Controllers/MenuController.php | 5 + app/Http/Livewire/ShowDiagnostico.php | 101 ++++++++++++ .../views/livewire/show-diagnostico.blade.php | 152 ++++++++++++++++++ resources/views/menu/diagnostico.blade.php | 7 + routes/web.php | 3 +- 5 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 app/Http/Livewire/ShowDiagnostico.php create mode 100644 resources/views/livewire/show-diagnostico.blade.php create mode 100644 resources/views/menu/diagnostico.blade.php diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index 5795220..f3dd03a 100755 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -112,6 +112,11 @@ class MenuController extends Controller return view('menu/log_historial'); } + public function showDiagnostico() + { + return view('menu/diagnostico'); + } + public function showroles() { return view('menu/roles'); diff --git a/app/Http/Livewire/ShowDiagnostico.php b/app/Http/Livewire/ShowDiagnostico.php new file mode 100644 index 0000000..bc67d45 --- /dev/null +++ b/app/Http/Livewire/ShowDiagnostico.php @@ -0,0 +1,101 @@ +cuenta = null; + $this->historial_perfiles = []; + $this->logs_relacionados = []; + $this->resumen = []; + + if (empty(trim($this->buscar_cuenta))) { + return; + } + + $this->cuenta = Cuentas::with('servicio') + ->where('correo', 'ILIKE', '%' . trim($this->buscar_cuenta) . '%') + ->first(); + + if (!$this->cuenta) { + return; + } + + // Todos los historial_cuenta de esta cuenta, con su historial padre + $this->historial_perfiles = Historial_cuenta::with(['historial.vendedor', 'historial.cliente']) + ->where('cuenta_id', $this->cuenta->id) + ->orderBy('perfil') + ->orderBy('created_at', 'desc') + ->get() + ->map(function ($hc) { + return [ + 'id' => $hc->id, + 'perfil' => $hc->perfil, + 'historial_id' => $hc->historial_id, + 'estado_historial' => $hc->historial->estado ?? 'N/A', + 'vendedor' => $hc->historial->vendedor->name ?? 'N/A', + 'cliente' => $hc->historial->nombre_cliente ?? ($hc->historial->cliente->name ?? 'N/A'), + 'fecha_inicio' => $hc->historial->fecha_inicio ?? 'N/A', + 'fecha_final' => $hc->historial->fecha_final ?? 'N/A', + 'created_at' => $hc->created_at, + ]; + }) + ->toArray(); + + // Logs relacionados con todos los historiales de esta cuenta + $historial_ids = Historial_cuenta::where('cuenta_id', $this->cuenta->id) + ->whereNotNull('historial_id') + ->pluck('historial_id') + ->unique(); + + $this->logs_relacionados = Log_general::with('user') + ->whereIn('historial_id', $historial_ids) + ->orderBy('created_at', 'desc') + ->take(50) + ->get() + ->map(function ($log) { + return [ + 'id' => $log->id, + 'tipo' => $log->tipo, + 'usuario' => $log->user->name ?? 'N/A', + 'detalle' => $log->detalle, + 'historial_id' => $log->historial_id, + 'created_at' => $log->created_at, + ]; + }) + ->toArray(); + + // Resumen por perfil + $perfiles_activos = collect($this->historial_perfiles)->where('estado_historial', 'activo'); + $perfiles_cancelados = collect($this->historial_perfiles)->where('estado_historial', 'cancelado'); + + $this->resumen = [ + 'total_registros' => count($this->historial_perfiles), + 'activos' => $perfiles_activos->count(), + 'cancelados' => $perfiles_cancelados->count(), + 'max_perfil_activo' => $perfiles_activos->max('perfil') ?? 0, + 'perfiles_unicos_activos' => $perfiles_activos->pluck('perfil')->unique()->sort()->values()->toArray(), + 'perfil_6_activos' => $perfiles_activos->where('perfil', 6)->count(), + 'perfil_6_cancelados' => $perfiles_cancelados->where('perfil', 6)->count(), + ]; + } + + public function render() + { + return view('livewire.show-diagnostico'); + } +} diff --git a/resources/views/livewire/show-diagnostico.blade.php b/resources/views/livewire/show-diagnostico.blade.php new file mode 100644 index 0000000..3f7e44c --- /dev/null +++ b/resources/views/livewire/show-diagnostico.blade.php @@ -0,0 +1,152 @@ +
{{ $cuenta->correo }}
+{{ $resumen['total_registros'] }}
+Total perfiles asignados
+{{ $resumen['activos'] }}
+Activos actualmente
+{{ $resumen['cancelados'] }}
+Cancelados / liberados
+{{ implode(', ', $resumen['perfiles_unicos_activos']) ?: 'ninguno' }}
+Perfiles activos
+Historial de perfiles asignados a esta cuenta
+| Perfil # | +Estado historial | +Vendedor | +Cliente | +Fecha inicio | +Fecha final | +Historial ID | +Asignado el | +
|---|---|---|---|---|---|---|---|
| {{ $hc['perfil'] }} | ++ {{ $hc['estado_historial'] }} + | +{{ $hc['vendedor'] }} | +{{ $hc['cliente'] }} | +{{ $hc['fecha_inicio'] }} | +{{ $hc['fecha_final'] }} | +{{ $hc['historial_id'] }} | +{{ $hc['created_at'] }} | +
| Sin registros | |||||||
Logs relacionados (últimos 50)
+| Tipo | +Usuario | +Historial ID | +Detalle | +Fecha | +
|---|---|---|---|---|
| + {{ $log['tipo'] }} + | +{{ $log['usuario'] }} | +{{ $log['historial_id'] }} | +{{ $log['detalle'] }} | +{{ $log['created_at'] }} | +
| Sin logs | ||||