nueva tabla pendientes

This commit is contained in:
Felipe
2023-10-17 15:38:54 -05:00
parent 0c15e3c3b0
commit c7ba02a974
5 changed files with 296 additions and 186 deletions
+212 -171
View File
@@ -7,9 +7,11 @@ use App\Models\Configuracione;
use App\Models\Cuentas; use App\Models\Cuentas;
use App\Models\Historial_cuenta; use App\Models\Historial_cuenta;
use App\Models\Historiale; use App\Models\Historiale;
use App\Models\Pendientes;
use App\Models\Promocion_tarifa; use App\Models\Promocion_tarifa;
use App\Models\Promociones; use App\Models\Promociones;
use App\Models\Saldo; use App\Models\Saldo;
use App\Models\Servicio;
use App\Models\Tarifas; use App\Models\Tarifas;
use App\Models\User; use App\Models\User;
use App\Notifications\compra; use App\Notifications\compra;
@@ -39,7 +41,7 @@ class ShowPromociones extends Component
public $eliminar_id; public $eliminar_id;
public $list; public $list;
public $list2; public $list2;
public $categorian; public $categorian;
public $photo; public $photo;
@@ -94,7 +96,7 @@ class ShowPromociones extends Component
public $cuentas; public $cuentas;
public $img_ver; public $img_ver;
public $fecha_editarPromo; public $fecha_editarPromo;
public $mensaje_servicio; public $mensaje_servicio;
public $categoria_photo; public $categoria_photo;
@@ -108,26 +110,26 @@ class ShowPromociones extends Component
public function render() public function render()
{ {
$date = Carbon::now()->subDay(30); $date = Carbon::now()->subDay(30);
$this->fecha= $date->format('Y-m-d'); $this->fecha = $date->format('Y-m-d');
$this->fechaActual = Carbon::now(); $this->fechaActual = Carbon::now();
$this->fechaActual = Carbon::parse($this->fechaActual); $this->fechaActual = Carbon::parse($this->fechaActual);
$this->fechaHoy = Carbon::now(); $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->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'); //$this->fechaHoy = $this->fechaHoy->format('d/m/Y');
if (empty($this->nombre_comprarPromo) && empty($this->email_comprarPromo)) { if (empty($this->nombre_comprarPromo) && empty($this->email_comprarPromo)) {
$usuario_actual = Auth::user(); $usuario_actual = Auth::user();
$this-> nombre_comprarPromo = $usuario_actual->name; $this->nombre_comprarPromo = $usuario_actual->name;
$this-> email_comprarPromo = $usuario_actual->email; $this->email_comprarPromo = $usuario_actual->email;
$this-> celular_comprarPromo = $usuario_actual->celular; $this->celular_comprarPromo = $usuario_actual->celular;
//dd($this-> nombre_tarjetaPlan); //dd($this-> nombre_tarjetaPlan);
} }
return view('livewire.show-promociones', [ return view('livewire.show-promociones', [
'categorias' => Categoria::get(), 'categorias' => Categoria::get(),
'tarifas' => Tarifas::with('servicio')->get(), 'tarifas' => Tarifas::with('servicio')->get(),
]); ]);
@@ -137,25 +139,25 @@ class ShowPromociones extends Component
{ {
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->with([ $consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->with([
'usuario_promos' => function ($query) { 'usuario_promos' => function ($query) {
$query->where('usuario_id', Auth::user()->id); $query->where('usuario_id', Auth::user()->id);
}, },
'tarifaPromo' => function ($query) { 'tarifaPromo' => function ($query) {
$query->where('rol_id', Auth::user()->rol->id); $query->where('rol_id', Auth::user()->rol->id);
} }
])->first(); ])->first();
//dd($consulta_verpromocion); //dd($consulta_verpromocion);
//$cuentas_creadas = Cuentas::whereDate('inicio','>=',$this->fecha)->where('servicio_id',$tarifas->servicio->id)->where('estado','!=','inactivo')->where('estado','!=','delete')->get(); //$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->consulta = $consulta_verpromocion;
// $this->precioAntes = $consulta_verpromocion->tarifas->first()->valor; // $this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
if (!empty($precio= $consulta_verpromocion->usuario_promos->first())) { if (!empty($precio = $consulta_verpromocion->usuario_promos->first())) {
$this->precioAhora = $precio->precio; $this->precioAhora = $precio->precio;
}else if(!empty($precio= $consulta_verpromocion->tarifaPromo->first())){ } else if (!empty($precio = $consulta_verpromocion->tarifaPromo->first())) {
$this->precioAhora = $precio->precio; $this->precioAhora = $precio->precio;
}else{ } else {
$this->precioAhora = $consulta_verpromocion->precio; $this->precioAhora = $consulta_verpromocion->precio;
} }
$this->imagen = $consulta_verpromocion->img_publicidad; $this->imagen = $consulta_verpromocion->img_publicidad;
$this->fechaLimite = $consulta_verpromocion->fecha_limite; $this->fechaLimite = $consulta_verpromocion->fecha_limite;
$this->nombrePromo = $consulta_verpromocion->nombre; $this->nombrePromo = $consulta_verpromocion->nombre;
@@ -170,7 +172,7 @@ class ShowPromociones extends Component
public function comprarPromo($id) public function comprarPromo($id)
{ {
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first(); $consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first();
$this->consulta = $consulta_verpromocion; $this->consulta = $consulta_verpromocion;
//$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor; //$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
@@ -180,7 +182,7 @@ class ShowPromociones extends Component
$this->fechaLimite = $consulta_verpromocion->fecha_limite; $this->fechaLimite = $consulta_verpromocion->fecha_limite;
$this->nombrePromo = $consulta_verpromocion->nombre; $this->nombrePromo = $consulta_verpromocion->nombre;
$this->dias = $consulta_verpromocion->dias; $this->dias = $consulta_verpromocion->dias;
$this->descripcionPromo = $consulta_verpromocion->descripcion; $this->descripcionPromo = $consulta_verpromocion->descripcion;
$this->fechaFinal = $this->fechaActual->addDay($this->dias); $this->fechaFinal = $this->fechaActual->addDay($this->dias);
$this->mensaje_servicio = $consulta_verpromocion->mensaje; $this->mensaje_servicio = $consulta_verpromocion->mensaje;
@@ -191,9 +193,20 @@ class ShowPromociones extends Component
/* ---------------- Btn Comprar ---------------- */ /* ---------------- Btn Comprar ---------------- */
public function getListeners()
{
return [
'confirmed', 'confirmarCompra', 'denegarCompra'
];
}
public $historial;
public $n = [];
public $f = [];
public $r = 0;
public function pagar() public function pagar()
{ {
$this->validate(); $this->validate();
@@ -216,7 +229,7 @@ class ShowPromociones extends Component
$historial = new Historiale(); $historial = new Historiale();
$historial->fecha_inicio = $this->fechaHoy; $historial->fecha_inicio = $this->fechaHoy;
$historial->fecha_final = $this->fechaFinal; $historial->fecha_final = $this->fechaFinal;
$historial->valor = $this->precioAhora *$this->cantidad_comprarPromo; $historial->valor = $this->precioAhora * $this->cantidad_comprarPromo;
$historial->tipo_pago = 'manual'; $historial->tipo_pago = 'manual';
$historial->estado = 'pendiente'; $historial->estado = 'pendiente';
$historial->vendedor_id = Auth()->user()->id; $historial->vendedor_id = Auth()->user()->id;
@@ -224,96 +237,137 @@ class ShowPromociones extends Component
$historial->cliente_id = $usuario_id; $historial->cliente_id = $usuario_id;
$historial->cantidad = $this->cantidad_comprarPromo; $historial->cantidad = $this->cantidad_comprarPromo;
$historial->nombre_cliente = $this->nombre_comprarPromo; $historial->nombre_cliente = $this->nombre_comprarPromo;
$historial->utilidad = $this->utilidad*$this->cantidad_comprarPromo; $historial->utilidad = $this->utilidad * $this->cantidad_comprarPromo;
$historial->save(); $historial->save();
$this->historial = $historial;
for ($p = 0; $p < (int)$this->cantidad_comprarPromo; $p++) { for ($p = 0; $p < (int)$this->cantidad_comprarPromo; $p++) {
//dd($this->cantidad_comprarPromo); //dd($this->cantidad_comprarPromo);
$n=[]; $this->n = [];
$r=0; $this->f = [];
$this->r = 0;
foreach ($this->consulta->tarifas as $tarifa) { foreach ($this->consulta->tarifas as $tarifa) {
$r=$r+$tarifa->pantallas; $this->r = $this->r + $tarifa->pantallas;
//dd($this->consulta->tarifas->count());
$pantallas_tarifa = $tarifa->pantallas; $pantallas_tarifa = $tarifa->pantallas;
$servicio_id = $tarifa->servicio_id; $servicio_id = $tarifa->servicio_id;
$pantalla_servicio = $tarifa->servicio->pantallas; $pantalla_servicio = $tarifa->servicio->pantallas;
$pantalla_servicio_completa = $tarifa->servicio->completa; $pantalla_servicio_completa = $tarifa->servicio->completa;
$faltante = $pantalla_servicio - $pantallas_tarifa; $faltante = $pantalla_servicio - $pantallas_tarifa;
//dd($tarifa); //dd($tarifa);
if ($pantalla_servicio_completa == $pantallas_tarifa) { if ($pantalla_servicio_completa == $pantallas_tarifa) {
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias-20); $this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias - 20);
$this->fecha_final_2 = $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) $cuenta = Cuentas::where('servicio_id', $servicio_id)->whereDate('inicio', '>=', $this->fecha)->whereDate('vencimiento', '>=', $this->fecha_final_1)
->whereDate('vencimiento','<=',$this->fecha_final_2) ->whereDate('vencimiento', '<=', $this->fecha_final_2)
->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado','pendiente')->having('historiales_count', '==', 0)->first(); ->Orderby('created_at', 'ASC')->with('historiales')->withCount('historiales')->where('estado', 'pendiente')->having('historiales_count', '==', 0)->first();
}else{ } 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(); $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)) { if (!is_null($cuenta)) {
$perfil = $cuenta->historiales_count; $perfil = $cuenta->historiales_count;
for ($y = 0; $y < (int)$pantallas_tarifa; $y++) { for ($y = 0; $y < (int)$pantallas_tarifa; $y++) {
$historial_cuenta = new Historial_cuenta(); $historial_cuenta = new Historial_cuenta();
$historial_cuenta->cuenta_id = $cuenta->id;
$historial_cuenta->historial_id = $historial->id; $historial_cuenta->historial_id = $historial->id;
$historial_cuenta->perfil = (int)$perfil + (int)$y+1; $historial_cuenta->cuenta_id = $cuenta->id;
$historial_cuenta->perfil = (int)$perfil + (int)$y + 1;
$historial_cuenta->save(); $historial_cuenta->save();
if (!empty($historial_cuenta->id)) { if (!empty($historial_cuenta->id)) {
array_push($n,$historial_cuenta->id); array_push($this->n, $historial_cuenta->id);
} }
} }
} else { } else {
array_push($this->f, $servicio_id);
$this->alert('warning', 'No hay cuentas disponibles de '.$tarifa->servicio->nombre, [ $this->alert('warning', 'No hay cuentas disponibles de ' . $tarifa->servicio->nombre, [
'position' => 'top' 'position' => 'top'
]); ]);
} }
$cuenta=null; $cuenta = null;
} }
} }
//dump($r, count($n)); if (count($this->f) > 0) {
if ($r == count($n) ) { $resultados = Servicio::whereIn('id', $this->f)->get();
// $eliminar = Historial_cuenta::whereIn('id', $n)->delete();
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first(); $message = '';
$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(); if ($resultados->count() > 0) {
//dd($eliminar); $nombresServicios = $resultados->pluck('nombre')->toArray();
$message = implode(', ', $nombresServicios);
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [ $this->alert('warning', 'No hay disponibilidad de ' . $message . ' en este momento.', [
'position' => 'top' 'position' => 'center',
'timer' => '30000',
'toast' => false,
'text' => '¿Te gustaría realizar la compra ahora y recibir tu pedido tan pronto como haya disponibilidad? anticipamos que estará disponible en un plazo máximo de 48 horas.',
'showConfirmButton' => true,
'onConfirmed' => 'confirmarCompra',
'showDenyButton' => false,
'onDenied' => 'denegarCompra',
'showCancelButton' => true,
'onDismissed' => 'denegarCompra',
'cancelButtonText' => 'No, abandonar.',
'confirmButtonText' => 'Sí, comprar.',
]); ]);
} }
}
}
$n=null; public function confirmarCompra()
}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]);
$eliminar = Historial_cuenta::whereIn('id',$n)->delete(); if ($cobro) {
//dump($eliminar); $this->historial->update(['estado' => 'activo']);
$this->modalComprarPromo = false;
$this->alert('warning', 'No hay promociones disponibles, comuniquese con soporte!', [
foreach ($this->f as $serviceId) {
$pendiente = new Pendientes();
$pendiente->historial_id = $this->historial->id;
$pendiente->cantidad = $this->cantidad_comprarPromo;
$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' 'position' => 'top'
]); ]);
$n=null;
} }
$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) public function credenciales($historial)
@@ -326,8 +380,8 @@ class ShowPromociones extends Component
$encryptado = Crypt::encryptString($historial->id); $encryptado = Crypt::encryptString($historial->id);
$enlace = '/credenciales?id=' . $encryptado; $enlace = '/credenciales?id=' . $encryptado;
$user =$historial->cliente; $user = $historial->cliente;
$notificacion = [ $notificacion = [
'enlace' => $enlace, 'enlace' => $enlace,
'fecha_final' => $historial->fecha_final, 'fecha_final' => $historial->fecha_final,
@@ -343,65 +397,63 @@ class ShowPromociones extends Component
'position' => 'top' 'position' => 'top'
]); ]);
$shortURLObject = ShortURL::destinationUrl('https://app.sirpremium.com.co'.$enlace)->make(); $shortURLObject = ShortURL::destinationUrl('https://app.sirpremium.com.co' . $enlace)->make();
$shortURL = $shortURLObject->default_short_url; $shortURL = $shortURLObject->default_short_url;
$message = $historial->promocion->nombre.'. Ver credenciales: '.$shortURL ; $message = $historial->promocion->nombre . '. Ver credenciales: ' . $shortURL;
$recipients= '+57'.$this->celular_comprarPromo; $recipients = '+57' . $this->celular_comprarPromo;
$this->sendMessage($message, $recipients); $this->sendMessage($message, $recipients);
$this->cantidad_comprarPromo = 1; $this->cantidad_comprarPromo = 1;
} }
public function sendMessage($message, $recipients) public function sendMessage($message, $recipients)
{ {
$auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0');
$curl = curl_init();
curl_setopt_array($curl, array( $auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0');
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); $curl = curl_init();
$err = curl_error($curl);
curl_close($curl); curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.labsmobile.com/json/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"message":"' . $message . '", "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic " . $auth_basic,
"Cache-Control: no-cache",
"Content-Type: application/json"
),
));
if ($err) { $response = curl_exec($curl);
$err = curl_error($curl);
$this->alert('warning', 'Error enviando SMS!'.$err, [ curl_close($curl);
'position' => 'top'
]);
} else {
if (!empty(json_decode($response)->subid)) { if ($err) {
$this->alert('success', 'Credenciales enviadas por Email y SMS! '.json_decode($response)->subid, [
'position' => 'top' $this->alert('warning', 'Error enviando SMS!' . $err, [
]);
}else{
$this->alert('success', 'Credenciales enviadas por Email! '.json_decode($response)->code, [
'position' => 'top' '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'
]);
}
} }
} }
}
@@ -409,9 +461,9 @@ class ShowPromociones extends Component
{ {
if (!empty($this->categoria_photo)) { if (!empty($this->categoria_photo)) {
$url_foto = $this->categoria_photo->store('photos'); $url_foto = $this->categoria_photo->store('photos');
}else{ } else {
$url_foto = ''; $url_foto = '';
} }
$categoria = new Categoria; $categoria = new Categoria;
$categoria->nombre = $this->nombre_categoria; $categoria->nombre = $this->nombre_categoria;
@@ -424,7 +476,7 @@ class ShowPromociones extends Component
public function add_tarifa() public function add_tarifa()
{ {
$consulta= Tarifas::find($this->tarifa_id_promocion); $consulta = Tarifas::find($this->tarifa_id_promocion);
$promocion_tarifa = new Promocion_tarifa; $promocion_tarifa = new Promocion_tarifa;
$promocion_tarifa->tarifa_id = $this->tarifa_id_promocion; $promocion_tarifa->tarifa_id = $this->tarifa_id_promocion;
$promocion_tarifa->nombre = $consulta->servicio->nombre; $promocion_tarifa->nombre = $consulta->servicio->nombre;
@@ -445,7 +497,7 @@ class ShowPromociones extends Component
} }
public function guardar() public function guardar()
{ {
$this->validate([ $this->validate([
'nombre_promocion' => 'required', 'nombre_promocion' => 'required',
'descripcion_promocion' => 'required', 'descripcion_promocion' => 'required',
@@ -455,20 +507,20 @@ class ShowPromociones extends Component
'fecha_limite_promocion' => 'required', 'fecha_limite_promocion' => 'required',
'categoria_id_promocion' => 'required', 'categoria_id_promocion' => 'required',
'photo' => 'required', 'photo' => 'required',
'list'=>'required', 'list' => 'required',
]); ]);
if (!empty($this->photo)) { if (!empty($this->photo)) {
$nombre=Str::random(10); $nombre = Str::random(10);
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){ $img = img::make($this->photo)->orientate()->resize(1000, null, function ($constraint) {
$constraint->aspectRatio(); $constraint->aspectRatio();
$constraint->upsize(); $constraint->upsize();
})->encode('webp'); })->encode('webp');
$location = "photos/".$nombre.".webp"; $location = "photos/" . $nombre . ".webp";
Storage::disk('local')->put($location, $img); Storage::disk('local')->put($location, $img);
$url_foto = $location; $url_foto = $location;
} else { } else {
@@ -505,8 +557,6 @@ class ShowPromociones extends Component
$this->limpiarInputPromocion(); $this->limpiarInputPromocion();
} }
public function eliminar($id) public function eliminar($id)
{ {
$this->eliminar_id = $id; $this->eliminar_id = $id;
@@ -526,13 +576,6 @@ class ShowPromociones extends Component
]); ]);
} }
public function getListeners()
{
return [
'confirmed'
];
}
public function confirmed() public function confirmed()
{ {
$consulta_promociones = Promociones::findOrFail($this->eliminar_id); $consulta_promociones = Promociones::findOrFail($this->eliminar_id);
@@ -565,45 +608,45 @@ class ShowPromociones extends Component
$consultas = Promocion_tarifa::selectRaw('promocion_tarifas.id as id, servicios.nombre as nombre, tarifas.pantallas as pantallas ') $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('tarifas', 'tarifas.id', '=', 'promocion_tarifas.tarifa_id')
->join('servicios', 'servicios.id', '=', 'tarifas.servicio_id') ->join('servicios', 'servicios.id', '=', 'tarifas.servicio_id')
->where('promocion_tarifas.promocion_id',$this->editar_promo_id) ->where('promocion_tarifas.promocion_id', $this->editar_promo_id)
->get(); ->get();
$this->list2 = collect(); $this->list2 = collect();
foreach ($consultas as $consulta) { foreach ($consultas as $consulta) {
$promocionTarifa = new Promocion_tarifa; $promocionTarifa = new Promocion_tarifa;
$promocionTarifa->tarifa_id = $this->tarifa_id_promocion; $promocionTarifa->tarifa_id = $this->tarifa_id_promocion;
$promocionTarifa->nombre = $consulta->nombre ; $promocionTarifa->nombre = $consulta->nombre;
$promocionTarifa->cantidad = $consulta->pantallas; $promocionTarifa->cantidad = $consulta->pantallas;
$promocionTarifa->identificador = $consulta->id; $promocionTarifa->identificador = $consulta->id;
$promocionTarifa->dias = $consulta->dias; $promocionTarifa->dias = $consulta->dias;
$this->list2->add($promocionTarifa); $this->list2->add($promocionTarifa);
} }
$this->editarPromo = true; $this->editarPromo = true;
} }
public function editarPromoUpdate() public function editarPromoUpdate()
{ {
if (!empty($this->photo)) { if (!empty($this->photo)) {
$nombre=Str::random(10); $nombre = Str::random(10);
$img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){ $img = img::make($this->photo)->orientate()->resize(1000, null, function ($constraint) {
$constraint->aspectRatio(); $constraint->aspectRatio();
$constraint->upsize(); $constraint->upsize();
})->encode('webp'); })->encode('webp');
$location = "photos/".$nombre.".webp"; $location = "photos/" . $nombre . ".webp";
Storage::disk('local')->put($location, $img); Storage::disk('local')->put($location, $img);
$url_foto = $location; $url_foto = $location;
} else { } else {
$url_foto = $this->img_ver; $url_foto = $this->img_ver;
} }
Promociones::where('id', $this->editar_promo_id)->update([ Promociones::where('id', $this->editar_promo_id)->update([
'precio' => $this->valor_editarPromo, 'precio' => $this->valor_editarPromo,
@@ -622,36 +665,34 @@ class ShowPromociones extends Component
$this->limpiarInputPromocion(); $this->limpiarInputPromocion();
} }
public function add_tarifa_list2() public function add_tarifa_list2()
{ {
$add = new Promocion_tarifa; $add = new Promocion_tarifa;
$add->promocion_id = $this->editar_promo_id; $add->promocion_id = $this->editar_promo_id;
$add->tarifa_id = $this->tarifa_id_promocion; $add->tarifa_id = $this->tarifa_id_promocion;
$add->save(); $add->save();
$consultas = Promocion_tarifa::selectRaw('promocion_tarifas.id as id, servicios.nombre as nombre, tarifas.pantallas as pantallas ') $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('tarifas', 'tarifas.id', '=', 'promocion_tarifas.tarifa_id')
->join('servicios', 'servicios.id', '=', 'tarifas.servicio_id') ->join('servicios', 'servicios.id', '=', 'tarifas.servicio_id')
->where('promocion_tarifas.promocion_id',$this->editar_promo_id) ->where('promocion_tarifas.promocion_id', $this->editar_promo_id)
->get(); ->get();
$this->list2 = collect(); $this->list2 = collect();
foreach ($consultas as $consulta) { foreach ($consultas as $consulta) {
$promocionTarifa = new Promocion_tarifa; $promocionTarifa = new Promocion_tarifa;
$promocionTarifa->tarifa_id = $this->tarifa_id_promocion; $promocionTarifa->tarifa_id = $this->tarifa_id_promocion;
$promocionTarifa->nombre = $consulta->nombre ; $promocionTarifa->nombre = $consulta->nombre;
$promocionTarifa->cantidad = $consulta->pantallas; $promocionTarifa->cantidad = $consulta->pantallas;
$promocionTarifa->identificador = $consulta->id; $promocionTarifa->identificador = $consulta->id;
$this->list2->add($promocionTarifa); $this->list2->add($promocionTarifa);
} }
} }
public function del_item_list2($id,$n) public function del_item_list2($id, $n)
{ {
Promocion_tarifa::where('id',$id)->delete(); Promocion_tarifa::where('id', $id)->delete();
$this->list2->pull($n); $this->list2->pull($n);
@@ -672,7 +713,7 @@ class ShowPromociones extends Component
$this->newCategoria = false; $this->newCategoria = false;
$this->newPromocion = false; $this->newPromocion = false;
$this->photo = null; $this->photo = null;
$this->mensaje_servicio=null; $this->mensaje_servicio = null;
$this->list = null; $this->list = null;
} }
+18 -12
View File
@@ -22,27 +22,33 @@ class Historiale extends Model
'nombre_cliente' 'nombre_cliente'
]; ];
public function vendedor(){ public function vendedor()
return $this ->belongsTo(User::class); {
return $this->belongsTo(User::class);
} }
public function tarifa(){ public function tarifa()
return $this ->belongsTo(Tarifas::class); {
return $this->belongsTo(Tarifas::class);
} }
public function promocion(){ public function promocion()
return $this ->belongsTo(Promociones::class); {
return $this->belongsTo(Promociones::class);
} }
public function cliente(){ public function cliente()
return $this ->belongsTo(User::class); {
return $this->belongsTo(User::class);
} }
public function cuentas(){ public function cuentas()
return $this ->belongsToMany(Cuentas::class,'historial_cuentas','historial_id','cuenta_id'); {
return $this->belongsToMany(Cuentas::class, 'historial_cuentas', 'historial_id', 'cuenta_id');
} }
public function cuentas_obsoletas(){ public function cuentas_obsoletas()
return $this ->belongsToMany(Cuentas::class,'logs','historial_id','cuenta_id'); {
return $this->belongsToMany(Cuentas::class, 'logs', 'historial_id', 'cuenta_id');
} }
} }
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Pendientes extends Model
{
use HasFactory;
protected $fillable = [
'historial_id',
'servicio_id',
'cantidad',
'estado',
];
public function servicio()
{
return $this->hasMany(Servicio::class, 'servicio_id');
}
public function historial()
{
return $this->hasMany(Historiale::class, 'historial_id');
}
}
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pendientes', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('historial_id')->nullable();;
$table->unsignedBigInteger('servicio_id')->nullable();;
$table->string('cantidad')->nullable();
$table->string('estado')->nullable();
$table->foreign('historial_id')->references('id')->on('historiales')->onDelete('cascade');
$table->foreign('servicio_id')->references('id')->on('servicios')->onUpdate('cascade');;
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pendientes');
}
};
@@ -9,9 +9,8 @@
verPro: false, verPro: false,
copiar: '' copiar: ''
}" class="h-full w-full md:my-2"> }" class="h-full w-full md:my-2">
<div class="fixed backdrop-blur-sm bg-white/70 left-0 bottom-0 top-0 right-0 h-full z-40" wire:loading
<div class=" fixed backdrop-blur-sm bg-white/70 left-0 bottom-0 top-0 right-0 h-full z-40" wire:loading wire:target="confirmarCompra,denegarCompra,add_tarifa_list2,del_item_list2,photo,verPromocion,comprarPromo,editarPromo,editarPromoUpdate,comprar,pagar,create_newCategoria,add_tarifa,del_item,guardar,eliminar">
wire:target="add_tarifa_list2,del_item_list2,photo,verPromocion,comprarPromo,editarPromo,editarPromoUpdate,comprar,pagar,create_newCategoria,add_tarifa,del_item,guardar,eliminar">
<div class="grid h-full place-items-center "> <div class="grid h-full place-items-center ">
<div class="max-w-xs"> <div class="max-w-xs">
<img src="./img/loading.gif" alt="" class="w-full text-center"> <img src="./img/loading.gif" alt="" class="w-full text-center">