diff --git a/app/Http/Livewire/ShowClientes.php b/app/Http/Livewire/ShowClientes.php index c06c602..ec3a500 100644 --- a/app/Http/Livewire/ShowClientes.php +++ b/app/Http/Livewire/ShowClientes.php @@ -37,9 +37,9 @@ class ShowClientes extends Component public $precio_paquete; public $dias_paquete; public $consulta_historial; - + public $venceHoy; - public $vencidosHoy =false; + public $vencidosHoy = false; public $visto = false; public $vencidHoy; public $configuracion; @@ -48,20 +48,21 @@ class ShowClientes extends Component public function render() - { $fechaHoy = Carbon::now(); + { + $fechaHoy = Carbon::now(); $this->fechaActual = date('d/m/Y'); $fechaVencimiento = Carbon::now()->subDay(30); - $consulta_clientes = Historiale::where('vendedor_id', Auth()->user()->id)->whereDate('fecha_final','>', $fechaVencimiento); + $consulta_clientes = Historiale::where('vendedor_id', Auth()->user()->id)->whereDate('fecha_final', '>', $fechaVencimiento); - $this->configuracion = User::where('id',Auth::user()->id)->whereDate('updated_at','!=', $fechaHoy)->first(); + $this->configuracion = User::where('id', Auth::user()->id)->whereDate('updated_at', '!=', $fechaHoy)->first(); - if($this->configuracion){ + if ($this->configuracion) { $this->vencidosHoy = true; - $this->vencidHoy= $consulta_clientes->whereDate('fecha_final', $fechaHoy)->get(); - $this->configuracion = User::where('id',Auth::user()->id)->update(['visto' => true]); + $this->vencidHoy = $consulta_clientes->whereDate('fecha_final', $fechaHoy)->get(); + $this->configuracion = User::where('id', Auth::user()->id)->update(['visto' => true]); } - $this->msj = Configuracione::orderby('id','desc')->select('msj_compra','msj_wp','clave_1','clave_2','clave_3','clave_4','clave_5','clave_6','iptv')->first(); + $this->msj = Configuracione::orderby('id', 'desc')->select('msj_compra', 'msj_wp', 'clave_1', 'clave_2', 'clave_3', 'clave_4', 'clave_5', 'clave_6', 'iptv')->first(); if (!empty($this->buscar)) { $consulta_clientes = $consulta_clientes->where(function ($query) { $query->whereHas('cuentas', function ($subQuery) { @@ -71,22 +72,22 @@ class ShowClientes extends Component }); }); } - + if ($this->venceHoy) { - + $fecha5 = Carbon::parse($fechaHoy)->subDay(5); $consulta_clientes = $consulta_clientes->whereDate('fecha_final', '<=', $fechaHoy) - ->whereDate('fecha_final', '>=', $fecha5); + ->whereDate('fecha_final', '>=', $fecha5); } $consulta_clientes = $consulta_clientes->with('tarifa', 'promocion', 'cliente') - ->orderBy('id', 'DESC') - ->paginate(15); + ->orderBy('id', 'DESC') + ->paginate(15); - // dd($consulta_clientes); - + // dd($consulta_clientes); + return view('livewire.show-clientes', [ 'clientes' => $consulta_clientes ]); @@ -94,13 +95,13 @@ class ShowClientes extends Component public function verCliente($id) { - $this->consulta_historial = Historiale::with('promocion', 'tarifa', 'cliente','cuentas')->where('id', $id)->first(); - // dd($this->consulta_historial ); + $this->consulta_historial = Historiale::with('promocion', 'tarifa', 'cliente', 'cuentas')->where('id', $id)->first(); + // dd($this->consulta_historial ); $this->verCliente = true; } - + public function enviarNotificacion($id) { @@ -121,7 +122,7 @@ class ShowClientes extends Component $this->alert('success', 'Notificación enviada', [ 'position' => 'top' - ]); + ]); } public function enviarNotificacionPromo($id) @@ -131,9 +132,9 @@ class ShowClientes extends Component $user = User::find($consulta_historial->cliente); - $nombre = $consulta_historial->promocion->nombre; - $descripcion = $consulta_historial->promocion->descripcion; - + $nombre = $consulta_historial->promocion->nombre; + $descripcion = $consulta_historial->promocion->descripcion; + $notificacion = [ //'valor' => $value['precio'], @@ -152,39 +153,37 @@ class ShowClientes extends Component ]); } - public function notSMSpromo($id){ + public function notSMSpromo($id) + { $consulta_historial = Historiale::where('id', $id)->with('promocion', 'cliente')->first(); $user = User::find($consulta_historial->cliente); $nombre = $consulta_historial->promocion->nombre; - $fecha=Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d'); - $fecha_humana= Carbon::parse($consulta_historial->fecha_final)->diffForHumans(); + $fecha = Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d'); + $fecha_humana = Carbon::parse($consulta_historial->fecha_final)->diffForHumans(); //dd($fecha_humana); //$descripcion = $consulta_historial->promocion->descripcion; - $message = 'Su '.$nombre.', Vence '.$fecha_humana.', '.$fecha.'. Renueva ahora!!' ; - $recipients= '+57'.$consulta_historial->cliente->celular; - - $this->sendMessage($message, $recipients); - + $message = 'Su ' . $nombre . ', Vence ' . $fecha_humana . ', ' . $fecha . '. Renueva ahora!!'; + $recipients = '+57' . $consulta_historial->cliente->celular; + $this->sendMessage($message, $recipients); } - public function notSMS($id){ + public function notSMS($id) + { $consulta_historial = Historiale::where('id', $id)->with('tarifa', 'cliente')->first(); $user = User::find($consulta_historial->cliente); $nombre = $consulta_historial->tarifa->servicio->nombre . '-' . $consulta_historial->tarifa->pantallas . 'P'; - $fecha=Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d'); - $fecha_humana= Carbon::parse($consulta_historial->fecha_final)->diffForHumans(); - - - $message = 'Su '.$nombre.', Vence '.$fecha_humana.', '.$fecha.'. Renueva ahora!!' ; - $recipients= '+57'.$consulta_historial->cliente->celular; - - $this->sendMessage($message, $recipients); + $fecha = Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d'); + $fecha_humana = Carbon::parse($consulta_historial->fecha_final)->diffForHumans(); + $message = 'Su ' . $nombre . ', Vence ' . $fecha_humana . ', ' . $fecha . '. Renueva ahora!!'; + $recipients = '+57' . $consulta_historial->cliente->celular; + + $this->sendMessage($message, $recipients); } public function sendMessage($message, $recipients) @@ -193,86 +192,99 @@ class ShowClientes extends Component // $account_sid = getenv("TWILIO_SID"); // $auth_token = getenv("TWILIO_TOKEN"); // $twilio_number = getenv("TWILIO_FROM"); - + // $client = new Client($account_sid, $auth_token); - + // $client->messages->create($recipients, // ['from' => $twilio_number, 'body' => $message] ); - + // $this->alert('success', 'Notificación enviada por SMS! ', [ // 'position' => 'top' // ]); - + // }catch(Exception $e){ // $this->alert('warning', 'Error enviando SMS!'.$e->getMessage(), [ // 'position' => 'top' // ]); - + // } - $auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0'); - //dd(getenv('USER_LABSMOBILE')); - $curl = curl_init(); + $auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0'); + //dd(getenv('USER_LABSMOBILE')); + $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.'","nofilter":"1, "tpoa":"Sender","recipient":[{"msisdn":"'.$recipients.'"}]}', - CURLOPT_HTTPHEADER => array( - "Authorization: Basic ".$auth_basic, - "Cache-Control: no-cache", - "Content-Type: application/json" - ), - )); - $response = curl_exec($curl); - $err = curl_error($curl); + 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 . '","nofilter":"1, "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}', + CURLOPT_HTTPHEADER => array( + "Authorization: Basic " . $auth_basic, + "Cache-Control: no-cache", + "Content-Type: application/json" + ), + )); - curl_close($curl); + $response = curl_exec($curl); + $err = curl_error($curl); - if ($err) { + curl_close($curl); - $this->alert('warning', 'Error enviando SMS!'.$err, [ + if ($err) { + + $this->alert('warning', 'Error enviando SMS!' . $err, [ + 'position' => 'top' + ]); + } else { + //dd($response); + if (!empty(json_decode($response)->subid)) { + $this->alert('success', 'Notificación enviada por SMS! ' . json_decode($response)->subid, [ + 'position' => 'top' + ]); + } else { + $this->alert('warning', 'Servicio de SMS en mantenimiento!' . json_decode($response)->code, [ + 'position' => 'top' + ]); + } + } + } + public function cerrar() + { + + $this->configuracion = User::where('id', Auth::user()->id)->update(['visto' => true]); + + //dd($this->configuracion); + $this->visto = true; + + $this->vencidosHoy = false; + } + + public function renovar($id) + { + + $historiale = Historiale::with('tarifa')->find($id); + + + if (!$historiale) { + return; + } + + $newFechaInicio = Carbon::parse($historiale->fecha_inicio)->addDays($historiale->tarifa->dias); + $newFechaFinal = Carbon::parse($historiale->fecha_final)->addDays($historiale->tarifa->dias); + + $historiale->fecha_inicio = $newFechaInicio; + $historiale->fecha_final = $newFechaFinal; + $historiale->save(); + + $this->alert('success', 'Registro renovado con éxito. Nuevas fechas aplicadas.', [ 'position' => 'top' ]); - - } else { - //dd($response); - if (!empty(json_decode($response)->subid)) { - $this->alert('success', 'Notificación enviada por SMS! '.json_decode($response)->subid, [ - 'position' => 'top' - ]); - }else{ - $this->alert('warning', 'Servicio de SMS en mantenimiento!'.json_decode($response)->code, [ - 'position' => 'top' - ]); - } - - } - - + public function saldoSuficiente() + { } - public function cerrar(){ - - $this->configuracion = User::where('id',Auth::user()->id)->update(['visto' => true]); - - //dd($this->configuracion); - $this->visto=true; - - $this->vencidosHoy = false; - - - } - - public function renovar(){ - - } - - } diff --git a/resources/views/livewire/show-clientes.blade.php b/resources/views/livewire/show-clientes.blade.php index 91f74fd..bfeb8da 100644 --- a/resources/views/livewire/show-clientes.blade.php +++ b/resources/views/livewire/show-clientes.blade.php @@ -126,6 +126,8 @@ @endif + {{$cliente->tarifa->valor}} + @if (!empty($cliente->tarifa_id))