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 @@ +
+
+ + {{-- Título --}} +
+ + Diagnóstico de cuenta +
+ + {{-- Buscador --}} +
+ + +
+ + @if (!empty($buscar_cuenta) && is_null($cuenta)) +
No se encontró ninguna cuenta con ese correo.
+ @endif + + @if ($cuenta) + + {{-- Info de la cuenta --}} +
+

{{ $cuenta->correo }}

+
+
Servicio{{ $cuenta->servicio->nombre ?? 'N/A' }}
+
Estado cuenta + {{ $cuenta->estado }} +
+
Vencimiento{{ $cuenta->vencimiento }}
+
Pantallas servicio{{ $cuenta->servicio->pantallas ?? 'N/A' }}
+
+
+ + {{-- Resumen --}} + @if (!empty($resumen)) +
+
+

{{ $resumen['total_registros'] }}

+

Total perfiles asignados

+
+
+

{{ $resumen['activos'] }}

+

Activos actualmente

+
+
+

{{ $resumen['cancelados'] }}

+

Cancelados / liberados

+
+
+

{{ implode(', ', $resumen['perfiles_unicos_activos']) ?: 'ninguno' }}

+

Perfiles activos

+
+
+ + @if ($resumen['perfil_6_cancelados'] > 0) +
+ ⚠️ El perfil 6 ha sido asignado y cancelado {{ $resumen['perfil_6_cancelados'] }} vez/veces. + Esto confirma que se está re-entregando el mismo perfil porque las compras anteriores fueron canceladas y liberaron el slot. +
+ @endif + @endif + + {{-- Tabla historial de perfiles --}} +
+

Historial de perfiles asignados a esta cuenta

+ + + + + + + + + + + + + + + @forelse ($historial_perfiles as $hc) + + + + + + + + + + + @empty + + @endforelse + +
Perfil #Estado historialVendedorClienteFecha inicioFecha finalHistorial IDAsignado el
{{ $hc['perfil'] }} + {{ $hc['estado_historial'] }} + {{ $hc['vendedor'] }}{{ $hc['cliente'] }}{{ $hc['fecha_inicio'] }}{{ $hc['fecha_final'] }}{{ $hc['historial_id'] }}{{ $hc['created_at'] }}
Sin registros
+
+ + {{-- Tabla logs relacionados --}} +
+

Logs relacionados (últimos 50)

+ + + + + + + + + + + + @forelse ($logs_relacionados as $log) + + + + + + + + @empty + + @endforelse + +
TipoUsuarioHistorial IDDetalleFecha
+ {{ $log['tipo'] }} + {{ $log['usuario'] }}{{ $log['historial_id'] }}{{ $log['detalle'] }}{{ $log['created_at'] }}
Sin logs
+
+ + @endif +
+
diff --git a/resources/views/menu/diagnostico.blade.php b/resources/views/menu/diagnostico.blade.php new file mode 100644 index 0000000..f22c8ba --- /dev/null +++ b/resources/views/menu/diagnostico.blade.php @@ -0,0 +1,7 @@ + +
+ +
+ + @include('layouts.footer') +
diff --git a/routes/web.php b/routes/web.php index d69b70d..643da27 100755 --- a/routes/web.php +++ b/routes/web.php @@ -68,8 +68,7 @@ Route::middleware(["auth", "solo_usuario_administrador"])->group(function () { Route::any('/logs', [MenuController::class, 'showlogs'])->name('logs'); Route::any('/logs-recargas', [MenuController::class, 'showLogRecargas'])->name('logsRecargas'); Route::any('/log-general', [MenuController::class, 'showLogGeneral'])->name('logGeneral'); - Route::any('/log-historial', [MenuController::class, 'showLogHistorial'])->name('logHistorial'); - Route::get('/utilidades', [MenuController::class, 'showutilidad'])->name('utilidades'); + Route::any('/log-historial', [MenuController::class, 'showLogHistorial'])->name('logHistorial'); Route::get('/diagnostico', [MenuController::class, 'showDiagnostico'])->name('diagnostico'); Route::get('/utilidades', [MenuController::class, 'showutilidad'])->name('utilidades'); Route::get('/mantenimiento', [MenuController::class, 'mantenimiento'])->name('mantenimiento'); Route::get('/rank-management', [MenuController::class, 'showgestionrangos'])->name('gestion-rangos'); });