From 6eb6e3bd2f200df5211f8e4033033b3d3242eb79 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:30:10 -0700 Subject: [PATCH] antes de comenzar la vista tarifas --- app/Http/Livewire/ShowTarifas.php | 13 +++ app/Http/Livewire/ShowUsuarios.php | 19 ++-- ...3_10_09_145454_add_utilidad_to_tarifas.php | 10 -- ...07_add_subvendedor_id_to_tarifas_table.php | 22 +++++ resources/views/layouts/navigation.blade.php | 47 +++++----- .../views/livewire/portada-servicio.blade.php | 2 +- .../views/livewire/show-tarifas.blade.php | 3 + .../views/livewire/show-usuarios.blade.php | 92 +++++++++---------- 8 files changed, 113 insertions(+), 95 deletions(-) create mode 100644 app/Http/Livewire/ShowTarifas.php create mode 100644 database/migrations/2025_06_16_181407_add_subvendedor_id_to_tarifas_table.php create mode 100644 resources/views/livewire/show-tarifas.blade.php diff --git a/app/Http/Livewire/ShowTarifas.php b/app/Http/Livewire/ShowTarifas.php new file mode 100644 index 0000000..2ec8cc7 --- /dev/null +++ b/app/Http/Livewire/ShowTarifas.php @@ -0,0 +1,13 @@ +orWhere('email', 'ILIKE', '%' . $this->buscar . '%'); }); + if ($this->verPreciosPersonalizados) { $consulta_usuarios = $consulta_usuarios->havingRaw('active_tarifas > 0 OR active_promos > 0'); } + if (!(Auth::user()->rol->nombre == "super")) { + $consulta_usuarios = $consulta_usuarios->where('subvendedor_id', Auth::user()->id); + } + $consulta_usuarios = $consulta_usuarios ->with('rol', 'saldo') ->orderBy('id', 'DESC') ->withCount('historiales_venta') ->paginate($this->entradas); - - - - - - - - - if (!empty($this->buscar_servicio)) { $this->consulta_tarifas = Tarifas::where('rol_id', $this->rol_usuario)->with([ 'servicio' => function ($query) { @@ -153,10 +149,10 @@ class ShowUsuarios extends Component } if (Auth::user()->rol->nombre == "super") { - $this->roles = Role::get(); + } else if (Auth::user()->subvendedor) { + $this->roles = Role::where('subvendedor_id', Auth::user()->id)->get(); } else { - $this->roles = Role::where('nombre', '=', 'distribuidor')->get(); } @@ -181,6 +177,7 @@ class ShowUsuarios extends Component $crear->email = $this->email; $crear->password = Hash::make($this->password); $crear->rol_id = $this->rol; + $crear->subvendedor_id = Auth::user()->rol->nombre == "super" ? null : Auth::user()->id; $crear->save(); $saldo = new saldo; diff --git a/database/migrations/2023_10_09_145454_add_utilidad_to_tarifas.php b/database/migrations/2023_10_09_145454_add_utilidad_to_tarifas.php index b47db1b..8ef0eb1 100755 --- a/database/migrations/2023_10_09_145454_add_utilidad_to_tarifas.php +++ b/database/migrations/2023_10_09_145454_add_utilidad_to_tarifas.php @@ -6,11 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - * - * @return void - */ public function up() { Schema::table('tarifas', function (Blueprint $table) { @@ -18,11 +13,6 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ public function down() { Schema::table('tarifas', function (Blueprint $table) { diff --git a/database/migrations/2025_06_16_181407_add_subvendedor_id_to_tarifas_table.php b/database/migrations/2025_06_16_181407_add_subvendedor_id_to_tarifas_table.php new file mode 100644 index 0000000..33d1982 --- /dev/null +++ b/database/migrations/2025_06_16_181407_add_subvendedor_id_to_tarifas_table.php @@ -0,0 +1,22 @@ +string('subvendedor_id')->nullable()->after('utilidad'); + }); + } + + public function down() + { + Schema::table('tarifas', function (Blueprint $table) { + $table->dropColumn('subvendedor_id'); + }); + } +}; diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 8dbb0f7..5111bf9 100755 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -107,33 +107,32 @@ - @if (auth()->user()->rol->nombre == 'super' || - auth()->user()->rol->nombre == 'administrador' || - auth()->user()->rol->nombre == 'editor') + @if (auth()->user()->subvendedor || auth()->user()->rol->nombre == 'super' || auth()->user()->rol->nombre == 'administrador' || auth()->user()->rol->nombre == 'editor')