var msg = '' var bancos_controllers = { init: function(){ $$('lst_cuentas_banco').attachEvent('onChange', lst_cuentas_banco_change) $$('cmd_agregar_retiro').attachEvent('onItemClick', cmd_agregar_retiro_click) $$('cmd_agregar_deposito').attachEvent('onItemClick', cmd_agregar_deposito_click) $$('cmd_guardar_retiro').attachEvent('onItemClick', cmd_guardar_retiro_click) $$('txt_retiro_importe').attachEvent('onChange', txt_retiro_importe_change) set_year_month() } } function set_year_month(){ var d = new Date() var y = $$('filtro_cuenta_year') var m = $$('filtro_cuenta_mes') webix.ajax().get('/values/cuentayears', { 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() y.getList().parse(values) y.blockEvent() m.blockEvent() y.setValue(d.getFullYear()) m.setValue(d.getMonth() + 1) y.unblockEvent() m.unblockEvent() } }) } function get_cuentas_banco(){ var list = $$('lst_cuentas_banco') webix.ajax().get('/cuentasbanco', {'tipo': 1}, { 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){ list.getList().parse(values.rows) list.blockEvent() list.setValue(values.rows[0].id) list.unblockEvent() $$('txt_cuenta_moneda').setValue(values.moneda) $$('txt_cuenta_saldo').setValue(values.saldo) get_estado_cuenta() } } }) } function get_estado_cuenta(rango){ if(rango == undefined){ var filtro = { cuenta: $$('lst_cuentas_banco').getValue(), year: $$('filtro_cuenta_year').getValue(), mes: $$('filtro_cuenta_mes').getValue(), } }else{ var filtro = { cuenta: $$('lst_cuentas_banco').getValue(), fechas: rango, } } var grid = $$('grid_cuentabanco') webix.ajax().get('/movbanco', filtro, { 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() grid.clearAll() if (values.ok){ grid.parse(values.rows, 'json') } } }) } function lst_cuentas_banco_change(nv, ov){ show('Cuenta change') } function get_retiro_forma_pago(){ webix.ajax().get('/values/formapago', {}, function(text, data){ var values = data.json() $$('lst_retiro_forma_pago').getList().parse(values) }) } function cmd_agregar_retiro_click(){ get_retiro_forma_pago() $$('multi_bancos').setValue('banco_retiro') } function cmd_agregar_deposito_click(){ showvar('Depósito') } function validate_retiro(values){ var importe = values.retiro_importe.replace('$', '').replace(',', '').trim() if(!importe){ msg = 'El importe es requerido' msg_error(msg) return false } importe = parseFloat(importe).round(2) if(importe <= 0){ msg = 'El importe debe ser mayor a cero' msg_error(msg) return false } if(!values.retiro_descripcion.trim()){ msg = 'La descripción es requerida' msg_error(msg) return false } var horas = $$('time_retiro').getText().split(':') var seg = parseInt(horas[2]) var min = parseInt(horas[1]) var horas = parseInt(horas[0]) if(horas > 23){ focus('time_retiro') msg = 'Hora inválida' msg_error(msg) return false } if(min > 59){ focus('time_retiro') msg = 'Hora inválida' msg_error(msg) return false } if(seg > 59){ focus('time_retiro') msg = 'Hora inválida' msg_error(msg) return false } return true } function guardar_retiro(values){ var form = $$('form_banco_retiro') var importe = get_float(values.retiro_importe) var data = new Object() data['cuenta'] = $$('lst_cuentas_banco').getValue() data['fecha'] = values.retiro_fecha data['hora'] = $$('time_retiro').getText() data['numero_operacion'] = values.retiro_referencia.trim() data['forma_pago'] = $$('lst_retiro_forma_pago').getValue() data['retiro'] = importe data['deposito'] = 0.0 data['descripcion'] = values.retiro_descripcion webix.ajax().post('/movbanco', data, { 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){ $$('txt_cuenta_saldo').setValue(values.saldo) get_estado_cuenta() $$('multi_bancos').setValue('banco_home') form.setValues({}) }else{ msg_error(values.msg) } } }) } function cmd_guardar_retiro_click(){ var form = $$('form_banco_retiro') if(!form.validate()) { msg_error('Valores inválidos') return } var values = form.getValues() if(!validate_retiro(values)){ return } msg = 'Todos los datos son correctos.

¿Deseas agregar este retiro?' webix.confirm({ title: 'Guardar Retiro', ok: 'Si', cancel: 'No', type: 'confirm-error', text: msg, callback:function(result){ if(result){ guardar_retiro(values) } } }) } function txt_retiro_importe_change(new_value, old_value){ if(!isFinite(new_value)){ this.config.value = old_value this.refresh() } }