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() { clean() {
return { return {
rut: rut => rut.includes('-') ? rut.split('-').join('') : rut rut: rut => rut.includes('-') || rut.includes('.') ? rut.replaceAll('-', '').replaceAll('.', '') : rut
} }
} }
get() { get() {
@ -200,26 +200,20 @@
verifier: digits => { verifier: digits => {
let sum = 0 let sum = 0
let mul = 2 let mul = 2
let i = digits.length let i = digits.length
while (i--) { while (i--) {
sum = sum + parseInt(digits.charAt(i)) * mul sum = sum + parseInt(digits.charAt(i)) * mul;
if (mul % 7 === 0) { (mul % 7 === 0) ? mul = 2 : mul++
mul = 2
} else {
mul++
}
} }
const res = sum % 11 const res = sum % 11
if (res === 0) { switch (res) {
return '0' case 0:
} else if (res === 1) { case 1:
return 'k' 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)) return this.get().verifier(rut).toLowerCase() === this.calculate().verifier(this.get().digits(rut))
} }
verify(event) { verify(event) {
this.alert().valid()
const input = $(event.currentTarget) const input = $(event.currentTarget)
const val = input.val() const val = input.val()
let new_val = this.clean().rut(val) let new_val = this.clean().rut(val)
@ -242,7 +237,6 @@
this.alert().invalid() this.alert().invalid()
return return
} }
this.alert().valid()
this.valid(new_val) this.valid(new_val)
} }
alert() { alert() {
@ -799,6 +793,7 @@
button.prop('disabled', true) button.prop('disabled', true)
button.css('cursor', 'wait') button.css('cursor', 'wait')
const body = new FormData(event.currentTarget) const body = new FormData(event.currentTarget)
if (body.get('unidad'))
const uri = '{{$urls->api}}/ventas/add' const uri = '{{$urls->api}}/ventas/add'
return fetchAPI(uri, {method: 'post', body}).then(response => { return fetchAPI(uri, {method: 'post', body}).then(response => {
if (!response) { if (!response) {