2017-10-07 23:52:11 -05:00
|
|
|
var msg = ''
|
2017-10-07 00:16:58 -05:00
|
|
|
var reg = /^[a-z]+$/i
|
|
|
|
//~ reg.test("somethingELSE")
|
2017-09-21 23:24:18 -05:00
|
|
|
|
|
|
|
var controllers = {
|
|
|
|
init: function(){
|
|
|
|
//~ Admin
|
|
|
|
$$('menu_user').attachEvent('onMenuItemClick', menu_user_click)
|
2017-10-07 23:52:11 -05:00
|
|
|
$$('multi_admin').attachEvent('onViewChange', multi_admin_change)
|
|
|
|
//~ Emisor
|
|
|
|
$$('cmd_save_emisor').attachEvent('onItemClick', cmd_save_emisor_click)
|
|
|
|
$$('emisor_cp').attachEvent('onKeyPress', emisor_postal_code_key_press)
|
|
|
|
$$('emisor_cp').attachEvent('onTimedKeyPress', emisor_postal_code_key_up)
|
|
|
|
$$('chk_escuela').attachEvent('onChange', chk_escuela_change)
|
|
|
|
$$('chk_ong').attachEvent('onChange', chk_ong_change)
|
|
|
|
|
2017-09-21 23:24:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function menu_user_click(id, e, node){
|
|
|
|
if (id == 1){
|
|
|
|
window.location = '/logout'
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_home_click(){
|
|
|
|
window.location = '/main'
|
|
|
|
}
|
2017-10-07 23:52:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
function cmd_save_emisor_click(){
|
|
|
|
var valid_cp = false
|
|
|
|
var form = $$('form_emisor')
|
|
|
|
|
|
|
|
if (!form.validate()){
|
|
|
|
msg = 'Valores inválidos'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var values = form.getValues()
|
|
|
|
|
|
|
|
var ids = $$('lst_emisor_regimen').getSelectedId()
|
|
|
|
if(!ids){
|
|
|
|
msg = 'Selecciona al menos un Regimen Fiscal'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(values.emisor_cp && values.emisor_cp.length != 5){
|
|
|
|
msg = 'Longitud inválida del C.P.'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(values.emisor_cp2 && values.emisor_cp2.length != 5){
|
|
|
|
msg = 'Longitud inválida del C.P. de Expedición'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}else if(values.emisor_cp2){
|
|
|
|
webix.ajax().sync().get('/values/cp', {cp: values.emisor_cp2}, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg = 'Error al consultar el C.P. de Expedición'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
if (values.estado == undefined){
|
|
|
|
msg = 'No se encontró el C.P., asegurate de que sea correcto'
|
|
|
|
msg_error(msg)
|
|
|
|
}else{
|
|
|
|
valid_cp = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if(!valid_cp){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(values.es_ong){
|
|
|
|
if(!values.ong_autorizacion){
|
|
|
|
msg = 'Si es ONG, el Número de Autorización del SAT es requerido'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(!values.ong_fecha){
|
|
|
|
msg = 'Si es ONG, la Fecha de Autorización del SAT es requerida'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(!values.ong_fecha_dof){
|
|
|
|
msg = 'Si es ONG, la Fecha de Publicación en DOF es requerida'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
values['regimenes'] = ids
|
|
|
|
webix.ajax().post('/emisor', values, {
|
|
|
|
error:function(text, data, XmlHttpRequest){
|
|
|
|
msg = 'Ocurrio un error, consulta a soporte técnico'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success:function(text, data, XmlHttpRequest){
|
|
|
|
var values = data.json()
|
|
|
|
if(values.ok){
|
|
|
|
msg_sucess('Emisor guardado correctamente')
|
|
|
|
}else{
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_emisor(){
|
|
|
|
var form = $$('form_emisor')
|
|
|
|
|
|
|
|
webix.ajax().get("/emisor", {}, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg = 'Error al consultar'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json()
|
|
|
|
if (values.ok){
|
|
|
|
var emisor = values.row.emisor
|
|
|
|
$$('lst_emisor_regimen').parse(values.row.regimenes)
|
|
|
|
form.setValues(emisor, true)
|
|
|
|
$$('lst_emisor_regimen').select(emisor.regimenes)
|
|
|
|
}else{
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function multi_admin_change(prevID, nextID){
|
|
|
|
//~ webix.message(nextID)
|
|
|
|
if(nextID == 'app_emisor'){
|
|
|
|
$$('tab_emisor').setValue('Datos Fiscales')
|
|
|
|
get_emisor()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function emisor_postal_code_key_up(){
|
|
|
|
var value = this.getValue()
|
|
|
|
|
|
|
|
if( value.length == 5 ){
|
|
|
|
webix.ajax().get('/values/cp', {cp: value}, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg = 'Error al consultar el C.P.'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
if (values.estado == undefined){
|
|
|
|
msg = 'No se encontró el C.P., asegurate de que sea correcto'
|
|
|
|
msg_error(msg)
|
|
|
|
} else {
|
|
|
|
$$('form_emisor').setValues({
|
|
|
|
emisor_cp2: value,
|
|
|
|
emisor_estado: values.estado,
|
|
|
|
emisor_municipio: values.municipio,
|
|
|
|
emisor_colonia: ''}, true)
|
|
|
|
$$('emisor_colonia').define('suggest', [])
|
|
|
|
if (webix.isArray(values.colonia)){
|
|
|
|
$$('emisor_colonia').define('suggest', values.colonia)
|
|
|
|
}else{
|
|
|
|
$$('form_emisor').setValues(
|
|
|
|
{emisor_colonia: values.colonia}, true)
|
|
|
|
}
|
|
|
|
$$('emisor_colonia').refresh()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function emisor_postal_code_key_press(code, e){
|
|
|
|
var data = [8, 9, 37, 39, 46]
|
|
|
|
if ( data.indexOf(code) >= 0 ){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( code < 48 || code > 57){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function chk_escuela_change(new_value, old_value){
|
|
|
|
var value = Boolean(new_value)
|
|
|
|
if (value){
|
|
|
|
$$('cmd_niveles').enable()
|
|
|
|
} else {
|
|
|
|
$$('cmd_niveles').disable()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function chk_ong_change(new_value, old_value){
|
|
|
|
var value = Boolean(new_value)
|
|
|
|
if (value){
|
|
|
|
$$('ong_autorizacion').enable()
|
|
|
|
$$('ong_fecha').enable()
|
|
|
|
$$('ong_fecha_dof').enable()
|
|
|
|
} else {
|
|
|
|
$$('ong_autorizacion').disable()
|
|
|
|
$$('ong_fecha').disable()
|
|
|
|
$$('ong_fecha_dof').disable()
|
|
|
|
}
|
|
|
|
}
|