This commit is contained in:
Juan Felipe Duarte
2025-07-31 15:19:22 -07:00
parent ca5fbd454a
commit c7586cf6cd
13 changed files with 215 additions and 34 deletions
+4
View File
@@ -254,6 +254,10 @@ class MenuController extends Controller
return view('menu/logs');
}
public function showlogscomisiones()
{
return view('menu/logs-comisiones');
}
public function showpromociones()
{
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Http\Livewire;
use App\Models\Log_general;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class ShowLogComisiones extends Component
{
public function render()
{
$consultaLogs = Log_general::whereIn('user_id', Auth::user()->subusuarios->pluck('id'))
->where('tipo', 'compra')
// ->where('detalle', 'LIKE', '%utilidad%')
->latest()
->get();
return view('livewire.show-log-comisiones',[
'consultaLogs' => $consultaLogs,
]);
}
}
+49 -4
View File
@@ -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 {
+45 -8
View File
@@ -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 {
+3 -3
View File
@@ -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'
]);
+2 -1
View File
@@ -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()
+5 -1
View File
@@ -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);
}
}
+5
View File
@@ -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');
}
}
+3 -2
View File
@@ -112,7 +112,7 @@
<li class="flex align-center flex-col">
<h4 @click="selected !== 0 ? selected = 0 : selected = null" class="cursor-pointer px-5 py-3 bg-[#b221fd] text-white text-center inline-block hover:bg-[#7a02b8] hover:shadow rounded-lg">
@if (auth()->user()->rol->nombre == 'super' || auth()->user()->rol->nombre == 'administrador' || auth()->user()->rol->nombre == 'editor')
Admin
@else
Subvendedor
@@ -124,6 +124,7 @@
@if (auth()->user()->subvendedor)
<a class="block cursor-pointer text-center hover:bg-[#d1d3e1] border-b w-full px-3 py-1" href="{{ route('roles') }}">Gestión Roles</a>
<a class="block cursor-pointer text-center hover:bg-[#d1d3e1] border-b w-full px-3 py-1" href="{{ route('usuarios') }}">Gestión Usuarios</a>
<a class="block cursor-pointer text-center hover:bg-[#d1d3e1] border-b w-full px-3 py-1" href="{{ route('usuarios') }}">Log Comisiones</a>
@if ( auth()->user()->rol->nombre != 'super')
<a class="block cursor-pointer text-center hover:bg-[#d1d3e1] border-b w-full px-3 py-1" href="{{ route('tarifas') }}">Gestión Tarifas</a>
@endif
@@ -346,4 +347,4 @@
</form>
</div>
</div>
</div>
</div>
@@ -0,0 +1,55 @@
<div class="p-6 max-w-7xl mx-auto">
<!-- Encabezado -->
<div class="flex items-center justify-between mb-6">
<h2 class="text-2xl font-semibold text-gray-800">Log comisiones</h2>
</div>
<!-- Input de búsqueda -->
{{-- <div class="mb-4">
<input type="text" wire:model.debounce.300ms="search" placeholder="" class="w-full px-4 py-2 border border-gray-300 rounded-xl shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent transition" />
</div> --}}
<!-- Tabla de datos -->
<div class="overflow-hidden rounded-xl shadow-md border border-gray-200 bg-white">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Compra</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Valor</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Utilidad</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Vendedor</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Servicio</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse($consultaLogs as $log)
<tr class="hover:bg-gray-50 transition">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">{{ \Carbon\Carbon::parse($log?->historial?->created_at ?? now())->format('y/m/d h:i a') }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $log?->historial?->valor ?? 'N/A' }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">{{ $log?->historial?->utilidad ?? 'N/A' }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">{{ $log?->user?->name ?? 'N/A' }} - {{ $log?->user?->email ?? 'N/A' }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700">
@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
</td>
</tr>
@empty
<tr>
<td colspan="5" class="px-6 py-4 text-center text-sm text-gray-500">No se encontraron resultados.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Paginación -->
<div class="mt-4">
{{-- {{ $productos->links() }} --}}
</div>
</div>
@@ -0,0 +1,3 @@
<x-app-layout>
<livewire:show-log-comisiones />
</x-app-layout>
+2 -2
View File
@@ -1,3 +1,3 @@
<x-app-layout>
<livewire:show-logs />
</x-app-layout>
<livewire:show-logs />
</x-app-layout>
+14 -13
View File
@@ -31,19 +31,20 @@ Route::any('/pruebas', [MenuController::class, 'pruebas'])->name('pruebas')
//Logueados
Route::middleware(["auth"])->group(function () {
Route::any('/clientes', [MenuController::class, 'showclientes'])->name('clientes');
Route::get('/servicios', [MenuController::class, 'showservicios'])->name('servicios');
Route::get('/top', [MenuController::class, 'showtop'])->name('top');
Route::any('/reportes', [MenuController::class, 'showreportes'])->name('reportes');
Route::get('/perfil', [MenuController::class, 'showperfil'])->name('perfil');
Route::get('/recarga', [MenuController::class, 'showrecarga'])->name('recarga');
Route::post('/recargas', [MenuController::class, 'recargas'])->name('recargas');
Route::get('/promociones', [MenuController::class, 'showpromociones'])->name('promociones');
Route::get('/wompi/{monto}', [MenuController::class, 'showwompi'])->name('wompi');
Route::any('/logs', [MenuController::class, 'showlogs'])->name('logs');
Route::any('/usuarios', [MenuController::class, 'showusuarios'])->name('usuarios');
Route::any('/roles', [MenuController::class, 'showroles'])->name('roles');
Route::any('/tarifas', [MenuController::class, 'showtarifas'])->name('tarifas');
Route::any('/clientes', [MenuController::class, 'showclientes'])->name('clientes');
Route::get('/servicios', [MenuController::class, 'showservicios'])->name('servicios');
Route::get('/top', [MenuController::class, 'showtop'])->name('top');
Route::any('/reportes', [MenuController::class, 'showreportes'])->name('reportes');
Route::get('/perfil', [MenuController::class, 'showperfil'])->name('perfil');
Route::get('/recarga', [MenuController::class, 'showrecarga'])->name('recarga');
Route::post('/recargas', [MenuController::class, 'recargas'])->name('recargas');
Route::get('/promociones', [MenuController::class, 'showpromociones'])->name('promociones');
Route::get('/wompi/{monto}', [MenuController::class, 'showwompi'])->name('wompi');
Route::any('/logs', [MenuController::class, 'showlogs'])->name('logs');
Route::any('/logs-comisiones', [MenuController::class, 'showlogscomisiones'])->name('logs-comisiones');
Route::any('/usuarios', [MenuController::class, 'showusuarios'])->name('usuarios');
Route::any('/roles', [MenuController::class, 'showroles'])->name('roles');
Route::any('/tarifas', [MenuController::class, 'showtarifas'])->name('tarifas');
});
// Editores