diff --git a/app/Http/Livewire/ShowUsuarios.php b/app/Http/Livewire/ShowUsuarios.php index f2c1cfd..69fcd60 100755 --- a/app/Http/Livewire/ShowUsuarios.php +++ b/app/Http/Livewire/ShowUsuarios.php @@ -302,6 +302,68 @@ class ShowUsuarios extends Component $this->modalSaldoDesc = true; } + public function addSaldoSubvendedor() + { + if (!$this->valor_recargar) { + $this->alert('warning', '¡Coloque un valor!', [ + 'position' => 'top' + ]); + return; + } + + $this->valor_recargar = str_replace([',', '.'], '', $this->valor_recargar); + $montoRecarga = (int) $this->valor_recargar; + + $miSaldo = Saldo::where('usuario_id', Auth::user()->id)->first(); + + if (!$miSaldo || $miSaldo->valor < $montoRecarga) { + $this->alert('error', 'No tienes saldo suficiente para hacer esta recarga.', [ + 'position' => 'top' + ]); + return; + } + + $miSaldoAnterior = $miSaldo->valor; + $miSaldo->update([ + 'valor' => $miSaldo->valor - $montoRecarga, + ]); + + $recarga = new recarga; + $recarga->payment_method_id = 'manual'; + $recarga->status = 'approved'; + $recarga->usuario_id = $this->user_saldo; + $recarga->saldo_id = $this->consulta_saldo->id; + $recarga->monto = $montoRecarga; + $recarga->valor_recarga = $montoRecarga; + $recarga->save(); + + $nuevoSaldoDestino = $this->saldo_actual + $montoRecarga; + $this->consulta_saldo->update([ + 'valor' => $nuevoSaldoDestino, + ]); + + $usuarioDestino = User::find($this->user_saldo); + $nombre = $usuarioDestino->name; + $email = $usuarioDestino->email; + + $logsGeneral = new Log_general(); + $logsGeneral->user_id = Auth::user()->id; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . + ' ha recargado a ' . $nombre . ' - ' . $email . ' la cantidad de $' . number_format($montoRecarga) . + ', de su saldo. Su saldo anterior: $' . number_format($miSaldoAnterior) . + ', saldo actual: $' . number_format($miSaldoAnterior - $montoRecarga) . + '. Saldo nuevo de ' . $nombre . ': $' . number_format($nuevoSaldoDestino); + $logsGeneral->tipo = 'recarga'; + $logsGeneral->historial_id = null; + $logsGeneral->save(); + + $this->alert('success', 'Saldo actualizado con éxito.', [ + 'position' => 'top' + ]); + + $this->limpiarSaldo(); + } + public function addSaldo() { if (!$this->valor_recargar) { diff --git a/resources/views/livewire/show-tarifas.blade.php b/resources/views/livewire/show-tarifas.blade.php index 08d1198..3cd410d 100644 --- a/resources/views/livewire/show-tarifas.blade.php +++ b/resources/views/livewire/show-tarifas.blade.php @@ -4,10 +4,10 @@ modTarifasPromo : @entangle('modTarifasPromo'), editarTarifa : @entangle('editarTarifa'), editarTarifaPromo: @entangle('editarTarifaPromo'), }" class="h-full w-full md:my-2"> -
+
- + loading

Cargando

@@ -20,31 +20,30 @@ editarTarifaPromo: @entangle('editarTarifaPromo'), Tarifas
- - @if (auth()->user()->subvendedor) - - Tarifas servicios - - - - - - @endif - - @if (auth()->user()->subvendedor) - - Tarifas promociones - - - - - - @endif -
- +
+ @if (auth()->user()->subvendedor) + + Tarifas servicios + + + + + + @endif + + @if (auth()->user()->subvendedor) + + Tarifas promociones + + + + + + @endif +
@@ -331,6 +330,5 @@ editarTarifaPromo: @entangle('editarTarifaPromo'),
- diff --git a/resources/views/livewire/show-usuarios.blade.php b/resources/views/livewire/show-usuarios.blade.php index 406753d..a6fee1a 100755 --- a/resources/views/livewire/show-usuarios.blade.php +++ b/resources/views/livewire/show-usuarios.blade.php @@ -78,14 +78,8 @@ Ventas Saldo Precios personalizados - - @if (auth()->user()->rol->nombre == 'super') - - - @elseif (Auth::user()->subvendedor) - - @else - @endif + + @@ -95,23 +89,24 @@ {{ $usuario->email ?? '' }} {{ $usuario->rol->nombre ?? '' }} {{ $usuario->historiales_venta_count ?? '' }} - @if (!empty($usuario->saldo->valor)) - {{ number_format($usuario->saldo->valor) ?? '' }} - @else - - @endif - + {{ number_format($usuario->saldo->valor ?? 0) ?? 0 }}

Tarifas: {{ $usuario->countActiveTarifas() ?? 0 }}, Promos: {{ $usuario->countActivePromos() ?? 0 }}

+ + @if (auth()->user()->rol->nombre == 'super') + + @else + @if (Auth::user()->subvendedor) + + @endif + @endif + @if (auth()->user()->rol->nombre == 'super') - - - - - @if ($usuario->subvendedor) - - @else - - @endif - - - - - - @else +
+ + + @if ($usuario->subvendedor) + + @else + + @endif + + + +
+ + @else @endif @endforeach @@ -641,15 +636,18 @@ -
+
- + @if (auth()->user()->rol->nombre === 'administrador' || auth()->user()->rol->nombre === 'super') + + @else + @if (Auth::user()->subvendedor) + + @endif + @endif - +