log general

This commit is contained in:
Felipe
2023-10-07 17:31:35 -05:00
parent 3d3a9cca5e
commit 41605dd83f
12 changed files with 174 additions and 63 deletions
+3
View File
@@ -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');
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Livewire;
use App\Models\Log_general;
use Livewire\Component;
class ShowLogGeneral extends Component
{
public $entradas;
public function render()
{
$logs = Log_general::orderby('id', 'desc')->paginate($this->entradas);
return view('livewire.show-log-general', [
'logs' => $logs
]);
}
}
+1
View File
@@ -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;
+37 -37
View File
@@ -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;
}
}
}
+19 -24
View File
@@ -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'
]);
}
}
}