From 41605dd83f143a2121176281a0be7ef4436bffae Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 7 Oct 2023 17:31:35 -0500 Subject: [PATCH] log general --- app/Http/Controllers/MenuController.php | 3 + app/Http/Livewire/ShowLogGeneral.php | 20 +++++ app/Http/Livewire/ShowPlanes.php | 1 + app/Http/Livewire/ShowServicios.php | 74 +++++++++---------- app/Http/Livewire/ShowUsuarios.php | 43 +++++------ app/Models/Log_general.php | 23 ++++++ ...10_07_155444_create_log_generals_table.php | 33 +++++++++ resources/views/layouts/navigation.blade.php | 1 + .../views/livewire/show-clientes.blade.php | 3 +- .../views/livewire/show-log-general.blade.php | 28 +++++++ resources/views/menu/log_general.blade.php | 7 ++ routes/web.php | 1 + 12 files changed, 174 insertions(+), 63 deletions(-) create mode 100644 app/Http/Livewire/ShowLogGeneral.php create mode 100644 app/Models/Log_general.php create mode 100644 database/migrations/2023_10_07_155444_create_log_generals_table.php create mode 100644 resources/views/livewire/show-log-general.blade.php create mode 100644 resources/views/menu/log_general.blade.php diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index 5afe2e9..f560e07 100644 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -79,6 +79,9 @@ class MenuController extends Controller public function showLogRecargas(){ return view('menu/logs_recargas'); } + public function showLogGeneral(){ + return view('menu/log_general'); + } public function showroles(){ return view('menu/roles'); diff --git a/app/Http/Livewire/ShowLogGeneral.php b/app/Http/Livewire/ShowLogGeneral.php new file mode 100644 index 0000000..bd9e331 --- /dev/null +++ b/app/Http/Livewire/ShowLogGeneral.php @@ -0,0 +1,20 @@ +paginate($this->entradas); + + return view('livewire.show-log-general', [ + 'logs' => $logs + ]); + } +} diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index b40762c..5a76bf5 100644 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -5,6 +5,7 @@ namespace App\Http\Livewire; use App\Models\Cuentas; use App\Models\Historiale; use App\Models\Historial_cuenta; +use App\Models\Log_general; use App\Models\Role; use App\Models\Servicio; use App\Models\Tarifas; diff --git a/app/Http/Livewire/ShowServicios.php b/app/Http/Livewire/ShowServicios.php index 97e3c0d..fefc880 100644 --- a/app/Http/Livewire/ShowServicios.php +++ b/app/Http/Livewire/ShowServicios.php @@ -8,6 +8,7 @@ use App\Models\Cuentas; use App\Models\Role; use App\Models\Historial_cuenta; use App\Models\Historiale; +use App\Models\Log_general; use App\Models\Promociones; use App\Models\Saldo; use App\Models\Servicio; @@ -89,7 +90,6 @@ class ShowServicios extends Component $this->nombre_tarjetaPlan = $this->usuario_actual->name; $this->email_tarjetaPlan = $this->usuario_actual->email; $this->celular_tarjetaPlan = $this->usuario_actual->celular; - } if (!empty($this->tarifa_id)) { $this->paquetesDisponibles(); @@ -124,7 +124,7 @@ class ShowServicios extends Component ->first(); $this->servicio_t = $this->tarifas->servicio; - + //Servicio por pantallas $this->cuentas_creadas = Cuentas::whereDate('inicio', '>=', $this->fecha) ->where('servicio_id', $this->servicio_t->id) @@ -139,10 +139,10 @@ class ShowServicios extends Component - //$prueba1 = $this->cuentas_creadas->count() * $this->servicio_t->pantallas ; - //$prueba2 = $this->cuentas_tomadas ; + //$prueba1 = $this->cuentas_creadas->count() * $this->servicio_t->pantallas ; + //$prueba2 = $this->cuentas_tomadas ; - //dd($prueba1, $prueba2 , $prueba1-$prueba2); + //dd($prueba1, $prueba2 , $prueba1-$prueba2); $this->servicio_id = $this->servicio_t->id; $this->tarifa_id = $id; @@ -179,8 +179,6 @@ class ShowServicios extends Component $this->tarjetaPlan = true; - - } public function paquetesDisponibles() { @@ -193,7 +191,6 @@ class ShowServicios extends Component if ($restantes_completas <= 10) { //$this->notificacionPocas($this->servicio_t,$restantes_completas); } - } else { $cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan; @@ -210,7 +207,6 @@ class ShowServicios extends Component if ($restantes <= 10) { //$this->notificacionPocas($this->servicio_t,$restantes); } - } } @@ -226,7 +222,6 @@ class ShowServicios extends Component ]; Notification::send($user, (new licencias($notificacion))); - } /* ---------------- Btn Comprar ---------------- */ @@ -265,7 +260,10 @@ class ShowServicios extends Component $historial->nombre_cliente = $this->nombre_tarjetaPlan; $historial->save(); + + $pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first(); + $servicioNombre = $pantallas->servicio->nombre; $servicio_id = $pantallas->servicio_id; $pantalla_servicio_completa = $pantallas->servicio->completa; $pantalla_servicio = $pantallas->servicio->pantallas; @@ -276,7 +274,6 @@ class ShowServicios extends Component $suma = $pantalla_servicio - $cantidad_solicitada; $cantidad_necesaria = $this->cantidad_tarjetaPlan; $cuenta = Cuentas::where('servicio_id', $this->servicio_id)->whereDate('inicio', '>=', $this->fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', $suma)->get(); - } elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) { //Cuentas completas $cantidad_necesaria = $this->cantidad_tarjetaPlan; @@ -287,7 +284,6 @@ class ShowServicios extends Component $suma2 = $pantalla_servicio - $pantallas; $cantidad_necesaria = $this->cantidad_tarjetaPlan; $cuenta = Cuentas::where('servicio_id', $this->servicio_id)->whereDate('inicio', '>=', $this->fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', $suma2)->get(); - } else { $cuenta = null; $cantidad_necesaria = null; @@ -296,7 +292,9 @@ class ShowServicios extends Component for ($h = 0; $h < (int) $cantidad_necesaria; $h++) { //dd($h); if (!empty($cuenta)) { - + + $cuentasMostar = ''; + $perfil = $cuenta[$h]->historiales_count; for ($y = 0; $y < (int) $pantallas; $y++) { @@ -307,14 +305,15 @@ class ShowServicios extends Component $historial_cuenta->perfil = (int) $perfil + (int) $y + 1; $historial_cuenta->save(); + if ($cuenta[$h]->correo != $cuentasMostar) { + $cuentasMostar .= $cuenta[$h]->correo . ' '; + } } - } else { $this->alert('warning', 'No hay cuentas disponibles!', [ 'position' => 'top' ]); } - } //dd($historial->cuentas); $descuento = Saldo::where('usuario_id', Auth::user()->id)->first(); @@ -326,6 +325,11 @@ class ShowServicios extends Component if ($cobro) { $historial->update(['estado' => 'activo']); + $logsGeneral = new Log_general(); + $logsGeneral->user_id = Auth::user()->id; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor; + $logsGeneral->save(); + $this->credenciales($historial); } else { $this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [ @@ -336,7 +340,6 @@ class ShowServicios extends Component $this->tarjetaPlan = false; $this->cantidad_tarjetaPlan = 1; - } public function credenciales($historial) @@ -375,7 +378,6 @@ class ShowServicios extends Component $recipients = '+57' . $this->celular_tarjetaPlan; $this->sendMessage($message, $recipients); - } public function sendMessage($message, $recipients) @@ -385,21 +387,23 @@ class ShowServicios extends Component $curl = curl_init(); - curl_setopt_array($curl, array( - CURLOPT_URL => "https://api.labsmobile.com/json/send", - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => "", - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 30, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => "POST", - CURLOPT_POSTFIELDS => '{"message":"' . $message . '", "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}', - CURLOPT_HTTPHEADER => array( - "Authorization: Basic " . $auth_basic, - "Cache-Control: no-cache", - "Content-Type: application/json" - ), - ) + curl_setopt_array( + $curl, + array( + CURLOPT_URL => "https://api.labsmobile.com/json/send", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => '{"message":"' . $message . '", "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}', + CURLOPT_HTTPHEADER => array( + "Authorization: Basic " . $auth_basic, + "Cache-Control: no-cache", + "Content-Type: application/json" + ), + ) ); $response = curl_exec($curl); @@ -412,7 +416,6 @@ class ShowServicios extends Component $this->alert('warning', 'Error enviando SMS!' . $err, [ 'position' => 'top' ]); - } else { if (!empty(json_decode($response)->subid)) { $this->alert('success', 'Credenciales enviadas por Email y SMS! ' . json_decode($response)->subid, [ @@ -423,15 +426,12 @@ class ShowServicios extends Component 'position' => 'top' ]); } - } } public function consultaTarifa($servicio1) { - $this->servicio = $servicio1; $this->verServ = false; } - -} \ No newline at end of file +} diff --git a/app/Http/Livewire/ShowUsuarios.php b/app/Http/Livewire/ShowUsuarios.php index b69c1da..bcac2e9 100644 --- a/app/Http/Livewire/ShowUsuarios.php +++ b/app/Http/Livewire/ShowUsuarios.php @@ -3,6 +3,7 @@ namespace App\Http\Livewire; use App\Models\Historiale; +use App\Models\Log_general; use App\Models\Promociones; use App\Models\recarga; use App\Models\Role; @@ -90,16 +91,17 @@ class ShowUsuarios extends Component public function render() { + $consulta_tarifas = TarifaPromo::take(1); - $consulta_usuarios = User::where('name', 'LIKE', '%' . $this->buscar . '%')->orWhere('email', 'LIKE', '%' . $this->buscar . '%')->with('rol', 'saldo')->orderBy('id','DESC')->withCount('historiales_venta')->paginate(15); + $consulta_usuarios = User::where('name', 'LIKE', '%' . $this->buscar . '%')->orWhere('email', 'LIKE', '%' . $this->buscar . '%')->with('rol', 'saldo')->orderBy('id', 'DESC')->withCount('historiales_venta')->paginate(15); if (!empty($this->buscar_servicio)) { $this->consulta_tarifas = Tarifas::where('rol_id', $this->rol_usuario)->with([ 'servicio' => function ($query) { - $query->Where('nombre', 'LIKE', '%' . $this->buscar_servicio . '%'); } + $query->Where('nombre', 'LIKE', '%' . $this->buscar_servicio . '%'); + } ])->get(); - } if (!empty($this->buscar_promo)) { @@ -154,7 +156,6 @@ class ShowUsuarios extends Component 'position' => 'top' ]); } - } //CONSULTAR SALDO// @@ -173,7 +174,6 @@ class ShowUsuarios extends Component $this->saldo_actual = $this->consulta_saldo->valor; $this->modalSaldo = true; - } public function saldodesc($user_saldo) { @@ -190,7 +190,6 @@ class ShowUsuarios extends Component $this->saldo_actual = $this->consulta_saldo->valor; $this->modalSaldoDesc = true; - } public function addSaldo() @@ -215,7 +214,6 @@ class ShowUsuarios extends Component $this->limpiarSaldo(); - } public function descontar() @@ -240,7 +238,6 @@ class ShowUsuarios extends Component $this->limpiarSaldo(); - } public function editar($id) @@ -253,7 +250,6 @@ class ShowUsuarios extends Component $this->rol_edit = $consulta->rol_id; $this->editar = true; - } public function actualizar() { @@ -370,7 +366,6 @@ class ShowUsuarios extends Component $this->alert('warning', 'Este usuario ya tiene esta promocion!', [ 'position' => 'top' ]); - } else { $usuarioPromo = new Usuario_promo(); $usuarioPromo->precio = $this->precioPromoGestion; @@ -390,7 +385,6 @@ class ShowUsuarios extends Component } $this->consulta_usuarioPromo = Usuario_promo::join('promociones', 'promocion_id', '=', 'promociones.id')->where('usuario_id', $this->usuarioGestion_id)->get(['usuario_promos.id', 'nombre', 'usuario_promos.visible', 'usuario_promos.precio']); - } public function eliminarUsuarioPromo($id) @@ -433,18 +427,22 @@ class ShowUsuarios extends Component } public function confirmed() - { - // Paso 1: Obtener el id del usuario eliminado -$usuarioEliminado = User::where('name', 'usuarioEliminado')->value('id'); - -// Paso 2: Actualizar los registros en la base de datos - $consultaHistorial=Historiale::where('vendedor_id', $this->delete_user) - ->update(['vendedor_id' => $usuarioEliminado,'cliente_id'=>$usuarioEliminado]); + { + // Paso 1: Obtener el id del usuario eliminado + $usuarioEliminado = User::where('name', 'usuarioEliminado')->value('id'); + // Paso 2: Actualizar los registros en la base de datos + $consultaHistorial = Historiale::where('vendedor_id', $this->delete_user) + ->update(['vendedor_id' => $usuarioEliminado, 'cliente_id' => $usuarioEliminado]); $user = User::find($this->delete_user); - $user->delete(); + $logsGeneral = new Log_general(); + $logsGeneral->user_id = Auth::user()->id; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha eliminado al usuario ' . $user->name . ' - ' . $user->email; + $logsGeneral->save(); + + $user->delete(); } public function editarPassword($id) @@ -498,7 +496,7 @@ $usuarioEliminado = User::where('name', 'usuarioEliminado')->value('id'); { $this->valor_recargar = null; $this->modalSaldo = false; - $this->modalSaldoDesc = false; + $this->modalSaldoDesc = false; } /* ------------- ACTUALIZAR ------------- */ @@ -519,7 +517,6 @@ $usuarioEliminado = User::where('name', 'usuarioEliminado')->value('id'); $this->alert('warning', 'Esta tarifa ya existe!', [ 'position' => 'top' ]); - } else { $tarifa = new TarifaPromo; $tarifa->precio = $this->precio_modTarifas; @@ -544,6 +541,4 @@ $usuarioEliminado = User::where('name', 'usuarioEliminado')->value('id'); 'position' => 'top' ]); } - - -} \ No newline at end of file +} diff --git a/app/Models/Log_general.php b/app/Models/Log_general.php new file mode 100644 index 0000000..ca10e5c --- /dev/null +++ b/app/Models/Log_general.php @@ -0,0 +1,23 @@ +belongsTo(User::class); + } +} diff --git a/database/migrations/2023_10_07_155444_create_log_generals_table.php b/database/migrations/2023_10_07_155444_create_log_generals_table.php new file mode 100644 index 0000000..ae81b9d --- /dev/null +++ b/database/migrations/2023_10_07_155444_create_log_generals_table.php @@ -0,0 +1,33 @@ +id(); + $table->foreignId('user_id')->constrained(); + $table->text('detalle'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('log_general'); + } +}; diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 5d25419..6cb4450 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -107,6 +107,7 @@ x-data="{ menuG:false}" Gestión Roles Gestión Servicios Gestión Categorias + Log general Logs cuentas Logs recargas Utilidades diff --git a/resources/views/livewire/show-clientes.blade.php b/resources/views/livewire/show-clientes.blade.php index de0ca34..27a8272 100644 --- a/resources/views/livewire/show-clientes.blade.php +++ b/resources/views/livewire/show-clientes.blade.php @@ -11,8 +11,7 @@ {{-- Buscador --}} -
+
+
+ + + + + + + Usuario + Detalle + Fecha + + + + @foreach ($logs as $log) + + {{ $log->user->name ?? '' }} + {{ $log->detalle ?? '' }} + {{ $log->created_at->format('d M Y h:m a') ?? '' }} + + @endforeach + + + {{ $logs->links() }} + + +
+
diff --git a/resources/views/menu/log_general.blade.php b/resources/views/menu/log_general.blade.php new file mode 100644 index 0000000..e8d030e --- /dev/null +++ b/resources/views/menu/log_general.blade.php @@ -0,0 +1,7 @@ + +
+ +
+ + @include('layouts.footer') +
\ No newline at end of file diff --git a/routes/web.php b/routes/web.php index be89a78..3299e91 100644 --- a/routes/web.php +++ b/routes/web.php @@ -73,6 +73,7 @@ Route::middleware(["auth", "solo_usuario_administrador"])->group(function () { Route::any('/logs',[MenuController::class,'showlogs' ])->name('logs'); Route::get('/import',[MenuController::class,'showimport' ])->name('import'); Route::any('/logs-recargas',[MenuController::class,'showLogRecargas' ])->name('logsRecargas'); + Route::any('/log-general',[MenuController::class,'showLogGeneral' ])->name('logGeneral'); Route::any('/roles',[MenuController::class,'showroles' ])->name('roles'); Route::get('/utilidades',[MenuController::class,'showutilidad' ])->name('utilidades'); });