From c7586cf6cdf3e26eb568ba9fb09d6d6c3450fb1b Mon Sep 17 00:00:00 2001 From: Juan Felipe Duarte <70235683+DuarteJFelipe@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:19:22 -0700 Subject: [PATCH] update --- app/Http/Controllers/MenuController.php | 4 ++ app/Http/Livewire/ShowLogComisiones.php | 25 +++++++++ app/Http/Livewire/ShowPromociones.php | 53 ++++++++++++++++-- app/Http/Livewire/ShowServicios.php | 53 +++++++++++++++--- app/Http/Livewire/ShowUsuarios.php | 6 +- app/Models/Historiale.php | 3 +- app/Models/Log_general.php | 6 +- app/Models/User.php | 5 ++ resources/views/layouts/navigation.blade.php | 5 +- .../livewire/show-log-comisiones.blade.php | 55 +++++++++++++++++++ .../views/menu/logs-comisiones.blade.php | 3 + resources/views/menu/logs.blade.php | 4 +- routes/web.php | 27 ++++----- 13 files changed, 215 insertions(+), 34 deletions(-) create mode 100644 app/Http/Livewire/ShowLogComisiones.php create mode 100644 resources/views/livewire/show-log-comisiones.blade.php create mode 100644 resources/views/menu/logs-comisiones.blade.php diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index 9e4f655..ec83bf0 100755 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -254,6 +254,10 @@ class MenuController extends Controller return view('menu/logs'); } + public function showlogscomisiones() + { + return view('menu/logs-comisiones'); + } public function showpromociones() { diff --git a/app/Http/Livewire/ShowLogComisiones.php b/app/Http/Livewire/ShowLogComisiones.php new file mode 100644 index 0000000..5e4adf8 --- /dev/null +++ b/app/Http/Livewire/ShowLogComisiones.php @@ -0,0 +1,25 @@ +subusuarios->pluck('id')) + ->where('tipo', 'compra') + // ->where('detalle', 'LIKE', '%utilidad%') + ->latest() + ->get(); + + + return view('livewire.show-log-comisiones',[ + 'consultaLogs' => $consultaLogs, + ]); + } +} diff --git a/app/Http/Livewire/ShowPromociones.php b/app/Http/Livewire/ShowPromociones.php index d60ca4f..8b875ed 100755 --- a/app/Http/Livewire/ShowPromociones.php +++ b/app/Http/Livewire/ShowPromociones.php @@ -256,6 +256,8 @@ class ShowPromociones extends Component $historial->utilidad = $this->utilidad * $this->cantidad_comprarPromo; $historial->save(); + $utilidad_total = (int) $this->utilidad * (int) $this->cantidad_comprarPromo; + $this->historial = $historial; for ($p = 0; $p < (int) $this->cantidad_comprarPromo; $p++) { @@ -290,8 +292,6 @@ class ShowPromociones extends Component ->where('historiales_count', '=', 0) ->orderBy('inicio', 'ASC') ->first(); - - } else { $baseQuery = Cuentas::select('*')->where('servicio_id', $servicio_id) ->whereDate('inicio', '>=', $this->fecha) @@ -304,10 +304,9 @@ class ShowPromociones extends Component ->where('historiales_count', '<=', (int) $faltante) ->orderBy('inicio', 'ASC') ->first(); - } - + if (!is_null($cuenta)) { $perfil = $cuenta->historiales_count; @@ -379,6 +378,52 @@ class ShowPromociones extends Component $logsGeneral->historial_id = $historial->id; $logsGeneral->save(); + // Si el campo subvendedor tiene id entonces la utilidad va a su subvendedor padre + if (Auth::user()->subvendedor_id) { + if ($utilidad_total > 0) { + $subvendedorPadre = User::with('saldo')->find(Auth::user()->subvendedor_id); + + if ($subvendedorPadre && $subvendedorPadre->saldo) { + // Sumar la utilidad al saldo actual + $nuevoSaldo = $subvendedorPadre->saldo->valor + $utilidad_total; + + // Actualizar el saldo + $subvendedorPadre->saldo->update([ + 'valor' => $nuevoSaldo + ]); + + // Registrar en el log la utilidad generada + $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->cantidad_tarjetaPlan . + ' por un valor de $' . $this->historial->valor . + ', Saldo anterior: $' . $saldo_anterior . + ', Nuevo saldo disponible: $' . $nuevo_saldo . + '. Esta compra generó una utilidad de $' . $utilidad_total . + ' al usuario padre ' . $subvendedorPadre->name . ' - ' . $subvendedorPadre->email . '.'; + $logsGeneral->historial_id = $historial->id; + $logsGeneral->tipo = 'compra'; + $logsGeneral->save(); + } + } + } else { + // Log sin utilidad al padre + $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 . + ', Saldo anterior: $' . $saldo_anterior . + ', Nuevo saldo disponible: $' . $nuevo_saldo; + $logsGeneral->historial_id = $historial->id; + $logsGeneral->tipo = 'compra'; + $logsGeneral->save(); + } + + $this->modalComprarPromo = false; $this->credenciales($historial); } else { diff --git a/app/Http/Livewire/ShowServicios.php b/app/Http/Livewire/ShowServicios.php index c9c55bd..7fe6fcf 100755 --- a/app/Http/Livewire/ShowServicios.php +++ b/app/Http/Livewire/ShowServicios.php @@ -122,7 +122,7 @@ class ShowServicios extends Component public function cargartarjetaPlan($id) { $this->tarifa_id = $id; //$this->tarjetaPlan=false; - //Buscar tarifas por el id + //Buscar tarifas por el id $tarifa_seleccionada = Tarifas::find($id); //Traer el servicio relacionado con esa tarifa $servicio_tarifa = $tarifa_seleccionada->servicio; @@ -145,7 +145,7 @@ class ShowServicios extends Component //Se añade a hoy la cantidad de dias de la tarifa ejem: 30 + 15. Da 45 despues de hoy. $this->fecha_final_2 = Carbon::now()->addDays($tarifa_seleccionada->dias + 20); - //Traer la tarifa personalizada del usuario para esta tarifa. + //Traer la tarifa personalizada del usuario para esta tarifa. $usuario_tarifa = Usuario_tarifa::where('usuario_id', auth()->user()->id) ->where('tarifa_id', $id) ->first(); @@ -202,6 +202,7 @@ class ShowServicios extends Component ->count(); //dd($cuentas_pantallas_tomadas); //Validar si el numero pantallas del servicio es igual o mayor que lo solicitado + if ($servicio_tarifa->pantallas >= $cantidad_solicitada) { //dd($servicio_tarifa->pantallas * $cuentas_pantallas->count()); //Cantidad de cuentas restantes * cantidad de pantallas del servicio / en las pantalla de la tarifa. @@ -426,14 +427,50 @@ class ShowServicios extends Component $historial->update(['estado' => 'activo']); - $logsGeneral = new Log_general(); - $logsGeneral->user_id = Auth::user()->id; - $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo; - $logsGeneral->historial_id = $historial->id; - $logsGeneral->tipo = 'compra'; - $logsGeneral->save(); + // Si el campo subvendedor tiene id entonces la utilidad va a su subvendedor padre + if (Auth::user()->subvendedor_id) { + if ($utilidad_total > 0) { + $subvendedorPadre = User::with('saldo')->find(Auth::user()->subvendedor_id); + if ($subvendedorPadre && $subvendedorPadre->saldo) { + // Sumar la utilidad al saldo actual + $nuevoSaldo = $subvendedorPadre->saldo->valor + $utilidad_total; + // Actualizar el saldo + $subvendedorPadre->saldo->update([ + 'valor' => $nuevoSaldo + ]); + + // Registrar en el log la utilidad generada + $logsGeneral = new Log_general(); + $logsGeneral->user_id = Auth::user()->id; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . + ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . + ' cantidad de ' . $this->cantidad_tarjetaPlan . + ' por un valor de $' . $total_valor . + ', Saldo anterior: $' . $saldo_anterior . + ', Nuevo saldo disponible: $' . $nuevo_saldo . + '. Esta compra generó una utilidad de $' . $utilidad_total . + ' al usuario padre ' . $subvendedorPadre->name . ' - ' . $subvendedorPadre->email . '.'; + $logsGeneral->historial_id = $historial->id; + $logsGeneral->tipo = 'compra'; + $logsGeneral->save(); + } + } + } else { + // Log sin utilidad al padre + $logsGeneral = new Log_general(); + $logsGeneral->user_id = Auth::user()->id; + $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . + ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . + ' cantidad de ' . $this->cantidad_tarjetaPlan . + ' por un valor de $' . $total_valor . + ', Saldo anterior: $' . $saldo_anterior . + ', Nuevo saldo disponible: $' . $nuevo_saldo . '.'; + $logsGeneral->historial_id = $historial->id; + $logsGeneral->tipo = 'compra'; + $logsGeneral->save(); + } $this->credenciales($historial); } else { diff --git a/app/Http/Livewire/ShowUsuarios.php b/app/Http/Livewire/ShowUsuarios.php index a6b5356..8f627b2 100755 --- a/app/Http/Livewire/ShowUsuarios.php +++ b/app/Http/Livewire/ShowUsuarios.php @@ -123,8 +123,8 @@ class ShowUsuarios extends Component }); }); } - - + + if (!(Auth::user()->rol->nombre == "super")) { $consulta_usuarios = $consulta_usuarios->where('subvendedor_id', Auth::user()->id); @@ -573,7 +573,7 @@ class ShowUsuarios extends Component ->exists(); - if ($this->precio < $this->valorBase) { + if ($this->precioTarifasGestion < $this->valorBase) { $this->alert('error', 'El precio no puede ser menor al costo del plan', [ 'position' => 'top' ]); diff --git a/app/Models/Historiale.php b/app/Models/Historiale.php index e71fa0b..6319259 100755 --- a/app/Models/Historiale.php +++ b/app/Models/Historiale.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model; class Historiale extends Model { use HasFactory; + protected $fillable = [ 'fecha_inicio', 'fecha_final', @@ -24,7 +25,7 @@ class Historiale extends Model public function vendedor() { - return $this->belongsTo(User::class , 'vendedor_id'); + return $this->belongsTo(User::class, 'vendedor_id'); } public function tarifa() diff --git a/app/Models/Log_general.php b/app/Models/Log_general.php index b597c86..f44fb88 100755 --- a/app/Models/Log_general.php +++ b/app/Models/Log_general.php @@ -16,11 +16,15 @@ class Log_general extends Model 'detalle', 'tipo', 'historial_id' - ]; public function user() { return $this->belongsTo(User::class); } + + public function historial() + { + return $this->belongsTo(Historiale::class); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 8d08dd1..902c8aa 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -102,4 +102,9 @@ class User extends Authenticatable { return $this->belongsTo(User::class, 'subvendedor_id'); } + + public function subusuarios() + { + return $this->hasMany(User::class, 'subvendedor_id'); + } } diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index eae07bd..ad797b2 100755 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -112,7 +112,7 @@
| Compra | +Valor | +Utilidad | +Vendedor | +Servicio | +
|---|---|---|---|---|
| {{ \Carbon\Carbon::parse($log?->historial?->created_at ?? now())->format('y/m/d h:i a') }} | +{{ $log?->historial?->valor ?? 'N/A' }} | +{{ $log?->historial?->utilidad ?? 'N/A' }} | +{{ $log?->user?->name ?? 'N/A' }} - {{ $log?->user?->email ?? 'N/A' }} | ++ @if (!empty($log?->historial?->promocion_id)) + {{ $log?->historial?->promocion?->nombre ?? 'Sin promoción' }} + @elseif(!empty($log?->historial?->tarifa_id)) + @if (empty($log?->historial?->tarifa?->servicio?->por_tiempo)) + {{ $log?->historial?->tarifa?->pantallas ?? 'N/A' }} P. de + @endif + {{ $log?->historial?->tarifa?->servicio?->nombre ?? 'Sin nombre' }} - {{ $log?->historial?->tarifa?->dias ?? 'N/A' }} d. + @endif + | +
| No se encontraron resultados. | +||||