update
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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'
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user