From 83ba4f71da190db3e0d09a86d8c7ead636bb82d5 Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Thu, 26 Jun 2025 11:05:53 -0700 Subject: [PATCH] update --- app/Http/Livewire/ShowTarifas.php | 156 +++++++++++++++++- app/Models/TarifaPromo.php | 2 +- .../views/livewire/show-planes.blade.php | 12 +- .../views/livewire/show-tarifas.blade.php | 102 +++++++++++- 4 files changed, 250 insertions(+), 22 deletions(-) diff --git a/app/Http/Livewire/ShowTarifas.php b/app/Http/Livewire/ShowTarifas.php index 95a1efa..6f54749 100644 --- a/app/Http/Livewire/ShowTarifas.php +++ b/app/Http/Livewire/ShowTarifas.php @@ -20,6 +20,8 @@ class ShowTarifas extends Component // Modales public $modTarifas = false; public $modTarifasPromo = false; + public $editarTarifa = false; + public $editarTarifaPromo = false; public $tarifas; public $planes; @@ -31,6 +33,8 @@ class ShowTarifas extends Component public $estado = true; public $valorBase; + public $tarifa_id; + // Tarifa datos public $servicio_id; public $plan_id; @@ -45,6 +49,7 @@ class ShowTarifas extends Component public function render() { $this->planes = Tarifas::where('servicio_id', $this->servicio_id)->where('rol_id', Auth::user()->rol->id)->where('estado', 'activo')->get(); + $this->promociones = TarifaPromo::where('promocion_id', $this->promocion_id)->where('rol_id', Auth::user()->rol->id)->where('visible', 'activo')->get(); if ($this->modTarifas) { $this->tarifas = Tarifas::where('servicio_id', $this->servicio_id)->where('rol_id', $this->rol_id)->where('estado', 'activo')->get(); @@ -52,7 +57,6 @@ class ShowTarifas extends Component if ($this->modTarifasPromo) { $this->tarifas = TarifaPromo::where('promocion_id', $this->promocion_id)->where('rol_id', $this->rol_id)->where('visible', 'activo')->get(); } - $this->promociones = TarifaPromo::where('promocion_id', $this->promocion_id)->where('rol_id', Auth::user()->rol->id)->where('visible', 'activo')->get(); return view('livewire.show-tarifas', [ 'roles' => Role::where('subvendedor_id', auth()->user()->id)->get(), @@ -151,7 +155,6 @@ class ShowTarifas extends Component $this->alert('success', '¡Tarifas creada correctamente!', [ 'position' => 'top' ]); - } else { $this->alert('error', 'Error inesperado', [ 'position' => 'top' @@ -202,7 +205,6 @@ class ShowTarifas extends Component $this->alert('success', '¡Tarifas creada correctamente!', [ 'position' => 'top' ]); - } else { $this->alert('error', 'Error inesperado', [ 'position' => 'top' @@ -212,16 +214,162 @@ class ShowTarifas extends Component } } - public function limpiarInputs(){ + public function editarTarifa($id) + { + $tarifa = Tarifas::find($id); + if ($tarifa) { + $this->editarTarifa = true; + $this->servicio_id = $tarifa->servicio_id; + $this->precio = $tarifa->valor; + $this->utilidad = $tarifa->utilidad; + $this->estado = $tarifa->estado == 'activo'; + $this->plan_id = $tarifa->plan_id; + $this->rol_id = $tarifa->rol_id; + $this->valorBase = $tarifa->valor - $tarifa->utilidad; + $this->tarifa_id = $tarifa->id; + } else { + $this->tarifa_id = null; + + $this->alert('error', 'Tarifa no encontrada', [ + 'position' => 'top' + ]); + } + } + + public function editarTarifaPromo($id) + { + $tarifa = TarifaPromo::find($id); + if ($tarifa) { + $this->editarTarifaPromo = true; + $this->promocion_id = $tarifa->promocion_id; + $this->precio = $tarifa->precio; + $this->utilidad = $tarifa->utilidad; + $this->estado = $tarifa->visible == 'activo'; + $this->plan_id = $tarifa->plan_id; + $this->rol_id = $tarifa->rol_id; + $this->valorBase = $tarifa->precio - $tarifa->utilidad; + $this->tarifa_id = $tarifa->id; + } else { + $this->tarifa_id = null; + + $this->alert('error', 'Tarifa no encontrada', [ + 'position' => 'top' + ]); + } + } + + public function actualizarTarifa() + { + $tarifa = Tarifas::find($this->tarifa_id); + + if (!$tarifa) { + $this->alert('error', 'Tarifa no encontrada', [ + 'position' => 'top' + ]); + return; + } + + $this->validate([ + 'precio' => 'required|numeric', + 'utilidad' => 'required', + 'estado' => 'required', + 'rol_id' => 'required', + ], [ + 'precio.required' => 'El campo precio es obligatorio', + 'utilidad.required' => 'El campo utilidad es obligatorio', + 'estado.required' => 'El campo estado es obligatorio', + 'rol_id.required' => 'El campo rol es obligatorio', + ]); + + if ($this->precio < $this->valorBase) { + $this->alert('error', 'El precio no puede ser menor al valor base', [ + 'position' => 'top' + ]); + return; + } + + $tarifa->update([ + 'valor' => $this->precio, + 'utilidad' => $this->utilidad, + 'estado' => $this->estado ? 'activo' : 'inactivo', + 'rol_id' => $this->rol_id, + ]); + + $this->limpiarEditarInputs(); + + $this->alert('success', '¡Tarifa actualizada correctamente!', [ + 'position' => 'top' + ]); + } + public function actualizarTarifaPromo() + { + $tarifa = TarifaPromo::find($this->tarifa_id); + + if (!$tarifa) { + $this->alert('error', 'Tarifa no encontrada', [ + 'position' => 'top' + ]); + return; + } + + $this->validate([ + 'precio' => 'required|numeric', + 'utilidad' => 'required', + 'estado' => 'required', + 'rol_id' => 'required', + ], [ + 'precio.required' => 'El campo precio es obligatorio', + 'utilidad.required' => 'El campo utilidad es obligatorio', + 'estado.required' => 'El campo estado es obligatorio', + 'rol_id.required' => 'El campo rol es obligatorio', + ]); + + if ($this->precio < $this->valorBase) { + $this->alert('error', 'El precio no puede ser menor al valor base', [ + 'position' => 'top' + ]); + return; + } + + $tarifa->update([ + 'precio' => $this->precio, + 'utilidad' => $this->utilidad, + 'visible' => $this->estado ? 'activo' : 'inactivo', + 'rol_id' => $this->rol_id, + ]); + + $this->limpiarEditarInputs(); + + $this->alert('success', '¡Tarifa actualizada correctamente!', [ + 'position' => 'top' + ]); + } + + public function limpiarEditarInputs() + { + $this->editarTarifa = false; + $this->editarTarifaPromo = false; + + $this->valorBase = null; + $this->estado = true; + $this->tarifa_id = null; + } + public function limpiarInputs() + { $this->modTarifas = false; + $this->modTarifasPromo = false; + $this->editarTarifa = false; + $this->editarTarifaPromo = false; $this->servicio_id = null; $this->promocion_id = null; + $this->precio = null; $this->utilidad = null; $this->estado = true; $this->plan_id = null; $this->rol_id = null; $this->valorBase = null; + $this->tarifa_id = null; } } diff --git a/app/Models/TarifaPromo.php b/app/Models/TarifaPromo.php index d18b664..480cc0e 100755 --- a/app/Models/TarifaPromo.php +++ b/app/Models/TarifaPromo.php @@ -10,10 +10,10 @@ class TarifaPromo extends Model use HasFactory; protected $fillable = [ + 'precio', 'utilidad', 'promocion_id', 'rol_id', - 'precio', 'visible', 'subvendedor_id', ]; diff --git a/resources/views/livewire/show-planes.blade.php b/resources/views/livewire/show-planes.blade.php index 20399dc..8caf882 100755 --- a/resources/views/livewire/show-planes.blade.php +++ b/resources/views/livewire/show-planes.blade.php @@ -793,8 +793,7 @@
- +
@@ -900,22 +899,17 @@
- +
- +
@endif - -
diff --git a/resources/views/livewire/show-tarifas.blade.php b/resources/views/livewire/show-tarifas.blade.php index 0768d95..08d1198 100644 --- a/resources/views/livewire/show-tarifas.blade.php +++ b/resources/views/livewire/show-tarifas.blade.php @@ -1,8 +1,10 @@
-
+
@@ -46,7 +48,7 @@ modTarifasPromo: @entangle('modTarifasPromo'),
-
+
+ + @foreach ($roles as $rol) + + @endforeach + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+ + + +
+
+
+
+ +
+
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+ + + +
+
+
+
+