saldo restado
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user