From c7ba02a9747314f3132a72c896814650714bb9ac Mon Sep 17 00:00:00 2001 From: Felipe Date: Tue, 17 Oct 2023 15:38:54 -0500 Subject: [PATCH] nueva tabla pendientes --- app/Http/Livewire/ShowPromociones.php | 383 ++++++++++-------- app/Models/Historiale.php | 30 +- app/Models/Pendientes.php | 27 ++ ...3_10_17_145853_create_pendientes_table.php | 37 ++ .../views/livewire/show-promociones.blade.php | 5 +- 5 files changed, 296 insertions(+), 186 deletions(-) create mode 100644 app/Models/Pendientes.php create mode 100644 database/migrations/2023_10_17_145853_create_pendientes_table.php diff --git a/app/Http/Livewire/ShowPromociones.php b/app/Http/Livewire/ShowPromociones.php index 8aab527..39736ff 100644 --- a/app/Http/Livewire/ShowPromociones.php +++ b/app/Http/Livewire/ShowPromociones.php @@ -7,9 +7,11 @@ 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; @@ -39,7 +41,7 @@ class ShowPromociones extends Component public $eliminar_id; public $list; public $list2; - + public $categorian; public $photo; @@ -94,7 +96,7 @@ class ShowPromociones extends Component public $cuentas; public $img_ver; public $fecha_editarPromo; - public $mensaje_servicio; + public $mensaje_servicio; public $categoria_photo; @@ -108,26 +110,26 @@ class ShowPromociones extends Component public function render() { $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::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->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; + $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(), ]); @@ -137,25 +139,25 @@ class ShowPromociones extends Component { $consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->with([ 'usuario_promos' => function ($query) { - $query->where('usuario_id', Auth::user()->id); - }, + $query->where('usuario_id', Auth::user()->id); + }, 'tarifaPromo' => function ($query) { - $query->where('rol_id', Auth::user()->rol->id); - } + $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->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())){ + } else if (!empty($precio = $consulta_verpromocion->tarifaPromo->first())) { $this->precioAhora = $precio->precio; - }else{ + } else { $this->precioAhora = $consulta_verpromocion->precio; } - + $this->imagen = $consulta_verpromocion->img_publicidad; $this->fechaLimite = $consulta_verpromocion->fecha_limite; $this->nombrePromo = $consulta_verpromocion->nombre; @@ -170,7 +172,7 @@ class ShowPromociones extends Component public function comprarPromo($id) { $consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first(); - + $this->consulta = $consulta_verpromocion; //$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor; @@ -180,7 +182,7 @@ class ShowPromociones extends Component $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; @@ -191,9 +193,20 @@ class ShowPromociones extends Component /* ---------------- Btn Comprar ---------------- */ + public function getListeners() + { + return [ + 'confirmed', 'confirmarCompra', 'denegarCompra' + ]; + } + + public $historial; + public $n = []; + public $f = []; + public $r = 0; public function pagar() - { + { $this->validate(); @@ -216,7 +229,7 @@ class ShowPromociones extends Component $historial = new Historiale(); $historial->fecha_inicio = $this->fechaHoy; $historial->fecha_final = $this->fechaFinal; - $historial->valor = $this->precioAhora *$this->cantidad_comprarPromo; + $historial->valor = $this->precioAhora * $this->cantidad_comprarPromo; $historial->tipo_pago = 'manual'; $historial->estado = 'pendiente'; $historial->vendedor_id = Auth()->user()->id; @@ -224,96 +237,137 @@ class ShowPromociones extends Component $historial->cliente_id = $usuario_id; $historial->cantidad = $this->cantidad_comprarPromo; $historial->nombre_cliente = $this->nombre_comprarPromo; - $historial->utilidad = $this->utilidad*$this->cantidad_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); - $n=[]; - $r=0; + $this->n = []; + $this->f = []; + $this->r = 0; + foreach ($this->consulta->tarifas as $tarifa) { - $r=$r+$tarifa->pantallas; - //dd($this->consulta->tarifas->count()); + $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); + $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(); + $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->cuenta_id = $cuenta->id; + $historial_cuenta->perfil = (int)$perfil + (int)$y + 1; $historial_cuenta->save(); if (!empty($historial_cuenta->id)) { - array_push($n,$historial_cuenta->id); + array_push($this->n, $historial_cuenta->id); } - } - } else { - - $this->alert('warning', 'No hay cuentas disponibles de '.$tarifa->servicio->nombre, [ + array_push($this->f, $servicio_id); + $this->alert('warning', 'No hay cuentas disponibles de ' . $tarifa->servicio->nombre, [ 'position' => 'top' ]); } - $cuenta=null; + $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 { + if (count($this->f) > 0) { + $resultados = Servicio::whereIn('id', $this->f)->get(); + // $eliminar = Historial_cuenta::whereIn('id', $n)->delete(); + $message = ''; - $eliminar = Historial_cuenta::whereIn('id',$n)->delete(); - //dd($eliminar); + if ($resultados->count() > 0) { + $nombresServicios = $resultados->pluck('nombre')->toArray(); + $message = implode(', ', $nombresServicios); - $this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [ - 'position' => 'top' + $this->alert('warning', 'No hay disponibilidad de ' . $message . ' en este momento.', [ + '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; - }else{ + 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]); - $eliminar = Historial_cuenta::whereIn('id',$n)->delete(); - //dump($eliminar); - - $this->alert('warning', 'No hay promociones disponibles, comuniquese con soporte!', [ + if ($cobro) { + $this->historial->update(['estado' => 'activo']); + $this->modalComprarPromo = false; + + 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' ]); - $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) @@ -326,8 +380,8 @@ class ShowPromociones extends Component $encryptado = Crypt::encryptString($historial->id); $enlace = '/credenciales?id=' . $encryptado; - $user =$historial->cliente; - + $user = $historial->cliente; + $notificacion = [ 'enlace' => $enlace, 'fecha_final' => $historial->fecha_final, @@ -343,65 +397,63 @@ class ShowPromociones extends Component '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; + $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->sendMessage($message, $recipients); - $this->cantidad_comprarPromo = 1; + $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" - ), - )); + $auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0'); - $response = curl_exec($curl); - $err = curl_error($curl); + $curl = curl_init(); - 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, [ - 'position' => 'top' - ]); - - } else { + curl_close($curl); - 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, [ + 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' + ]); + } } - } -} @@ -409,9 +461,9 @@ class ShowPromociones extends Component { if (!empty($this->categoria_photo)) { $url_foto = $this->categoria_photo->store('photos'); - }else{ - $url_foto = ''; - } + } else { + $url_foto = ''; + } $categoria = new Categoria; $categoria->nombre = $this->nombre_categoria; @@ -424,7 +476,7 @@ class ShowPromociones extends Component 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->tarifa_id = $this->tarifa_id_promocion; $promocion_tarifa->nombre = $consulta->servicio->nombre; @@ -445,7 +497,7 @@ class ShowPromociones extends Component } public function guardar() - { + { $this->validate([ 'nombre_promocion' => 'required', 'descripcion_promocion' => 'required', @@ -455,20 +507,20 @@ class ShowPromociones extends Component 'fecha_limite_promocion' => 'required', 'categoria_id_promocion' => 'required', 'photo' => 'required', - 'list'=>'required', + 'list' => 'required', ]); if (!empty($this->photo)) { - $nombre=Str::random(10); - - $img = img::make($this->photo)->orientate()->resize(1000, null, function($constraint){ + $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"; + $location = "photos/" . $nombre . ".webp"; Storage::disk('local')->put($location, $img); $url_foto = $location; } else { @@ -505,8 +557,6 @@ class ShowPromociones extends Component $this->limpiarInputPromocion(); } - - public function eliminar($id) { $this->eliminar_id = $id; @@ -526,13 +576,6 @@ class ShowPromociones extends Component ]); } - public function getListeners() - { - return [ - 'confirmed' - ]; - } - public function confirmed() { $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 ') - ->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(); - + ->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->nombre = $consulta->nombre; $promocionTarifa->cantidad = $consulta->pantallas; - $promocionTarifa->identificador = $consulta->id; - $promocionTarifa->dias = $consulta->dias; + $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; + $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; + $url_foto = $this->img_ver; } - + Promociones::where('id', $this->editar_promo_id)->update([ 'precio' => $this->valor_editarPromo, @@ -622,36 +665,34 @@ class ShowPromociones extends Component $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(); - + ->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->nombre = $consulta->nombre; $promocionTarifa->cantidad = $consulta->pantallas; - $promocionTarifa->identificador = $consulta->id; + $promocionTarifa->identificador = $consulta->id; $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); @@ -672,7 +713,7 @@ class ShowPromociones extends Component $this->newCategoria = false; $this->newPromocion = false; $this->photo = null; - $this->mensaje_servicio=null; + $this->mensaje_servicio = null; $this->list = null; } diff --git a/app/Models/Historiale.php b/app/Models/Historiale.php index cdbcd9e..c50be30 100644 --- a/app/Models/Historiale.php +++ b/app/Models/Historiale.php @@ -22,27 +22,33 @@ class Historiale extends Model 'nombre_cliente' ]; - public function vendedor(){ - return $this ->belongsTo(User::class); + public function vendedor() + { + return $this->belongsTo(User::class); } - public function tarifa(){ - return $this ->belongsTo(Tarifas::class); + public function tarifa() + { + return $this->belongsTo(Tarifas::class); } - public function promocion(){ - return $this ->belongsTo(Promociones::class); + public function promocion() + { + return $this->belongsTo(Promociones::class); } - public function cliente(){ - return $this ->belongsTo(User::class); + public function cliente() + { + return $this->belongsTo(User::class); } - public function cuentas(){ - return $this ->belongsToMany(Cuentas::class,'historial_cuentas','historial_id','cuenta_id'); + public function cuentas() + { + return $this->belongsToMany(Cuentas::class, 'historial_cuentas', 'historial_id', 'cuenta_id'); } - public function cuentas_obsoletas(){ - return $this ->belongsToMany(Cuentas::class,'logs','historial_id','cuenta_id'); + public function cuentas_obsoletas() + { + return $this->belongsToMany(Cuentas::class, 'logs', 'historial_id', 'cuenta_id'); } } diff --git a/app/Models/Pendientes.php b/app/Models/Pendientes.php new file mode 100644 index 0000000..d67260c --- /dev/null +++ b/app/Models/Pendientes.php @@ -0,0 +1,27 @@ +hasMany(Servicio::class, 'servicio_id'); + } + public function historial() + { + return $this->hasMany(Historiale::class, 'historial_id'); + } +} diff --git a/database/migrations/2023_10_17_145853_create_pendientes_table.php b/database/migrations/2023_10_17_145853_create_pendientes_table.php new file mode 100644 index 0000000..109bfaa --- /dev/null +++ b/database/migrations/2023_10_17_145853_create_pendientes_table.php @@ -0,0 +1,37 @@ +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'); + } +}; diff --git a/resources/views/livewire/show-promociones.blade.php b/resources/views/livewire/show-promociones.blade.php index 9467906..9ebca0a 100644 --- a/resources/views/livewire/show-promociones.blade.php +++ b/resources/views/livewire/show-promociones.blade.php @@ -9,9 +9,8 @@ verPro: false, copiar: '' }" class="h-full w-full md:my-2"> - -
+