FIX: Validacion de RUT

This commit is contained in:
Juan Pablo Vial
2025-01-08 14:53:49 -03:00
parent 713fcc6ab8
commit ce9078328a

View File

@ -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) {