This commit is contained in:
Felipe
2023-07-27 10:47:39 -05:00
parent 25914187f5
commit 91589bed85
2 changed files with 128 additions and 107 deletions
+91 -79
View File
@@ -39,7 +39,7 @@ class ShowClientes extends Component
public $consulta_historial; public $consulta_historial;
public $venceHoy; public $venceHoy;
public $vencidosHoy =false; public $vencidosHoy = false;
public $visto = false; public $visto = false;
public $vencidHoy; public $vencidHoy;
public $configuracion; public $configuracion;
@@ -48,20 +48,21 @@ class ShowClientes extends Component
public function render() public function render()
{ $fechaHoy = Carbon::now(); {
$fechaHoy = Carbon::now();
$this->fechaActual = date('d/m/Y'); $this->fechaActual = date('d/m/Y');
$fechaVencimiento = Carbon::now()->subDay(30); $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->vencidosHoy = true;
$this->vencidHoy= $consulta_clientes->whereDate('fecha_final', $fechaHoy)->get(); $this->vencidHoy = $consulta_clientes->whereDate('fecha_final', $fechaHoy)->get();
$this->configuracion = User::where('id',Auth::user()->id)->update(['visto' => true]); $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)) { if (!empty($this->buscar)) {
$consulta_clientes = $consulta_clientes->where(function ($query) { $consulta_clientes = $consulta_clientes->where(function ($query) {
$query->whereHas('cuentas', function ($subQuery) { $query->whereHas('cuentas', function ($subQuery) {
@@ -76,16 +77,16 @@ class ShowClientes extends Component
$fecha5 = Carbon::parse($fechaHoy)->subDay(5); $fecha5 = Carbon::parse($fechaHoy)->subDay(5);
$consulta_clientes = $consulta_clientes->whereDate('fecha_final', '<=', $fechaHoy) $consulta_clientes = $consulta_clientes->whereDate('fecha_final', '<=', $fechaHoy)
->whereDate('fecha_final', '>=', $fecha5); ->whereDate('fecha_final', '>=', $fecha5);
} }
$consulta_clientes = $consulta_clientes->with('tarifa', 'promocion', 'cliente') $consulta_clientes = $consulta_clientes->with('tarifa', 'promocion', 'cliente')
->orderBy('id', 'DESC') ->orderBy('id', 'DESC')
->paginate(15); ->paginate(15);
// dd($consulta_clientes); // dd($consulta_clientes);
return view('livewire.show-clientes', [ return view('livewire.show-clientes', [
'clientes' => $consulta_clientes 'clientes' => $consulta_clientes
@@ -94,8 +95,8 @@ class ShowClientes extends Component
public function verCliente($id) public function verCliente($id)
{ {
$this->consulta_historial = Historiale::with('promocion', 'tarifa', 'cliente','cuentas')->where('id', $id)->first(); $this->consulta_historial = Historiale::with('promocion', 'tarifa', 'cliente', 'cuentas')->where('id', $id)->first();
// dd($this->consulta_historial ); // dd($this->consulta_historial );
$this->verCliente = true; $this->verCliente = true;
} }
@@ -131,8 +132,8 @@ class ShowClientes extends Component
$user = User::find($consulta_historial->cliente); $user = User::find($consulta_historial->cliente);
$nombre = $consulta_historial->promocion->nombre; $nombre = $consulta_historial->promocion->nombre;
$descripcion = $consulta_historial->promocion->descripcion; $descripcion = $consulta_historial->promocion->descripcion;
$notificacion = [ $notificacion = [
@@ -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(); $consulta_historial = Historiale::where('id', $id)->with('promocion', 'cliente')->first();
$user = User::find($consulta_historial->cliente); $user = User::find($consulta_historial->cliente);
$nombre = $consulta_historial->promocion->nombre; $nombre = $consulta_historial->promocion->nombre;
$fecha=Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d'); $fecha = Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d');
$fecha_humana= Carbon::parse($consulta_historial->fecha_final)->diffForHumans(); $fecha_humana = Carbon::parse($consulta_historial->fecha_final)->diffForHumans();
//dd($fecha_humana); //dd($fecha_humana);
//$descripcion = $consulta_historial->promocion->descripcion; //$descripcion = $consulta_historial->promocion->descripcion;
$message = 'Su '.$nombre.', Vence '.$fecha_humana.', '.$fecha.'. Renueva ahora!!' ; $message = 'Su ' . $nombre . ', Vence ' . $fecha_humana . ', ' . $fecha . '. Renueva ahora!!';
$recipients= '+57'.$consulta_historial->cliente->celular; $recipients = '+57' . $consulta_historial->cliente->celular;
$this->sendMessage($message, $recipients);
$this->sendMessage($message, $recipients);
} }
public function notSMS($id){ public function notSMS($id)
{
$consulta_historial = Historiale::where('id', $id)->with('tarifa', 'cliente')->first(); $consulta_historial = Historiale::where('id', $id)->with('tarifa', 'cliente')->first();
$user = User::find($consulta_historial->cliente); $user = User::find($consulta_historial->cliente);
$nombre = $consulta_historial->tarifa->servicio->nombre . '-' . $consulta_historial->tarifa->pantallas . 'P'; $nombre = $consulta_historial->tarifa->servicio->nombre . '-' . $consulta_historial->tarifa->pantallas . 'P';
$fecha=Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d'); $fecha = Carbon::parse($consulta_historial->fecha_final)->format('Y/m/d');
$fecha_humana= Carbon::parse($consulta_historial->fecha_final)->diffForHumans(); $fecha_humana = Carbon::parse($consulta_historial->fecha_final)->diffForHumans();
$message = 'Su '.$nombre.', Vence '.$fecha_humana.', '.$fecha.'. Renueva ahora!!' ; $message = 'Su ' . $nombre . ', Vence ' . $fecha_humana . ', ' . $fecha . '. Renueva ahora!!';
$recipients= '+57'.$consulta_historial->cliente->celular; $recipients = '+57' . $consulta_historial->cliente->celular;
$this->sendMessage($message, $recipients);
$this->sendMessage($message, $recipients);
} }
public function sendMessage($message, $recipients) public function sendMessage($message, $recipients)
@@ -209,70 +208,83 @@ class ShowClientes extends Component
// ]); // ]);
// } // }
$auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0'); $auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0');
//dd(getenv('USER_LABSMOBILE')); //dd(getenv('USER_LABSMOBILE'));
$curl = curl_init(); $curl = curl_init();
curl_setopt_array($curl, array( curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.labsmobile.com/json/send", CURLOPT_URL => "https://api.labsmobile.com/json/send",
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "", CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10, CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30, CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"message":"'.$message.'","nofilter":"1, "tpoa":"Sender","recipient":[{"msisdn":"'.$recipients.'"}]}', CURLOPT_POSTFIELDS => '{"message":"' . $message . '","nofilter":"1, "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}',
CURLOPT_HTTPHEADER => array( CURLOPT_HTTPHEADER => array(
"Authorization: Basic ".$auth_basic, "Authorization: Basic " . $auth_basic,
"Cache-Control: no-cache", "Cache-Control: no-cache",
"Content-Type: application/json" "Content-Type: application/json"
), ),
)); ));
$response = curl_exec($curl); $response = curl_exec($curl);
$err = curl_error($curl); $err = curl_error($curl);
curl_close($curl); curl_close($curl);
if ($err) { if ($err) {
$this->alert('warning', 'Error enviando SMS!'.$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' '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]);
}
public function cerrar(){
$this->configuracion = User::where('id',Auth::user()->id)->update(['visto' => true]);
//dd($this->configuracion); //dd($this->configuracion);
$this->visto=true; $this->visto = true;
$this->vencidosHoy = false; $this->vencidosHoy = false;
} }
public function renovar(){ 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'
]);
}
public function saldoSuficiente()
{
} }
} }
@@ -126,6 +126,8 @@
</td> </td>
@endif @endif
{{$cliente->tarifa->valor}}
@if (!empty($cliente->tarifa_id)) @if (!empty($cliente->tarifa_id))
<td class=" w-[1rem]"> <td class=" w-[1rem]">
<button <button
@@ -157,14 +159,21 @@
wire:click="verCliente({{ $cliente->id }})" wire:click="verCliente({{ $cliente->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 hover:rounded-t-[1rem]">Ver</button> class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 hover:rounded-t-[1rem]">Ver</button>
@if (!empty($cliente->cuentas->first()->estado)) @if (!empty($cliente->cuentas->first()->estado))
@if ($cliente->cuentas->first()->estado == 'pendiente' && $cliente->tarifa->servicio->renovacion == true) @if ($cliente->cuentas->first()->estado == 'pendiente' && $cliente->tarifa->servicio->renovacion == true)
{{-- renovar --}} {{-- renovar --}}
<button x-on:click="openOption=!openOption"
wire:click="renovar({{ $cliente->id }})" @if (Auth::user()->saldo->valor >= $cliente->tarifa->valor)
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 hover:rounded-t-[1rem]">Renovar</button> <button x-on:click="openOption=!openOption"
wire:click="renovar({{ $cliente->id }})"
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300">Renovar</button>
@else
<button
class="text-gray-500 w-full py-1 hover:bg-gray-200 border-b border-gray-300 active:bg-red-500 active:text-white cursor-not-allowed">Renovar</button>
@endif
@endif @endif
@endif @endif
{{-- whatsapp --}} {{-- whatsapp --}}
<a x-on:click="openOption=!openOption" target="_blank" <a x-on:click="openOption=!openOption" target="_blank"
href="https://wa.me/57{{ $cliente->cliente->celular ?? '' }}?text=Hola *{{ $cliente->cliente->name ?? '' }}* tu servicio de *{{ $cliente->tarifa->servicio->nombre }} de {{ $cliente->tarifa->pantallas }} pantallas * vence el *{{ $cliente->fecha_final }}*" href="https://wa.me/57{{ $cliente->cliente->celular ?? '' }}?text=Hola *{{ $cliente->cliente->name ?? '' }}* tu servicio de *{{ $cliente->tarifa->servicio->nombre }} de {{ $cliente->tarifa->pantallas }} pantallas * vence el *{{ $cliente->fecha_final }}*"