From f67702334ca3f781f0f2ce3cbcbaddee51bb78c8 Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:34:08 -0500 Subject: [PATCH] Update ShowPlanes.php --- app/Http/Livewire/ShowPlanes.php | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index 263aa52..2e2b61e 100755 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -312,12 +312,45 @@ class ShowPlanes extends Component ]); - Log_historial::create([ 'user_id' => Auth::user()->id, 'detalle' => 'El usuario ha renovado y liberado la cuenta ' . $cuenta_renovar->correo ]); + if ($this->estado === 'activo') { + $servicioPantallas = Servicio::find($this->servicio_newCuenta)->pantallas; + + $cuentasPendientes = Pendientes::where('estado', 'pendiente')->where('servicio_id', $this->servicio_newCuenta)->take($servicioPantallas)->get(); + + foreach ($cuentasPendientes as $i => $cuentaPendiente) { + $servicioName = $cuentaPendiente->servicio->nombre; + + $historial_cuenta = new Historial_cuenta(); + $historial_cuenta->historial_id = $cuentaPendiente->historial_id; + $historial_cuenta->cuenta_id = $id->id; + $historial_cuenta->perfil = $i + 1; + $historial_cuenta->save(); + $cuentaPendiente->update(['estado' => 'cerrado']); + + $cuentaPendiente->historial->vendedor->notify(new NotificacionPendiente($servicioName)); + + $consulta = new Notificacion(); + $consulta->remitente_id = Auth::user()->id; + $consulta->destinatario_id = $historial_cuenta->historial->vendedor_id; + $consulta->titulo = "Licencia asignada para $servicioName"; + $consulta->descripcion = 'La licencia de ' . $servicioName . ' ha sido activada y ahora puedes utilizar tu cuenta sin problemas. Tus credenciales son: correo: ' . $historial_cuenta->cuenta->correo . ' contraseña: ' . $historial_cuenta->cuenta->password; + $consulta->estado = true; + $consulta->todos = false; + $consulta->save(); + + Log_historial::create([ + 'user_id' => $cuentaPendiente->historial->cliente->id, + 'detalle' => 'La cuenta de ' . $servicioName . ' ha sido renovada y asignada desde pendiente, correo: ' . $historial_cuenta->cuenta->correo . ' contraseña: ' . $historial_cuenta->cuenta->password . ', al usuario ' . $cuentaPendiente->historial->cliente->name, + ]); + } + + } + $this->alert('success', 'Cuenta renovada y liberada correctamente!', [ 'position' => 'top' ]); @@ -453,6 +486,11 @@ class ShowPlanes extends Component $consulta->estado = true; $consulta->todos = false; $consulta->save(); + + Log_historial::create([ + 'user_id' => $cuentaPendiente->historial->cliente->id, + 'detalle' => 'La cuenta de ' . $servicioName . ' ha sido creada y asignada desde pendiente, correo: ' . $historial_cuenta->cuenta->correo . ' contraseña: ' . $historial_cuenta->cuenta->password . ', al usuario ' . $cuentaPendiente->historial->cliente->name, + ]); } }