From ce9078328ab17ce768d6571f71c875f1e7cbb3b3 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Wed, 8 Jan 2025 14:53:49 -0300 Subject: [PATCH] FIX: Validacion de RUT --- app/resources/views/ventas/add.blade.php | 27 ++++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/resources/views/ventas/add.blade.php b/app/resources/views/ventas/add.blade.php index fc631e1..7f84505 100644 --- a/app/resources/views/ventas/add.blade.php +++ b/app/resources/views/ventas/add.blade.php @@ -186,7 +186,7 @@ } clean() { return { - rut: rut => rut.includes('-') ? rut.split('-').join('') : rut + rut: rut => rut.includes('-') || rut.includes('.') ? rut.replaceAll('-', '').replaceAll('.', '') : rut } } get() { @@ -200,26 +200,20 @@ verifier: digits => { let sum = 0 let mul = 2 - let i = digits.length while (i--) { - sum = sum + parseInt(digits.charAt(i)) * mul - if (mul % 7 === 0) { - mul = 2 - } else { - mul++ - } + sum = sum + parseInt(digits.charAt(i)) * mul; + (mul % 7 === 0) ? mul = 2 : mul++ } - const res = sum % 11 - if (res === 0) { - return '0' - } else if (res === 1) { - return 'k' + switch (res) { + case 0: + case 1: + return res.toString() + default: + return `${11 - res}` } - - return `${11 - res}` } } } @@ -230,6 +224,7 @@ return this.get().verifier(rut).toLowerCase() === this.calculate().verifier(this.get().digits(rut)) } verify(event) { + this.alert().valid() const input = $(event.currentTarget) const val = input.val() let new_val = this.clean().rut(val) @@ -242,7 +237,6 @@ this.alert().invalid() return } - this.alert().valid() this.valid(new_val) } alert() { @@ -799,6 +793,7 @@ button.prop('disabled', true) button.css('cursor', 'wait') const body = new FormData(event.currentTarget) + if (body.get('unidad')) const uri = '{{$urls->api}}/ventas/add' return fetchAPI(uri, {method: 'post', body}).then(response => { if (!response) {