Created
October 16, 2019 20:22
-
-
Save monroy95/f59cefbe6c80dfa2f618dac49496054d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frappe.ui.form.on('Customer', { | |
nit: function (frm) { | |
var nit_validado; | |
var cus_supp = frm.doc.customer_name; // Nombre de cliente o proveedor | |
var nit = frm.doc.nit; | |
if (nit === "C/F" || nit === "c/f") { | |
frm.enable_save(); // Activa y Muestra el boton guardar de Sales Invoice | |
} else { | |
var nd, add = 0; | |
if (nd = /^(\d+)\-?([\dk])$/i.exec(nit)) { | |
nd[2] = (nd[2].toLowerCase() == 'k') ? 10 : parseInt(nd[2]); | |
for (var i = 0; i < nd[1].length; i++) { | |
add += ((((i - nd[1].length) * -1) + 1) * nd[1][i]); | |
} | |
nit_validado = ((11 - (add % 11)) % 11) == nd[2]; | |
} else { | |
nit_validado = false; | |
} | |
if (nit_validado === false) { | |
frappe.show_alert({ | |
indicator: 'orange', | |
message: __(` | |
NIT de <a href= '#Form/Customer/${cus_supp}'><b>${cus_supp}</b></a> no es correcto. Si no tiene disponible el NIT modifiquelo a C/F. | |
`) | |
}); | |
frm.disable_save(); // Desactiva y Oculta el boton de guardar en Sales Invoice | |
} | |
if (nit_validado === true) { | |
frm.enable_save(); // Activa y Muestra el boton guardar de Sales Invoice | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment