saldo restado

This commit is contained in:
Juan Felipe Duarte
2025-06-26 16:50:48 -07:00
parent 83ba4f71da
commit f72062fffd
3 changed files with 127 additions and 69 deletions
+62
View File
@@ -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) {