diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index ea8e1b2..6434f64 100755 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -29,7 +29,7 @@ use AshAllenDesign\ShortURL\Facades\ShortURL; class MenuController extends Controller { - + public function showwelcome(){ $consulta_promociones = slider::get(); @@ -37,7 +37,7 @@ class MenuController extends Controller 'promociones' => $consulta_promociones, ]); } - + public function showclientes(){ return view('menu/clientes'); } @@ -58,7 +58,7 @@ class MenuController extends Controller } public function showconfiguracion(){ return view('menu/configuracion'); - } + } public function showplanes(){ return view('menu/planes'); } @@ -85,12 +85,15 @@ class MenuController extends Controller public function showLogGeneral(){ return view('menu/log_general'); } + public function showLogHistorial(){ + return view('menu/log_historial'); + } public function showroles(){ return view('menu/roles'); } - + public function pay($estado){ return view('menu/order',[ @@ -98,14 +101,14 @@ class MenuController extends Controller ]); } - - + + public function showcredenciales(Request $request){ $credencial = Crypt::decryptString($request->id); $consulta_historiales = Historiale::where('id',$credencial)->with('cuentas')->first(); $msj = Configuracione::orderby('id','desc')->select('msj_compra','msj_wp','clave_1','clave_2','clave_3','clave_4','clave_5','clave_6','iptv')->first(); - + return view('menu/credenciales',[ 'consulta' =>$consulta_historiales, 'msj' => $msj, @@ -114,14 +117,14 @@ class MenuController extends Controller public function order( Request $request ){ - + $payment_id= $request->get('payment_id'); $response = Http::get("https://api.mercadopago.com/v1/payments/$payment_id" . "?access_token=APP_USR-7353579040069171-102716-58fdd1f52a604a1febd18a638227f603-260361439"); $response = json_decode($response); - + $status = $response->status; if ($status == 'approved') { - + $metodo_pago = $response->payment_method_id; $referencia = $response->external_reference; $consulta = recarga::where('reference',$referencia)->where('status',$status)->exists(); @@ -129,27 +132,27 @@ class MenuController extends Controller $update_recargas = recarga::where('reference',$referencia)->update(['status' => $status,'payment_method_id'=> $metodo_pago]); $recarga = recarga::where('reference',$referencia)->with('usuario')->first(); $usuario= $recarga->usuario; - + $saldo = $usuario->saldo; $saldo_anterior = $saldo->valor; $rol = $usuario->rol->nombre; $monto = $recarga->valor_recarga; - + if (!empty($saldo_anterior)) { - + $valor= (float)$saldo_anterior + (float)$monto ; $nuevo_saldo = $saldo->update(['valor'=>$valor]); }else{ $nuevo_saldo = $saldo->update(['valor'=>$monto]); } - + } $estado= 'aprobado'; - + }elseif($status == 'pending'){ - - + + $metodo_pago = $response->payment_method_id; $referencia = $response->external_reference; $update_recargas = recarga::where('reference',$referencia)->update(['status' => $status,'payment_method_id'=> $metodo_pago]); @@ -157,8 +160,8 @@ class MenuController extends Controller $estado= 'pendiente'; }else{ - - + + $metodo_pago = $response->payment_method_id; $referencia = $response->external_reference; $update_recargas = recarga::where('reference',$referencia)->update(['status' => $status,'payment_method_id'=> $metodo_pago]); @@ -167,15 +170,15 @@ class MenuController extends Controller $estado ='rechazado'; }; - + return redirect()->route('pay',$estado); } - + public function showwebhooks(Request $request){ - + } public function recargas(){ @@ -207,7 +210,7 @@ class MenuController extends Controller return view('menu/promo'); } - + public function showlogs(){ return view('menu/logs'); } @@ -216,15 +219,15 @@ class MenuController extends Controller public function showpromociones(){ return view('menu/promociones'); } - + public function showimport(){ return view('menu/importar'); } - + public function showcategoria(){ return view('menu/categoria'); } - + public function showcategorias(){ return view('menu/ver'); } @@ -237,11 +240,11 @@ class MenuController extends Controller $payment_id= $request->get('payment_id'); $response = Http::get("https://api.mercadopago.com/v1/payments/$payment_id" . "?access_token=APP_USR-7353579040069171-102716-58fdd1f52a604a1febd18a638227f603-260361439"); $response = json_decode($response); - - + + $status = $response->status; if ($status == 'approved') { - + foreach($response->additional_info->items as $item){ $consulta = Historiale::where('id', $item->id)->first(); $tarifa_id=$consulta->tarifa_id; @@ -251,22 +254,22 @@ class MenuController extends Controller //SERVICIO// if (!empty($consulta->tarifa_id)) { - + $pantallas = Tarifas::where('id', $tarifa_id)->with('servicio')->first(); $servicio_id= $pantallas->servicio_id; $pantalla_servicio = $pantallas->servicio->pantallas; $pantalla_servicio_completa = $pantallas->servicio->completa; - - - + + + $pantallas= $pantallas ->pantallas ?? null; $cantidad_tarjetaPlan = $consulta->cantidad; - + $cantidad_solicitada = (int)$cantidad_tarjetaPlan*(int)$pantallas; //dd($cantidad_tarjetaPlan); if((int)$pantalla_servicio_completa >= (int)$cantidad_solicitada ){ $suma = $pantalla_servicio-$cantidad_solicitada; - + $cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado','activo')->having('historiales_count', '<=', $suma)->first(); }elseif((int)$pantalla_servicio_completa == (int)$cantidad_solicitada){ $this->fecha_final_1 = $today = Carbon::now()->addDays($pantallas->dias-15); @@ -276,13 +279,13 @@ class MenuController extends Controller }else{ $cuenta=null; } - - + + if (!empty($cuenta) ) { - + $perfil = $cuenta->historiales_count; - for ($n=1; $n <= $cantidad_solicitada ; $n++) { - + for ($n=1; $n <= $cantidad_solicitada ; $n++) { + $historial_cuenta = new Historial_cuenta(); $historial_cuenta->cuenta_id = $cuenta->id; $historial_cuenta->historial_id = $item->id; @@ -290,74 +293,74 @@ class MenuController extends Controller $historial_cuenta->save(); //dd($historial_cuenta->id); } - + if (($n-1) == $cantidad_solicitada) { - + $consulta->update(['estado'=>'activo']); $this->cred($consulta); $encryptado = Crypt::encryptString($consulta->id); //dd('llegue'); return redirect('/credenciales?id='.$encryptado); - + }else{ - + return 'Error en la asignacion de cuentas, comuniquese con soporte!'; - + } - - + + }else{ //dd($cuenta); $suma2= $pantalla_servicio - $pantallas; - - - for ($h=0; $h < (int)$cantidad_tarjetaPlan ; $h++) { + + + for ($h=0; $h < (int)$cantidad_tarjetaPlan ; $h++) { //dd($n); $cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado','activo')->having('historiales_count', '<=', (int)$suma2)->first(); //dd($cuenta); if (!empty($cuenta)) { $perfil = $cuenta->historiales_count; - for ($y=0; $y < (int)$pantallas ; $y++) { + for ($y=0; $y < (int)$pantallas ; $y++) { //dd($pantallas); $historial_cuenta = new Historial_cuenta; $historial_cuenta->cuenta_id = $cuenta->id; $historial_cuenta->historial_id = $item->id; $historial_cuenta->perfil = (int)$perfil + (int)$y+1; $historial_cuenta->save(); - + } - + }else{ return 'No hay cuentas disponibles, comuniquese con soporte!'; } } - - + + $consulta->update(['estado'=>'activo']); $this->cred($consulta); $encryptado = Crypt::encryptString($consulta->id); return redirect('/credenciales?id='.$encryptado); - - + + } - - - - + + + + } - //PROMOCION + //PROMOCION if (!empty($consulta->promocion_id)){ for ($p = 0; $p < (int)$consulta->cantidad; $p++) { //dd($this->cantidad_comprarPromo); foreach ($consulta->promocion->tarifas as $tarifa) { - + $pantallas_tarifa = $tarifa->pantallas; $servicio_id = $tarifa->servicio_id; $pantalla_servicio = $tarifa->servicio->pantallas; $pantalla_servicio_completa = $tarifa->servicio->completa; - + $faltante = $pantalla_servicio - $pantallas_tarifa; if ($pantalla_servicio_completa == $pantallas_tarifa) { $this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias-15); @@ -367,44 +370,44 @@ class MenuController extends Controller $cuenta = Cuentas::where('servicio_id', $servicio_id)->whereDate('inicio','>=',$fecha)->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', (int)$faltante)->first(); } //dd($tarifa); - - + + if (!empty($cuenta)) { $perfil = $cuenta->historiales_count; for ($y = 0; $y < (int)$pantallas_tarifa; $y++) { - + $historial_cuenta = new Historial_cuenta(); $historial_cuenta->cuenta_id = $cuenta->id; $historial_cuenta->historial_id = $item->id; $historial_cuenta->perfil = (int)$perfil + (int)$y+1; $historial_cuenta->save(); } - - + + } else { - + return 'No hay cuentas disponibles, comuniquese con soporte!'; } } } - + if (!empty($y)) { - + $consulta->update(['estado'=>'activo']); $this->cred($consulta); $encryptado = Crypt::encryptString($consulta->id); //dd('llegue'); return redirect('/credenciales?id='.$encryptado); - + }else{ return 'No hay cuentas disponibles, comuniquese con soporte!'; } } - - + + } - + } @@ -416,15 +419,15 @@ public function wompi_pagos(Request $request){ $response = Http::get("https://sandbox.wompi.co/v1/transactions/136099-1677473887-65588"); $response = json_decode($response); //dd($response); - + } public function wompi_hook(Request $request){ - //return json_encode('hola'); + //return json_encode('hola'); if (!empty($request)) { - - + + foreach($request->data as $item ){ //return $item; @@ -432,8 +435,8 @@ public function wompi_hook(Request $request){ $user_id = $item['reference']; $monto = substr($item['amount_in_cents'], 0, -2); $metodo_pago = $item['payment_method_type']; - - + + } $update_recargas = recarga::where('reference',$referencia)->update(['status' => $status,'payment_method_id'=> $metodo_pago]); @@ -448,30 +451,30 @@ public function wompi_hook(Request $request){ if ($rol == "super" || $rol == "administrador" || $rol == "distribuidor") { $monto_adicional = 500; } - + if (!empty($saldo_anterior)) { - + $valor= (float)$saldo_anterior + (float)$monto - (float)$monto_adicional; $nuevo_saldo = $saldo->update(['valor'=>$valor]); - + // return $nuevo_saldo; - + } } } - - - + + + } public function cred($consulta){ - + $encryptado = Crypt::encryptString($consulta->id); $enlace = '/credenciales?id='.$encryptado; - + $user=User::find($consulta->cliente); if (!empty($consulta->promocion_id)){ { @@ -489,7 +492,7 @@ public function cred($consulta){ 'servicio' => $consulta->promocion->nombre, 'tipo' => 'compra', 'vendedor' => Role::where('nombre','super')->first()->usuarios->first()->name, - + ]; } @@ -510,21 +513,21 @@ public function cred($consulta){ 'servicio' => $consulta->tarifa->servicio->nombre.'-'.$consulta->tarifa->pantallas. 'pantallas', 'tipo' => 'compra', 'vendedor' => Role::where('nombre','super')->first()->usuarios->first()->name, - + ]; } - + Notification::send($user, new compra($notificacion)); - - + + } - + } public function sendMessage($message, $recipients) { - + $auth_basic = base64_encode(getenv("USER_LABSMOBILE").':'.getenv("PASS_LABSMOBILE")); @@ -553,10 +556,10 @@ public function sendMessage($message, $recipients) if ($err) { - - + + } else { - + } } public function showmp(Request $request){ @@ -571,7 +574,7 @@ public function showmp(Request $request){ //return $response; $response = json_decode($response); $status = $response->status; - + if ($status == 'approved') { $metodo_pago = $response->payment_method_id; $referencia = $response->external_reference; @@ -580,15 +583,15 @@ public function showmp(Request $request){ $update_recargas = recarga::where('reference',$referencia)->update(['status' => $status,'payment_method_id'=> $metodo_pago]); $recarga = recarga::where('reference',$referencia)->with('usuario')->first(); $usuario= $recarga->usuario; - + $saldo = $usuario->saldo; $saldo_anterior = $saldo->valor; $monto = $recarga->valor_recarga; - + $valor= (float)$saldo_anterior + (float)$monto ; $nuevo_saldo = $saldo->update(['valor'=>$valor]); - - + + } } @@ -605,9 +608,9 @@ public function pruebas (){ $consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cliente')->get(); foreach ($consulta_historial as $item) { - + $user = User::find($item->cliente->id); - + if (!empty($item->promocion_id)) { $nombre= $item->promocion->nombre; @@ -629,7 +632,7 @@ $consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cli Notification::sendNow($user, new Vencimiento($notificacion)); // $fecha=Carbon::parse($item->fecha_final)->format('d/m/Y'); - + //$message = 'Su '.$nombre.', Vence Hoy, '.$fecha.'. Renueva ahora!!' ; //$recipients= '+57'.$item->cliente->celular; @@ -659,12 +662,12 @@ $consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cli //curl_close($curl); //return $response; //if ($err) { - - + + //} else { - + //} - + } @@ -673,7 +676,7 @@ $consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cli $consulta_historial1= Historiale::whereDate('fecha_final','<',$fechaHoy1)->with('cliente','cuentas')->get(); foreach ($consulta_historial1 as $item1) { - + foreach($item1->cuentas->unique() as $item2){ //dd($item2); $logs = new log; @@ -683,7 +686,7 @@ $consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cli } //$eliminar_cuentas = Historial_cuenta::where('historial_id',$item1->id)->truncate(); //dd('termine'); - + } } -} \ No newline at end of file +} diff --git a/app/Http/Livewire/ShowLogHistorial.php b/app/Http/Livewire/ShowLogHistorial.php new file mode 100644 index 0000000..8eb6163 --- /dev/null +++ b/app/Http/Livewire/ShowLogHistorial.php @@ -0,0 +1,33 @@ +buscar) { + $query->where('detalle', 'like', '%' . $this->buscar . '%'); + } + + if ($this->filtro_fecha) { + $query->whereDate('created_at', $this->filtro_fecha); + } + + $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); + + return view('livewire.show-log-historial', [ + 'logs' => $logs + ]); + } +} diff --git a/app/Models/Log_historial.php b/app/Models/Log_historial.php new file mode 100644 index 0000000..6b57cb7 --- /dev/null +++ b/app/Models/Log_historial.php @@ -0,0 +1,23 @@ +belongsTo(User::class); + } +} diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 049dafd..6af8ef4 100755 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -80,6 +80,7 @@ Log general Log cuentas @if (auth()->user()->rol->nombre == 'super') + Log historial Log recargas Gestión Promociones Gestión Usuarios diff --git a/resources/views/livewire/show-log-historial.blade.php b/resources/views/livewire/show-log-historial.blade.php new file mode 100644 index 0000000..eec8a24 --- /dev/null +++ b/resources/views/livewire/show-log-historial.blade.php @@ -0,0 +1,47 @@ +