From 5f402b112982f63110d38161223f5fe6f0c350cd Mon Sep 17 00:00:00 2001 From: Felipe Date: Tue, 7 Nov 2023 15:09:17 -0500 Subject: [PATCH] update planes --- app/Http/Livewire/ShowPlanes.php | 91 +++++++++++++++++--------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index e1b5536..4659fa1 100644 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -488,12 +488,12 @@ class ShowPlanes extends Component $usuario->password = '123456'; $usuario->celular = '+57'; $usuario->rol_id = $rol_id; - // $usuario->save(); + $usuario->save(); $usuario_id = $usuario->id; } - dd($this->tarifa); + // dd($this->tarifa); $historial = new Historiale; $historial->fecha_inicio = Carbon::now(); @@ -505,57 +505,64 @@ class ShowPlanes extends Component $historial->tarifa_id = $tarifa['id']; $historial->cliente_id = $usuario_id; $historial->cantidad = $tarifa['pantallas']; - // $historial->save(); - - - if ($this->consulta_verUsuarios->estado == 'pendiente') { // completa - $perfiles = $this->consulta_verUsuarios->servicio->completa; - } - - if ($this->consulta_verUsuarios->estado == 'activo') { // pantallas - $perfiles = $this->consulta_verUsuarios->servicio->pantallas; - } - - - dd($this->consulta_verUsuarios); - + $historial->save(); $consultaHC = Historial_cuenta::where('cuenta_id', $this->consulta_verUsuarios->id)->orderBy('created_at', 'desc')->first()->perfil ?? 0; - - if ($consultaHC) { - if ($consultaHC < 5) { + + if ($this->consulta_verUsuarios->estado == 'pendiente') { // completa + $perfiles = $this->consulta_verUsuarios->servicio->completa; + + for ($i = 0; $i < $perfiles; $i++) { $historial_cuenta = new Historial_cuenta; $historial_cuenta->cuenta_id = $this->consulta_verUsuarios->id; $historial_cuenta->historial_id = $historial->id; - $historial_cuenta->perfil = $consultaHC + 1; - // $historial_cuenta->save(); - - $this->alert('success', 'Usuario añadido correctamente!', [ - 'position' => 'top' - ]); - - - $this->addUser = false; - $this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $this->id_cuentaVer)->first(); - }else{ - $historial->delete(); - $this->alert('warning', 'Ya haz alcanzado el maximo de perfiles!', [ - 'position' => 'top' - ]); + $historial_cuenta->perfil = $i + 1; + $historial_cuenta->save(); } - } else { - $historial_cuenta = new Historial_cuenta; - $historial_cuenta->cuenta_id = $this->consulta_verUsuarios->id; - $historial_cuenta->historial_id = $historial->id; - $historial_cuenta->perfil = $consultaHC + 1; - // $historial_cuenta->save(); - + $this->alert('success', 'Usuario añadido correctamente!', [ 'position' => 'top' ]); - + $this->addUser = false; + $this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $this->id_cuentaVer)->first(); + } + + if ($this->consulta_verUsuarios->estado == 'activo') { // pantallas + $perfiles = $this->consulta_verUsuarios->servicio->pantallas; + + if ($consultaHC) { + if ($consultaHC < $perfiles) { + $historial_cuenta = new Historial_cuenta; + $historial_cuenta->cuenta_id = $this->consulta_verUsuarios->id; + $historial_cuenta->historial_id = $historial->id; + $historial_cuenta->perfil = $consultaHC + 1; + $historial_cuenta->save(); + + $this->alert('success', 'Usuario añadido correctamente!', [ + 'position' => 'top' + ]); + + $this->addUser = false; + $this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $this->id_cuentaVer)->first(); + } else { + $historial->delete(); + $this->alert('warning', 'Ya haz alcanzado el maximo de perfiles!', [ + 'position' => 'top' + ]); + } + } else { + $historial_cuenta = new Historial_cuenta; + $historial_cuenta->cuenta_id = $this->consulta_verUsuarios->id; + $historial_cuenta->historial_id = $historial->id; + $historial_cuenta->perfil = $consultaHC + 1; + $historial_cuenta->save(); + + $this->alert('success', 'Usuario añadido correctamente!', [ + 'position' => 'top' + ]); + } $this->addUser = false; $this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $this->id_cuentaVer)->first(); }