Initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
use Livewire\WithFileUploads;
|
||||
use Livewire\Component;
|
||||
use App\Imports\UsersImport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class Import extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public $photo;
|
||||
public $importado;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.import');
|
||||
}
|
||||
|
||||
public function import()
|
||||
{
|
||||
$data=Excel::import(new UsersImport, $this->photo);
|
||||
$this->photo=null;
|
||||
$this->importado = 'true';
|
||||
// aquí se puede procesar los datos obtenidos
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
use App\Models\recarga;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class LogsRecargas extends Component
|
||||
{
|
||||
public $aprobado;
|
||||
public $buscar;
|
||||
use WithPagination;
|
||||
|
||||
public function render()
|
||||
{
|
||||
$consulta_historial = Recarga::orderBy('id', 'DESC');
|
||||
|
||||
if (!empty($this->aprobado)) {
|
||||
$consulta_historial->where('status', 'approved');
|
||||
}
|
||||
|
||||
if (!empty($this->buscar)) {
|
||||
$consulta_historial->whereHas('usuario', function ($query) {
|
||||
$query->where('email', 'like', '%' . $this->buscar . '%');
|
||||
});
|
||||
}
|
||||
|
||||
// Limitar resultados a un máximo de 200
|
||||
$resultados = $consulta_historial->take(200)->paginate(30);
|
||||
|
||||
// Restablecer la paginación después de limitar los resultados
|
||||
$resultados->setCollection($resultados->getCollection()->values());
|
||||
|
||||
|
||||
|
||||
|
||||
return view('livewire.logs-recargas',[
|
||||
'historial_recargas' => $resultados
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Livewire\Component;
|
||||
|
||||
class Portada extends Component
|
||||
{
|
||||
|
||||
public $promociones;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.portada');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Promocion_tarifa;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\Role;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\Servicio;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use App\Notifications\compra;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Livewire\Component;
|
||||
|
||||
class PortadaServicio extends Component
|
||||
{
|
||||
|
||||
use LivewireAlert;
|
||||
|
||||
public $categoria_id;
|
||||
|
||||
public $nombre_promocion;
|
||||
public $descripcion_promocion;
|
||||
public $valor_promocion;
|
||||
public $estado_promocion;
|
||||
public $fecha_limite_promocion;
|
||||
public $categoria_id_promocion;
|
||||
|
||||
public $fechaFinal;
|
||||
|
||||
public $tarifa_id_promocion;
|
||||
public $dias_comprarPromo;
|
||||
public $valor_comprarPromo;
|
||||
public $nombre_comprarPromo;
|
||||
public $celular_comprarPromo;
|
||||
public $email_comprarPromo;
|
||||
public $cantidad_comprarPromo = 1;
|
||||
|
||||
public $newCategoria = false;
|
||||
public $nombre_categoria;
|
||||
public $descripcion_categoria;
|
||||
|
||||
public $modalComprarPromo = false;
|
||||
|
||||
public $verPromo = false;
|
||||
public $precioAntes;
|
||||
public $precioAhora;
|
||||
public $fechaLimite;
|
||||
public $nombrePromo;
|
||||
public $descripcionPromo;
|
||||
|
||||
public $editarPromo = false;
|
||||
public $nombre_editarPromo;
|
||||
public $descripcion_editarPromo;
|
||||
public $valor_editarPromo;
|
||||
public $estado_editarPromo;
|
||||
public $fecha_limite_editarPromo;
|
||||
public $categoria_id_editarPromo;
|
||||
public $editar_promo_id;
|
||||
public $imagen;
|
||||
public $dias;
|
||||
public $total;
|
||||
public $consulta;
|
||||
public $fechaHoy;
|
||||
public $fechafinal;
|
||||
public $fecha;
|
||||
public $credenciales;
|
||||
public $cuentas;
|
||||
|
||||
|
||||
protected $rules = [
|
||||
'nombre_comprarPromo' => 'required',
|
||||
'celular_comprarPromo' => 'required',
|
||||
'email_comprarPromo' => 'required',
|
||||
'cantidad_comprarPromo' => 'required',
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
$date = Carbon::now()->subDay(8);
|
||||
$this->fecha= $date->format('Y-m-d');
|
||||
|
||||
$this->fechaActual = Carbon::now();
|
||||
$this->fechaActual = Carbon::parse($this->fechaActual);
|
||||
|
||||
$this->fechaHoy = Carbon::now();
|
||||
$this->fechaHoy = $this->fechaHoy->format('d/m/Y');
|
||||
|
||||
$consulta_promociones = Promociones::with('tarifas')->where('visible', 'true');
|
||||
if (!is_null($this->categoria_id)) {
|
||||
$consulta_promociones = $consulta_promociones->where('categoria_id', 'LIKE', '%' . $this->categoria_id . '%');
|
||||
}
|
||||
//dd($consulta_promociones->get());
|
||||
$consulta_promociones = $consulta_promociones->get();
|
||||
|
||||
return view('livewire.portada-servicio',[
|
||||
'promociones' => $consulta_promociones,
|
||||
'categorias' => Categoria::get(),
|
||||
'tarifas' => Tarifas::with('servicio')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function verPromocion($id)
|
||||
{
|
||||
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first();
|
||||
|
||||
$this->consulta = $consulta_verpromocion;
|
||||
$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
|
||||
|
||||
$this->precioAhora = $consulta_verpromocion->precio;
|
||||
$this->imagen = $consulta_verpromocion->img_publicidad;
|
||||
$this->fechaLimite = $consulta_verpromocion->fecha_limite;
|
||||
$this->nombrePromo = $consulta_verpromocion->nombre;
|
||||
$this->dias = $consulta_verpromocion->dias;
|
||||
$this->descripcionPromo = $consulta_verpromocion->descripcion;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->dias);
|
||||
|
||||
$this->verPromo = true;
|
||||
}
|
||||
|
||||
public function comprarPromo($id)
|
||||
{
|
||||
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first();
|
||||
|
||||
$this->consulta = $consulta_verpromocion;
|
||||
$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
|
||||
|
||||
$this->precioAhora = $consulta_verpromocion->precio;
|
||||
$this->imagen = $consulta_verpromocion->img_publicidad;
|
||||
$this->fechaLimite = $consulta_verpromocion->fecha_limite;
|
||||
$this->nombrePromo = $consulta_verpromocion->nombre;
|
||||
$this->dias = $consulta_verpromocion->dias;
|
||||
$this->descripcionPromo = $consulta_verpromocion->descripcion;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->dias);
|
||||
|
||||
|
||||
$this->modalComprarPromo = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ---------------- Btn Comprar ---------------- */
|
||||
|
||||
|
||||
public function pagar()
|
||||
{
|
||||
|
||||
$this->validate();
|
||||
|
||||
|
||||
$usuario_existe = User::firstWhere('email', $this->email_comprarPromo)->id ?? null;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$usuario = new User;
|
||||
$usuario->name = $this->nombre_tarjetaPlan;
|
||||
$usuario->email = $this->email_tarjetaPlan;
|
||||
$usuario->password = '123';
|
||||
$usuario->celular = $this->celular_tarjetaPlan;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
} else {
|
||||
|
||||
$usuario_id = $usuario_existe;
|
||||
}
|
||||
if (empty(Auth::user())) {
|
||||
$historial = new Historiale();
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->precioAhora *$this->cantidad_comprarPromo;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Role::where('nombre','super')->first()->usuarios->first()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->save();
|
||||
|
||||
}else{
|
||||
$historial = new Historiale();
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->precioAhora *$this->cantidad_comprarPromo;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Auth::user()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->save();
|
||||
}
|
||||
|
||||
return redirect('/comprar?monto='.$historial->valor.'&id='.$historial->id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function limpiarInputPromocion()
|
||||
{
|
||||
$this->nombre_promocion = '';
|
||||
$this->descripcion_promocion = '';
|
||||
$this->valor_promocion = '';
|
||||
$this->estado_promocion = null;
|
||||
$this->fecha_limite_promocion = null;
|
||||
$this->categoria_id_promocion = null;
|
||||
$this->newCategoria = false;
|
||||
$this->newPromocion = false;
|
||||
|
||||
$this->list = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowAdmin extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.show-admin');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Intervention\Image\ImageManagerStatic as Img;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
||||
class ShowCategoria extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithFileUploads;
|
||||
|
||||
public $categoria_id;
|
||||
public $photo;
|
||||
public $img;
|
||||
public $nombre;
|
||||
public $descripcion;
|
||||
public $editarCategoria=false;
|
||||
public $nuevaCategoria=false;
|
||||
|
||||
|
||||
protected $rules = [
|
||||
'photo' =>'required',
|
||||
'nombre' => 'required',
|
||||
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
$consulta_categoria = Categoria::get();
|
||||
|
||||
return view('livewire.show-categoria',[
|
||||
'categorias' => $consulta_categoria,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
if (!empty($this->photo)) {
|
||||
|
||||
$nombre=Str::random(10);
|
||||
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location = "photos/".$nombre.".webp";
|
||||
Storage::disk('local')->put($location, $img);
|
||||
$url_foto = $location;
|
||||
} else {
|
||||
$url_foto = '';
|
||||
}
|
||||
|
||||
|
||||
$guardar_categoria = new Categoria;
|
||||
$guardar_categoria->nombre = $this->nombre;
|
||||
$guardar_categoria->imagen = $url_foto;
|
||||
$guardar_categoria->descripcion = $this->descripcion;
|
||||
$guardar_categoria->save();
|
||||
|
||||
$this->alert('success', 'Categoria creada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->nuevaCategoria=false;
|
||||
}
|
||||
|
||||
public function editar($id)
|
||||
{
|
||||
|
||||
$consulta_categorias = Categoria::FindOrFail($id);
|
||||
|
||||
$this->categoria_id = $consulta_categorias->id;
|
||||
$this->nombre = $consulta_categorias->nombre;
|
||||
$this->descripcion = $consulta_categorias->descripcion;
|
||||
$this->img = $consulta_categorias->imagen;
|
||||
}
|
||||
public function update()
|
||||
{
|
||||
|
||||
if (!empty($this->photo)) {
|
||||
|
||||
$nombre=Str::random(10);
|
||||
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location = "photos/".$nombre.".webp";
|
||||
Storage::disk('local')->put($location, $img);
|
||||
$url_foto = $location;
|
||||
} else {
|
||||
$url_foto = $this->img;
|
||||
}
|
||||
|
||||
|
||||
Categoria::where('id', $this->categoria_id)->update([
|
||||
'nombre' => $this->nombre,
|
||||
'descripcion' => $this->descripcion,
|
||||
'imagen' => $url_foto
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Categoria actualizada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
$this->limpiarInputCategoria();
|
||||
$this->editarCategoria=false;
|
||||
}
|
||||
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
Categoria::where('id',$id)->delete();
|
||||
|
||||
$this->alert('success', 'Categoria eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function limpiarInputCategoria()
|
||||
{
|
||||
$this->photo = null;
|
||||
$this->nombre = '';
|
||||
$this->descripcion = '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Vencimiento;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use App\Models\Configuracione;
|
||||
use Livewire\WithPagination;
|
||||
use Twilio\Rest\Client;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
|
||||
class ShowClientes extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithPagination;
|
||||
|
||||
public $date;
|
||||
public $buscar;
|
||||
public $fechaActual;
|
||||
|
||||
public $verCliente = false;
|
||||
|
||||
public $ver_nombre;
|
||||
public $ver_email;
|
||||
public $ver_fecha_inicio;
|
||||
public $ver_fecha_vencimiento;
|
||||
public $ver_paquete;
|
||||
public $precio_paquete;
|
||||
public $dias_paquete;
|
||||
public $consulta_historial;
|
||||
|
||||
public $venceHoy;
|
||||
public $vencidosHoy =false;
|
||||
public $visto = false;
|
||||
public $vencidHoy;
|
||||
public $configuracion;
|
||||
public $msj;
|
||||
|
||||
|
||||
|
||||
public function render()
|
||||
{ $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);
|
||||
|
||||
$this->configuracion = User::where('id',Auth::user()->id)->whereDate('updated_at','!=', $fechaHoy)->first();
|
||||
|
||||
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->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) {
|
||||
$subQuery->where('correo', 'LIKE', '%' . $this->buscar . '%');
|
||||
})->orWhereHas('cliente', function ($subQuery) {
|
||||
$subQuery->where('email', 'LIKE', '%' . $this->buscar . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ($this->venceHoy) {
|
||||
|
||||
$fecha5 = Carbon::parse($fechaHoy)->subDay(5);
|
||||
$consulta_clientes = $consulta_clientes->whereDate('fecha_final', '<=', $fechaHoy)
|
||||
->whereDate('fecha_final', '>=', $fecha5);
|
||||
}
|
||||
|
||||
$consulta_clientes = $consulta_clientes->with('tarifa', 'promocion', 'cliente')
|
||||
->orderBy('id', 'DESC')
|
||||
->paginate(15);
|
||||
|
||||
|
||||
|
||||
// dd($consulta_clientes);
|
||||
|
||||
return view('livewire.show-clientes', [
|
||||
'clientes' => $consulta_clientes
|
||||
]);
|
||||
}
|
||||
|
||||
public function verCliente($id)
|
||||
{
|
||||
$this->consulta_historial = Historiale::with('promocion', 'tarifa', 'cliente','cuentas')->where('id', $id)->first();
|
||||
// dd($this->consulta_historial );
|
||||
|
||||
$this->verCliente = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function enviarNotificacion($id)
|
||||
{
|
||||
$consulta_historial = Historiale::where('id', $id)->with('tarifa', 'cliente')->first();
|
||||
$user = User::find($consulta_historial->cliente);
|
||||
|
||||
$notificacion = [
|
||||
//'valor' => $value['precio'],
|
||||
'fecha_final' => $consulta_historial->fecha_final,
|
||||
'cliente' => $consulta_historial->cliente->name,
|
||||
'servicio' => $consulta_historial->tarifa->servicio->nombre . '-' . $consulta_historial->tarifa->pantallas . 'pantallas',
|
||||
'tipo' => 'vencimiento',
|
||||
'vendedor' => auth()->user()->username,
|
||||
|
||||
];
|
||||
|
||||
Notification::send($user, new Vencimiento($notificacion));
|
||||
|
||||
$this->alert('success', 'Notificación enviada', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
public function enviarNotificacionPromo($id)
|
||||
{
|
||||
|
||||
$consulta_historial = Historiale::where('id', $id)->with('promocion', 'cliente')->first();
|
||||
$user = User::find($consulta_historial->cliente);
|
||||
|
||||
|
||||
$nombre = $consulta_historial->promocion->nombre;
|
||||
$descripcion = $consulta_historial->promocion->descripcion;
|
||||
|
||||
|
||||
$notificacion = [
|
||||
//'valor' => $value['precio'],
|
||||
'fecha_final' => $consulta_historial->fecha_final,
|
||||
'cliente' => $consulta_historial->cliente->name,
|
||||
'servicio' => 'PROMO ' . $nombre . '-' . $descripcion,
|
||||
'tipo' => 'vencimiento',
|
||||
'vendedor' => auth()->user()->username,
|
||||
|
||||
];
|
||||
|
||||
Notification::send($user, new Vencimiento($notificacion));
|
||||
|
||||
$this->alert('success', 'Notificación enviada', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
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();
|
||||
//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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function sendMessage($message, $recipients)
|
||||
{
|
||||
// try {
|
||||
// $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();
|
||||
|
||||
|
||||
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_close($curl);
|
||||
|
||||
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(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Configuracione;
|
||||
use App\Models\slider;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Livewire\WithFileUploads;
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use Intervention\Image\ImageManagerStatic as Img;
|
||||
use Illuminate\Support\Str;
|
||||
use Artisan;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
||||
class ShowConfiguracion extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithFileUploads;
|
||||
|
||||
public $nombre;
|
||||
public $slogan;
|
||||
public $photo;
|
||||
public $color_boton;
|
||||
public $color_barra;
|
||||
public $color_menu;
|
||||
public $url_logo;
|
||||
public $slider;
|
||||
public $delete_slider;
|
||||
|
||||
public $photo_top;
|
||||
|
||||
public $imgP1;
|
||||
public $imgP2;
|
||||
public $imgP3;
|
||||
public $imgP4;
|
||||
public $imgP5;
|
||||
public $imgP6;
|
||||
public $imgP7;
|
||||
public $imgP8;
|
||||
public $imgP9;
|
||||
public $imgP10;
|
||||
|
||||
public $premio_1;
|
||||
public $premio_2;
|
||||
public $premio_3;
|
||||
public $premio_4;
|
||||
public $premio_5;
|
||||
public $premio_6;
|
||||
public $premio_7;
|
||||
public $premio_8;
|
||||
public $premio_9;
|
||||
public $premio_10;
|
||||
|
||||
|
||||
public $mensaje_top;
|
||||
public $img_top;
|
||||
public $mensaje_msj_compra;
|
||||
public $mensaje_msj_wp;
|
||||
|
||||
public $clave_1;
|
||||
public $clave_2;
|
||||
public $clave_3;
|
||||
public $clave_4;
|
||||
public $clave_5;
|
||||
public $clave_6;
|
||||
|
||||
public $iptv;
|
||||
public $notificacion;
|
||||
|
||||
public $consulta_configuracion;
|
||||
|
||||
public function render()
|
||||
{
|
||||
//$consulta = Configuracione::with('usuario')->orderby('id','desc');
|
||||
$consulta_configuracion= Configuracione::with('usuario')->orderby('id','desc')->first();
|
||||
$this->consulta_configuracion = $consulta_configuracion;
|
||||
//dd($consulta_configuraciones);
|
||||
if (empty($this->nombre) && empty($this->slogan) && empty($this->color_boton) ) {
|
||||
|
||||
$this->nombre = $consulta_configuracion->nombre;
|
||||
$this->slogan = $consulta_configuracion->slogan;
|
||||
$this->color_boton = $consulta_configuracion->color_boton;
|
||||
$this->url_logo = $consulta_configuracion->url_logo;
|
||||
$this->color_barra = $consulta_configuracion->color_barra;
|
||||
$this->color_menu = $consulta_configuracion->color_menu;
|
||||
|
||||
//top
|
||||
$this->top_1 = $consulta_configuracion->top_1;
|
||||
$this->top_2 = $consulta_configuracion->top_2;
|
||||
$this->top_3 = $consulta_configuracion->top_3;
|
||||
$this->top_4 = $consulta_configuracion->top_4;
|
||||
$this->top_5 = $consulta_configuracion->top_5;
|
||||
$this->top_6 = $consulta_configuracion->top_6;
|
||||
$this->top_7 = $consulta_configuracion->top_7;
|
||||
$this->top_8 = $consulta_configuracion->top_8;
|
||||
$this->top_9 = $consulta_configuracion->top_9;
|
||||
$this->top_10 = $consulta_configuracion->top_10;
|
||||
|
||||
$this->premio_1 = $consulta_configuracion->premio_1;
|
||||
$this->premio_2 = $consulta_configuracion->premio_2;
|
||||
$this->premio_3 = $consulta_configuracion->premio_3;
|
||||
$this->premio_4 = $consulta_configuracion->premio_4;
|
||||
$this->premio_5 = $consulta_configuracion->premio_5;
|
||||
$this->premio_6 = $consulta_configuracion->premio_6;
|
||||
$this->premio_7 = $consulta_configuracion->premio_7;
|
||||
$this->premio_8 = $consulta_configuracion->premio_8;
|
||||
$this->premio_9 = $consulta_configuracion->premio_9;
|
||||
$this->premio_10 = $consulta_configuracion->premio_10;
|
||||
|
||||
$this->img_top = $consulta_configuracion->img_top;
|
||||
$this->mensaje_top = $consulta_configuracion->mensaje_top;
|
||||
|
||||
//msj
|
||||
|
||||
$this->mensaje_msj_compra= $consulta_configuracion->msj_compra;
|
||||
$this->mensaje_msj_wp= $consulta_configuracion->msj_wp;
|
||||
|
||||
$this->clave_1 = $consulta_configuracion->clave_1;
|
||||
$this->clave_2 = $consulta_configuracion->clave_2;
|
||||
$this->clave_3 = $consulta_configuracion->clave_3;
|
||||
$this->clave_4 = $consulta_configuracion->clave_4;
|
||||
$this->clave_5 = $consulta_configuracion->clave_5;
|
||||
$this->clave_6 = $consulta_configuracion->clave_6;
|
||||
|
||||
$this->iptv = $consulta_configuracion->iptv;
|
||||
$this->notificacion = $consulta_configuracion->hora;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return view('livewire.show-configuracion',[
|
||||
'sliders' => slider::get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function guardarclaves(){
|
||||
$claves=$this->consulta_configuracion->update([
|
||||
'clave_1' => $this->clave_1,
|
||||
'clave_2' => $this->clave_2,
|
||||
'clave_3' => $this->clave_3,
|
||||
'clave_4' => $this->clave_4,
|
||||
'clave_5' => $this->clave_5,
|
||||
'clave_6' => $this->clave_6,
|
||||
]);
|
||||
|
||||
if ($claves) {
|
||||
|
||||
$this->alert('success', 'claves actualizado', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function guardar(){
|
||||
|
||||
if (!empty($this->photo)) {
|
||||
$nombre=Str::random(10);
|
||||
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location = "photos/".$nombre.".webp";
|
||||
|
||||
Storage::disk('local')->put($location, $img);
|
||||
|
||||
$url_logo = $location;
|
||||
}else{
|
||||
$url_logo = $this->url_logo ;
|
||||
}
|
||||
|
||||
$configuracion=$this->consulta_configuracion->update([
|
||||
'nombre' => $this->nombre,
|
||||
'slogan' => $this->slogan,
|
||||
'color_boton' => $this->color_boton,
|
||||
'url_logo' => $url_logo,
|
||||
'color_barra' => $this->color_barra,
|
||||
'color_menu'=> $this->color_menu,
|
||||
'usermodifico_id'=>Auth::user()->id,
|
||||
|
||||
]);
|
||||
if ($configuracion) {
|
||||
|
||||
$this->alert('success', 'Configuración actualizada', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function guardarSlider(){
|
||||
|
||||
if (!empty($this->slider)) {
|
||||
|
||||
$nombre=Str::random(12);
|
||||
|
||||
$img = img::make($this->slider)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location = "photos/".$nombre.".webp";
|
||||
|
||||
Storage::disk('local')->put($location, $img);
|
||||
|
||||
$url_slider = $location;
|
||||
}else{
|
||||
$url_slider = '' ;
|
||||
}
|
||||
|
||||
$guardar = new slider;
|
||||
$guardar->slider = $url_slider;
|
||||
$guardar->save();
|
||||
|
||||
$this->slider = '';
|
||||
}
|
||||
|
||||
public function cancelarSlider()
|
||||
{
|
||||
$this->slider = '';
|
||||
}
|
||||
|
||||
public function deleteSlider($id)
|
||||
{
|
||||
$this->delete_slider = $id;
|
||||
$this->alert('warning', '¿Eliminar slider?', [
|
||||
'position' => 'center',
|
||||
'timer' => '10000',
|
||||
'toast' => false,
|
||||
'text' => 'Esta seguro',
|
||||
'showConfirmButton' => true,
|
||||
'onConfirmed' => 'confirmed',
|
||||
'showDenyButton' => false,
|
||||
'onDenied' => '',
|
||||
'showCancelButton' => true,
|
||||
'onDismissed' => '',
|
||||
'cancelButtonText' => 'Salir',
|
||||
'confirmButtonText' => 'Si',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return [
|
||||
'confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
public function confirmed(){
|
||||
slider::where('id',$this->delete_slider)->delete();
|
||||
|
||||
$this->alert('success', 'Imagen eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
public function guardarTop(){
|
||||
|
||||
if (!empty($this->photo_top)) {
|
||||
$nombre=Str::random(10);
|
||||
$img = img::make($this->photo_top)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
$location = "photos/".$nombre.".webp";
|
||||
Storage::disk('local')->put($location, $img);
|
||||
$photo_top = $location;
|
||||
|
||||
}else{
|
||||
$photo_top = $this->img_top ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP1)) {
|
||||
$imgP1=$this->imgP1->store('photos');
|
||||
}else{
|
||||
$imgP1 = $this->top_1 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP2)) {
|
||||
$imgP2=$this->imgP2->store('photos');
|
||||
}else{
|
||||
$imgP2 = $this->top_2 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP3)) {
|
||||
$imgP3=$this->imgP3->store('photos');
|
||||
}else{
|
||||
$imgP3 = $this->top_3 ;
|
||||
}
|
||||
if (!empty($this->imgP4)) {
|
||||
$imgP4=$this->imgP4->store('photos');
|
||||
}else{
|
||||
$imgP4 = $this->top_4 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP5)) {
|
||||
$imgP5=$this->imgP5->store('photos');
|
||||
}else{
|
||||
$imgP5 = $this->top_5 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP6)) {
|
||||
$imgP6=$this->imgP6->store('photos');
|
||||
}else{
|
||||
$imgP6 = $this->top_6 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP7)) {
|
||||
$imgP7=$this->imgP7->store('photos');
|
||||
}else{
|
||||
$imgP7 = $this->top_7 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP8)) {
|
||||
$imgP8=$this->imgP8->store('photos');
|
||||
}else{
|
||||
$imgP8 = $this->top_8 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP9)) {
|
||||
$imgP9=$this->imgP9->store('photos');
|
||||
}else{
|
||||
$imgP9 = $this->top_9 ;
|
||||
}
|
||||
|
||||
if (!empty($this->imgP10)) {
|
||||
$imgP10=$this->imgP10->store('photos');
|
||||
}else{
|
||||
$imgP10 = $this->top_10 ;
|
||||
}
|
||||
|
||||
$top = $this->consulta_configuracion->update([
|
||||
|
||||
'top_1' => $imgP1,
|
||||
'top_2' => $imgP2,
|
||||
'top_3' => $imgP3,
|
||||
'top_4' => $imgP4,
|
||||
'top_5' => $imgP5,
|
||||
'top_6' => $imgP6,
|
||||
'top_7' => $imgP7,
|
||||
'top_8' => $imgP8,
|
||||
'top_9' => $imgP9,
|
||||
'top_10' => $imgP10,
|
||||
|
||||
'img_top' => $photo_top,
|
||||
'mensaje_top' => $this->mensaje_top,
|
||||
'premio_1' => $this->premio_1,
|
||||
'premio_2' => $this->premio_2,
|
||||
'premio_3' => $this->premio_3,
|
||||
'premio_4' => $this->premio_4,
|
||||
'premio_5' => $this->premio_5,
|
||||
'premio_6' => $this->premio_6,
|
||||
'premio_7' => $this->premio_7,
|
||||
'premio_8' => $this->premio_8,
|
||||
'premio_9' => $this->premio_9,
|
||||
'premio_10' => $this->premio_10,
|
||||
|
||||
|
||||
]);
|
||||
|
||||
if($top){
|
||||
$this->alert('success', 'Top distribuidores actualizado', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function guardarMsjCompra(){
|
||||
$msj = $this->consulta_configuracion->update([
|
||||
'msj_compra' => $this->mensaje_msj_compra,
|
||||
'msj_wp' => $this->mensaje_msj_wp,
|
||||
]);
|
||||
|
||||
if ($msj) {
|
||||
|
||||
$this->alert('success', 'Mensaje actualizado', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function guardariptv(){
|
||||
// dd($this->iptv);
|
||||
$iptv = $this->consulta_configuracion->update([
|
||||
'iptv' => $this->iptv,
|
||||
]);
|
||||
|
||||
if ($iptv) {
|
||||
|
||||
$this->alert('success', 'iptv actualizado', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function eliminarC(){
|
||||
//$eliminar_cuentas = Cuentas::truncate();
|
||||
$this->alert('warning', 'Funcion deshabilitada ', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
public function eliminarR(){
|
||||
// $eliminar_cuentas = Historial_cuenta::truncate();
|
||||
$this->alert('warning', 'Funcion deshabilitada ', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
public function eliminarH(){
|
||||
//$desasociar_cuentas = Historiale::truncate();
|
||||
$this->alert('warning', 'Funcion deshabilitada ', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
public function guardarnot(){
|
||||
$notificacion = $this->consulta_configuracion->update([
|
||||
'hora' => $this->notificacion,
|
||||
]);
|
||||
$this->alert('success', 'La hora de notificación ha sido actualizada.', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
public function eliminarCache(){
|
||||
Artisan::call('cache:clear');
|
||||
Artisan::call('config:clear');
|
||||
Artisan::call('view:clear');
|
||||
Artisan::call('route:cache');
|
||||
|
||||
|
||||
$this->alert('success', 'Cache removido correctamente', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Promociones;
|
||||
use App\Models\Role;
|
||||
use App\Models\Servicio;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
|
||||
class ShowIndex extends Component
|
||||
{
|
||||
|
||||
public function render()
|
||||
{
|
||||
$promociones = Promociones::where('visible','true')->limit(4)->get();
|
||||
|
||||
$this->rol_id = Role::where('nombre','cliente')->value('id');
|
||||
|
||||
$planes = Servicio::where('estado','activo')->withMax(['tarifas' => function ($query) {
|
||||
$query->where('rol_id', $this->rol_id);
|
||||
}],'valor')->withMin(['tarifas' => function ($query) {
|
||||
$query->where('rol_id', $this->rol_id);
|
||||
}],'valor')->get();
|
||||
|
||||
return view('livewire.show-index',[
|
||||
'planes' => $planes,
|
||||
'promociones' => $promociones,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use Livewire\Component;
|
||||
|
||||
class ShowIndexCategoria extends Component
|
||||
{
|
||||
public $verPro=false;
|
||||
public $categorian;
|
||||
public $imagen;
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
$consulta_categoria = Categoria::get();
|
||||
return view('livewire.show-index-categoria',[
|
||||
'categorias' => $consulta_categoria
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\Role;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ShowIndexPromo extends Component
|
||||
{
|
||||
public $nombre_comprarPromo;
|
||||
public $celular_comprarPromo;
|
||||
public $email_comprarPromo;
|
||||
public $cantidad_comprarPromo = 1;
|
||||
public $fechaHoy;
|
||||
public $fechaFinal;
|
||||
public $promo_id;
|
||||
|
||||
protected $rules = [
|
||||
'nombre_comprarPromo' => 'required',
|
||||
'celular_comprarPromo' => 'required',
|
||||
'email_comprarPromo' => 'required',
|
||||
'cantidad_comprarPromo' => 'required',
|
||||
];
|
||||
public function render(Request $request)
|
||||
{
|
||||
if (empty($this->promo_id)) {
|
||||
$this->promo_id = $request->promo;
|
||||
}
|
||||
|
||||
$consulta_promo = Promociones::find($this->promo_id);
|
||||
$this->consulta= $consulta_promo;
|
||||
|
||||
$promociones= Promociones::where('visible','true')->get();
|
||||
$fechaActual = Carbon::now();
|
||||
$this->fechaHoy = $fechaActual;
|
||||
//dd($consulta_promo);
|
||||
$this->fechaFinal = $fechaActual->addDay($consulta_promo->dias);
|
||||
|
||||
|
||||
|
||||
return view('livewire.show-index-promo',[
|
||||
'promo' => $consulta_promo,
|
||||
'promociones'=>$promociones
|
||||
]);
|
||||
}
|
||||
|
||||
public function comprar()
|
||||
{
|
||||
|
||||
$this->validate();
|
||||
|
||||
|
||||
$usuario_existe = User::firstWhere('email', $this->email_comprarPromo)->id ?? null;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$usuario = new User;
|
||||
$usuario->name = $this->nombre_tarjetaPlan;
|
||||
$usuario->email = $this->email_tarjetaPlan;
|
||||
$usuario->password = '123';
|
||||
$usuario->celular = $this->celular_tarjetaPlan;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
} else {
|
||||
|
||||
$usuario_id = $usuario_existe;
|
||||
}
|
||||
if (empty(Auth::user())) {
|
||||
$historial = new Historiale();
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->consulta->precio *$this->cantidad_comprarPromo;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Role::where('nombre','super')->first()->usuarios->first()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->save();
|
||||
}else{
|
||||
$historial = new Historiale;
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->consulta->precio *$this->cantidad_comprarPromo ;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Auth::user()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->save();
|
||||
}
|
||||
|
||||
return redirect('/comprar?monto='.$historial->valor.'&id='.$historial->id);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Role;
|
||||
use App\Models\Servicio;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ShowIndexServicio extends Component
|
||||
{
|
||||
|
||||
public $tarifa_id;
|
||||
public $fechaFinal;
|
||||
public $disponibles;
|
||||
public $fechaActual;
|
||||
public $valor;
|
||||
public $servicio_id;
|
||||
|
||||
public $celular_tarjetaPlan;
|
||||
public $nombre_tarjetaPlan;
|
||||
public $email_tarjetaPlan;
|
||||
public $cantidad_tarjetaPlan = 1;
|
||||
public $total;
|
||||
public $rol_id;
|
||||
|
||||
protected $rules = [
|
||||
'nombre_tarjetaPlan' => 'required',
|
||||
'cantidad_tarjetaPlan' => 'required',
|
||||
'email_tarjetaPlan' => 'required',
|
||||
'celular_tarjetaPlan' => 'required',
|
||||
];
|
||||
|
||||
public function render(Request $request)
|
||||
{
|
||||
if (empty($this->servicio_id)) {
|
||||
$this->servicio_id = $request->servicio;
|
||||
}
|
||||
$this->total = (int) $this->valor * (int)$this->cantidad_tarjetaPlan;
|
||||
$this->fechaHoy = Carbon::now();
|
||||
$this->fechaHoy = $this->fechaHoy->format('d/m/Y');
|
||||
|
||||
$fechaActual = Carbon::now();
|
||||
$this->fechaActual = Carbon::parse($this->fechaActual);
|
||||
|
||||
$date = $fechaActual ->subDay(8);
|
||||
$this->fecha= $date->format('Y-m-d');
|
||||
|
||||
if (!empty($this->tarifa_id)) {
|
||||
|
||||
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifas->dias-15);
|
||||
$this->fecha_final_2 = $today = Carbon::now()->addDays($tarifas->dias+15);
|
||||
|
||||
$tarifas = Tarifas::with('servicio')->where('id', $this->tarifa_id)->first();
|
||||
|
||||
$cuentas_creadas = Cuentas::whereDate('inicio','>=',$this->fecha)->where('servicio_id',$this->servicio_id)->where('estado','activo')->get();
|
||||
$cuentas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_creadas->pluck('id'))->count();
|
||||
|
||||
|
||||
$cuentas_completas = Cuentas::whereDate('inicio','>=',$this->fecha)->whereDate('vencimiento','>=',$this->fecha_final_1)->whereDate('vencimiento','<=',$this->fecha_final_2)->where('servicio_id',$tarifas->servicio->id)->where('estado','pendiente')->get();
|
||||
$cuentas_completas_tomadas = Historial_cuenta::whereIn('cuenta_id', $cuentas_completas->pluck('id'))
|
||||
->count();
|
||||
|
||||
$this->fechaFinal = $this->fechaActual->addDay($tarifas->dias);
|
||||
$this->fechaFinal = $this->fechaFinal->format('d/m/Y');
|
||||
if ($tarifas->pantallas == $tarifas->servicio->completa) {
|
||||
$this->disponibles = (($cuentas_completas->count()*$tarifas->servicio->completa) - $cuentas_completas_tomadas)/ $tarifas->pantallas;
|
||||
}else{
|
||||
$this->disponibles = (($cuentas_creadas->count()*$tarifas->servicio->pantallas) - $cuentas_tomadas)/ $tarifas->pantallas;
|
||||
}
|
||||
|
||||
$this->valor= $tarifas->valor;
|
||||
}
|
||||
|
||||
|
||||
$this->rol_id = Role::where('nombre','cliente')->value('id');
|
||||
|
||||
|
||||
$planes = Servicio::where('estado','activo')->withMax(['tarifas' => function ($query) {
|
||||
$query->where('rol_id', $this->rol_id);
|
||||
}],'valor')->withMin(['tarifas' => function ($query) {
|
||||
$query->where('rol_id', $this->rol_id);
|
||||
}],'valor')->with(['tarifas' => function ($query) {
|
||||
$query->where('rol_id', $this->rol_id);
|
||||
}])->get();
|
||||
|
||||
foreach ($planes as $plan ) {
|
||||
if($plan->id == $this->servicio_id){
|
||||
$servicio = $plan;
|
||||
}
|
||||
|
||||
}
|
||||
return view('livewire.show-index-servicio',[
|
||||
'servicio' =>$servicio,
|
||||
'planes' =>$planes
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ---------------- Btn Comprar ---------------- */
|
||||
public function comprar()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$total_valor = (int) $this->valor * (int)$this->cantidad_tarjetaPlan;
|
||||
|
||||
$usuario_existe = User::firstWhere('email', $this->email_tarjetaPlan)->id ?? null;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$usuario = new User;
|
||||
$usuario->name = $this->nombre_tarjetaPlan;
|
||||
$usuario->email = $this->email_tarjetaPlan;
|
||||
$usuario->password = '123';
|
||||
$usuario->celular = $this->celular_tarjetaPlan;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
}else{
|
||||
|
||||
$usuario_id = $usuario_existe;
|
||||
|
||||
}
|
||||
|
||||
$historial = new Historiale;
|
||||
$historial->fecha_inicio = $this->fechaActual;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $total_valor ;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
if (empty(Auth::user())) { // SI esta logueado o no
|
||||
$historial->vendedor_id = Role::where('nombre','super')->first()->usuarios->first()->id;
|
||||
}else{
|
||||
$historial->vendedor_id = Auth::user()->id;
|
||||
}
|
||||
$historial->tarifa_id = $this->tarifa_id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_tarjetaPlan;
|
||||
$historial->save();
|
||||
|
||||
|
||||
return redirect('/comprar?monto='.$historial->valor.'&id='.$historial->id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Configuracione;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\slider;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowInicio extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
|
||||
public function render()
|
||||
{
|
||||
$consulta_promociones = slider::get();
|
||||
//dd($consulta_promociones);
|
||||
|
||||
return view('livewire.show-inicio',[
|
||||
'promociones' => $consulta_promociones,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
use App\Models\Historiale;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ShowLogs extends Component
|
||||
{
|
||||
Use WithPagination;
|
||||
public $buscar;
|
||||
|
||||
public function render()
|
||||
{
|
||||
$fechaVencimiento = Carbon::now()->subDay(30);
|
||||
//dd($fechaVencimiento);
|
||||
$consulta_historial = Historiale::with('promocion', 'tarifa', 'vendedor','cuentas','cuentas_obsoletas')->whereDate('fecha_final','>', $fechaVencimiento)->orderBy('id', 'DESC')
|
||||
->when(!empty($this->buscar), function ($query) {
|
||||
$query->whereHas('cuentas', function ($subquery) {
|
||||
$subquery->where('correo', 'LIKE', '%' . $this->buscar . '%');
|
||||
})->orWhereHas('vendedor', function ($subquery) {
|
||||
$subquery->where('email', 'LIKE', '%' . $this->buscar . '%');
|
||||
});
|
||||
});
|
||||
// Limitar resultados a un máximo de 200
|
||||
$resultados= $consulta_historial->take(200)->paginate(20);
|
||||
|
||||
// Restablecer la paginación después de limitar los resultados
|
||||
$resultados->setCollection($resultados->getCollection()->values());
|
||||
|
||||
|
||||
//dd($consulta_historial);
|
||||
return view('livewire.show-logs',['logs'=>$resultados]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
use Illuminate\Http\Request;
|
||||
use Livewire\Component;
|
||||
use App\Models\recarga;
|
||||
use App\Models\Saldo;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowOrder extends Component
|
||||
{
|
||||
|
||||
use LivewireAlert;
|
||||
|
||||
public $estado;
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
return view('livewire.show-order');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
|
||||
class ShowPerfil extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithFileUploads;
|
||||
|
||||
|
||||
public $nombre;
|
||||
public $email;
|
||||
public $celular;
|
||||
public $cedula;
|
||||
public $rol;
|
||||
public $url_imagen;
|
||||
public $url_imagen_d;
|
||||
public $url;
|
||||
|
||||
public $modalPassword = false;
|
||||
|
||||
public $newPassword;
|
||||
|
||||
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (empty($this->nombre)) {
|
||||
|
||||
$consulta_perfil = User::with('rol')->where('id', Auth()->user()->id)->first();
|
||||
|
||||
$this->nombre = $consulta_perfil->name;
|
||||
$this->email = $consulta_perfil->email;
|
||||
$this->celular = $consulta_perfil->celular;
|
||||
$this->cedula = $consulta_perfil->cedula;
|
||||
$this->rol = $consulta_perfil->rol->nombre;
|
||||
$this->url_imagen_d = $consulta_perfil->img_perfil;
|
||||
}
|
||||
|
||||
return view('livewire.show-perfil');
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
if ($this->url_imagen) {
|
||||
$this->url = $this->url_imagen->store('photos');
|
||||
} else {
|
||||
$this->url = null;
|
||||
}
|
||||
|
||||
if (!empty($this->nombre) && !empty($this->email) && !empty($this->celular) && !empty($this->cedula)) {
|
||||
|
||||
User::where('id', Auth()->user()->id)->update([
|
||||
'name' => $this->nombre,
|
||||
'email' => $this->email,
|
||||
'celular' => $this->celular,
|
||||
'cedula' => $this->cedula,
|
||||
'img_perfil' => $this->url
|
||||
]);
|
||||
|
||||
$this->alert('success', 'La informacion se actualizo correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} else {
|
||||
$this->alert('warning', 'Llene todos los campos!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function cambiar_password()
|
||||
{
|
||||
$this->modalPassword = true;
|
||||
}
|
||||
|
||||
public function confirmar()
|
||||
{
|
||||
|
||||
$validatedData = $this->validate([
|
||||
'newPassword' => 'required'
|
||||
]);
|
||||
|
||||
User::where('id', Auth()->user()->id)->update([
|
||||
'password' => Hash::make($this->newPassword),
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Contraseña actualizada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->limpiarContra();
|
||||
}
|
||||
|
||||
public function limpiarContra()
|
||||
{
|
||||
$this->newPassword = '';
|
||||
$this->modalPassword = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,543 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Role;
|
||||
use App\Models\Servicio;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\user;
|
||||
use Carbon\Carbon;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Livewire\WithFileUploads;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
|
||||
class ShowPlanes extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithFileUploads;
|
||||
use WithPagination;
|
||||
|
||||
public $delete_cuenta;
|
||||
public $informacionTarifaRol;
|
||||
|
||||
public $newCuenta = false;
|
||||
public $renovar = false;
|
||||
public $serviciosModal = false;
|
||||
public $modTarifas = false;
|
||||
|
||||
public $roles_modTarifas;
|
||||
public $pantallas_modTarifas;
|
||||
public $precio_modTarifas = 0;
|
||||
|
||||
public $estadoTarifa = true;
|
||||
public $diasTarifa = '30';
|
||||
public $servicio_modTarifas;
|
||||
|
||||
|
||||
public $buscar;
|
||||
public $servicios_id;
|
||||
public $fechaActual;
|
||||
public $id_cuentaVer;
|
||||
public $consulta_verUsuarios;
|
||||
public $nombre_servicios = '';
|
||||
|
||||
|
||||
public $nombre_servicio;
|
||||
public $descripcion_servicio;
|
||||
public $estado_servicio;
|
||||
public $color_servicio;
|
||||
|
||||
|
||||
public $servicio_newCuenta;
|
||||
public $usuario_newCuenta;
|
||||
public $password_newCuenta;
|
||||
public $fecha_inicial;
|
||||
public $fecha_final;
|
||||
|
||||
|
||||
public $observacionesm = false;
|
||||
public $observaciones;
|
||||
public $id_observacion;
|
||||
|
||||
public $observacionesm1 = false;
|
||||
public $observaciones1;
|
||||
public $id_observacion1;
|
||||
|
||||
|
||||
public $usuario_renovar;
|
||||
public $password_renovar;
|
||||
public $fecha_inicial_renovar;
|
||||
public $fecha_final_renovar;
|
||||
|
||||
public $servicio;
|
||||
|
||||
public $photo;
|
||||
public $photo_inicio;
|
||||
|
||||
public $estado='activo';
|
||||
public $completa;
|
||||
public $pantallas;
|
||||
public $venceHoy;
|
||||
public $activoHoy;
|
||||
public $libres = null;
|
||||
|
||||
public $delete_1=['1'];
|
||||
public $tarifas;
|
||||
public $addUser;
|
||||
public $usuarios;
|
||||
|
||||
public $selectedOption;
|
||||
public $searchTerm = '';
|
||||
public $tarifa;
|
||||
public $perfil;
|
||||
public $repetidas;
|
||||
|
||||
public $editarTarifaRol = false;
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->fechaActual = date('Y-m-d');
|
||||
|
||||
$consulta_tarifas = Tarifas::take(1);
|
||||
|
||||
if(empty($this->fecha_inicial)){
|
||||
$this->fecha_inicial=Carbon::now()->format('Y-m-d');
|
||||
$this->fecha_final=Carbon::now()->addDay(30)->format('Y-m-d');
|
||||
}
|
||||
if ($this->servicio_modTarifas) {
|
||||
$this->tarifas = Tarifas::with('rol')
|
||||
->where('servicio_id', $this->servicio_modTarifas)
|
||||
->where('estado', 'activo')
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
// Empezamos definiendo la consulta básica
|
||||
$consulta_cuentas = Cuentas::where('correo', 'LIKE', '%'.$this->buscar.'%')
|
||||
->withCount('historiales')
|
||||
->with('historiales')
|
||||
->orderBy('id','DESC');
|
||||
|
||||
$consulta_cuentas = $consulta_cuentas->when(!empty($this->servicios_id), function ($query) {
|
||||
return $query->where('servicio_id', $this->servicios_id);
|
||||
})
|
||||
->when(!empty($this->completa), function ($query) {
|
||||
return $query->where('estado', 'pendiente');
|
||||
})
|
||||
->when(!empty($this->pantallas), function ($query) {
|
||||
return $query->where('estado', 'activo');
|
||||
})
|
||||
->when(!empty($this->activoHoy), function ($query) {
|
||||
$fechaHoy = Carbon::now()->subDay(1);
|
||||
return $query->whereDate('vencimiento', '>', $fechaHoy);
|
||||
})
|
||||
->when($this->venceHoy, function ($query) {
|
||||
$fechaHoy = Carbon::now()->addDay(1);
|
||||
return $query->whereDate('vencimiento', '<', $fechaHoy);
|
||||
})
|
||||
->when($this->libres, function ($query) {
|
||||
return $query->whereDoesntHave('historiales');
|
||||
});
|
||||
|
||||
if (!empty($this->repetidas)) {
|
||||
$consulta_cuentas = $consulta_cuentas->whereIn('correo', function ($subquery) {
|
||||
$subquery->select('correo')
|
||||
->from('cuentas')
|
||||
->groupBy('correo')
|
||||
->havingRaw('COUNT(*) > 1');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$consulta_cuentas = $consulta_cuentas->paginate(30);
|
||||
|
||||
if ( $this->searchTerm) {
|
||||
$this->usuarios = User::where('email', 'LIKE', '%' . $this->searchTerm . '%')->get();
|
||||
if ($this->selectedOption) {
|
||||
$this->searchTerm = $this->selectedOption;
|
||||
}
|
||||
}else{
|
||||
$this->selectedOption = null;
|
||||
}
|
||||
|
||||
|
||||
return view('livewire.show-planes', [
|
||||
|
||||
'cuentas' => $consulta_cuentas,
|
||||
'servicios' => Servicio::where('estado','activo')->get(),
|
||||
'roles' => Role::get()
|
||||
]);
|
||||
}
|
||||
|
||||
//modal Ver
|
||||
public function ver($id, $nom)
|
||||
{
|
||||
$this->id_cuentaVer = $id;
|
||||
$this->consulta_verUsuarios = Cuentas::with('historiales','servicio')->where('id', $id)->first();
|
||||
//dd($this->consulta_verUsuarios);
|
||||
$this->nombre_servicios = $nom;
|
||||
}
|
||||
public function openRenovar()
|
||||
{
|
||||
$this->renovar = true;
|
||||
|
||||
$id = $this->id_cuentaVer;
|
||||
|
||||
$renovarCuenta = Cuentas::findOrFail($id);
|
||||
$this->usuario_renovar = $renovarCuenta->correo;
|
||||
$this->password_renovar = $renovarCuenta->password;
|
||||
$this->fecha_inicial_renovar = $renovarCuenta->inicio;
|
||||
$this->fecha_final_renovar = $renovarCuenta->vencimiento;
|
||||
$this->estado = $renovarCuenta->estado;
|
||||
}
|
||||
public function saveRenovar()
|
||||
{
|
||||
$id = $this->id_cuentaVer;
|
||||
|
||||
|
||||
Cuentas::where('id', $id)->update([
|
||||
'correo' => $this->usuario_renovar,
|
||||
'password' => $this->password_renovar,
|
||||
'inicio' => date('Y-m-d', strtotime(strval($this->fecha_inicial_renovar))),
|
||||
'vencimiento' => date('Y-m-d', strtotime(strval($this->fecha_final_renovar))),
|
||||
'estado' => $this->estado,
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Cuenta renovada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->renovar = false;
|
||||
}
|
||||
|
||||
/* ------------- CREAR ------------- */
|
||||
public function createNewCuenta()
|
||||
{
|
||||
$this->validate([
|
||||
'servicio_newCuenta' => 'required',
|
||||
'usuario_newCuenta' => 'required',
|
||||
'password_newCuenta' => 'required',
|
||||
'fecha_inicial' => 'required',
|
||||
'fecha_final' => 'required',
|
||||
'estado' => 'required',
|
||||
]);
|
||||
|
||||
|
||||
if($consulta_cuenta = Cuentas::where('correo',$this->usuario_newCuenta)->exists()){
|
||||
$this->alert('warning', 'La cuenta ya existe', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}else{
|
||||
$cuenta = new Cuentas;
|
||||
$cuenta->servicio_id = $this->servicio_newCuenta;
|
||||
$cuenta->correo = $this->usuario_newCuenta;
|
||||
$cuenta->password = $this->password_newCuenta;
|
||||
$cuenta->inicio = date('Y-m-d', strtotime(strval($this->fecha_inicial)));
|
||||
$cuenta->vencimiento = date('Y-m-d', strtotime(strval($this->fecha_final)));
|
||||
$cuenta->estado = $this->estado;
|
||||
$cuenta->save();
|
||||
|
||||
$this->alert('success', 'Cuenta creada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->limpiarInputNewCuenta();
|
||||
|
||||
$this->newCuenta = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public function createServicio()
|
||||
{
|
||||
$url_foto = $this->photo->store('photos');
|
||||
$url_foto_inicio = $this->photo_inicio->store('photos');
|
||||
|
||||
$servicio = new Servicio;
|
||||
$servicio->nombre = $this->nombre_servicio;
|
||||
$servicio->descripcion = $this->descripcion_servicio;
|
||||
$servicio->estado = $this->estado_servicio;
|
||||
$servicio->color_fondo = $this->color_servicio;
|
||||
$servicio->pantallas = '6';
|
||||
$servicio->img = $url_foto;
|
||||
$servicio->img_inicio = $url_foto_inicio;
|
||||
$servicio->save();
|
||||
|
||||
$this->alert('success', 'Servicio creado correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->serviciosModal = false;
|
||||
}
|
||||
public function verObservacion($id)
|
||||
{
|
||||
$verObservacion = Historiale::findOrFail($id);
|
||||
|
||||
$this->id_observacion = $id;
|
||||
$this->observaciones = $verObservacion->observaciones;
|
||||
}
|
||||
public function update()
|
||||
{
|
||||
Historiale::where('id', $this->id_observacion)->update(['observaciones' => $this->observaciones,]);
|
||||
|
||||
$this->alert('success', 'Observacion añadida correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->observacionesm = false;
|
||||
}
|
||||
|
||||
public function verObservacion1($id)
|
||||
{
|
||||
$verObservacion = Cuentas::findOrFail($id);
|
||||
|
||||
$this->id_observacion1 = $id;
|
||||
|
||||
$this->observaciones1 = $verObservacion->observaciones;
|
||||
}
|
||||
public function update_observaciones1()
|
||||
{
|
||||
Cuentas::where('id', $this->id_observacion1)->update(['observaciones' => $this->observaciones1,]);
|
||||
|
||||
$this->alert('success', 'Observacion añadida correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->observacionesm1 = false;
|
||||
}
|
||||
|
||||
public function delete_cuenta($id)
|
||||
{
|
||||
$this->delete_cuenta = $id;
|
||||
$this->alert('warning', '¿Eliminar cuenta?', [
|
||||
'position' => 'center',
|
||||
'timer' => '10000',
|
||||
'toast' => false,
|
||||
'text' => 'Esta seguro',
|
||||
'showConfirmButton' => true,
|
||||
'onConfirmed' => 'confirmed',
|
||||
'showDenyButton' => false,
|
||||
'onDenied' => '',
|
||||
'showCancelButton' => true,
|
||||
'onDismissed' => '',
|
||||
'cancelButtonText' => 'Salir',
|
||||
'confirmButtonText' => 'Si',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return [
|
||||
'confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
public function confirmed()
|
||||
{
|
||||
Cuentas::where('id', $this->delete_cuenta)->delete();
|
||||
|
||||
$this->alert('success', 'Cuenta eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
/* ------------- ACTUALIZAR ------------- */
|
||||
public function updateTarifas()
|
||||
{
|
||||
$consulta_existe = Tarifas::where('pantallas', $this->pantallas_modTarifas)
|
||||
->where('servicio_id', $this->servicio_modTarifas)
|
||||
->where('rol_id', $this->roles_modTarifas)
|
||||
->where('dias', $this->diasTarifa)
|
||||
->exists();
|
||||
|
||||
if ($consulta_existe) {
|
||||
$this->alert('warning', '¡Esta tarifa ya existe!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} elseif (empty($this->servicio_modTarifas)) {
|
||||
$this->alert('warning', '¡Seleccione un servicio!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} elseif (empty($this->precio_modTarifas)) {
|
||||
$this->alert('warning', '¡Coloque un precio!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} else {
|
||||
$tarifa = new Tarifas;
|
||||
$tarifa->pantallas = $this->pantallas_modTarifas;
|
||||
$tarifa->dias = $this->diasTarifa;
|
||||
$tarifa->valor = $this->precio_modTarifas;
|
||||
$tarifa->estado = $this->estadoTarifa ? 'activo' : 'inactivo';
|
||||
$tarifa->servicio_id = $this->servicio_modTarifas;
|
||||
$tarifa->rol_id = $this->roles_modTarifas;
|
||||
$tarifa->save();
|
||||
|
||||
$this->alert('success', '¡Tarifas actualizadas correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* ------------- ELIMINAR ------------- */
|
||||
|
||||
public function eliminarModTarifa($id)
|
||||
{
|
||||
Tarifas::where('id',$id)->delete();
|
||||
|
||||
$this->alert('success', 'Tarifas eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
/* ------------- LIMPIAR CAMPOS ------------- */
|
||||
public function limpiarInputObservaciones()
|
||||
{
|
||||
$this->observaciones = '';
|
||||
}
|
||||
public function limpiarInputObservaciones1()
|
||||
{
|
||||
$this->observaciones1 = '';
|
||||
$this->observacionesm1 = false;
|
||||
}
|
||||
public function limpiarInputNewCuenta()
|
||||
{
|
||||
$this->servicio_newCuenta = null;
|
||||
$this->usuario_newCuenta = '';
|
||||
$this->password_newCuenta = '';
|
||||
$this->fecha_inicial = null;
|
||||
$this->fecha_final = null;
|
||||
|
||||
$this->newCuenta = false;
|
||||
}
|
||||
public function limpiarInputServiciosModal()
|
||||
{
|
||||
$this->nombre_servicio = '';
|
||||
$this->descripcion_servicio = '';
|
||||
$this->estado_servicio = null;
|
||||
$this->color_servicio = null;
|
||||
}
|
||||
|
||||
public function eliminarCuentas(){
|
||||
|
||||
$consulta_cuentas = Cuentas::whereIn('id',$this->delete_1)->delete();
|
||||
|
||||
}
|
||||
|
||||
public function openAdd(){
|
||||
|
||||
$this->addUser = true;
|
||||
|
||||
|
||||
}
|
||||
public function saveUser(){
|
||||
|
||||
$this->validate([
|
||||
'tarifa' => 'required',
|
||||
|
||||
]);
|
||||
|
||||
|
||||
$tarifa = json_decode($this->tarifa, true);
|
||||
//dd($this->tarifa['dias']);
|
||||
$usuario_existe = User::firstWhere('email', $this->searchTerm)->id ?? null;
|
||||
$usuario_id = $usuario_existe;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$rol_id=Role::where('nombre','cliente')->value('id');
|
||||
$usuario = new User;
|
||||
$usuario->name = 'AssignedUser';
|
||||
$usuario->email = $this->searchTerm;
|
||||
$usuario->password = '123456';
|
||||
$usuario->celular = '+57';
|
||||
$usuario->rol_id = $rol_id;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
}
|
||||
|
||||
|
||||
$historial = new Historiale;
|
||||
$historial->fecha_inicio = Carbon::now();
|
||||
$historial->fecha_final = Carbon::now()->addDay($tarifa['dias']);
|
||||
$historial->valor = '0';
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'activo';
|
||||
$historial->vendedor_id = Auth()->user()->id;
|
||||
$historial->tarifa_id = $tarifa['id'];
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $tarifa['pantallas'];
|
||||
$historial->save();
|
||||
|
||||
$consultaHC = Historial_cuenta::where('cuenta_id',$this->consulta_verUsuarios->id)->where('perfil',$this->perfil)->exists();
|
||||
|
||||
if (!$consultaHC) {
|
||||
$historial_cuenta = new Historial_cuenta;
|
||||
$historial_cuenta->cuenta_id = $this->consulta_verUsuarios->id;
|
||||
$historial_cuenta->historial_id = $historial->id;
|
||||
$historial_cuenta->perfil = $this->perfil;
|
||||
$historial_cuenta->save();
|
||||
|
||||
$this->alert('success', 'Usuario añadido correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->addUser = false;
|
||||
$this->consulta_verUsuarios = Cuentas::with('historiales','servicio')->where('id', $this->id_cuentaVer)->first();
|
||||
|
||||
}else{
|
||||
$historial->delete();
|
||||
$this->alert('warning', 'El perfil ya se encuentra en uso!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function editar($tarifa){
|
||||
//dd($tarifa);
|
||||
$this->editarTarifaRol=true;
|
||||
$this->informacionTarifaRol = $tarifa;
|
||||
|
||||
$this->roles_modTarifas = $tarifa['rol_id'];
|
||||
$this->pantallas_modTarifas = $tarifa['pantallas'];
|
||||
$this->precio_modTarifas = $tarifa['valor'];
|
||||
$this->diasTarifa = $tarifa['dias'];
|
||||
$this->estadoTarifa = $tarifa['estado'];
|
||||
$this->servicio_modTarifas = $tarifa['servicio_id'];
|
||||
}
|
||||
|
||||
public function actualizarTarifaRol($id){
|
||||
//dd($id);
|
||||
$validateData = $this->validate([
|
||||
'roles_modTarifas'=> 'required',
|
||||
'pantallas_modTarifas' => 'required',
|
||||
'precio_modTarifas'=> 'required',
|
||||
'diasTarifa' => 'required',
|
||||
'estadoTarifa'=> 'required'
|
||||
]);
|
||||
$consulta = Tarifas::find($id)->update([
|
||||
'pantallas' => $this->pantallas_modTarifas,
|
||||
'dias' => $this->diasTarifa,
|
||||
'valor'=> $this->precio_modTarifas,
|
||||
'estado'=> $this->estadoTarifa,
|
||||
'rol_id' => $this->roles_modTarifas,
|
||||
'servicio_id' => $this->servicio_modTarifas
|
||||
|
||||
]);
|
||||
$this->alert('success', 'Tarifa actualizada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->editarTarifaRol = false;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,674 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Configuracione;
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Promocion_tarifa;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use App\Notifications\compra;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Intervention\Image\ImageManagerStatic as Img;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use Exception;
|
||||
use Twilio\Rest\Client;
|
||||
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
||||
|
||||
|
||||
class ShowPromociones extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
use LivewireAlert;
|
||||
|
||||
public $categoria_id;
|
||||
|
||||
public $eliminar_id;
|
||||
public $list;
|
||||
public $list2;
|
||||
|
||||
public $categorian;
|
||||
public $photo;
|
||||
|
||||
public $newPromocion = false;
|
||||
public $nombre_promocion;
|
||||
public $descripcion_promocion;
|
||||
public $valor_promocion;
|
||||
public $estado_promocion;
|
||||
public $fecha_limite_promocion;
|
||||
public $categoria_id_promocion;
|
||||
|
||||
public $fechaFinal;
|
||||
|
||||
public $tarifa_id_promocion;
|
||||
public $dias_comprarPromo;
|
||||
public $valor_comprarPromo;
|
||||
public $nombre_comprarPromo;
|
||||
public $celular_comprarPromo;
|
||||
public $email_comprarPromo;
|
||||
public $cantidad_comprarPromo = 1;
|
||||
|
||||
public $newCategoria = false;
|
||||
public $nombre_categoria;
|
||||
public $descripcion_categoria;
|
||||
|
||||
public $modalComprarPromo = false;
|
||||
|
||||
public $verPromo = false;
|
||||
public $precioAntes;
|
||||
public $precioAhora;
|
||||
public $fechaLimite;
|
||||
public $nombrePromo;
|
||||
public $descripcionPromo;
|
||||
|
||||
public $editarPromo = false;
|
||||
public $nombre_editarPromo;
|
||||
public $descripcion_editarPromo;
|
||||
public $valor_editarPromo;
|
||||
public $estado_editarPromo;
|
||||
public $fecha_limite_editarPromo;
|
||||
public $categoria_id_editarPromo;
|
||||
public $editar_promo_id;
|
||||
public $imagen;
|
||||
public $dias;
|
||||
public $total;
|
||||
public $consulta;
|
||||
public $fechaHoy;
|
||||
public $fechafinal;
|
||||
public $fecha;
|
||||
public $credenciales;
|
||||
public $cuentas;
|
||||
public $img_ver;
|
||||
public $fecha_editarPromo;
|
||||
public $mensaje_servicio;
|
||||
|
||||
|
||||
public $categoria_photo;
|
||||
|
||||
protected $rules = [
|
||||
'nombre_comprarPromo' => 'required',
|
||||
'celular_comprarPromo' => 'required',
|
||||
'email_comprarPromo' => 'required',
|
||||
'cantidad_comprarPromo' => 'required',
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
$date = Carbon::now()->subDay(30);
|
||||
$this->fecha= $date->format('Y-m-d');
|
||||
|
||||
$this->fechaActual = Carbon::now();
|
||||
$this->fechaActual = Carbon::parse($this->fechaActual);
|
||||
$this->fechaHoy = Carbon::now();
|
||||
$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->fechaHoy = $this->fechaHoy->format('d/m/Y');
|
||||
|
||||
if (empty($this->nombre_comprarPromo) && empty($this->email_comprarPromo)) {
|
||||
$usuario_actual = Auth::user();
|
||||
$this-> nombre_comprarPromo = $usuario_actual->name;
|
||||
$this-> email_comprarPromo = $usuario_actual->email;
|
||||
$this-> celular_comprarPromo = $usuario_actual->celular;
|
||||
//dd($this-> nombre_tarjetaPlan);
|
||||
}
|
||||
|
||||
|
||||
return view('livewire.show-promociones', [
|
||||
|
||||
'categorias' => Categoria::get(),
|
||||
'tarifas' => Tarifas::with('servicio')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function verPromocion($id)
|
||||
{
|
||||
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->with([
|
||||
'usuario_promos' => function ($query) {
|
||||
$query->where('usuario_id', Auth::user()->id);
|
||||
},
|
||||
'tarifaPromo' => function ($query) {
|
||||
$query->where('rol_id', Auth::user()->rol->id);
|
||||
}
|
||||
])->first();
|
||||
//dd($consulta_verpromocion);
|
||||
//$cuentas_creadas = Cuentas::whereDate('inicio','>=',$this->fecha)->where('servicio_id',$tarifas->servicio->id)->where('estado','!=','inactivo')->where('estado','!=','delete')->get();
|
||||
|
||||
$this->consulta = $consulta_verpromocion;
|
||||
// $this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
|
||||
if (!empty($precio= $consulta_verpromocion->usuario_promos->first())) {
|
||||
$this->precioAhora = $precio->precio;
|
||||
}else if(!empty($precio= $consulta_verpromocion->tarifaPromo->first())){
|
||||
$this->precioAhora = $precio->precio;
|
||||
}else{
|
||||
$this->precioAhora = $consulta_verpromocion->precio;
|
||||
}
|
||||
|
||||
$this->imagen = $consulta_verpromocion->img_publicidad;
|
||||
$this->fechaLimite = $consulta_verpromocion->fecha_limite;
|
||||
$this->nombrePromo = $consulta_verpromocion->nombre;
|
||||
$this->dias = $consulta_verpromocion->dias;
|
||||
$this->descripcionPromo = $consulta_verpromocion->descripcion;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->dias);
|
||||
$this->mensaje_servicio = $consulta_verpromocion->mensaje;
|
||||
|
||||
$this->verPromo = true;
|
||||
}
|
||||
|
||||
public function comprarPromo($id)
|
||||
{
|
||||
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first();
|
||||
|
||||
$this->consulta = $consulta_verpromocion;
|
||||
//$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
|
||||
|
||||
$this->precioAhora = $consulta_verpromocion->precio;
|
||||
$this->imagen = $consulta_verpromocion->img_publicidad;
|
||||
$this->fechaLimite = $consulta_verpromocion->fecha_limite;
|
||||
$this->nombrePromo = $consulta_verpromocion->nombre;
|
||||
$this->dias = $consulta_verpromocion->dias;
|
||||
|
||||
$this->descripcionPromo = $consulta_verpromocion->descripcion;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->dias);
|
||||
$this->mensaje_servicio = $consulta_verpromocion->mensaje;
|
||||
|
||||
|
||||
$this->modalComprarPromo = true;
|
||||
}
|
||||
|
||||
/* ---------------- Btn Comprar ---------------- */
|
||||
|
||||
|
||||
public function pagar()
|
||||
{
|
||||
|
||||
$this->validate();
|
||||
|
||||
$usuario_existe = User::firstWhere('email', $this->email_comprarPromo)->id ?? null;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$usuario = new User;
|
||||
$usuario->name = $this->nombre_comprarPromo;
|
||||
$usuario->email = $this->email_comprarPromo;
|
||||
$usuario->password = '123';
|
||||
$usuario->celular = $this->celular_comprarPromo;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
} else {
|
||||
|
||||
$usuario_id = $usuario_existe;
|
||||
}
|
||||
|
||||
$historial = new Historiale();
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->precioAhora *$this->cantidad_comprarPromo;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Auth()->user()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->nombre_cliente = $this->nombre_comprarPromo;
|
||||
$historial->save();
|
||||
|
||||
for ($p = 0; $p < (int)$this->cantidad_comprarPromo; $p++) {
|
||||
//dd($this->cantidad_comprarPromo);
|
||||
$n=[];
|
||||
$r=0;
|
||||
foreach ($this->consulta->tarifas as $tarifa) {
|
||||
$r=$r+$tarifa->pantallas;
|
||||
//dd($this->consulta->tarifas->count());
|
||||
$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;
|
||||
|
||||
//dd($tarifa);
|
||||
if ($pantalla_servicio_completa == $pantallas_tarifa) {
|
||||
|
||||
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias-20);
|
||||
$this->fecha_final_2 = $today = Carbon::now()->addDays($tarifa->dias+20);
|
||||
|
||||
$cuenta = Cuentas::where('servicio_id',$servicio_id)->whereDate('inicio','>=',$this->fecha)->whereDate('vencimiento','>=',$this->fecha_final_1)
|
||||
->whereDate('vencimiento','<=',$this->fecha_final_2)
|
||||
->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado','pendiente')->having('historiales_count', '==', 0)->first();
|
||||
}else{
|
||||
$cuenta = Cuentas::where('servicio_id', $servicio_id)->whereDate('inicio','>=',$this->fecha)->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', (int)$faltante)->first();
|
||||
}
|
||||
|
||||
if (!is_null($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 = $historial->id;
|
||||
$historial_cuenta->perfil = (int)$perfil + (int)$y+1;
|
||||
$historial_cuenta->save();
|
||||
if (!empty($historial_cuenta->id)) {
|
||||
array_push($n,$historial_cuenta->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->alert('warning', 'No hay cuentas disponibles de '.$tarifa->servicio->nombre, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
$cuenta=null;
|
||||
}
|
||||
}
|
||||
//dump($r, count($n));
|
||||
if ($r == count($n) ) {
|
||||
|
||||
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first();
|
||||
$saldo_anterior = $descuento->valor;
|
||||
$nuevo_saldo = $saldo_anterior - ($this->precioAhora *$this->cantidad_comprarPromo);
|
||||
$cobro = $descuento->update(['valor' => $nuevo_saldo]);
|
||||
//dd($cobro);
|
||||
if ($cobro) {
|
||||
$historial->update(['estado' => 'activo']);
|
||||
$this->modalComprarPromo = false;
|
||||
$this->credenciales($historial);
|
||||
|
||||
} else {
|
||||
|
||||
$eliminar = Historial_cuenta::whereIn('id',$n)->delete();
|
||||
//dd($eliminar);
|
||||
|
||||
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
$n=null;
|
||||
}else{
|
||||
|
||||
$eliminar = Historial_cuenta::whereIn('id',$n)->delete();
|
||||
//dump($eliminar);
|
||||
|
||||
$this->alert('warning', 'No hay promociones disponibles, comuniquese con soporte!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
$n=null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function credenciales($historial)
|
||||
{
|
||||
|
||||
$this->cuentas = $historial;
|
||||
|
||||
$this->credenciales = true;
|
||||
|
||||
$encryptado = Crypt::encryptString($historial->id);
|
||||
$enlace = '/credenciales?id=' . $encryptado;
|
||||
|
||||
$user =$historial->cliente;
|
||||
|
||||
$notificacion = [
|
||||
'enlace' => $enlace,
|
||||
'fecha_final' => $historial->fecha_final,
|
||||
'cliente' => $historial->cliente->name,
|
||||
'servicio' => $historial->promocion->nombre,
|
||||
'tipo' => 'compra',
|
||||
'vendedor' => auth()->user()->username,
|
||||
|
||||
];
|
||||
|
||||
Notification::send($user, new compra($notificacion));
|
||||
$this->alert('success', 'Credenciales enviadas a su email!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$shortURLObject = ShortURL::destinationUrl('https://app.sirpremium.com.co'.$enlace)->make();
|
||||
$shortURL = $shortURLObject->default_short_url;
|
||||
$message = $historial->promocion->nombre.'. Ver credenciales: '.$shortURL ;
|
||||
$recipients= '+57'.$this->celular_comprarPromo;
|
||||
|
||||
$this->sendMessage($message, $recipients);
|
||||
|
||||
$this->cantidad_comprarPromo = 1;
|
||||
}
|
||||
|
||||
public function sendMessage($message, $recipients)
|
||||
{
|
||||
|
||||
|
||||
$auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0');
|
||||
|
||||
$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"
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
|
||||
$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, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}else{
|
||||
$this->alert('success', 'Credenciales enviadas por Email! '.json_decode($response)->code, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function create_newCategoria()
|
||||
{
|
||||
if (!empty($this->categoria_photo)) {
|
||||
$url_foto = $this->categoria_photo->store('photos');
|
||||
}else{
|
||||
$url_foto = '';
|
||||
}
|
||||
|
||||
$categoria = new Categoria;
|
||||
$categoria->nombre = $this->nombre_categoria;
|
||||
$categoria->descripcion = $this->descripcion_categoria;
|
||||
$categoria->imagen = $url_foto;
|
||||
$categoria->save();
|
||||
|
||||
$this->newCategoria = false;
|
||||
}
|
||||
|
||||
public function add_tarifa()
|
||||
{
|
||||
$consulta= Tarifas::find($this->tarifa_id_promocion);
|
||||
$promocion_tarifa = new Promocion_tarifa;
|
||||
$promocion_tarifa->tarifa_id = $this->tarifa_id_promocion;
|
||||
$promocion_tarifa->nombre = $consulta->servicio->nombre;
|
||||
$promocion_tarifa->cantidad = $consulta->pantallas;
|
||||
$promocion_tarifa->dias = $consulta->dias;
|
||||
|
||||
if (is_null($this->list)) {
|
||||
|
||||
$this->list = collect();
|
||||
}
|
||||
|
||||
$this->list->add($promocion_tarifa);
|
||||
}
|
||||
|
||||
public function del_item($id)
|
||||
{
|
||||
$this->list->pull($id);
|
||||
}
|
||||
|
||||
public function guardar()
|
||||
{
|
||||
$this->validate([
|
||||
'nombre_promocion' => 'required',
|
||||
'descripcion_promocion' => 'required',
|
||||
'valor_promocion' => 'required',
|
||||
'estado_promocion' => 'required',
|
||||
'fecha_limite_promocion' => 'required',
|
||||
'categoria_id_promocion' => 'required',
|
||||
'photo' => 'required',
|
||||
'list'=>'required',
|
||||
]);
|
||||
|
||||
|
||||
if (!empty($this->photo)) {
|
||||
|
||||
$nombre=Str::random(10);
|
||||
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location = "photos/".$nombre.".webp";
|
||||
Storage::disk('local')->put($location, $img);
|
||||
$url_foto = $location;
|
||||
} else {
|
||||
$url_foto = null;
|
||||
}
|
||||
|
||||
$nueva_promocion = new Promociones;
|
||||
$nueva_promocion->nombre = $this->nombre_promocion;
|
||||
$nueva_promocion->descripcion = $this->descripcion_promocion;
|
||||
$nueva_promocion->precio = $this->valor_promocion;
|
||||
$nueva_promocion->visible = $this->estado_promocion;
|
||||
$nueva_promocion->fecha_limite = $this->fecha_limite_promocion;
|
||||
$nueva_promocion->categoria_id = $this->categoria_id_promocion;
|
||||
$nueva_promocion->img_publicidad = $url_foto;
|
||||
$nueva_promocion->dias = 30;
|
||||
$nueva_promocion->mensaje = $this->mensaje_servicio;
|
||||
$nueva_promocion->save();
|
||||
|
||||
|
||||
foreach ($this->list as $item) {
|
||||
$guardar_promotarifa = new Promocion_tarifa;
|
||||
$guardar_promotarifa->promocion_id = $nueva_promocion->id;
|
||||
$guardar_promotarifa->tarifa_id = $item['tarifa_id']; //falta
|
||||
$guardar_promotarifa->save();
|
||||
}
|
||||
|
||||
$this->newPromocion = false;
|
||||
|
||||
$this->alert('success', 'Promocion creada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->limpiarInputPromocion();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function eliminar($id)
|
||||
{
|
||||
$this->eliminar_id = $id;
|
||||
$this->alert('warning', '¿Eliminar promocion?', [
|
||||
'position' => 'center',
|
||||
'timer' => '10000',
|
||||
'toast' => false,
|
||||
'text' => 'Esta seguro',
|
||||
'showConfirmButton' => true,
|
||||
'onConfirmed' => 'confirmed',
|
||||
'showDenyButton' => false,
|
||||
'onDenied' => '',
|
||||
'showCancelButton' => true,
|
||||
'onDismissed' => '',
|
||||
'cancelButtonText' => 'Salir',
|
||||
'confirmButtonText' => 'Si',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return [
|
||||
'confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
public function confirmed()
|
||||
{
|
||||
$consulta_promociones = Promociones::findOrFail($this->eliminar_id);
|
||||
$nombre = $consulta_promociones->nombre;
|
||||
|
||||
Promociones::where('id', $this->eliminar_id)->update([
|
||||
'nombre' => $nombre . '-Delete',
|
||||
'visible' => 'false',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ---------------- Editar Promocion ---------------- */
|
||||
|
||||
public function editarPromo($id)
|
||||
{
|
||||
$promocion = Promociones::where('id', $id)->first();
|
||||
|
||||
// $this->imagen_editarPromo= $promocion->img_publicidad;
|
||||
$this->editar_promo_id = $promocion->id;
|
||||
$this->valor_editarPromo = $promocion->precio;
|
||||
$this->fecha_editarPromo = $promocion->fecha_limite;
|
||||
$this->nombre_editarPromo = $promocion->nombre;
|
||||
$this->descripcion_editarPromo = $promocion->descripcion;
|
||||
$this->estado_editarPromo = $promocion->visible;
|
||||
$this->categoria_id_editarPromo = $promocion->categoria_id;
|
||||
$this->img_ver = $promocion->img_publicidad;
|
||||
$this->mensaje_servicio = $promocion->mensaje;
|
||||
|
||||
|
||||
$consultas = Promocion_tarifa::selectRaw('promocion_tarifas.id as id, servicios.nombre as nombre, tarifas.pantallas as pantallas ')
|
||||
->join('tarifas', 'tarifas.id', '=', 'promocion_tarifas.tarifa_id')
|
||||
->join('servicios', 'servicios.id', '=', 'tarifas.servicio_id')
|
||||
->where('promocion_tarifas.promocion_id',$this->editar_promo_id)
|
||||
->get();
|
||||
|
||||
$this->list2 = collect();
|
||||
|
||||
foreach ($consultas as $consulta) {
|
||||
$promocionTarifa = new Promocion_tarifa;
|
||||
|
||||
$promocionTarifa->tarifa_id = $this->tarifa_id_promocion;
|
||||
$promocionTarifa->nombre = $consulta->nombre ;
|
||||
$promocionTarifa->cantidad = $consulta->pantallas;
|
||||
$promocionTarifa->identificador = $consulta->id;
|
||||
$promocionTarifa->dias = $consulta->dias;
|
||||
|
||||
$this->list2->add($promocionTarifa);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->editarPromo = true;
|
||||
}
|
||||
public function editarPromoUpdate()
|
||||
{
|
||||
|
||||
if (!empty($this->photo)) {
|
||||
$nombre=Str::random(10);
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
$location = "photos/".$nombre.".webp";
|
||||
Storage::disk('local')->put($location, $img);
|
||||
$url_foto = $location;
|
||||
} else {
|
||||
$url_foto = $this->img_ver;
|
||||
}
|
||||
|
||||
|
||||
Promociones::where('id', $this->editar_promo_id)->update([
|
||||
'precio' => $this->valor_editarPromo,
|
||||
'fecha_limite' => $this->fecha_editarPromo,
|
||||
'visible' => $this->estado_editarPromo,
|
||||
'categoria_id' => $this->categoria_id_editarPromo,
|
||||
'nombre' => $this->nombre_editarPromo,
|
||||
'descripcion' => $this->descripcion_editarPromo,
|
||||
'img_publicidad' => $url_foto,
|
||||
'mensaje' => $this->mensaje_servicio,
|
||||
]);
|
||||
|
||||
$this->editarPromo = false;
|
||||
|
||||
$this->list2 = null;
|
||||
$this->limpiarInputPromocion();
|
||||
}
|
||||
public function add_tarifa_list2()
|
||||
{
|
||||
$add = new Promocion_tarifa;
|
||||
$add->promocion_id = $this->editar_promo_id;
|
||||
$add->tarifa_id = $this->tarifa_id_promocion;
|
||||
$add->save();
|
||||
|
||||
$consultas = Promocion_tarifa::selectRaw('promocion_tarifas.id as id, servicios.nombre as nombre, tarifas.pantallas as pantallas ')
|
||||
->join('tarifas', 'tarifas.id', '=', 'promocion_tarifas.tarifa_id')
|
||||
->join('servicios', 'servicios.id', '=', 'tarifas.servicio_id')
|
||||
->where('promocion_tarifas.promocion_id',$this->editar_promo_id)
|
||||
->get();
|
||||
|
||||
$this->list2 = collect();
|
||||
|
||||
foreach ($consultas as $consulta) {
|
||||
$promocionTarifa = new Promocion_tarifa;
|
||||
|
||||
$promocionTarifa->tarifa_id = $this->tarifa_id_promocion;
|
||||
$promocionTarifa->nombre = $consulta->nombre ;
|
||||
$promocionTarifa->cantidad = $consulta->pantallas;
|
||||
$promocionTarifa->identificador = $consulta->id;
|
||||
|
||||
$this->list2->add($promocionTarifa);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public function del_item_list2($id,$n)
|
||||
{
|
||||
Promocion_tarifa::where('id',$id)->delete();
|
||||
|
||||
$this->list2->pull($n);
|
||||
|
||||
$this->alert('success', 'Tarifa de usuario eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
public function limpiarInputPromocion()
|
||||
{
|
||||
$this->nombre_promocion = '';
|
||||
$this->descripcion_promocion = '';
|
||||
$this->valor_promocion = '';
|
||||
$this->estado_promocion = null;
|
||||
$this->fecha_limite_promocion = null;
|
||||
$this->categoria_id_promocion = null;
|
||||
$this->newCategoria = false;
|
||||
$this->newPromocion = false;
|
||||
$this->photo = null;
|
||||
$this->mensaje_servicio=null;
|
||||
|
||||
$this->list = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use constants;
|
||||
|
||||
use App\Models\recarga;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use WpOrg\Requests\Requests;
|
||||
|
||||
|
||||
|
||||
class ShowRecarga extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
public $numero_nequi;
|
||||
public $valor_recarga;
|
||||
public $nequi =false;
|
||||
public $cobrar = false;
|
||||
public $monto = 0;
|
||||
|
||||
|
||||
public function render()
|
||||
{
|
||||
// $this->fechaActual = date('d/m/Y');
|
||||
if (auth()->user()->rol->nombre == "super" || auth()->user()->rol->nombre == "administrador" || auth()->user()->rol->nombre == "distribuidor") {
|
||||
$this->cobrar = true;
|
||||
$this->monto = "500";
|
||||
}
|
||||
$consulta_historial = recarga::where('usuario_id',Auth::user()->id)->orderBy('id','DESC')->limit(20)->get();
|
||||
|
||||
$consulta_saldo = User::where('id',Auth::user()->id)->with('saldo')->first();
|
||||
|
||||
return view('livewire.show-recarga',[
|
||||
'user' => $consulta_saldo,
|
||||
'historial_recargas' => $consulta_historial
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function pagar(){
|
||||
|
||||
//auth2.0
|
||||
$client_id='5ml5b35ijjk13f4q99utnsm97e';
|
||||
$client_secret='1b3703aq0o6t1rrfti13q7uf7f42glik3gsf81s0d783shblmt8l';
|
||||
$api_key='aHLdWJTpuM9YYnV9ruq4V6bH5esa8wUN69E1qmrM';
|
||||
$endpoint="https://oauth.sandbox.nequi.com/oauth2/token?grant_type=client_credentials";
|
||||
$date= Carbon::now()->format('Y-m-d\TH:i:s.z\Z');
|
||||
//dd($date);
|
||||
|
||||
//dd($this->numero_nequi);
|
||||
//push
|
||||
$RestEndpoint = '/payments/v2/-services-paymentservice-unregisteredpayment';
|
||||
|
||||
try{
|
||||
$authorization = 'Basic ' . base64_encode($client_id . ':' . $client_secret);
|
||||
$headers = array(
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => $authorization
|
||||
);
|
||||
|
||||
//Solicitud
|
||||
$request = Requests::post($endpoint, $headers);
|
||||
|
||||
|
||||
if (isset($request->status_code) && $request->status_code == 200 && isset($request->body) && !empty($request->body))
|
||||
{
|
||||
$response = json_decode($request->body);
|
||||
|
||||
$tokenExpiresAt = new DateTime();
|
||||
$tokenExpiresAt->add(new DateInterval('PT' . $response->expires_in . 'S'));
|
||||
$token = $response->access_token;
|
||||
$tokenType = $response->token_type;
|
||||
} else {
|
||||
|
||||
throw new Exception('Unable to connect to Nequi, please check the information sent.');
|
||||
}
|
||||
}catch(Exception $e){
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
// pago
|
||||
$headers1 = array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => $token,
|
||||
'x-api-key' => $api_key
|
||||
);
|
||||
|
||||
$options1 = array(
|
||||
'timeout' => 30
|
||||
|
||||
);
|
||||
$endpoint1 = 'https://api.sandbox.nequi.com' . $RestEndpoint;
|
||||
|
||||
$body1 = json_encode(array(
|
||||
'RequestMessage' => array(
|
||||
'RequestHeader' => array(
|
||||
'Channel' => 'PNP04-C001',
|
||||
'RequestDate' => $date,
|
||||
'MessageID' => '1234567890',
|
||||
'ClientID' => $client_id,
|
||||
'Destination' => array(
|
||||
'ServiceName' => 'PaymentsService',
|
||||
'ServiceOperation' => 'unregisteredPayment',
|
||||
'ServiceRegion' => 'C001',
|
||||
'ServiceVersion' => '1.2.0'
|
||||
)
|
||||
),
|
||||
'RequestBody' => array(
|
||||
'any' => array(
|
||||
'unregisteredPaymentRQ' => array(
|
||||
'phoneNumber'=> $this->numero_nequi,
|
||||
'code' => 'NIT_1',
|
||||
'value' => $this->valor_recarga,
|
||||
'reference1' => 'Recarga SirPremium',
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
$request1 = Requests::post($endpoint1, $headers1, $body1, $options1);
|
||||
|
||||
|
||||
if (isset($request1->status_code) && $request1->status_code == 200 && isset($request1->body) && !empty($request1->body)
|
||||
) {
|
||||
|
||||
|
||||
try {
|
||||
$response1 = json_decode($request1->body);
|
||||
//dd($response1 = json_decode($request1->body));
|
||||
$status = $response1->ResponseMessage->ResponseHeader->Status;
|
||||
$statusCode = isset($status) ? $status->StatusCode : '';
|
||||
$statusDesc = isset($status) ? $status->StatusDesc : '';
|
||||
|
||||
if ($statusCode == 0) {
|
||||
|
||||
$this->alert('success', 'Solicitud de pago enviada', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$payment = $response1->ResponseMessage->ResponseBody->any->unregisteredPaymentRS;
|
||||
$trnId = isset($payment) ? trim($payment->transactionId) : '';
|
||||
|
||||
if ( !empty($trnId)) {
|
||||
|
||||
$recarga = new recarga;
|
||||
$recarga-> payment_type_id= '';
|
||||
$recarga-> payment_method_id= '';
|
||||
$recarga-> status= $statusCode;
|
||||
$recarga-> usuario_id= Auth::user()->id;
|
||||
$recarga-> saldo_id= Auth::user()->saldo->id;
|
||||
$recarga-> monto= $this->valor_recarga;
|
||||
$recarga->save();
|
||||
|
||||
$consulta_saldo = Saldo::where('usuario_id',Auth::user()->id)->first();
|
||||
$nuevo_saldo = $consulta_saldo->valor + $this->valor_recarga ;
|
||||
$consulta_saldo->update(['valor'=> $nuevo_saldo]);
|
||||
$this->alert('success', 'Saldo actualizado', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->nequi = false;
|
||||
}
|
||||
$this->alert('success', $trnId, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
} else {
|
||||
$this->alert('warning', $statusCode . ' = ' . $statusDesc, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->alert('wanrning','Unable to connect to Nequi, please check the information sent', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\recarga;
|
||||
|
||||
|
||||
class ShowRecargas extends Component
|
||||
{
|
||||
public $monto;
|
||||
public $referencia;
|
||||
|
||||
public function render(Request $request)
|
||||
{
|
||||
|
||||
if (empty($this->referencia)){
|
||||
$this->referencia = Str::random(20);
|
||||
|
||||
$this->monto = (((($request->recharge)*0.03) + '700' )* 0.19)+ ((($request->recharge)*0.03) + '700' ) + $request->recharge;
|
||||
|
||||
$recargas = new recarga;
|
||||
$recargas->monto = $this->monto;
|
||||
$recargas->reference = $this->referencia;
|
||||
$recargas-> status = 'Procesando MP';
|
||||
$recargas-> usuario_id = auth()->user()->id;
|
||||
$recargas-> saldo_id= auth()->user()->saldo->id;
|
||||
$recargas-> valor_recarga = $request->recharge;
|
||||
$recargas->save();
|
||||
}
|
||||
|
||||
|
||||
return view('livewire.show-recargas');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class ShowReportes extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithPagination;
|
||||
|
||||
public $fecha;
|
||||
public $mes;
|
||||
public $usuario;
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
// $this->fechaActual = Carbon::now();
|
||||
// $this->fechaActual = Carbon::parse($this->fechaActual);
|
||||
if(!empty($this->usuario)){
|
||||
$id_user = $this->usuario;
|
||||
|
||||
$consulta_suma = Historiale::where('vendedor_id', $id_user)->sum('valor');
|
||||
$consulta_cantidad = Historiale::where('vendedor_id', $id_user)->count();
|
||||
|
||||
if (!empty($this->mes)) {
|
||||
|
||||
$consulta_suma = Historiale::where('vendedor_id', $id_user)->whereMonth('created_at',$this->mes)->sum('valor');
|
||||
$consulta_cantidad = Historiale::where('vendedor_id', $id_user)->whereMonth('created_at',$this->mes)->count();
|
||||
}
|
||||
|
||||
|
||||
}elseif(empty($this->usuario)){
|
||||
if(auth()->user()->rol->nombre == "super" || auth()->user()->rol->nombre == "administrador"){
|
||||
$consulta_suma = Historiale::sum('valor');
|
||||
$consulta_cantidad = Historiale::count();
|
||||
}else{
|
||||
|
||||
$consulta_suma = Historiale::where('vendedor_id', auth()->user()->id)->whereMonth('created_at',$this->mes)->sum('valor');
|
||||
$consulta_cantidad = Historiale::where('vendedor_id', auth()->user()->id)->whereMonth('created_at',$this->mes)->count();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!empty($this->mes)) {
|
||||
|
||||
$consulta_suma = Historiale::whereMonth('created_at',$this->mes)->sum('valor');
|
||||
$consulta_cantidad = Historiale::whereMonth('created_at',$this->mes)->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$distribuidores = Role::where('nombre','distribuidor')->with('usuarios')->first();
|
||||
|
||||
$historial = Historiale::where('cliente_id', auth()->user()->id)->orderBy('id','DESC')->paginate(10);
|
||||
//dd($historial);
|
||||
|
||||
return view('livewire.show-reportes',[
|
||||
'suma' => $consulta_suma,
|
||||
'cantidad' => $consulta_cantidad,
|
||||
'roles' => $distribuidores,
|
||||
'historiales' => $historial,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
use App\Models\Role;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowRoles extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
public $editar= false;
|
||||
public $nombre;
|
||||
public $add;
|
||||
public $ro;
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
|
||||
$consulta_roles = Role::withCount('usuarios')->get();
|
||||
//dd($consulta_roles);
|
||||
return view('livewire.show-roles',['roles'=>$consulta_roles]);
|
||||
}
|
||||
|
||||
public function editar($id){
|
||||
$this->nombre = Role::find($id)->nombre;
|
||||
$this->ro = $id;
|
||||
$this->editar = true;
|
||||
}
|
||||
|
||||
public function crear(){
|
||||
if (!empty($this->nombre)) {
|
||||
$crear_rol = new Role;
|
||||
$crear_rol->nombre = $this->nombre;
|
||||
$crear_rol->save();
|
||||
|
||||
$this->alert('success', 'Rol creado correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
$this->add = false;
|
||||
}else{
|
||||
$this->alert('warning', 'Campo Nombre sin diligenciar!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function eliminar($id)
|
||||
{
|
||||
$this->ro = $id;
|
||||
$this->alert('warning', '¿Eliminar rol?', [
|
||||
'position' => 'center',
|
||||
'timer' => '10000',
|
||||
'toast' => false,
|
||||
'text' => 'Esta seguro',
|
||||
'showConfirmButton' => true,
|
||||
'onConfirmed' => 'confirmed',
|
||||
'showDenyButton' => false,
|
||||
'onDenied' => '',
|
||||
'showCancelButton' => true,
|
||||
'onDismissed' => '',
|
||||
'cancelButtonText' => 'Salir',
|
||||
'confirmButtonText' => 'Si',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return [
|
||||
'confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
public function confirmed()
|
||||
{
|
||||
$eliminar= Role::find($this->ro)->delete();
|
||||
$this->alert('success', 'Rol eliminado!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function limpiarInputAdd(){
|
||||
$this->editar= false;
|
||||
$this->add = false;
|
||||
|
||||
}
|
||||
|
||||
public function actualizar(){
|
||||
$eliminar= Role::find($this->ro);
|
||||
//dd($eliminar);
|
||||
$eliminar->update(['nombre'=>$this->nombre]);
|
||||
|
||||
$this->alert('success', 'Rol actualizado!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->editar=false;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Servicio;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Intervention\Image\ImageManagerStatic as Img;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
|
||||
class ShowServicio extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithFileUploads;
|
||||
|
||||
public $serviciosModal = false;
|
||||
public $serviciosEditar = false;
|
||||
|
||||
public $servicio_id;
|
||||
public $nombre_servicio;
|
||||
public $descripcion_servicio;
|
||||
public $estado_servicio;
|
||||
public $color_servicio;
|
||||
public $img;
|
||||
public $img_inicio;
|
||||
public $pantallas;
|
||||
public $mensaje_servicio;
|
||||
public $photo;
|
||||
public $photo_inicio;
|
||||
public $tiempo = false;
|
||||
public $perfiles;
|
||||
public $password;
|
||||
public $completa;
|
||||
public $ver_url;
|
||||
public $url;
|
||||
public $renovacion = false;
|
||||
|
||||
protected $rules = [
|
||||
'nombre_servicio' => 'required',
|
||||
'estado_servicio' => 'required',
|
||||
'pantallas' => 'required',
|
||||
'completa' => 'required',
|
||||
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
if ($this->tiempo) {
|
||||
$this->pantallas = 1;
|
||||
$this->completa = 1;
|
||||
}
|
||||
|
||||
$consulta = Servicio::Orderby('estado')->get();
|
||||
return view('livewire.show-servicio', [
|
||||
'servicios' => $consulta,
|
||||
]);
|
||||
}
|
||||
|
||||
public function createServicio()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
if (!empty($this->photo)) {
|
||||
$nombre = Str::random(10);
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
$location = "photos/" . $nombre . ".webp";
|
||||
Storage::disk('local')->put($location, $img);
|
||||
$url_foto = $location;
|
||||
} else {
|
||||
$url_foto = $this->img;
|
||||
}
|
||||
if (!empty($this->photo_inicio)) {
|
||||
$nombre_inicio = Str::random(10);
|
||||
$img_inicio = img::make($this->photo_inicio)->orientate()->resize(1000, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location_inicio = "photos/" . $nombre_inicio . ".webp";
|
||||
Storage::disk('local')->put($location_inicio, $img_inicio);
|
||||
$url_foto_inicio = $location_inicio;
|
||||
|
||||
} else {
|
||||
$url_foto_inicio = null;
|
||||
}
|
||||
|
||||
|
||||
$servicio = new Servicio;
|
||||
$servicio->nombre = $this->nombre_servicio;
|
||||
$servicio->descripcion = $this->descripcion_servicio;
|
||||
$servicio->estado = $this->estado_servicio;
|
||||
$servicio->color_fondo = $this->color_servicio;
|
||||
$servicio->pantallas = $this->pantallas;
|
||||
$servicio->img = $url_foto;
|
||||
$servicio->img_inicio = $url_foto_inicio;
|
||||
$servicio->mensaje = $this->mensaje_servicio;
|
||||
$servicio->completa = $this->completa;
|
||||
$servicio->por_tiempo = $this->tiempo;
|
||||
$servicio->ver_perfiles = $this->perfiles;
|
||||
$servicio->perfiles = $this->password;
|
||||
$servicio->ver_url = $this->ver_url;
|
||||
$servicio->url = $this->url;
|
||||
$servicio->renovacion = $this->renovacion;
|
||||
$servicio->save();
|
||||
|
||||
$this->alert('success', 'Servicio creado correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->serviciosModal = false;
|
||||
}
|
||||
|
||||
|
||||
public function editar($id)
|
||||
{
|
||||
|
||||
$consulta_servicios = Servicio::FindOrFail($id);
|
||||
|
||||
$this->servicio_id = $consulta_servicios->id;
|
||||
$this->nombre_servicio = $consulta_servicios->nombre;
|
||||
$this->descripcion_servicio = $consulta_servicios->descripcion;
|
||||
$this->estado_servicio = $consulta_servicios->estado;
|
||||
$this->color_servicio = $consulta_servicios->color_fondo;
|
||||
$this->pantallas = $consulta_servicios->pantallas;
|
||||
$this->img = $consulta_servicios->img;
|
||||
$this->img_inicio = $consulta_servicios->img_inicio;
|
||||
$this->mensaje_servicio = $consulta_servicios->mensaje;
|
||||
$this->completa = $consulta_servicios->completa;
|
||||
$this->tiempo = $consulta_servicios->por_tiempo == 1 ? true : false;
|
||||
$this->perfiles = $consulta_servicios->ver_perfiles;
|
||||
$this->ver_url = $consulta_servicios->ver_url;
|
||||
$this->url = $consulta_servicios->url;
|
||||
$this->renovacion = $consulta_servicios->renovacion == 1 ? true : false;
|
||||
}
|
||||
public function guardar()
|
||||
{
|
||||
if (!empty($this->photo)) {
|
||||
|
||||
$nombre = Str::random(10);
|
||||
|
||||
$img = img::make($this->photo)->orientate()->resize(1000, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location = "photos/" . $nombre . ".webp";
|
||||
|
||||
Storage::disk('local')->put($location, $img);
|
||||
|
||||
$url_foto = $location;
|
||||
|
||||
} else {
|
||||
|
||||
$url_foto = $this->img;
|
||||
|
||||
}
|
||||
|
||||
if (!empty($this->photo_inicio)) {
|
||||
|
||||
$nombre_inicio = Str::random(10);
|
||||
|
||||
$img_inicio = img::make($this->photo_inicio)->orientate()->resize(1000, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
})->encode('webp');
|
||||
|
||||
$location_inicio = "photos/" . $nombre_inicio . ".webp";
|
||||
|
||||
Storage::disk('local')->put($location_inicio, $img_inicio);
|
||||
|
||||
$url_foto_inicio = $location_inicio;
|
||||
|
||||
} else {
|
||||
$url_foto_inicio = $this->img_inicio;
|
||||
}
|
||||
|
||||
Servicio::where('id', $this->servicio_id)->update([
|
||||
'nombre' => $this->nombre_servicio,
|
||||
'descripcion' => $this->descripcion_servicio,
|
||||
'estado' => $this->estado_servicio,
|
||||
'color_fondo' => $this->color_servicio,
|
||||
'pantallas' => $this->pantallas,
|
||||
'img' => $url_foto,
|
||||
'img_inicio' => $url_foto_inicio,
|
||||
'mensaje' => $this->mensaje_servicio,
|
||||
'completa' => $this->completa,
|
||||
'por_tiempo' => $this->tiempo == 1 ? true : false,
|
||||
'ver_perfiles' => $this->perfiles,
|
||||
'perfiles' => $this->password,
|
||||
'ver_url' => $this->ver_url,
|
||||
'url' => $this->url,
|
||||
'renovacion' => $this->renovacion == 1 ? true : false,
|
||||
]);
|
||||
|
||||
$this->serviciosEditar = false;
|
||||
$this->limpiarInputServiciosModal();
|
||||
}
|
||||
|
||||
|
||||
public function desactivar($id)
|
||||
{
|
||||
Servicio::where('id', $id)->update([
|
||||
'estado' => 'inactivo',
|
||||
]);
|
||||
}
|
||||
|
||||
public function activar($id)
|
||||
{
|
||||
Servicio::where('id', $id)->update([
|
||||
'estado' => 'activo',
|
||||
]);
|
||||
}
|
||||
public function eliminar($id)
|
||||
{
|
||||
$this->delete_servicio = $id;
|
||||
$this->alert('warning', '¿Eliminar servicio?', [
|
||||
'position' => 'center',
|
||||
'timer' => '10000',
|
||||
'toast' => false,
|
||||
'text' => 'Esta seguro',
|
||||
'showConfirmButton' => true,
|
||||
'onConfirmed' => 'confirmed',
|
||||
'showDenyButton' => false,
|
||||
'onDenied' => '',
|
||||
'showCancelButton' => true,
|
||||
'onDismissed' => '',
|
||||
'cancelButtonText' => 'Salir',
|
||||
'confirmButtonText' => 'Si',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return [
|
||||
'confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
public function confirmed()
|
||||
{
|
||||
Servicio::where('id', $this->delete_servicio)->delete();
|
||||
}
|
||||
|
||||
public function limpiarInputServiciosModal()
|
||||
{
|
||||
$this->nombre_servicio = '';
|
||||
$this->descripcion_servicio = '';
|
||||
$this->estado_servicio = null;
|
||||
$this->color_servicio = null;
|
||||
$this->pantallas = null;
|
||||
$this->photo = null;
|
||||
$this->photo_inicio = null;
|
||||
$this->mensaje_servicio = null;
|
||||
$this->completa = null;
|
||||
$this->tiempo = null;
|
||||
$this->renovacion = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Configuracione;
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Role;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\Servicio;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use App\Models\Usuario_tarifa;
|
||||
use App\Notifications\compra;
|
||||
use App\Notifications\licencias;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Twilio\Rest\Client;
|
||||
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
||||
|
||||
class ShowServicios extends Component
|
||||
{
|
||||
public $servicio;
|
||||
public $tarjetaPlan = false;
|
||||
public $tarifa_id;
|
||||
public $servicio_id = 2;
|
||||
|
||||
public $servicio_tarjetaPlan;
|
||||
public $pantallas_tarjetaPlan;
|
||||
public $dias_tarjetaPlan;
|
||||
public $valor_tarjetaPlan;
|
||||
public $colorFondo_tarjetaPlan;
|
||||
public $celular_tarjetaPlan;
|
||||
public $nombre_tarjetaPlan;
|
||||
public $email_tarjetaPlan;
|
||||
public $cantidad_tarjetaPlan = 1;
|
||||
public $consulta_tarifas;
|
||||
|
||||
public $fechaActual;
|
||||
public $fechaHoy;
|
||||
public $fechaFinal;
|
||||
public $cuentas;
|
||||
|
||||
public $disponibles;
|
||||
public $credenciales = false;
|
||||
public $tarifa;
|
||||
public $fecha;
|
||||
public $msj;
|
||||
public $mensaje;
|
||||
////
|
||||
public $tarifas;
|
||||
public $servicio_t;
|
||||
public $cuentas_completas;
|
||||
public $cuentas_completas_tomadas;
|
||||
public $cuentas_creadas;
|
||||
public $cuentas_tomadas;
|
||||
public $tiempo_tarjetaPlan;
|
||||
public $verServ;
|
||||
public $fecha_final_1;
|
||||
public $fecha_final_2;
|
||||
|
||||
use LivewireAlert;
|
||||
protected $rules = [
|
||||
'nombre_tarjetaPlan' => 'required',
|
||||
'cantidad_tarjetaPlan' => 'required',
|
||||
'email_tarjetaPlan' => 'required',
|
||||
'celular_tarjetaPlan' => 'required',
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->fechaHoy = Carbon::now();
|
||||
$this->fechaActual = Carbon::parse($this->fechaHoy);
|
||||
$date = $this->fechaHoy->subDay(30);
|
||||
$this->fecha = $date->format('Y-m-d');
|
||||
|
||||
$this->usuario_actual = Auth::user();
|
||||
|
||||
if (empty($this->nombre_tarjetaPlan) && empty($this->email_tarjetaPlan)) {
|
||||
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
$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();
|
||||
|
||||
$consulta_servicios = Servicio::where('estado', 'activo')
|
||||
->with([
|
||||
'tarifas' => function ($query) {
|
||||
$query->where('rol_id', $this->usuario_actual->rol->id)
|
||||
->with([
|
||||
'usuario_tarifas' => function ($query) {
|
||||
$query->where('usuario_id', $this->usuario_actual->id);
|
||||
}
|
||||
]);
|
||||
}
|
||||
])
|
||||
->get();
|
||||
|
||||
|
||||
return view('livewire.show-servicios', [
|
||||
'servicios' => $consulta_servicios,
|
||||
]);
|
||||
}
|
||||
|
||||
public function cargartarjetaPlan($id)
|
||||
{
|
||||
$this->tarifas = Tarifas::with('servicio')
|
||||
->where('id', $id)
|
||||
->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)
|
||||
->where('estado', 'activo')
|
||||
->get();
|
||||
|
||||
|
||||
$this->cuentas_tomadas = Historial_cuenta::whereIn('cuenta_id', $this->cuentas_creadas
|
||||
->pluck('id'))
|
||||
->count();
|
||||
|
||||
|
||||
|
||||
|
||||
//$prueba1 = $this->cuentas_creadas->count() * $this->servicio_t->pantallas ;
|
||||
//$prueba2 = $this->cuentas_tomadas ;
|
||||
|
||||
//dd($prueba1, $prueba2 , $prueba1-$prueba2);
|
||||
|
||||
$this->servicio_id = $this->servicio_t->id;
|
||||
$this->tarifa_id = $id;
|
||||
$this->servicio_tarjetaPlan = $this->servicio_t->nombre;
|
||||
$this->tiempo_tarjetaPlan = $this->servicio_t->por_tiempo;
|
||||
$this->pantallas_tarjetaPlan = $this->tarifas->pantallas;
|
||||
$this->dias_tarjetaPlan = $this->tarifas->dias;
|
||||
$this->fecha_final_1 = $today = Carbon::now();
|
||||
$this->fecha_final_2 = $today = Carbon::now();
|
||||
$this->mensaje = $this->servicio_t->mensaje;
|
||||
|
||||
//Servicio por cuenta completa
|
||||
$this->cuentas_completas = Cuentas::whereDate('inicio', '>=', $this->fecha)
|
||||
->whereDate('vencimiento', '>=', $this->fecha_final_1->addDays($this->tarifas->dias - 20))
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2->addDays($this->tarifas->dias + 20))
|
||||
->where('servicio_id', $this->tarifas->servicio->id)
|
||||
->where('estado', 'pendiente')
|
||||
->get();
|
||||
$this->cuentas_completas_tomadas = Historial_cuenta::whereIn('cuenta_id', $this->cuentas_completas->pluck('id'))
|
||||
->count();
|
||||
$usuario_tarifa = Usuario_tarifa::where('usuario_id', auth()->user()->id)
|
||||
->where('tarifa_id', $id)
|
||||
->first();
|
||||
|
||||
$this->valor_tarjetaPlan = ($usuario_tarifa) ? $usuario_tarifa->precio : $this->tarifas->valor;
|
||||
|
||||
$this->colorFondo_tarjetaPlan = $this->servicio_t->color_fondo;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->tarifas->dias);
|
||||
|
||||
|
||||
//Cantidad de paquetes disponibles
|
||||
$this->paquetesDisponibles();
|
||||
|
||||
|
||||
|
||||
$this->tarjetaPlan = true;
|
||||
|
||||
|
||||
}
|
||||
public function paquetesDisponibles()
|
||||
{
|
||||
|
||||
if ($this->tarifas->pantallas == $this->servicio_t->completa) {
|
||||
|
||||
$this->disponibles = (($this->cuentas_completas->count() * $this->servicio_t->completa) - $this->cuentas_completas_tomadas) / $this->tarifas->pantallas;
|
||||
$restantes_completas = $this->cuentas_completas->count() - ($this->cuentas_completas_tomadas / $this->servicio_t->completa);
|
||||
|
||||
if ($restantes_completas <= 10) {
|
||||
//$this->notificacionPocas($this->servicio_t,$restantes_completas);
|
||||
}
|
||||
|
||||
} else {
|
||||
$cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan;
|
||||
|
||||
if ($this->servicio_t->pantallas >= $cantidad_solicitada) {
|
||||
$this->disponibles = (($this->cuentas_creadas->count() * $this->servicio_t->pantallas) - $this->cuentas_tomadas) / $this->tarifas->pantallas;
|
||||
$restantes = $this->cuentas_creadas->count() - ($this->cuentas_tomadas / $this->servicio_t->pantallas);
|
||||
} else {
|
||||
$this->disponibles = ($this->cuentas_creadas->count() - $this->cuentas_tomadas);
|
||||
|
||||
$restantes = $this->cuentas_creadas->count() - ($this->cuentas_tomadas);
|
||||
}
|
||||
|
||||
|
||||
if ($restantes <= 10) {
|
||||
//$this->notificacionPocas($this->servicio_t,$restantes);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function notificacionPocas($servicio, $restantes)
|
||||
{
|
||||
$roles = Role::where('nombre', 'super')->with('usuarios')->first();
|
||||
$user = $roles->usuarios;
|
||||
|
||||
$notificacion = [
|
||||
'servicio' => $servicio->nombre,
|
||||
'cantidad' => $restantes,
|
||||
'tipo' => 'cuentas normales',
|
||||
];
|
||||
|
||||
Notification::send($user, (new licencias($notificacion)));
|
||||
|
||||
}
|
||||
|
||||
/* ---------------- Btn Comprar ---------------- */
|
||||
public function comprar()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan;
|
||||
$total_valor = (int) $this->valor_tarjetaPlan * (int) $this->cantidad_tarjetaPlan;
|
||||
|
||||
$usuario_existe = User::firstWhere('email', $this->email_tarjetaPlan)->id ?? null;
|
||||
$usuario_id = $usuario_existe;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$usuario = new User;
|
||||
$usuario->name = $this->nombre_tarjetaPlan;
|
||||
$usuario->email = $this->email_tarjetaPlan;
|
||||
$usuario->password = '123';
|
||||
$usuario->celular = '+57' . $this->celular_tarjetaPlan;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
}
|
||||
|
||||
//dd($this->fechaFinal);
|
||||
$historial = new Historiale;
|
||||
$historial->fecha_inicio = Carbon::now();
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $total_valor;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Auth()->user()->id;
|
||||
$historial->tarifa_id = $this->tarifa_id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_tarjetaPlan;
|
||||
$historial->nombre_cliente = $this->nombre_tarjetaPlan;
|
||||
$historial->save();
|
||||
|
||||
$pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first();
|
||||
$servicio_id = $pantallas->servicio_id;
|
||||
$pantalla_servicio_completa = $pantallas->servicio->completa;
|
||||
$pantalla_servicio = $pantallas->servicio->pantallas;
|
||||
|
||||
$pantallas = $pantallas->pantallas ?? null;
|
||||
|
||||
if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) {
|
||||
$suma = $pantalla_servicio - $cantidad_solicitada;
|
||||
$cantidad_necesaria = 1;
|
||||
$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;
|
||||
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)->whereDate('inicio', '>=', $this->fecha)->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
||||
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
||||
->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado', 'pendiente')->having('historiales_count', '==', 0)->get();
|
||||
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
|
||||
$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;
|
||||
}
|
||||
|
||||
for ($h = 0; $h < (int) $cantidad_necesaria; $h++) {
|
||||
|
||||
if (!empty($cuenta)) {
|
||||
$perfil = $cuenta[$h]->historiales_count;
|
||||
|
||||
for ($y = 0; $y < (int) $pantallas; $y++) {
|
||||
|
||||
$historial_cuenta = new Historial_cuenta;
|
||||
$historial_cuenta->cuenta_id = $cuenta[$h]->id;
|
||||
$historial_cuenta->historial_id = $historial->id;
|
||||
$historial_cuenta->perfil = (int) $perfil + (int) $y + 1;
|
||||
$historial_cuenta->save();
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->alert('warning', 'No hay cuentas disponibles!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first();
|
||||
|
||||
$saldo_anterior = $descuento->valor;
|
||||
//dd($saldo_anterior);
|
||||
$nuevo_saldo = $saldo_anterior - $total_valor;
|
||||
$cobro = $descuento->update(['valor' => $nuevo_saldo]);
|
||||
if ($cobro) {
|
||||
$historial->update(['estado' => 'activo']);
|
||||
$this->credenciales($historial);
|
||||
} else {
|
||||
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$this->tarjetaPlan = false;
|
||||
$this->cantidad_tarjetaPlan = 1;
|
||||
|
||||
}
|
||||
|
||||
public function credenciales($historial)
|
||||
{
|
||||
|
||||
$this->cuentas = $historial;
|
||||
|
||||
$this->credenciales = true;
|
||||
|
||||
$encryptado = Crypt::encryptString($historial->id);
|
||||
$enlace = '/credenciales?id=' . $encryptado;
|
||||
|
||||
|
||||
$user = $historial->cliente;
|
||||
|
||||
$notificacion = [
|
||||
'enlace' => $enlace,
|
||||
'fecha_final' => $historial->fecha_final,
|
||||
'cliente' => $historial->cliente->name,
|
||||
'servicio' => $historial->tarifa->servicio->nombre . '-' . $historial->tarifa->pantallas . 'pantallas',
|
||||
'tipo' => 'compra',
|
||||
'vendedor' => auth()->user()->username,
|
||||
|
||||
];
|
||||
|
||||
Notification::send($user, (new compra($notificacion)));
|
||||
|
||||
|
||||
$this->alert('success', 'Credenciales enviadas a su email!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$shortURLObject = ShortURL::destinationUrl('https://app.sirpremium.com.co' . $enlace)->make();
|
||||
$shortURL = $shortURLObject->default_short_url;
|
||||
$message = $historial->tarifa->servicio->nombre . '-' . $historial->tarifa->pantallas . 'P. Ver credenciales: ' . $shortURL;
|
||||
$recipients = '+57' . $this->celular_tarjetaPlan;
|
||||
|
||||
$this->sendMessage($message, $recipients);
|
||||
|
||||
}
|
||||
|
||||
public function sendMessage($message, $recipients)
|
||||
{
|
||||
|
||||
$auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0');
|
||||
|
||||
$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"
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
|
||||
$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, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} else {
|
||||
$this->alert('success', 'Credenciales enviadas por Email! ' . json_decode($response)->code, [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function consultaTarifa($servicio1)
|
||||
{
|
||||
|
||||
$this->servicio = $servicio1;
|
||||
$this->verServ = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class ShowSlider extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.show-slider');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Configuracione;
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
|
||||
class ShowTop extends Component
|
||||
{ public $configuracion;
|
||||
|
||||
use LivewireAlert;
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->configuracion = Configuracione::orderby('id','desc')->first();
|
||||
|
||||
$consulta_ventas = User::with(['historiales_venta' => function ($query) {
|
||||
$query->whereMonth('fecha_inicio', date('m'));
|
||||
}])
|
||||
->withCount(['historiales_venta' => function ($query) {
|
||||
$query->whereMonth('fecha_inicio', date('m'));
|
||||
}])
|
||||
->orderBy('historiales_venta_count', 'desc')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
|
||||
//dd($consulta_ventas);
|
||||
return view('livewire.show-top',[
|
||||
'usuarios' => $consulta_ventas,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\recarga;
|
||||
use App\Models\Role;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use App\Models\Usuario_promo;
|
||||
use App\Models\Usuario_tarifa;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Livewire\Component;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use App\Models\Servicio;
|
||||
use App\Models\TarifaPromo;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
|
||||
class ShowUsuarios extends Component
|
||||
{
|
||||
use LivewireAlert;
|
||||
use WithPagination;
|
||||
|
||||
public $roles;
|
||||
public $nombre;
|
||||
public $email;
|
||||
public $password;
|
||||
public $rol;
|
||||
public $buscar;
|
||||
public $newPassword;
|
||||
public $pass_id;
|
||||
|
||||
public $modalPassword = false;
|
||||
|
||||
public $id_edit;
|
||||
public $nombre_edit;
|
||||
public $email_edit;
|
||||
public $password_edit;
|
||||
public $rol_edit;
|
||||
|
||||
public $editar = false;
|
||||
public $add = false;
|
||||
public $gestion = false;
|
||||
public $gestionPromo = false;
|
||||
public $delete_user;
|
||||
|
||||
public $modalSaldo = false;
|
||||
public $saldo_actual;
|
||||
public $nuevo_saldo;
|
||||
public $valor_recargar;
|
||||
public $user_saldo;
|
||||
|
||||
public $consulta_tarifas;
|
||||
public $consulta_usuarioTarifas;
|
||||
public $usuario_nombre;
|
||||
public $precioTarifa;
|
||||
public $tarifasGestion;
|
||||
public $estadoTarifa;
|
||||
public $usuarioGestion_id;
|
||||
public $precioTarifasGestion;
|
||||
public $buscar_servicio;
|
||||
public $rol_usuario;
|
||||
|
||||
public $consulta_promociones;
|
||||
public $consulta_usuarioPromo;
|
||||
public $precioPromoGestion;
|
||||
public $promoGestion;
|
||||
public $estadoPromo;
|
||||
public $buscar_promo;
|
||||
|
||||
public $servicio_modTarifas;
|
||||
public $roles_modTarifas;
|
||||
public $precio_modTarifas = 0;
|
||||
public $consulta_saldo;
|
||||
public $modTarifas;
|
||||
|
||||
|
||||
|
||||
protected $rules = [
|
||||
'nombre' => 'required',
|
||||
'email' => 'required',
|
||||
'password' => 'required',
|
||||
'rol' => 'required',
|
||||
];
|
||||
|
||||
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);
|
||||
|
||||
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 . '%'); }
|
||||
])->get();
|
||||
|
||||
}
|
||||
|
||||
if (!empty($this->buscar_promo)) {
|
||||
$this->consulta_promo = Promociones::where('visible', '!=', 'false')->where('nombre', 'like', '%' . $this->buscar_promo . '%')->get();
|
||||
}
|
||||
|
||||
if ($this->gestionPromo == true) {
|
||||
$this->consulta_usuarioPromo = Usuario_promo::where('usuario_id', $this->usuarioGestion_id)->with('usuario', 'promocion')->get();
|
||||
}
|
||||
if (!empty($this->servicio_modTarifas)) {
|
||||
$consulta_tarifas = TarifaPromo::with('rol')->where('promocion_id', $this->servicio_modTarifas)->get();
|
||||
}
|
||||
|
||||
$this->roles = Role::get();
|
||||
|
||||
return view('livewire.show-usuarios', [
|
||||
'usuarios' => $consulta_usuarios,
|
||||
'tarifas' => $consulta_tarifas,
|
||||
'promo' => Promociones::where('visible', 'true')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/// Crear usuario ///
|
||||
public function crear()
|
||||
{
|
||||
|
||||
$this->validate();
|
||||
|
||||
$consulta_user = User::where('email', $this->email)->exists();
|
||||
|
||||
if (!$consulta_user) {
|
||||
$crear = new User;
|
||||
$crear->name = $this->nombre;
|
||||
$crear->email = $this->email;
|
||||
$crear->password = Hash::make($this->password);
|
||||
$crear->rol_id = $this->rol;
|
||||
$crear->save();
|
||||
|
||||
$saldo = new saldo;
|
||||
$saldo->valor = '0';
|
||||
$saldo->usuario_id = $crear->id;
|
||||
$saldo->save();
|
||||
|
||||
if ($crear) {
|
||||
$this->alert('success', 'Usuario creado con èxito!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
$this->add = false;
|
||||
} else {
|
||||
$this->alert('warning', 'Este correo ya está registrado!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//CONSULTAR SALDO//
|
||||
public function saldo($user_saldo)
|
||||
{
|
||||
$this->user_saldo = $user_saldo;
|
||||
$this->consulta_saldo = Saldo::where('usuario_id', $this->user_saldo)->first();
|
||||
|
||||
if (is_null($this->consulta_saldo)) {
|
||||
$saldo = new Saldo;
|
||||
$saldo->valor = 0;
|
||||
$saldo->usuario_id = $this->user_saldo;
|
||||
$saldo->save();
|
||||
$this->consulta_saldo = $saldo;
|
||||
}
|
||||
|
||||
$this->saldo_actual = $this->consulta_saldo->valor;
|
||||
$this->modalSaldo = true;
|
||||
|
||||
}
|
||||
|
||||
public function addSaldo()
|
||||
{
|
||||
$recarga = new recarga;
|
||||
$recarga->payment_method_id = 'manual';
|
||||
$recarga->status = 'Aprovada';
|
||||
$recarga->usuario_id = $this->user_saldo;
|
||||
$recarga->saldo_id = $this->consulta_saldo->id;
|
||||
$recarga->monto = $this->valor_recargar;
|
||||
$recarga->valor_recarga = $this->valor_recargar;
|
||||
$recarga->save();
|
||||
|
||||
|
||||
$this->consulta_saldo->update([
|
||||
'valor' => $this->saldo_actual + $this->valor_recargar
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Saldo actualizado con exito!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
|
||||
$this->limpiarSaldo();
|
||||
|
||||
}
|
||||
|
||||
public function editar($id)
|
||||
{
|
||||
$this->id_edit = $id;
|
||||
|
||||
$consulta = User::FindOrFail($this->id_edit);
|
||||
$this->nombre_edit = $consulta->name;
|
||||
$this->email_edit = $consulta->email;
|
||||
$this->rol_edit = $consulta->rol_id;
|
||||
|
||||
$this->editar = true;
|
||||
|
||||
}
|
||||
public function actualizar()
|
||||
{
|
||||
$this->validate(
|
||||
[
|
||||
'nombre_edit' => 'required',
|
||||
'email_edit' => 'required',
|
||||
'rol_edit' => 'required',
|
||||
]
|
||||
);
|
||||
User::where('id', $this->id_edit)->update([
|
||||
'name' => $this->nombre_edit,
|
||||
'email' => $this->email_edit,
|
||||
'rol_id' => $this->rol_edit
|
||||
]);
|
||||
|
||||
$this->editar = false;
|
||||
|
||||
$this->alert('success', 'Usuario actualizado con exito!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
public function gestionar($id, $rid, $usuNom)
|
||||
{
|
||||
|
||||
$this->usuarioGestion_id = $id;
|
||||
$this->rol_usuario = $rid;
|
||||
$this->usuario_nombre = $usuNom;
|
||||
|
||||
$this->consulta_tarifas = Tarifas::where('rol_id', $rid)->with('servicio')->get();
|
||||
|
||||
$this->consulta_usuarioTarifas = Usuario_tarifa::where('usuario_id', $this->usuarioGestion_id)->with('tarifa')->get();
|
||||
//dd($this->consulta_usuarioTarifas);
|
||||
|
||||
$this->gestion = true;
|
||||
}
|
||||
|
||||
public function addtarifas()
|
||||
{
|
||||
$consulta_existe = Usuario_tarifa::where('tarifa_id', $this->tarifasGestion)
|
||||
->where('usuario_id', $this->usuarioGestion_id)
|
||||
->exists();
|
||||
|
||||
if ($consulta_existe) {
|
||||
$this->alert('warning', '¡Este usuario ya tiene esta tarifa!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} elseif (empty($this->tarifasGestion)) {
|
||||
$this->alert('warning', '¡Seleccione una tarifa!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} elseif (empty($this->precioTarifasGestion)) {
|
||||
$this->alert('warning', '¡Coloque un precio!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} else {
|
||||
$usuarioTarifa = new Usuario_tarifa;
|
||||
$usuarioTarifa->precio = $this->precioTarifasGestion;
|
||||
$usuarioTarifa->tarifa_id = $this->tarifasGestion;
|
||||
$usuarioTarifa->usuario_id = $this->usuarioGestion_id;
|
||||
$usuarioTarifa->visible = $this->estadoTarifa ? 'false' : 'true';
|
||||
$usuarioTarifa->save();
|
||||
|
||||
$this->alert('success', '¡Tarifas del usuario actualizadas correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
$this->consulta_usuarioTarifas = Usuario_tarifa::where('usuario_id', $this->usuarioGestion_id)
|
||||
->with('tarifa')
|
||||
->get();
|
||||
|
||||
|
||||
$this->precioTarifasGestion = null;
|
||||
}
|
||||
|
||||
public function eliminarUsuarioTarifa($id)
|
||||
{
|
||||
Usuario_tarifa::where('id', $id)->delete();
|
||||
|
||||
$this->alert('success', 'Tarifa de usuario eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->consulta_usuarioTarifas = Usuario_tarifa::where('usuario_id', $this->usuarioGestion_id)->with('tarifa')->get();
|
||||
}
|
||||
|
||||
public function gestionarPromociones($id, $usuNom)
|
||||
{
|
||||
$this->usuarioGestion_id = $id;
|
||||
$this->usuario_nombre = $usuNom;
|
||||
|
||||
$this->consulta_promo = Promociones::where('visible', '!=', 'false')->get();
|
||||
|
||||
//$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']);
|
||||
$this->consulta_usuarioPromo = Usuario_promo::where('usuario_id', $this->usuarioGestion_id)->with('usuario', 'promocion')->get();
|
||||
$this->gestionPromo = true;
|
||||
}
|
||||
|
||||
public function addpromos()
|
||||
{
|
||||
$consulta_existe = Usuario_promo::where('promocion_id', $this->promoGestion)->where('usuario_id', $this->usuarioGestion_id)->get();
|
||||
|
||||
|
||||
if (empty($this->promoGestion)) {
|
||||
$this->alert('warning', 'Seleccione una promocion!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} else {
|
||||
|
||||
if ($consulta_existe->count() > 0) {
|
||||
|
||||
$this->alert('warning', 'Este usuario ya tiene esta promocion!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
} else {
|
||||
$usuarioPromo = new Usuario_promo();
|
||||
$usuarioPromo->precio = $this->precioPromoGestion;
|
||||
$usuarioPromo->promocion_id = $this->promoGestion;
|
||||
$usuarioPromo->usuario_id = $this->usuarioGestion_id;
|
||||
if ($this->estadoPromo) {
|
||||
$usuarioPromo->visible = 'false';
|
||||
} else {
|
||||
$usuarioPromo->visible = 'true';
|
||||
}
|
||||
$usuarioPromo->save();
|
||||
|
||||
$this->alert('success', 'promociones del usuario actualizadas correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$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)
|
||||
{
|
||||
Usuario_promo::where('id', $id)->delete();
|
||||
|
||||
$this->alert('success', 'Promocion de usuario eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$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 eliminar($id)
|
||||
{
|
||||
$this->delete_user = $id;
|
||||
$this->alert('warning', '¿Eliminar usuario?', [
|
||||
'position' => 'center',
|
||||
'timer' => '10000',
|
||||
'toast' => false,
|
||||
'text' => 'Esta seguro',
|
||||
'showConfirmButton' => true,
|
||||
'onConfirmed' => 'confirmed',
|
||||
'showDenyButton' => false,
|
||||
'onDenied' => '',
|
||||
'showCancelButton' => true,
|
||||
'onDismissed' => '',
|
||||
'cancelButtonText' => 'Salir',
|
||||
'confirmButtonText' => 'Si',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
{
|
||||
return [
|
||||
'confirmed'
|
||||
];
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
|
||||
$user = User::find($this->delete_user);
|
||||
$user->delete();
|
||||
|
||||
}
|
||||
|
||||
public function editarPassword($id)
|
||||
{
|
||||
$this->pass_id = $id;
|
||||
|
||||
$this->modalPassword = true;
|
||||
}
|
||||
|
||||
public function confirmarNewPassword()
|
||||
{
|
||||
|
||||
$validatedData = $this->validate([
|
||||
'newPassword' => 'required'
|
||||
]);
|
||||
|
||||
User::where('id', $this->pass_id)->update([
|
||||
'password' => Hash::make($this->newPassword),
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Contraseña actualizada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->limpiarContra();
|
||||
}
|
||||
|
||||
public function limpiarInputAdd()
|
||||
{
|
||||
$this->nombre = '';
|
||||
$this->email = '';
|
||||
$this->rol = null;
|
||||
|
||||
$this->add = false;
|
||||
}
|
||||
|
||||
public function limpiarInputEdit()
|
||||
{
|
||||
$this->nombre_edit = '';
|
||||
$this->email_edit = '';
|
||||
$this->rol_edit = null;
|
||||
|
||||
$this->editar = false;
|
||||
}
|
||||
public function limpiarContra()
|
||||
{
|
||||
$this->newPassword = '';
|
||||
$this->modalPassword = false;
|
||||
}
|
||||
public function limpiarSaldo()
|
||||
{
|
||||
$this->valor_recargar = null;
|
||||
$this->modalSaldo = false;
|
||||
}
|
||||
|
||||
/* ------------- ACTUALIZAR ------------- */
|
||||
public function updateTarifas()
|
||||
{
|
||||
|
||||
$consulta_existe = TarifaPromo::where('promocion_id', $this->servicio_modTarifas)->where('rol_id', $this->roles_modTarifas)->get();
|
||||
//dd($consulta_existe);
|
||||
|
||||
if (empty($this->servicio_modTarifas)) {
|
||||
$this->alert('warning', 'Seleccione una promocion!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
} else {
|
||||
|
||||
if ($consulta_existe->count() > 0) {
|
||||
|
||||
$this->alert('warning', 'Esta tarifa ya existe!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
} else {
|
||||
$tarifa = new TarifaPromo;
|
||||
$tarifa->precio = $this->precio_modTarifas;
|
||||
$tarifa->promocion_id = $this->servicio_modTarifas;
|
||||
$tarifa->rol_id = $this->roles_modTarifas;
|
||||
$tarifa->save();
|
||||
|
||||
$this->alert('success', 'Tarifas actualizadas correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------- ELIMINAR ------------- */
|
||||
|
||||
public function eliminarModTarifa($id)
|
||||
{
|
||||
TarifaPromo::where('id', $id)->delete();
|
||||
|
||||
$this->alert('success', 'Tarifas eliminada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class ShowUtilidades extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.show-utilidades');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\recarga;
|
||||
|
||||
|
||||
class ShowWompi extends Component
|
||||
{
|
||||
public $monto;
|
||||
public $referencia;
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (empty($this->referencia)){
|
||||
$this->referencia = Str::random(20);
|
||||
|
||||
$recargas = new recarga;
|
||||
$recargas->monto = $this->monto;
|
||||
$recargas->reference = $this->referencia;
|
||||
$recargas-> status = 'pendiente_wompi';
|
||||
$recargas-> usuario_id = auth()->user()->id;
|
||||
$recargas-> saldo_id= auth()->user()->saldo->id;
|
||||
$recargas->save();
|
||||
}
|
||||
|
||||
|
||||
return view('livewire.show-wompi');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Showcomprar extends Component
|
||||
{
|
||||
public $monto;
|
||||
public $historial_id;
|
||||
|
||||
public function render(Request $request)
|
||||
{ //dd($request);
|
||||
$this->monto = $request->monto;
|
||||
$this->historial_id = $request->id;
|
||||
//dd($this->id = $request->id);
|
||||
return view('livewire.showcomprar');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user