ip
This commit is contained in:
@@ -15,19 +15,27 @@ class ShowRecargas extends Component
|
|||||||
|
|
||||||
public function render(Request $request)
|
public function render(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (empty($this->referencia)){
|
if (empty($this->referencia)){
|
||||||
|
|
||||||
|
// Leer recharge directamente o desde el campo formateado como fallback
|
||||||
|
$rechargeRaw = $request->recharge ?? $request->recharge_format ?? '';
|
||||||
|
$recharge = (int) preg_replace('/\D/', '', $rechargeRaw);
|
||||||
|
|
||||||
|
if ($recharge <= 0) {
|
||||||
|
return redirect()->route('recarga')->with('error', 'Ingrese un monto válido para recargar.');
|
||||||
|
}
|
||||||
|
|
||||||
$this->referencia = Str::random(20);
|
$this->referencia = Str::random(20);
|
||||||
|
|
||||||
$this->monto = (((($request->recharge)*0.03) + '700' )* 0.19)+ ((($request->recharge)*0.03) + '700' ) + $request->recharge;
|
$this->monto = ((($recharge * 0.03) + 700) * 0.19) + (($recharge * 0.03) + 700) + $recharge;
|
||||||
|
|
||||||
$recargas = new recarga;
|
$recargas = new recarga;
|
||||||
$recargas->monto = $this->monto;
|
$recargas->monto = $this->monto;
|
||||||
$recargas->reference = $this->referencia;
|
$recargas->reference = $this->referencia;
|
||||||
$recargas-> status = 'Procesando MP';
|
$recargas->status = 'Procesando MP';
|
||||||
$recargas-> usuario_id = auth()->user()->id;
|
$recargas->usuario_id = auth()->user()->id;
|
||||||
$recargas-> saldo_id= auth()->user()->saldo->id;
|
$recargas->saldo_id = auth()->user()->saldo->id;
|
||||||
$recargas-> valor_recarga = $request->recharge;
|
$recargas->valor_recarga = $recharge;
|
||||||
$recargas->save();
|
$recargas->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<div class="text-center bg-[#000029] text-white text-lg font-semibold rounded-lg py-2 mb-4">
|
<div class="text-center bg-[#000029] text-white text-lg font-semibold rounded-lg py-2 mb-4">
|
||||||
Recargar saldo
|
Recargar saldo
|
||||||
</div>
|
</div>
|
||||||
<form action="/recargas" method="post" class="text-center">
|
<form action="/recargas" method="post" class="text-center" onsubmit="return prepareRecarga(this)">
|
||||||
@csrf
|
@csrf
|
||||||
<div class="flex justify-center mb-4">
|
<div class="flex justify-center mb-4">
|
||||||
Saldo actual: <p class="font-semibold"> ${{ number_format($user->saldo->valor) }}</p>
|
Saldo actual: <p class="font-semibold"> ${{ number_format($user->saldo->valor) }}</p>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
Monto a recargar
|
Monto a recargar
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="tel" name="recharge" id="valor_recarga" wire:model="valor_recarga" class="hidden">
|
<input type="hidden" name="recharge" id="valor_recarga">
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -132,10 +132,25 @@
|
|||||||
<script>
|
<script>
|
||||||
function formatInput(input) {
|
function formatInput(input) {
|
||||||
let unformattedValue = input.value.replace(/\D/g, '');
|
let unformattedValue = input.value.replace(/\D/g, '');
|
||||||
|
|
||||||
let formattedValue = unformattedValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
let formattedValue = unformattedValue.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
|
||||||
input.value = formattedValue;
|
input.value = formattedValue;
|
||||||
|
// Actualizar el input oculto directamente sin esperar a Livewire
|
||||||
|
var hidden = document.getElementById('valor_recarga');
|
||||||
|
if (hidden) hidden.value = unformattedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareRecarga(form) {
|
||||||
|
var formatEl = form.querySelector('#valor_recarga_format');
|
||||||
|
var hiddenEl = form.querySelector('#valor_recarga');
|
||||||
|
if (formatEl && hiddenEl) {
|
||||||
|
var clean = formatEl.value.replace(/\D/g, '');
|
||||||
|
if (!clean || parseInt(clean) <= 0) {
|
||||||
|
alert('Por favor ingrese un monto válido.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
hiddenEl.value = clean;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user