757 lines
26 KiB
PHP
Executable File
757 lines
26 KiB
PHP
Executable File
<?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\Pendientes;
|
|
use App\Models\Promocion_tarifa;
|
|
use App\Models\Promociones;
|
|
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 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 $utilidad;
|
|
|
|
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|numeric|min:1',
|
|
];
|
|
|
|
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->utilidad = $consulta_verpromocion->utilidad ?? '';
|
|
$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 getListeners()
|
|
{
|
|
return [
|
|
'confirmed', 'confirmarCompra', 'denegarCompra'
|
|
];
|
|
}
|
|
|
|
public $historial;
|
|
public $n = [];
|
|
public $f = [];
|
|
public $r = 0;
|
|
|
|
public function pagar()
|
|
{
|
|
$this->validate();
|
|
|
|
if ($this->cantidad_comprarPromo == 0) {
|
|
$this->alert('error', 'La cantidad debe ser mayor a 0', [
|
|
'position' => 'top'
|
|
]);
|
|
return;
|
|
}
|
|
|
|
if (auth()->user()->saldo->valor < $this->precioAhora * $this->cantidad_comprarPromo) {
|
|
$this->alert('error', 'Saldo insuficiente', [
|
|
'position' => 'top'
|
|
]);
|
|
return;
|
|
}
|
|
|
|
$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->utilidad = $this->utilidad * $this->cantidad_comprarPromo;
|
|
$historial->save();
|
|
|
|
$this->historial = $historial;
|
|
|
|
for ($p = 0; $p < (int)$this->cantidad_comprarPromo; $p++) {
|
|
//dd($this->cantidad_comprarPromo);
|
|
$this->n = [];
|
|
$this->f = [];
|
|
$this->r = 0;
|
|
|
|
foreach ($this->consulta->tarifas as $tarifa) {
|
|
$this->r = $this->r + $tarifa->pantallas;
|
|
$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', 'DESC')->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', 'DESC')->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->historial_id = $historial->id;
|
|
$historial_cuenta->cuenta_id = $cuenta->id;
|
|
$historial_cuenta->perfil = (int)$perfil + (int)$y + 1;
|
|
$historial_cuenta->save();
|
|
if (!empty($historial_cuenta->id)) {
|
|
array_push($this->n, $historial_cuenta->id);
|
|
}
|
|
}
|
|
} else {
|
|
array_push($this->f, $servicio_id);
|
|
$this->alert('warning', 'No hay cuentas disponibles de ' . $tarifa->servicio->nombre, [
|
|
'position' => 'top'
|
|
]);
|
|
}
|
|
$cuenta = null;
|
|
$this->modalComprarPromo = false;
|
|
}
|
|
}
|
|
if (count($this->f) > 0) {
|
|
$resultados = Servicio::whereIn('id', $this->f)->get();
|
|
// $eliminar = Historial_cuenta::whereIn('id', $n)->delete();
|
|
$message = '';
|
|
|
|
if ($resultados->count() > 0) {
|
|
$nombresServicios = $resultados->pluck('nombre')->toArray();
|
|
$message = implode(', ', $nombresServicios);
|
|
|
|
$this->alert('warning', 'No hay disponibilidad de ' . $message . ' en este momento.', [
|
|
'position' => 'center',
|
|
'timer' => '60000',
|
|
'toast' => false,
|
|
'text' => '¿Te gustaría realizar la compra ahora y recibir tu pedido tan pronto como haya disponibilidad?.',
|
|
'allowOutsideClick' => false,
|
|
'allowEscapeKey' => false,
|
|
'showConfirmButton' => true,
|
|
'showCancelButton' => false,
|
|
'showDenyButton' => true,
|
|
'onConfirmed' => 'confirmarCompra',
|
|
'onDenied' => 'denegarCompra',
|
|
// 'cancelButtonText' => 'No, abandonar.',
|
|
'denyButtonText' => 'No, abandonar.',
|
|
'confirmButtonText' => 'Sí, comprar.',
|
|
]);
|
|
}
|
|
} else {
|
|
$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]);
|
|
|
|
if ($cobro) {
|
|
$historial->update(['estado' => 'activo']);
|
|
$this->modalComprarPromo = false;
|
|
$this->credenciales($historial);
|
|
} else {
|
|
$eliminar = Historial_cuenta::whereIn('id', $this->n)->delete();
|
|
|
|
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
|
|
'position' => 'top'
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function confirmarCompra()
|
|
{
|
|
$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]);
|
|
|
|
if ($cobro) {
|
|
$this->historial->update(['estado' => 'activo']);
|
|
$this->modalComprarPromo = false;
|
|
|
|
foreach ($this->f as $serviceId) {
|
|
|
|
for ($y = 0; $y < (int)$this->cantidad_comprarPromo; $y++) {
|
|
$pendiente = new Pendientes();
|
|
$pendiente->historial_id = $this->historial->id;
|
|
$pendiente->cantidad = '1';
|
|
$pendiente->estado = 'pendiente';
|
|
$pendiente->servicio_id = $serviceId;
|
|
$pendiente->save();
|
|
}
|
|
}
|
|
|
|
$this->credenciales($this->historial);
|
|
} else {
|
|
Historial_cuenta::whereIn('id', $this->n)->delete();
|
|
|
|
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
|
|
'position' => 'top'
|
|
]);
|
|
}
|
|
|
|
|
|
$this->alert('success', 'Compra exitosa!', [
|
|
'position' => 'top'
|
|
]);
|
|
|
|
$this->f = null;
|
|
$this->n = null;
|
|
$this->r = 0;
|
|
$this->modalComprarPromo = false;
|
|
}
|
|
public function denegarCompra()
|
|
{
|
|
Historial_cuenta::whereIn('id', $this->n)->delete();
|
|
|
|
$this->alert('success', 'Compra cancelada!', [
|
|
'position' => 'top'
|
|
]);
|
|
$this->f = null;
|
|
$this->n = null;
|
|
$this->r = 0;
|
|
$this->modalComprarPromo = false;
|
|
}
|
|
|
|
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',
|
|
'utilidad' => '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->utilidad = $this->utilidad;
|
|
$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 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->utilidad = '';
|
|
$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;
|
|
}
|
|
}
|