forked from elmau/empresa-libre
299 lines
7.9 KiB
JavaScript
299 lines
7.9 KiB
JavaScript
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)
|
|
$$('grid_cfdi_este_deposito').attachEvent('onAfterDrop', grid_cfdi_este_deposito_after_drop)
|
|
$$('grid_cfdi_por_pagar').attachEvent('onAfterDrop', grid_cfdi_por_pagar_after_drop)
|
|
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_bancos_forma_pago(retiro){
|
|
webix.ajax().get('/values/formapago', {}, function(text, data){
|
|
var values = data.json()
|
|
if(retiro){
|
|
$$('lst_retiro_forma_pago').getList().parse(values)
|
|
}else{
|
|
$$('lst_deposito_forma_pago').getList().parse(values)
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
function get_facturas_por_pagar(){
|
|
var grid1 = $$('grid_cfdi_este_deposito')
|
|
var grid2 = $$('grid_cfdi_por_pagar')
|
|
|
|
var ids = []
|
|
grid1.data.each(function(obj){
|
|
ids.push(obj.id)
|
|
})
|
|
|
|
webix.ajax().get('/invoices', {'opt': 'porpagar', 'ids': ids}, {
|
|
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()
|
|
grid2.clearAll()
|
|
if (values.ok){
|
|
grid2.parse(values.rows, 'json')
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
function cmd_agregar_retiro_click(){
|
|
get_bancos_forma_pago(true)
|
|
$$('multi_bancos').setValue('banco_retiro')
|
|
}
|
|
|
|
|
|
function cmd_agregar_deposito_click(){
|
|
get_bancos_forma_pago(false)
|
|
get_facturas_por_pagar()
|
|
$$('multi_bancos').setValue('banco_deposito')
|
|
}
|
|
|
|
|
|
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.<br><br>¿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()
|
|
}
|
|
}
|
|
|
|
|
|
function actualizar_deposito(grid){
|
|
grid.sort("#fecha#", "desc", "date")
|
|
|
|
var suma = 0
|
|
var descripcion = ''
|
|
grid.data.each(function(obj){
|
|
suma += obj.saldo.to_float()
|
|
descripcion += 'Pago de la factura: ' + obj.serie + obj.folio + ' del '
|
|
descripcion += 'cliente: ' + obj.cliente + '\n'
|
|
obj.importe = obj.saldo
|
|
})
|
|
$$('txt_deposito_importe').setValue(suma)
|
|
$$('deposito_descripcion').setValue(descripcion)
|
|
grid.refresh()
|
|
}
|
|
|
|
|
|
function grid_cfdi_por_pagar_after_drop(context, native_event){
|
|
var grid = $$('grid_cfdi_este_deposito')
|
|
actualizar_deposito(grid)
|
|
}
|
|
|
|
|
|
function grid_cfdi_este_deposito_after_drop(context, native_event){
|
|
var grid = $$('grid_cfdi_este_deposito')
|
|
actualizar_deposito(grid)
|
|
}
|