From accc50965228e8fa543d42c480524c4630790f72 Mon Sep 17 00:00:00 2001 From: Felipe Date: Fri, 1 Mar 2024 10:46:35 -0500 Subject: [PATCH] porfavor hacer la migracion --- app/Http/Livewire/ShowLogGeneral.php | 9 +- app/Http/Livewire/ShowLogHistorial.php | 14 +- app/Http/Livewire/ShowPlanes.php | 22 +++ ..._01_095422_create_log_historials_table.php | 27 +++ .../livewire/show-log-historial.blade.php | 40 ++-- .../views/livewire/show-usuarios.blade.php | 184 +++++++++--------- routes/web.php | 1 - 7 files changed, 186 insertions(+), 111 deletions(-) create mode 100644 database/migrations/2024_03_01_095422_create_log_historials_table.php diff --git a/app/Http/Livewire/ShowLogGeneral.php b/app/Http/Livewire/ShowLogGeneral.php index de48dd8..1465880 100755 --- a/app/Http/Livewire/ShowLogGeneral.php +++ b/app/Http/Livewire/ShowLogGeneral.php @@ -10,8 +10,8 @@ class ShowLogGeneral extends Component public $entradas; public $buscar; - public $filtro_fecha; - + public $filtro_fecha; + public function render() { $query = Log_general::query(); @@ -23,11 +23,12 @@ class ShowLogGeneral extends Component if ($this->filtro_fecha) { $query->whereDate('created_at', $this->filtro_fecha); } - - $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); + + $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); return view('livewire.show-log-general', [ 'logs' => $logs ]); } } + diff --git a/app/Http/Livewire/ShowLogHistorial.php b/app/Http/Livewire/ShowLogHistorial.php index 993c48a..c36d27d 100644 --- a/app/Http/Livewire/ShowLogHistorial.php +++ b/app/Http/Livewire/ShowLogHistorial.php @@ -4,6 +4,7 @@ namespace App\Http\Livewire; use App\Models\Log_general; use App\Models\Log_historial; +use App\Models\User; use Livewire\Component; class ShowLogHistorial extends Component @@ -13,9 +14,11 @@ class ShowLogHistorial extends Component public $buscar; public $filtro_fecha; + public $user_id; + public function render() { - $query = Log_general::query(); + $query = Log_historial::query(); if ($this->buscar) { $query->where('detalle', 'like', '%' . $this->buscar . '%'); @@ -25,10 +28,17 @@ class ShowLogHistorial extends Component $query->whereDate('created_at', $this->filtro_fecha); } + if ($this->user_id) { + $query->where('user_id', $this->user_id); + } + $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); + $users = User::orderBy('name')->get(); + return view('livewire.show-log-historial', [ - 'logs' => $logs + 'logs' => $logs, + 'users' => $users ]); } } diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index 2897cd5..9c2b25e 100755 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -6,6 +6,7 @@ use App\Models\Cuentas; use App\Models\Historiale; use App\Models\Historial_cuenta; use App\Models\Log_general; +use App\Models\Log_historial; use App\Models\Notificacion; use App\Models\Pendientes; use App\Models\Role; @@ -280,6 +281,11 @@ class ShowPlanes extends Component $cuenta->estado = $this->estado; $cuenta->save(); + Log_historial::create([ + 'user_id' => Auth::user()->id, + 'detalle' => 'El usuario ha creado la cuenta ' . $cuenta->correo + ]); + if ($this->estado === 'activo') { $servicioPantallas = Servicio::find($this->servicio_newCuenta)->pantallas; @@ -487,8 +493,24 @@ class ShowPlanes extends Component public function eliminarCuentas() { + $cuentas = Cuentas::whereIn('id', $this->delete_1)->get(); + + if ($cuentas) { + forEach ($cuentas as $cuenta) { + Log_historial::create([ + 'user_id' => Auth::user()->id, + 'detalle' => 'El usuario ha eliminado la cuenta ' . $cuenta->correo + ]); + } + } $consulta_cuentas = Cuentas::whereIn('id', $this->delete_1)->delete(); + + $this->alert('success', 'Cuentas eliminadas correctamente!', [ + 'position' => 'top' + ]); + + $this->delete_1 = []; } public function openAdd() diff --git a/database/migrations/2024_03_01_095422_create_log_historials_table.php b/database/migrations/2024_03_01_095422_create_log_historials_table.php new file mode 100644 index 0000000..ef84be7 --- /dev/null +++ b/database/migrations/2024_03_01_095422_create_log_historials_table.php @@ -0,0 +1,27 @@ +id(); + + $table->text('detalle'); + $table->unsignedBigInteger('user_id'); + + $table->timestamps(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + } + + public function down() + { + Schema::dropIfExists('log_historial'); + } +}; diff --git a/resources/views/livewire/show-log-historial.blade.php b/resources/views/livewire/show-log-historial.blade.php index eec8a24..2efd220 100644 --- a/resources/views/livewire/show-log-historial.blade.php +++ b/resources/views/livewire/show-log-historial.blade.php @@ -1,28 +1,46 @@
-
-
+
+
- - + + Log historial
- - +
-
- + +
+
- {{-- + Usuario @@ -42,6 +60,6 @@ {{ $logs->links() }} - --}} +
diff --git a/resources/views/livewire/show-usuarios.blade.php b/resources/views/livewire/show-usuarios.blade.php index ac8db5e..19c5a86 100755 --- a/resources/views/livewire/show-usuarios.blade.php +++ b/resources/views/livewire/show-usuarios.blade.php @@ -6,9 +6,9 @@ gestionPromo: @entangle('gestionPromo'), modalPassword: @entangle('modalPassword'), modTarifas: @entangle('modTarifas'), - modalSaldoDesc:@entangle('modalSaldoDesc'), + modalSaldoDesc: @entangle('modalSaldoDesc'), }" class="h-full w-full md:my-2"> -
@@ -18,43 +18,34 @@
-
+
-
+
- + - + Usuario
@if (auth()->user()->rol->nombre !== 'administrador' && auth()->user()->rol->nombre !== 'editor') - Añadir usuario - - - - - Mod. - tarifas promos. - - - - - - @endif -
+ Añadir + usuario + + + + + Mod. + tarifas promos. + + + + + + @endif +
@@ -62,13 +53,12 @@ {{-- Buscar --}}
- +
{{-- -Tabla usuarios - --}}
- +
@@ -119,8 +109,10 @@ - + @@ -253,13 +247,13 @@ + xmlns:svgjs="http://svgjs.com/svgjs" class="w-6 cursor-pointer" x="0" + y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512" + xml:space="preserve"> - + Utilidad

-
@@ -376,13 +372,13 @@ + xmlns:svgjs="http://svgjs.com/svgjs" class="w-6 cursor-pointer" x="0" + y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512" + xml:space="preserve"> - + - {{-- Modal quitar saldo --}} -
-
-
-
- Descontar saldo -
-
-
- Saldo actual: $

{{ number_format($saldo_actual) }}

-
-
- Monto a descontar -
-
- + {{-- Modal quitar saldo --}} +
+
+
+
+ Descontar saldo +
+
+
+ Saldo actual: $

{{ number_format($saldo_actual) }}

+
+
+ Monto a descontar +
+
+ -
Tu valor total seria: $

- {{ $saldo_actual - $valor_recargar }} +

Tu valor total seria: $

+ {{ $saldo_actual - $valor_recargar }} -

-
-
+

+
+
-
- - - - - - -
+
+ + + + + + +
-
+
-
-
-
+
+
+
{{-- Modal tarifas --}} @@ -715,7 +711,9 @@

Utilidad

- + @@ -748,8 +746,8 @@ + r="10" data-original="#e63946" class=""> + group(function () { Route::get('/promociones', [MenuController::class, 'showpromociones'])->name('promociones'); Route::get('/wompi/{monto}', [MenuController::class, 'showwompi'])->name('wompi'); Route::any('/logs', [MenuController::class, 'showlogs'])->name('logs'); - Route::any('/log-general', [MenuController::class, 'showLogGeneral'])->name('logGeneral'); }); // Editores
Nombre