From 9d3f9ff3d5dba5ac24b040115a8884d6ec3523ef Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 30 Apr 2024 22:09:19 -0500 Subject: [PATCH] UPDATE --- app/Http/Livewire/ShowPromociones.php | 86 ++++++++++++++++----------- app/Http/Livewire/ShowServicios.php | 2 - 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/app/Http/Livewire/ShowPromociones.php b/app/Http/Livewire/ShowPromociones.php index c61267b..64c9740 100755 --- a/app/Http/Livewire/ShowPromociones.php +++ b/app/Http/Livewire/ShowPromociones.php @@ -123,8 +123,8 @@ class ShowPromociones extends Component 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->email_comprarPromo = $usuario_actual->email; + $this->celular_comprarPromo = $usuario_actual->celular; //dd($this-> nombre_tarjetaPlan); } @@ -197,7 +197,9 @@ class ShowPromociones extends Component public function getListeners() { return [ - 'confirmed', 'confirmarCompra', 'denegarCompra' + 'confirmed', + 'confirmarCompra', + 'denegarCompra' ]; } @@ -217,7 +219,7 @@ class ShowPromociones extends Component return; } - if (auth()->user()->saldo->valor < $this->precioAhora * $this->cantidad_comprarPromo) { + if (auth()->user()->saldo->valor < $this->precioAhora * $this->cantidad_comprarPromo) { $this->alert('error', 'Saldo insuficiente', [ 'position' => 'top' ]); @@ -243,7 +245,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; @@ -256,7 +258,7 @@ class ShowPromociones extends Component $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); $this->n = []; $this->f = []; @@ -276,21 +278,34 @@ class ShowPromociones extends Component $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) + $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(); + ->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', 'DESC')->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)) { $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->historial_id = $historial->id; - $historial_cuenta->cuenta_id = $cuenta->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($this->n, $historial_cuenta->id); @@ -335,7 +350,7 @@ class ShowPromociones extends Component } else { $descuento = Saldo::where('usuario_id', Auth::user()->id)->first(); $saldo_anterior = $descuento->valor; - $nuevo_saldo = $saldo_anterior - ($this->precioAhora * $this->cantidad_comprarPromo); + $nuevo_saldo = $saldo_anterior - ($this->precioAhora * $this->cantidad_comprarPromo); $cobro = $descuento->update(['valor' => $nuevo_saldo]); if ($cobro) { @@ -343,7 +358,7 @@ class ShowPromociones extends Component $logsGeneral = new Log_general(); $logsGeneral->user_id = Auth::user()->id; - $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad ?? '' . ' por un valor de $' . $this->historial->valor ?? ''; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad ?? '' . ' por un valor de $' . $this->historial->valor ?? ''; $logsGeneral->save(); $this->modalComprarPromo = false; @@ -362,7 +377,7 @@ class ShowPromociones extends Component { $descuento = Saldo::where('usuario_id', Auth::user()->id)->first(); $saldo_anterior = $descuento->valor; - $nuevo_saldo = $saldo_anterior - ($this->precioAhora * $this->cantidad_comprarPromo); + $nuevo_saldo = $saldo_anterior - ($this->precioAhora * $this->cantidad_comprarPromo); $cobro = $descuento->update(['valor' => $nuevo_saldo]); if ($cobro) { @@ -371,7 +386,7 @@ class ShowPromociones extends Component foreach ($this->f as $serviceId) { - for ($y = 0; $y < (int)$this->cantidad_comprarPromo; $y++) { + for ($y = 0; $y < (int) $this->cantidad_comprarPromo; $y++) { $pendiente = new Pendientes(); $pendiente->historial_id = $this->historial->id; $pendiente->cantidad = '1'; @@ -383,7 +398,7 @@ class ShowPromociones extends Component $logsGeneral = new Log_general(); $logsGeneral->user_id = Auth::user()->id; - $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad ?? '' . ' por un valor de $' . $this->historial->valor ?? '' . ' y algunos han quedado pendientes'; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado la promocion ' . $this->consulta->nombre . ' - ' . $this->consulta->descripcion . ' cantidad de ' . $this->historial->cantidad ?? '' . ' por un valor de $' . $this->historial->valor ?? '' . ' y algunos han quedado pendientes'; $logsGeneral->save(); $this->credenciales($this->historial); @@ -455,7 +470,7 @@ class ShowPromociones extends Component $this->cantidad_comprarPromo = 1; } - public function sendMessage($message, $recipients) + public function sendMessage($message, $recipients) { @@ -463,21 +478,24 @@ class ShowPromociones extends Component $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" - ), - )); + 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); @@ -592,7 +610,7 @@ class ShowPromociones extends Component 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->tarifa_id = $item['tarifa_id']; //falta $guardar_promotarifa->save(); } diff --git a/app/Http/Livewire/ShowServicios.php b/app/Http/Livewire/ShowServicios.php index 360d902..b8006b0 100755 --- a/app/Http/Livewire/ShowServicios.php +++ b/app/Http/Livewire/ShowServicios.php @@ -285,8 +285,6 @@ class ShowServicios extends Component if ((int) $pantalla_servicio >= (int) $cantidad_solicitada && (int) $pantalla_servicio_completa != (int) $this->pantallas_tarjetaPlan) { $suma = $pantalla_servicio - $cantidad_solicitada; - - $cantidad_necesaria = $this->cantidad_tarjetaPlan; $cuenta = Cuentas::where('servicio_id', $this->servicio_id) ->whereDate('inicio', '>=', $this->fecha)