diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index 8f3a451..4659fa1 100755 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -472,6 +472,10 @@ class ShowPlanes extends Component $tarifa = json_decode($this->tarifa, true); + + + // dd($tarifa) + //dd($this->tarifa['dias']); $usuario_existe = User::firstWhere('email', $this->searchTerm)->id ?? null; $usuario_id = $usuario_existe; @@ -489,6 +493,7 @@ class ShowPlanes extends Component $usuario_id = $usuario->id; } + // dd($this->tarifa); $historial = new Historiale; $historial->fecha_inicio = Carbon::now(); @@ -502,14 +507,19 @@ class ShowPlanes extends Component $historial->cantidad = $tarifa['pantallas']; $historial->save(); - $consultaHC = Historial_cuenta::where('cuenta_id', $this->consulta_verUsuarios->id)->where('perfil', $this->perfil)->exists(); - if (!$consultaHC) { - $historial_cuenta = new Historial_cuenta; - $historial_cuenta->cuenta_id = $this->consulta_verUsuarios->id; - $historial_cuenta->historial_id = $historial->id; - $historial_cuenta->perfil = $this->perfil; - $historial_cuenta->save(); + $consultaHC = Historial_cuenta::where('cuenta_id', $this->consulta_verUsuarios->id)->orderBy('created_at', 'desc')->first()->perfil ?? 0; + + 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 = $i + 1; + $historial_cuenta->save(); + } $this->alert('success', 'Usuario añadido correctamente!', [ 'position' => 'top' @@ -517,11 +527,44 @@ class ShowPlanes extends Component $this->addUser = false; $this->consulta_verUsuarios = Cuentas::with('historiales', 'servicio')->where('id', $this->id_cuentaVer)->first(); - } else { - $historial->delete(); - $this->alert('warning', 'El perfil ya se encuentra en uso!', [ - 'position' => 'top' - ]); + } + + 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(); } } diff --git a/resources/views/components/listado-planes.blade.php b/resources/views/components/listado-planes.blade.php index d556a10..fbe6374 100755 --- a/resources/views/components/listado-planes.blade.php +++ b/resources/views/components/listado-planes.blade.php @@ -55,8 +55,7 @@
Ocupado
@endif @else -+
{{ $cuenta->historiales_count ?? '0' }}/{{ $cuenta->servicio->pantallas ?? '0' }} @endif @if ($historiales >= '1') {{ $historiales }} diff --git a/resources/views/livewire/show-planes.blade.php b/resources/views/livewire/show-planes.blade.php index 1fc87be..5ee1b42 100755 --- a/resources/views/livewire/show-planes.blade.php +++ b/resources/views/livewire/show-planes.blade.php @@ -6,8 +6,8 @@ serviciosModal: @entangle('serviciosModal'), ver: false, renovar: @entangle('renovar'), - addUser:@entangle('addUser'), - editarTarifaRol:@entangle('editarTarifaRol'), + addUser: @entangle('addUser'), + editarTarifaRol: @entangle('editarTarifaRol'), }" class="h-full w-full md:my-2">