diff --git a/app/Http/Livewire/ShowServicios.php b/app/Http/Livewire/ShowServicios.php index f44da35..db56fd4 100755 --- a/app/Http/Livewire/ShowServicios.php +++ b/app/Http/Livewire/ShowServicios.php @@ -177,23 +177,27 @@ class ShowServicios extends Component ->whereDate('vencimiento', '<=', $this->fecha_final_2) ->where('servicio_id', $servicio_tarifa->id) ->where('estado', 'activo') - ->with('perfil') - ->whereDoesntHave('perfil', function ($query) use ($cantidad_restante) { - $query->select('cuenta_id') - ->groupBy('cuenta_id') - ->havingRaw("COUNT(*) >= $cantidad_restante"); - }) + //->with('perfil') + //->whereDoesntHave('perfil', function ($query) use ($cantidad_restante) { + // $query->select('cuenta_id') + // ->groupBy('cuenta_id') + // ->havingRaw("COUNT(*) >= $cantidad_restante"); + //}) + ->withCount('historiales') + ->where('estado', 'activo') + ->having('historiales_count', '<=', $cantidad_restante) ->get(); //dd($cuentas_pantallas); $cuentas_pantallas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_pantallas ->pluck('id')) ->count(); - + //dd($cuentas_pantallas_tomadas); //Validar si el numero pantallas del servicio es igual o mayor que lo solicitado if ($servicio_tarifa->pantallas >= $cantidad_solicitada) { //Cantidad de cuentas restantes * cantidad de pantallas del servicio / en las pantalla de la tarifa. $this->disponibles = (($cuentas_pantallas->count() * $servicio_tarifa->pantallas) - $cuentas_pantallas_tomadas) / $tarifa_seleccionada->pantallas; + //dd($this->disponibles) ; } else { $this->disponibles = $cuentas_pantallas; }