2018-09-25 01:24:37 -05:00
|
|
|
//~ Empresa Libre
|
|
|
|
//~ Copyright (C) 2016-2018 Mauricio Baeza Servin (web@correolibre.net)
|
|
|
|
//~
|
|
|
|
//~ This program is free software: you can redistribute it and/or modify
|
|
|
|
//~ it under the terms of the GNU General Public License as published by
|
|
|
|
//~ the Free Software Foundation, either version 3 of the License, or
|
|
|
|
//~ (at your option) any later version.
|
|
|
|
//~
|
|
|
|
//~ This program is distributed in the hope that it will be useful,
|
|
|
|
//~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
//~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
//~ GNU General Public License for more details.
|
|
|
|
//~
|
|
|
|
//~ You should have received a copy of the GNU General Public License
|
|
|
|
//~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-10-04 23:22:05 -05:00
|
|
|
var query = []
|
|
|
|
var grid = null
|
2017-10-06 00:10:27 -05:00
|
|
|
var msg = ''
|
2017-11-08 23:47:15 -06:00
|
|
|
var result = false
|
|
|
|
var tipo_relacion = ''
|
2017-11-12 18:50:41 -06:00
|
|
|
var anticipo = false
|
2017-11-26 13:56:10 -06:00
|
|
|
var donativo = false
|
2017-12-30 19:32:24 -06:00
|
|
|
var cfg_invoice = new Object()
|
2017-10-04 23:22:05 -05:00
|
|
|
|
|
|
|
|
2018-09-25 01:24:37 -05:00
|
|
|
function init_config_invoices(){
|
|
|
|
var multi_currency = get_config('multi_currency')
|
|
|
|
var g = $$('grid_invoices')
|
|
|
|
|
|
|
|
if(multi_currency){
|
|
|
|
g.showColumn('total')
|
|
|
|
g.showColumn('currency')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-29 04:09:02 -06:00
|
|
|
var invoices_controllers = {
|
|
|
|
init: function(){
|
2017-12-31 00:17:20 -06:00
|
|
|
//~ Invoices
|
|
|
|
$$('cmd_new_invoice').attachEvent("onItemClick", cmd_new_invoice_click)
|
|
|
|
$$('cmd_refacturar').attachEvent("onItemClick", cmd_refacturar_click)
|
2018-01-02 18:24:55 -06:00
|
|
|
$$('cmd_invoice_report_pdf').attachEvent('onItemClick', cmd_invoice_report_pdf_click)
|
|
|
|
$$('cmd_invoice_report_xls').attachEvent('onItemClick', cmd_invoice_report_xls_click)
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('cmd_delete_invoice').attachEvent("onItemClick", cmd_delete_invoice_click)
|
|
|
|
$$('cmd_timbrar').attachEvent('onItemClick', cmd_timbrar_click)
|
|
|
|
$$('cmd_close_invoice').attachEvent('onItemClick', cmd_close_invoice_click)
|
|
|
|
$$('search_client_id').attachEvent('onKeyPress', search_client_id_key_press)
|
|
|
|
$$('grid_clients_found').attachEvent('onValueSuggest', grid_clients_found_click)
|
|
|
|
$$('search_product_id').attachEvent('onKeyPress', search_product_id_key_press)
|
|
|
|
$$('grid_products_found').attachEvent('onValueSuggest', grid_products_found_click)
|
2018-01-29 13:21:06 -06:00
|
|
|
$$('grid_students_found').attachEvent('onValueSuggest', grid_students_found_click)
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('grid_details').attachEvent('onItemClick', grid_details_click)
|
|
|
|
$$('grid_details').attachEvent('onHeaderClick', grid_details_header_click)
|
|
|
|
$$('grid_details').attachEvent('onBeforeEditStart', grid_details_before_edit_start)
|
|
|
|
$$('grid_details').attachEvent('onBeforeEditStop', grid_details_before_edit_stop)
|
2020-04-16 22:35:41 -05:00
|
|
|
$$('grid_details').attachEvent('onAfterEditStop', grid_details_after_edit_stop)
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('cmd_invoice_timbrar').attachEvent('onItemClick', cmd_invoice_timbrar_click)
|
|
|
|
$$('cmd_invoice_sat').attachEvent('onItemClick', cmd_invoice_sat_click)
|
2018-02-13 12:05:44 -06:00
|
|
|
$$('cmd_invoice_verify_sat').attachEvent('onItemClick', cmd_invoice_verify_sat_click)
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('cmd_invoice_cancelar').attachEvent('onItemClick', cmd_invoice_cancelar_click)
|
|
|
|
$$('grid_invoices').attachEvent('onItemClick', grid_invoices_click)
|
2018-01-16 22:04:27 -06:00
|
|
|
$$('grid_invoices').attachEvent('onSelectChange', grid_invoices_on_select_change)
|
|
|
|
$$('grid_invoices').attachEvent('onHeaderClick', grid_invoices_on_header_click)
|
2018-06-15 00:05:55 -05:00
|
|
|
$$('grid_invoices').attachEvent('onSubViewCreate', grid_invoices_on_subview_create)
|
|
|
|
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('filter_year').attachEvent('onChange', filter_year_change)
|
|
|
|
$$('filter_month').attachEvent('onChange', filter_month_change)
|
|
|
|
$$('filter_dates').attachEvent('onChange', filter_dates_change)
|
|
|
|
$$('cmd_prefactura').attachEvent('onItemClick', cmd_prefactura_click)
|
2018-02-20 11:03:21 -06:00
|
|
|
$$('cmd_preinvoice_generate_delete').attachEvent('onItemClick', cmd_preinvoice_generate_delete_click)
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('cmd_cfdi_relacionados').attachEvent('onItemClick', cmd_cfdi_relacionados_click)
|
|
|
|
$$('lst_metodo_pago').attachEvent('onChange', lst_metodo_pago_change)
|
|
|
|
$$('lst_moneda').attachEvent('onChange', lst_moneda_change)
|
2018-02-22 18:27:05 -06:00
|
|
|
$$('lst_tipo_comprobante').attachEvent('onChange', lst_tipo_comprobante_change)
|
2017-12-31 00:17:20 -06:00
|
|
|
$$('lst_serie').attachEvent('onChange', lst_serie_change)
|
2018-06-03 00:00:04 -05:00
|
|
|
$$('txt_tipo_cambio').attachEvent('onBlur', txt_tipo_cambio_lost_focus)
|
2017-12-31 00:17:20 -06:00
|
|
|
|
2017-12-29 04:09:02 -06:00
|
|
|
$$('cmd_cfdi_notes').attachEvent('onItemClick', cmd_cfdi_notes_click)
|
2018-01-16 23:13:50 -06:00
|
|
|
$$('cmd_admin_invoice_notes').attachEvent('onItemClick', cmd_admin_invoice_notes_click)
|
2018-01-19 22:16:19 -06:00
|
|
|
$$('cmd_import_invoice').attachEvent('onItemClick', cmd_import_invoice_click)
|
2017-12-29 04:09:02 -06:00
|
|
|
|
2019-01-17 22:00:07 -06:00
|
|
|
$$('txt_folio_custom').attachEvent('onKeyPress', txt_folio_custom_key_press);
|
|
|
|
$$('txt_folio_custom').attachEvent('onBlur', txt_folio_custom_lost_focus);
|
|
|
|
|
2019-02-15 17:51:13 -06:00
|
|
|
$$('search_by').attachEvent('onKeyPress', search_by_key_press)
|
|
|
|
$$('search_by').attachEvent('onItemClick', search_by_click)
|
|
|
|
|
2017-12-29 04:09:02 -06:00
|
|
|
webix.extend($$('grid_invoices'), webix.ProgressBar)
|
2018-09-25 01:24:37 -05:00
|
|
|
|
|
|
|
init_config_invoices()
|
|
|
|
|
2018-06-03 00:00:04 -05:00
|
|
|
focus('search_client_name')
|
2017-12-29 04:09:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-02 23:24:31 -06:00
|
|
|
function get_condicion_pago(){
|
|
|
|
webix.ajax().get('/values/condicionespago', {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
$$('txt_condicion_pago').define('suggest', values)
|
|
|
|
$$('txt_condicion_pago').refresh()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-04 23:22:05 -05:00
|
|
|
function get_series(){
|
2018-02-23 23:58:13 -06:00
|
|
|
webix.ajax().sync().get('/values/series', function(text, data){
|
2017-10-04 23:22:05 -05:00
|
|
|
var values = data.json()
|
|
|
|
table_series.clear()
|
|
|
|
table_series.insert(values)
|
|
|
|
pre = values[0]
|
|
|
|
$$('lst_serie').getList().parse(values)
|
|
|
|
$$('lst_serie').setValue(pre.id)
|
2017-10-15 02:30:55 -05:00
|
|
|
if(pre.usarcon){
|
|
|
|
$$('lst_tipo_comprobante').setValue(pre.usarcon)
|
2017-10-04 23:22:05 -05:00
|
|
|
$$('lst_tipo_comprobante').config.readonly = true
|
|
|
|
$$('lst_tipo_comprobante').refresh()
|
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
if(values.length == 1){
|
|
|
|
$$('lst_serie').config.readonly = true
|
|
|
|
$$('lst_serie').refresh()
|
|
|
|
}
|
2017-10-04 23:22:05 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_monedas(){
|
|
|
|
webix.ajax().get('/values/monedas', function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
pre = values[0]
|
|
|
|
$$('lst_moneda').getList().parse(values)
|
|
|
|
$$('lst_moneda').setValue(pre.id)
|
2017-10-06 00:10:27 -05:00
|
|
|
if(values.length == 1){
|
|
|
|
$$('fs_moneda').hide()
|
|
|
|
}
|
2017-10-04 23:22:05 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_uso_cfdi(){
|
2017-10-07 00:16:58 -05:00
|
|
|
get_uso_cfdi_to_table({key: true})
|
|
|
|
query = table_usocfdi.chain().data()
|
2017-10-06 00:10:27 -05:00
|
|
|
$$('lst_uso_cfdi').getList().parse(query)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_regimen_fiscal(){
|
|
|
|
webix.ajax().get('/values/regimenes', function(text, data){
|
2017-10-04 23:22:05 -05:00
|
|
|
var values = data.json()
|
|
|
|
pre = values[0]
|
2017-10-06 00:10:27 -05:00
|
|
|
$$('lst_regimen_fiscal').getList().parse(values)
|
|
|
|
$$('lst_regimen_fiscal').setValue(pre.id)
|
|
|
|
if(values.length == 1){
|
|
|
|
$$('fs_regimen_fiscal').hide()
|
|
|
|
}
|
2017-10-04 23:22:05 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-13 00:13:34 -06:00
|
|
|
function validar_timbrar(){
|
|
|
|
webix.ajax().sync().get('/values/validartimbrar', function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
if(!values.ok){
|
|
|
|
msg_error(values.msg)
|
|
|
|
$$('cmd_timbrar').disable()
|
|
|
|
}else{
|
|
|
|
if(values.msg){
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
$$('cmd_timbrar').enable()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-04 23:22:05 -05:00
|
|
|
function default_config(){
|
2017-10-05 15:33:25 -05:00
|
|
|
webix.ajax().sync().get('/values/taxes', function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
table_taxes.clear()
|
|
|
|
table_taxes.insert(values)
|
|
|
|
})
|
2017-10-04 23:22:05 -05:00
|
|
|
get_series()
|
2017-12-20 01:15:48 -06:00
|
|
|
get_forma_pago('lst_forma_pago')
|
2017-10-04 23:22:05 -05:00
|
|
|
get_monedas()
|
|
|
|
get_uso_cfdi()
|
2017-10-06 00:10:27 -05:00
|
|
|
get_regimen_fiscal()
|
2017-10-04 23:22:05 -05:00
|
|
|
table_pt.clear()
|
|
|
|
table_totals.clear()
|
2017-11-11 11:17:49 -06:00
|
|
|
|
2017-12-13 00:13:34 -06:00
|
|
|
validar_timbrar()
|
2017-11-19 14:34:54 -06:00
|
|
|
|
|
|
|
webix.ajax().sync().get('/values/configtimbrar', function(text, data){
|
|
|
|
var values = data.json()
|
2017-12-24 22:09:21 -06:00
|
|
|
//~ showvar(values)
|
2017-11-19 14:34:54 -06:00
|
|
|
show('chk_cfdi_anticipo', values.cfdi_anticipo)
|
|
|
|
show('chk_cfdi_donativo', values.cfdi_donativo)
|
2018-01-02 18:24:55 -06:00
|
|
|
show('lst_metodo_pago', !values.cfdi_metodo_pago)
|
|
|
|
show('txt_condicion_pago', !values.cfdi_condicion_pago)
|
2017-12-30 19:32:24 -06:00
|
|
|
if(!values.cfdi_ine){
|
2017-11-20 00:47:23 -06:00
|
|
|
$$('tv_invoice').getTabbar().hideOption('INE')
|
|
|
|
}else{
|
|
|
|
$$('tv_invoice').getTabbar().showOption('INE')
|
|
|
|
}
|
2020-03-01 23:18:26 -06:00
|
|
|
if(!values.cfdi_leyendasfiscales){
|
|
|
|
$$('tv_invoice').getTabbar().hideOption('Leyendas Fiscales')
|
|
|
|
}else{
|
|
|
|
get_leyendas_fiscales()
|
|
|
|
$$('tv_invoice').getTabbar().showOption('Leyendas Fiscales')
|
|
|
|
}
|
|
|
|
cfg_invoice['leyendasfiscales'] = values.cfdi_leyendasfiscales
|
2018-01-29 13:21:06 -06:00
|
|
|
cfg_invoice['edu'] = values.cfdi_edu
|
2017-12-30 19:32:24 -06:00
|
|
|
cfg_invoice['open_pdf'] = values.cfdi_open_pdf
|
2018-01-18 15:12:33 -06:00
|
|
|
cfg_invoice['tax_locales'] = values.cfdi_tax_locales
|
2018-01-21 21:38:29 -06:00
|
|
|
cfg_invoice['tax_decimals'] = values.cfdi_tax_decimals
|
2018-01-22 20:06:22 -06:00
|
|
|
cfg_invoice['with_taxes'] = values.cfdi_with_taxes
|
2018-02-08 01:04:58 -06:00
|
|
|
cfg_invoice['add_same_product'] = values.cfdi_add_same_product
|
2018-05-23 23:42:57 -05:00
|
|
|
cfg_invoice['tax_locales_truncate'] = values.cfdi_tax_locales_truncate
|
2018-07-10 23:34:32 -05:00
|
|
|
cfg_invoice['decimales_precios'] = get_config('decimales_precios')
|
2018-01-08 09:40:35 -06:00
|
|
|
if(values.cfdi_show_pedimento){
|
|
|
|
$$('grid_details').showColumn('pedimento')
|
|
|
|
}
|
2018-01-29 13:21:06 -06:00
|
|
|
if(values.cfdi_edu){
|
|
|
|
$$('grid_details').showColumn('student')
|
|
|
|
}
|
2018-01-31 01:47:01 -06:00
|
|
|
show('fs_students', values.cfdi_edu)
|
2019-02-14 22:50:17 -06:00
|
|
|
show('fs_divisas', values.cfdi_divisas)
|
2019-01-17 22:00:07 -06:00
|
|
|
show('txt_folio_custom', values.cfdi_folio_custom)
|
2020-04-16 22:35:41 -05:00
|
|
|
show('txt_total_cant', values.cfdi_show_total_cant)
|
2017-11-19 14:34:54 -06:00
|
|
|
})
|
2017-10-04 23:22:05 -05:00
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
|
|
|
|
2018-01-22 20:06:22 -06:00
|
|
|
function price_without_taxes(price, id){
|
|
|
|
var final_price = price
|
|
|
|
|
|
|
|
query = table_pt.chain().find({'product': id}).data()
|
|
|
|
for(var tax of query){
|
|
|
|
impuesto = table_taxes.findOne({'id': tax.tax})
|
|
|
|
if(impuesto.tipo == 'E'){
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var tasa = 1.00 + impuesto.tasa.to_float()
|
|
|
|
if(impuesto.tipo == 'T' && impuesto.name == 'IVA'){
|
2018-07-10 23:34:32 -05:00
|
|
|
final_price = (price / tasa).round(cfg_invoice['decimales_precios'])
|
2018-01-22 20:06:22 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return final_price
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-23 23:58:13 -06:00
|
|
|
function cmd_new_invoice_click(){
|
2017-10-04 23:22:05 -05:00
|
|
|
var form = $$('form_invoice')
|
|
|
|
var grid_totals = $$('grid_totals')
|
|
|
|
grid = $$('grid_details')
|
2017-06-27 15:43:02 -05:00
|
|
|
|
2017-10-04 23:22:05 -05:00
|
|
|
default_config()
|
|
|
|
form.adjust()
|
2017-12-29 04:09:02 -06:00
|
|
|
form.setValues({id: 0, id_partner: 0, lbl_client: 'Ninguno', notas: ''})
|
2017-11-02 23:24:31 -06:00
|
|
|
get_condicion_pago()
|
2017-10-04 23:22:05 -05:00
|
|
|
grid.clearAll()
|
|
|
|
grid_totals.clearAll()
|
|
|
|
grid_totals.add({id: 1, concepto: 'SubTotal', importe: 0})
|
2017-11-08 23:47:15 -06:00
|
|
|
$$('cmd_cfdi_relacionados').disable()
|
2017-10-04 23:22:05 -05:00
|
|
|
$$('multi_invoices').setValue('invoices_new')
|
2017-11-01 10:36:27 -06:00
|
|
|
form.focus('search_client_name')
|
2017-10-04 23:22:05 -05:00
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
function cmd_edit_invoice_click(id, e, node){
|
|
|
|
|
|
|
|
$$("multi_invoices").setValue("invoices_new")
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function delete_invoice(id){
|
|
|
|
webix.ajax().del('/invoices', {id: id}, function(text, xml, xhr){
|
|
|
|
if(xhr.status == 200){
|
2017-10-10 18:49:05 -05:00
|
|
|
gi.remove(id)
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok('Factura eliminada correctamente')
|
2017-10-06 00:10:27 -05:00
|
|
|
}else{
|
|
|
|
msg_error('No se pudo eliminar')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-27 15:43:02 -05:00
|
|
|
|
|
|
|
function cmd_delete_invoice_click(id, e, node){
|
2017-10-16 23:36:10 -05:00
|
|
|
if(gi.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
2017-10-10 18:49:05 -05:00
|
|
|
var row = gi.getSelectedItem()
|
2018-01-16 22:04:27 -06:00
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una factura')
|
|
|
|
return
|
|
|
|
}
|
2018-01-16 22:04:27 -06:00
|
|
|
if (row instanceof Array){
|
|
|
|
msg_error('Selecciona solo una factura')
|
|
|
|
return
|
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
|
2017-10-10 18:49:05 -05:00
|
|
|
if(row.uuid){
|
2017-10-06 00:10:27 -05:00
|
|
|
msg_error('Solo se pueden eliminar facturas sin timbrar')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-08 23:47:15 -06:00
|
|
|
msg = '¿Estás seguro de eliminar la siguiente Factura?<BR><BR>'
|
2017-10-06 00:10:27 -05:00
|
|
|
msg += '(' + row['folio'] + ') ' + row['cliente']
|
|
|
|
msg += '<BR><BR>ESTA ACCIÓN NO SE PUEDE DESHACER'
|
|
|
|
webix.confirm({
|
|
|
|
title:'Eliminar Factura',
|
|
|
|
ok:'Si',
|
|
|
|
cancel:'No',
|
|
|
|
type:'confirm-error',
|
|
|
|
text:msg,
|
|
|
|
callback:function(result){
|
|
|
|
if (result){
|
|
|
|
delete_invoice(row['id'])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function validate_invoice(values){
|
|
|
|
|
|
|
|
if(values.id_partner == 0){
|
|
|
|
webix.UIManager.setFocus('search_client_name')
|
|
|
|
msg = 'Selecciona un cliente'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!grid.count()){
|
|
|
|
webix.UIManager.setFocus('search_product_id')
|
|
|
|
msg = 'Agrega al menos un producto o servicio'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-10-07 00:16:58 -05:00
|
|
|
var uso_cfdi = $$('lst_uso_cfdi').getValue()
|
|
|
|
if(uso_cfdi.trim() == ""){
|
|
|
|
webix.UIManager.setFocus('lst_uso_cfdi')
|
|
|
|
msg = 'El Uso del CFDI es requerido'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var forma_pago = $$('lst_forma_pago').getValue()
|
|
|
|
if(forma_pago.trim() == ""){
|
|
|
|
webix.UIManager.setFocus('lst_forma_pago')
|
|
|
|
msg = 'La Forma de pago es requerida'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
var tipo_cambio = $$('txt_tipo_cambio').getValue()
|
|
|
|
if(tipo_cambio.trim() == ""){
|
|
|
|
webix.UIManager.setFocus('txt_tipo_cambio')
|
|
|
|
msg = 'El Tipo de Cambio es requerido'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isNaN(tipo_cambio * 1)){
|
|
|
|
webix.UIManager.setFocus('txt_tipo_cambio')
|
|
|
|
msg = 'El Tipo de Cambio debe ser un valor númerico'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var moneda = $$('lst_moneda').getValue()
|
|
|
|
if(moneda == 'MXN' && tipo_cambio != 1){
|
|
|
|
webix.UIManager.setFocus('txt_tipo_cambio')
|
|
|
|
msg = 'Si la moneda es MXN, el Tipo de Cambio debe ser 1.00'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if(moneda != 'MXN' && tipo_cambio == 1){
|
|
|
|
webix.UIManager.setFocus('txt_tipo_cambio')
|
|
|
|
msg = 'Si la moneda no es MXN, el Tipo de Cambio debe ser diferente de 1.00'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-11-12 18:50:41 -06:00
|
|
|
anticipo = $$('chk_cfdi_anticipo').getValue()
|
|
|
|
if(anticipo){
|
|
|
|
var mp = $$('lst_metodo_pago').getValue()
|
|
|
|
if(mp != 'PUE'){
|
|
|
|
msg = 'En anticipos, el método de pago debe ser: Pago en una sola exhibición'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if(grid.count() != 1){
|
|
|
|
msg = 'Los anticipos solo llevan un concepto'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-11-19 00:42:16 -06:00
|
|
|
var r = grid.data.getRange()
|
|
|
|
if(r[0].clave_sat != CLAVE_ANTICIPOS){
|
|
|
|
msg = 'La clave del SAT para anticipos debe ser: ' + CLAVE_ANTICIPOS
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-11-12 18:50:41 -06:00
|
|
|
query = table_relaciones.chain().data()
|
|
|
|
if(query.length > 0){
|
|
|
|
msg = 'Los anticipos no deben llevar CFDI relacionados'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 21:26:54 -06:00
|
|
|
donativo = $$('chk_cfdi_donativo').getValue()
|
|
|
|
if(donativo){
|
|
|
|
query = table_totals.chain().data()
|
|
|
|
for(var t of query){
|
|
|
|
tax = table_taxes.findOne({'id': t.tax})
|
|
|
|
if(tax.tipo != 'E'){
|
|
|
|
msg = 'Los donativos deben de ser exentos'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 00:47:23 -06:00
|
|
|
usar_ine = $$('chk_cfdi_usar_ine').getValue()
|
|
|
|
if(usar_ine){
|
|
|
|
var id_contabilidad = $$('txt_ine_idcontabilidad').getValue().trim()
|
|
|
|
if(!id_contabilidad){
|
|
|
|
$$('tv_invoice').getTabbar().setValue('INE')
|
|
|
|
msg = 'El ID de contabilidad es requerido si se usa el complemento INE'
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!id_contabilidad.is_number()){
|
|
|
|
$$('tv_invoice').getTabbar().setValue('INE')
|
|
|
|
msg = 'El ID de contabilidad deben ser solo digitos'
|
|
|
|
msg_error(msg)
|
2020-04-16 22:35:41 -05:00
|
|
|
return false
|
2017-11-20 00:47:23 -06:00
|
|
|
}
|
|
|
|
|
2021-05-31 12:59:45 -05:00
|
|
|
if(id_contabilidad.length > 6){
|
2017-11-20 00:47:23 -06:00
|
|
|
$$('tv_invoice').getTabbar().setValue('INE')
|
2021-05-31 12:59:45 -05:00
|
|
|
msg = 'El ID de contabilidad deben tener máximo seis digitos'
|
2017-11-20 00:47:23 -06:00
|
|
|
msg_error(msg)
|
2020-04-16 22:35:41 -05:00
|
|
|
return false
|
2017-11-20 00:47:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-16 13:52:30 -06:00
|
|
|
var tipo_comprobante = $$('lst_tipo_comprobante').getValue()
|
|
|
|
if(tipo_comprobante == 'T'){
|
|
|
|
msg_ok('El CFDI es de tipo Traslado')
|
|
|
|
}
|
|
|
|
|
2020-04-16 22:35:41 -05:00
|
|
|
var rows = grid.data.getRange()
|
|
|
|
for (i = 0; i < rows.length; i++) {
|
|
|
|
var importe = rows[i]['importe']
|
|
|
|
if(!importe){
|
|
|
|
var msg = 'No es posible facturar importes en cero, revisa la línea: ' + (i + 1)
|
|
|
|
msg_error(msg)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function update_grid_invoices(values){
|
|
|
|
if(values.new){
|
2017-10-10 18:49:05 -05:00
|
|
|
gi.add(values.row)
|
2017-10-06 00:10:27 -05:00
|
|
|
}else{
|
2017-10-10 18:49:05 -05:00
|
|
|
gi.updateItem(values.row['id'], values.row)
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
2017-11-12 21:56:45 -06:00
|
|
|
|
|
|
|
function send_anticipo_egreso(id){
|
|
|
|
webix.ajax().get('/values/anticipoegreso', {id: id}, function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
if(values.ok){
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok(values.msg)
|
2017-11-12 21:56:45 -06:00
|
|
|
gi.add(values.row)
|
|
|
|
}else{
|
|
|
|
webix.alert({
|
|
|
|
title: 'Error al Timbrar',
|
|
|
|
text: values.msg,
|
|
|
|
type: 'alert-error'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function generar_anticipo_egreso(id){
|
|
|
|
msg = 'La factura tiene un CFDI de anticipo relacionado<BR><BR>'
|
|
|
|
msg += '¿Deseas generar la factura de egreso correspondiente?'
|
|
|
|
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Generar Egreso',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
send_anticipo_egreso(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-07 00:16:58 -05:00
|
|
|
function send_timbrar(id){
|
2018-06-03 00:00:04 -05:00
|
|
|
webix.ajax().post('invoices', {opt: 'timbrar', id: id}, function(text, data){
|
2017-10-07 00:16:58 -05:00
|
|
|
var values = data.json()
|
|
|
|
if(values.ok){
|
2018-02-13 23:12:21 -06:00
|
|
|
cmd_update_timbres_click()
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok(values.msg)
|
2017-10-10 18:49:05 -05:00
|
|
|
gi.updateItem(id, values.row)
|
2017-11-12 21:56:45 -06:00
|
|
|
if(values.anticipo){
|
|
|
|
//~ generar_anticipo_egreso(id)
|
|
|
|
//~ show('Generar egreso de anticipo')
|
|
|
|
}
|
2017-12-30 19:32:24 -06:00
|
|
|
if(cfg_invoice.open_pdf){
|
|
|
|
get_pdf(id)
|
|
|
|
}
|
2017-10-07 00:16:58 -05:00
|
|
|
}else{
|
|
|
|
webix.alert({
|
|
|
|
title: 'Error al Timbrar',
|
|
|
|
text: values.msg,
|
|
|
|
type: 'alert-error'
|
|
|
|
})
|
2018-01-08 13:57:15 -06:00
|
|
|
gi.updateItem(id, values.row)
|
2017-10-07 00:16:58 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
|
|
|
|
function save_invoice(data){
|
|
|
|
var result = false
|
|
|
|
var values = NaN
|
|
|
|
|
|
|
|
webix.ajax().sync().post('invoices', data, {
|
|
|
|
error:function(text, data, XmlHttpRequest){
|
|
|
|
msg = 'Ocurrio un error, consulta a soporte técnico'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success:function(text, data, XmlHttpRequest){
|
|
|
|
values = data.json();
|
|
|
|
if(values.ok){
|
2017-11-26 00:15:14 -06:00
|
|
|
msg_ok('Factura guardada correctamente<BR>Enviando a timbrar...')
|
2017-10-06 00:10:27 -05:00
|
|
|
update_grid_invoices(values)
|
2017-11-22 00:46:23 -06:00
|
|
|
gi.select(values.row['id'], false)
|
2017-10-07 00:16:58 -05:00
|
|
|
send_timbrar(values.row['id'])
|
2017-10-06 00:10:27 -05:00
|
|
|
result = true
|
|
|
|
}else{
|
2017-10-10 18:49:05 -05:00
|
|
|
msg_error(values.msg)
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if(result){
|
|
|
|
table_pt.clear()
|
|
|
|
table_totals.clear()
|
|
|
|
grid.clearAll()
|
|
|
|
$$('grid_totals').clearAll()
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
|
|
|
|
2017-11-05 00:13:48 -06:00
|
|
|
function save_preinvoice(data){
|
|
|
|
var result = false
|
|
|
|
var values = NaN
|
|
|
|
|
|
|
|
webix.ajax().sync().post('preinvoices', data, {
|
|
|
|
error:function(text, data, XmlHttpRequest){
|
|
|
|
msg = 'Ocurrio un error, consulta a soporte técnico'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success:function(text, data, XmlHttpRequest){
|
|
|
|
values = data.json();
|
|
|
|
if(values.ok){
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok('Pre Factura generada correctamente')
|
2017-11-05 00:13:48 -06:00
|
|
|
result = true
|
|
|
|
}else{
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if(result){
|
|
|
|
table_pt.clear()
|
|
|
|
table_totals.clear()
|
|
|
|
grid.clearAll()
|
|
|
|
$$('grid_totals').clearAll()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-08 23:47:15 -06:00
|
|
|
function guardar_y_timbrar(values){
|
|
|
|
query = table_relaciones.chain().data()
|
|
|
|
var ids = []
|
|
|
|
if(query.length > 0){
|
|
|
|
for (i = 0; i < query.length; i++) {
|
|
|
|
ids.push(query[i]['id'])
|
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var rows = grid.data.getRange()
|
|
|
|
for (i = 0; i < rows.length; i++) {
|
2018-02-08 01:04:58 -06:00
|
|
|
delete rows[i]['id']
|
2017-10-06 00:10:27 -05:00
|
|
|
delete rows[i]['delete']
|
|
|
|
delete rows[i]['clave']
|
2017-11-19 00:42:16 -06:00
|
|
|
delete rows[i]['clave_sat']
|
2017-10-06 00:10:27 -05:00
|
|
|
delete rows[i]['importe']
|
2018-01-29 13:21:06 -06:00
|
|
|
delete rows[i]['student']
|
2017-10-06 00:10:27 -05:00
|
|
|
rows[i]['valor_unitario'] = parseFloat(rows[i]['valor_unitario'])
|
2017-11-12 23:27:40 -06:00
|
|
|
rows[i]['descuento'] = parseFloat(rows[i]['descuento'])
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
var data = new Object()
|
|
|
|
data['id'] = values.id
|
|
|
|
data['cliente'] = values.id_partner
|
|
|
|
data['productos'] = rows
|
|
|
|
data['serie'] = $$('lst_serie').getText()
|
|
|
|
data['forma_pago'] = $$('lst_forma_pago').getValue()
|
|
|
|
data['condiciones_pago'] = $$('txt_condicion_pago').getValue().trim()
|
|
|
|
data['moneda'] = $$('lst_moneda').getValue()
|
|
|
|
data['tipo_cambio'] = $$('txt_tipo_cambio').getValue()
|
|
|
|
data['tipo_comprobante'] = $$('lst_tipo_comprobante').getValue()
|
|
|
|
data['metodo_pago'] = $$('lst_metodo_pago').getValue()
|
|
|
|
data['uso_cfdi'] = $$('lst_uso_cfdi').getValue()
|
|
|
|
data['regimen_fiscal'] = $$('lst_regimen_fiscal').getValue()
|
2017-11-08 23:47:15 -06:00
|
|
|
data['relacionados'] = ids
|
|
|
|
data['tipo_relacion'] = tipo_relacion
|
2017-11-12 18:50:41 -06:00
|
|
|
data['anticipo'] = anticipo
|
2017-11-26 13:56:10 -06:00
|
|
|
data['donativo'] = donativo
|
2017-12-29 04:09:02 -06:00
|
|
|
data['notas'] = values.notas
|
2019-01-17 22:00:07 -06:00
|
|
|
data['folio_custom'] = $$('txt_folio_custom').getValue()
|
2019-02-14 22:50:17 -06:00
|
|
|
data['divisas'] = $$('opt_divisas').getValue()
|
2020-03-01 23:18:26 -06:00
|
|
|
data['leyendas_fiscales'] = $$('grid_leyendas_fiscales').getSelectedId(true, true)
|
|
|
|
$$('grid_leyendas_fiscales').unselectAll()
|
2017-10-06 00:10:27 -05:00
|
|
|
|
2017-11-20 00:47:23 -06:00
|
|
|
var usar_ine = $$('chk_cfdi_usar_ine').getValue()
|
|
|
|
if(usar_ine){
|
2021-05-31 12:59:45 -05:00
|
|
|
ine_type_comite = $$('lst_ine_tipo_comite').getValue()
|
2017-11-20 00:47:23 -06:00
|
|
|
var valores = {
|
|
|
|
TipoProceso: $$('lst_ine_tipo_proceso').getValue(),
|
|
|
|
IdContabilidad: $$('txt_ine_idcontabilidad').getValue(),
|
2021-05-31 12:59:45 -05:00
|
|
|
ClaveEntidad: $$('lst_ine_key_entidad').getValue(),
|
|
|
|
Ambito: $$('lst_ine_ambito').getValue(),
|
|
|
|
}
|
|
|
|
if(ine_type_comite){
|
|
|
|
valores['TipoComite'] = ine_type_comite
|
2017-11-20 00:47:23 -06:00
|
|
|
}
|
|
|
|
data['ine'] = valores
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
if(!save_invoice(data)){
|
2017-06-27 15:43:02 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-08 23:47:15 -06:00
|
|
|
table_relaciones.clear()
|
|
|
|
tipo_relacion = ''
|
2017-11-12 18:50:41 -06:00
|
|
|
anticipo = false
|
2017-11-12 21:56:45 -06:00
|
|
|
$$('chk_cfdi_anticipo').setValue(0)
|
2017-11-26 13:56:10 -06:00
|
|
|
$$('chk_cfdi_donativo').setValue(0)
|
2017-11-26 00:15:14 -06:00
|
|
|
$$('chk_cfdi_usar_ine').setValue(0)
|
2017-11-12 21:56:45 -06:00
|
|
|
|
2017-12-29 04:09:02 -06:00
|
|
|
$$('form_invoice').setValues({id_partner: 0, lbl_partner: 'Ninguno', notas:''})
|
2017-10-04 23:22:05 -05:00
|
|
|
$$('multi_invoices').setValue('invoices_home')
|
2017-11-08 23:47:15 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_timbrar_click(id, e, node){
|
|
|
|
var form = this.getFormView();
|
|
|
|
|
|
|
|
if(!form.validate()) {
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Valores inválidos')
|
2017-11-08 23:47:15 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var values = form.getValues()
|
|
|
|
if(!validate_invoice(values)){
|
|
|
|
return
|
|
|
|
}
|
2018-02-16 13:52:30 -06:00
|
|
|
|
|
|
|
var tipo_comprobante = $$('lst_tipo_comprobante').getValue()
|
|
|
|
|
2017-11-08 23:47:15 -06:00
|
|
|
query = table_relaciones.chain().data()
|
|
|
|
msg = '¿Todos los datos son correctos?<BR><BR>'
|
|
|
|
if(query.length > 0){
|
|
|
|
msg += 'La factura tiene CFDI relacionados<BR><BR>'
|
|
|
|
}
|
2017-11-12 18:50:41 -06:00
|
|
|
if(anticipo){
|
2017-11-26 13:56:10 -06:00
|
|
|
msg += 'La factura es un Anticipo<BR><BR>'
|
|
|
|
}
|
|
|
|
if(donativo){
|
|
|
|
msg += 'La factura es un Donativo'
|
|
|
|
if($$('lst_forma_pago').getValue()=='12'){
|
|
|
|
msg += ' en Especie'
|
|
|
|
}
|
|
|
|
msg += '<BR><BR>'
|
2017-11-12 18:50:41 -06:00
|
|
|
}
|
2017-11-26 00:15:14 -06:00
|
|
|
usar_ine = $$('chk_cfdi_usar_ine').getValue()
|
|
|
|
if(usar_ine){
|
|
|
|
msg += 'Estas usando el complemento INE<BR><BR>'
|
|
|
|
}
|
2018-02-16 13:52:30 -06:00
|
|
|
|
|
|
|
if(tipo_comprobante == 'T'){
|
2018-02-20 10:11:48 -06:00
|
|
|
msg += 'El Tipo de Comprobante es Traslado, el total será puesto a 0 (Cero), asegurate de que sea el tipo de comprobante correcto<BR><BR>'
|
2018-02-16 13:52:30 -06:00
|
|
|
}
|
|
|
|
|
2020-03-01 23:18:26 -06:00
|
|
|
if(cfg_invoice['leyendasfiscales']){
|
|
|
|
var rows = $$('grid_leyendas_fiscales').getSelectedId(true, true)
|
|
|
|
if(rows.length == 0){
|
|
|
|
msg += 'No se agregará ninguna leyenda fiscal<BR><BR>'
|
|
|
|
}else if(rows.length == 1){
|
|
|
|
msg += 'Se agregará una leyenda fiscal<BR><BR>'
|
|
|
|
}else{
|
|
|
|
msg += 'Se agregarán ' + rows.length + ' leyendas fiscales<BR><BR>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 13:52:30 -06:00
|
|
|
msg += '¿Estás seguro de timbrar esta factura?<BR><BR>'
|
2017-11-08 23:47:15 -06:00
|
|
|
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Timbrar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
guardar_y_timbrar(values)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2017-10-04 23:22:05 -05:00
|
|
|
}
|
2017-06-27 15:43:02 -05:00
|
|
|
|
|
|
|
|
2017-10-04 23:22:05 -05:00
|
|
|
function cmd_close_invoice_click(id, e, node){
|
|
|
|
$$('multi_invoices').setValue('invoices_home')
|
|
|
|
}
|
2017-10-05 12:16:20 -05:00
|
|
|
|
|
|
|
|
2017-10-05 15:33:25 -05:00
|
|
|
function search_client_by_id(id){
|
2017-10-05 12:16:20 -05:00
|
|
|
var msg = ''
|
2017-10-05 15:33:25 -05:00
|
|
|
webix.ajax().get('/values/client', {'id': id}, {
|
2017-10-05 12:16:20 -05:00
|
|
|
error: function(text, data, xhr) {
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Error al consultar')
|
2017-10-05 12:16:20 -05:00
|
|
|
},
|
|
|
|
success: function(text, data, xhr){
|
|
|
|
var values = data.json()
|
|
|
|
if (values.ok){
|
2017-10-05 15:33:25 -05:00
|
|
|
set_client(values.row)
|
2017-10-05 12:16:20 -05:00
|
|
|
}else{
|
|
|
|
msg = 'No se encontró un cliente con la clave: ' + id
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error(msg)
|
2017-10-05 12:16:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-05 15:33:25 -05:00
|
|
|
function set_client(row){
|
2017-10-05 12:16:20 -05:00
|
|
|
var form = $$('form_invoice')
|
|
|
|
var html = '<span class="webix_icon fa-user"></span><span class="lbl_partner">'
|
|
|
|
form.setValues({
|
2017-10-07 00:16:58 -05:00
|
|
|
id_partner:row.id, search_client_id:'', search_client_name:'',
|
2018-01-10 23:39:15 -06:00
|
|
|
forma_pago: row.forma_pago, uso_cfdi: row.uso_cfdi,
|
|
|
|
notas: row.notas}, true)
|
2017-10-05 12:16:20 -05:00
|
|
|
html += row.nombre + ' (' + row.rfc + ')</span>'
|
2017-10-05 15:33:25 -05:00
|
|
|
$$('lbl_client').setValue(html)
|
2017-11-08 23:47:15 -06:00
|
|
|
$$('cmd_cfdi_relacionados').enable()
|
2017-10-05 12:16:20 -05:00
|
|
|
form.focus('search_product_id')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-05 15:33:25 -05:00
|
|
|
function grid_clients_found_click(obj){
|
|
|
|
set_client(obj)
|
2017-10-05 12:16:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-05 15:33:25 -05:00
|
|
|
function search_client_id_key_press(code, e){
|
2017-10-05 12:16:20 -05:00
|
|
|
var value = this.getValue()
|
|
|
|
if(code == 13 && value.length > 0){
|
|
|
|
var id = parseInt(value, 10)
|
|
|
|
if (isNaN(id)){
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Captura una clave válida')
|
2017-10-05 12:16:20 -05:00
|
|
|
}else{
|
2017-10-05 15:33:25 -05:00
|
|
|
search_client_by_id(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 23:36:22 -06:00
|
|
|
function calcular_impuestos(){
|
|
|
|
var tmp = null
|
|
|
|
var subtotal = 0
|
|
|
|
var id = 2
|
|
|
|
var grid_totals = $$('grid_totals')
|
|
|
|
var impuesto_producto = 0
|
|
|
|
var impuesto = null
|
2020-04-16 22:35:41 -05:00
|
|
|
var total_cant = 0
|
2017-12-12 23:36:22 -06:00
|
|
|
|
|
|
|
table_totals.clear()
|
|
|
|
grid_totals.clearAll()
|
|
|
|
grid_totals.add({id: 1, concepto: 'SubTotal', importe: 0})
|
|
|
|
|
2018-02-22 18:27:05 -06:00
|
|
|
var tc = $$('lst_tipo_comprobante').getValue()
|
|
|
|
if(tc=='T'){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-12 23:36:22 -06:00
|
|
|
grid.eachRow(function(row){
|
|
|
|
var product = grid.getItem(row)
|
2018-01-18 15:12:33 -06:00
|
|
|
var valor_unitario = parseFloat(product.valor_unitario)
|
|
|
|
var cantidad = parseFloat(product.cantidad)
|
|
|
|
var import2 = (valor_unitario * cantidad).round(DECIMALES)
|
2017-12-12 23:36:22 -06:00
|
|
|
var importe = parseFloat(product.importe)
|
2020-04-16 22:35:41 -05:00
|
|
|
|
2017-12-12 23:36:22 -06:00
|
|
|
subtotal += importe
|
2020-04-16 22:35:41 -05:00
|
|
|
total_cant += cantidad
|
|
|
|
|
2018-02-08 01:04:58 -06:00
|
|
|
query = table_pt.chain().find({'product': product.id_product}).data()
|
2017-12-12 23:36:22 -06:00
|
|
|
for(var tax of query){
|
|
|
|
impuesto = table_taxes.findOne({'id': tax.tax})
|
|
|
|
if(impuesto.tipo == 'E'){
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var base = importe
|
2018-01-18 15:12:33 -06:00
|
|
|
if(cfg_invoice['tax_locales'] && impuesto.key == '000'){
|
|
|
|
base = import2
|
|
|
|
}
|
|
|
|
|
2018-01-21 21:38:29 -06:00
|
|
|
if(cfg_invoice.tax_decimals){
|
|
|
|
impuesto_producto = (impuesto.tasa * base).round(DECIMALES_TAX)
|
|
|
|
}else{
|
|
|
|
impuesto_producto = (impuesto.tasa * base).round(DECIMALES)
|
|
|
|
}
|
2018-05-23 23:42:57 -05:00
|
|
|
|
|
|
|
if(cfg_invoice['tax_locales_truncate'] && impuesto.key == '000'){
|
|
|
|
impuesto_producto = Math.trunc(impuesto.tasa * base * 100) / 100
|
|
|
|
}
|
|
|
|
|
2018-08-03 23:01:21 -05:00
|
|
|
if(impuesto.tipo == 'R'){
|
|
|
|
impuesto_producto = (impuesto_producto * -1).round(DECIMALES)
|
|
|
|
}
|
|
|
|
|
2017-12-12 23:36:22 -06:00
|
|
|
tmp = table_totals.findOne({'tax': tax.tax})
|
|
|
|
if(tmp === null){
|
|
|
|
table_totals.insert({'tax': tax.tax, 'importe': impuesto_producto})
|
|
|
|
}else{
|
|
|
|
tmp.importe += impuesto_producto
|
|
|
|
table_totals.update(tmp)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var tipo = ''
|
|
|
|
var concepto = ''
|
|
|
|
|
|
|
|
query = table_totals.chain().data()
|
|
|
|
for(var t of query){
|
|
|
|
tax = table_taxes.findOne({'id': t.tax})
|
|
|
|
if(tax.tipo == 'E'){
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
tipo = 'Traslado '
|
|
|
|
if(tax.tipo == 'R'){
|
|
|
|
tipo = 'Retención '
|
|
|
|
}
|
|
|
|
concepto = tipo + tax.name + ' (' + tax.tasa + ')'
|
|
|
|
grid_totals.add({id: id, concepto: concepto, importe: t.importe})
|
|
|
|
id += 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = {importe: subtotal}
|
|
|
|
grid_totals.updateItem(1, row)
|
2020-04-16 22:35:41 -05:00
|
|
|
$$('txt_total_cant').setValue(format_decimal_2(total_cant))
|
2017-12-12 23:36:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-01 19:34:34 -05:00
|
|
|
function set_product(data){
|
|
|
|
var taxes = data.taxes
|
|
|
|
var values = data.row
|
2017-10-05 15:33:25 -05:00
|
|
|
var form = $$('form_invoice')
|
2018-02-08 01:04:58 -06:00
|
|
|
var row = undefined
|
|
|
|
|
|
|
|
if(!cfg_invoice['add_same_product']){
|
|
|
|
for(var id in grid.data.pull){
|
|
|
|
if(grid.getItem(id).id_product == values.id_product){
|
|
|
|
row = grid.getItem(id)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 15:33:25 -05:00
|
|
|
|
|
|
|
values['delete'] = '-'
|
|
|
|
if (row == undefined){
|
|
|
|
values['cantidad'] = 1
|
|
|
|
values['importe'] = values['valor_unitario']
|
2021-06-01 19:34:34 -05:00
|
|
|
//~ grid.add(values)
|
2017-10-05 15:33:25 -05:00
|
|
|
} else {
|
|
|
|
values['cantidad'] = parseFloat(row.cantidad) + 1
|
2017-11-14 20:04:01 -06:00
|
|
|
values['descuento'] = parseFloat(row.descuento)
|
|
|
|
values['valor_unitario'] = parseFloat(row.valor_unitario)
|
|
|
|
var precio_final = values['valor_unitario'] - values['descuento']
|
|
|
|
values['importe'] = (precio_final * values['cantidad']).round(DECIMALES)
|
2021-06-01 19:34:34 -05:00
|
|
|
//~ grid.updateItem(row.id, values)
|
2017-10-05 15:33:25 -05:00
|
|
|
}
|
2017-11-19 00:42:16 -06:00
|
|
|
form.setValues({search_product_id: '', search_product_name: ''}, true)
|
2017-10-05 15:33:25 -05:00
|
|
|
|
2021-06-01 19:34:34 -05:00
|
|
|
//~ Validate stock
|
|
|
|
if(values.inventario){
|
|
|
|
if(values.cantidad > values.existencia){
|
|
|
|
msg_error('No hay suficiente existencia de este producto')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(row == undefined){
|
|
|
|
grid.add(values)
|
|
|
|
}else{
|
|
|
|
grid.updateItem(row.id, values)
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:33:25 -05:00
|
|
|
for(var v of taxes){
|
|
|
|
var pt = table_pt.findOne(v)
|
|
|
|
if(pt === null){
|
|
|
|
table_pt.insert(v)
|
|
|
|
}
|
|
|
|
}
|
2017-12-12 23:36:22 -06:00
|
|
|
calcular_impuestos()
|
2017-10-05 15:33:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function grid_products_found_click(obj){
|
2018-01-08 22:11:31 -06:00
|
|
|
search_product_by_key(obj.clave)
|
2017-10-05 15:33:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-29 13:21:06 -06:00
|
|
|
function grid_students_found_click(obj){
|
|
|
|
var form = $$('form_invoice')
|
|
|
|
var row = grid.getSelectedItem()
|
|
|
|
|
|
|
|
if (row == undefined){
|
|
|
|
msg = 'Selecciona un registro primero'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var values = {
|
|
|
|
id_student: obj.id,
|
|
|
|
student: obj.nombre + ' ' + obj.paterno + ' ' + obj.materno,
|
|
|
|
}
|
|
|
|
grid.updateItem(row.id, values)
|
|
|
|
form.setValues({search_student: ''}, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-08 22:11:31 -06:00
|
|
|
function search_product_by_key(key){
|
|
|
|
webix.ajax().get('/values/productokey', {'key': key}, {
|
2017-10-05 15:33:25 -05:00
|
|
|
error: function(text, data, xhr) {
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Error al consultar')
|
2017-10-05 15:33:25 -05:00
|
|
|
},
|
|
|
|
success: function(text, data, xhr){
|
|
|
|
var values = data.json()
|
|
|
|
if (values.ok){
|
|
|
|
set_product(values)
|
|
|
|
} else {
|
2018-01-08 22:11:31 -06:00
|
|
|
msg = 'No se encontró un producto con la clave: ' + key
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error(msg)
|
2017-10-05 15:33:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function search_product_id_key_press(code, e){
|
2018-01-08 22:11:31 -06:00
|
|
|
var value = this.getValue().trim()
|
2017-10-05 15:33:25 -05:00
|
|
|
if(code == 13 && value.length > 0){
|
2018-01-08 22:11:31 -06:00
|
|
|
search_product_by_key(value)
|
2017-10-05 12:16:20 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-05 15:33:25 -05:00
|
|
|
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
function grid_details_before_edit_start(id){
|
2018-02-08 01:35:35 -06:00
|
|
|
var columns = ['', 'unidad', 'descripcion', 'pedimento','cantidad', 'valor_unitario', 'descuento']
|
2017-10-06 00:10:27 -05:00
|
|
|
if(!columns.indexOf(id.column)){
|
|
|
|
return !this.getItem(id.row)[id.column]
|
|
|
|
}
|
2018-03-01 00:03:53 -06:00
|
|
|
var tc = $$('lst_tipo_comprobante').getValue()
|
|
|
|
if(tc=='T' && id.column=='descuento'){
|
|
|
|
return false
|
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function grid_details_before_edit_stop(state, editor){
|
|
|
|
var row = grid.getItem(editor.row)
|
|
|
|
|
2018-02-08 01:35:35 -06:00
|
|
|
if(editor.column == 'unidad'){
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
if(editor.column == 'descripcion'){
|
|
|
|
if(!state.value.trim()){
|
|
|
|
msg = 'La descripción no puede estar vacía'
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error(msg)
|
2017-10-06 00:10:27 -05:00
|
|
|
grid.blockEvent()
|
|
|
|
state.value = state.old
|
|
|
|
grid.editCancel()
|
|
|
|
grid.unblockEvent()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
state.value = state.value.trim()
|
2017-12-26 00:02:34 -06:00
|
|
|
if(state.value.length > 1000){
|
|
|
|
msg = 'La descripción tiene más de 1000 caracteres, esta '
|
|
|
|
msg += 'descripción será rechazada por el SAT. Edita esta '
|
|
|
|
msg += 'descripción hasta que ya no veas este mensaje. <BR>'
|
|
|
|
msg += '<BR>Caracteres: ' + state.value.length
|
|
|
|
msg_error(msg)
|
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-01-08 09:40:35 -06:00
|
|
|
if(editor.column == 'pedimento'){
|
|
|
|
state.value = state.value.trim()
|
2018-01-08 16:00:55 -06:00
|
|
|
if(state.value.length != 21){
|
|
|
|
msg = 'El Pedimento debe ser de 21 caracteres, será '
|
2018-06-03 00:00:04 -05:00
|
|
|
msg += 'rechazado por el SAT. Editalo hasta que ya '
|
2018-01-08 09:40:35 -06:00
|
|
|
msg += 'no veas este mensaje de error. <BR>'
|
|
|
|
msg += '<BR>Caracteres: ' + state.value.length
|
|
|
|
msg_error(msg)
|
|
|
|
}
|
|
|
|
if(state.value){
|
|
|
|
if(!validate_pedimento(state.value)){
|
|
|
|
msg = 'El formato del Pedimento es erroneo, será rechazado por el SAT'
|
|
|
|
msg_error(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
if(editor.column == 'cantidad'){
|
|
|
|
var cantidad = parseFloat(state.value)
|
|
|
|
if(isNaN(cantidad)){
|
|
|
|
msg = 'La cantidad debe ser un número'
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error(msg)
|
2017-10-06 00:10:27 -05:00
|
|
|
grid.blockEvent()
|
|
|
|
state.value = state.old
|
|
|
|
grid.editCancel()
|
|
|
|
grid.unblockEvent()
|
|
|
|
return true
|
|
|
|
}
|
2018-06-03 00:00:04 -05:00
|
|
|
|
|
|
|
cantidad = cantidad.round(DECIMALES)
|
2021-06-01 19:34:34 -05:00
|
|
|
|
|
|
|
//~ Validate stock
|
|
|
|
if(row['inventario']){
|
|
|
|
if(cantidad > row['existencia']){
|
|
|
|
msg = 'No hay suficiente existencia de este producto'
|
|
|
|
msg_error(msg)
|
|
|
|
grid.blockEvent()
|
|
|
|
state.value = state.old
|
|
|
|
grid.editCancel()
|
|
|
|
grid.unblockEvent()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 00:00:04 -05:00
|
|
|
grid.blockEvent()
|
|
|
|
state.value = cantidad
|
|
|
|
grid.unblockEvent()
|
|
|
|
|
2017-11-12 23:27:40 -06:00
|
|
|
var valor_unitario = parseFloat(row['valor_unitario'])
|
|
|
|
var descuento = parseFloat(row['descuento'])
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(editor.column == 'valor_unitario'){
|
2018-01-22 20:06:22 -06:00
|
|
|
if(isNaN(state.value)){
|
2017-10-06 00:10:27 -05:00
|
|
|
msg = 'El valor unitario debe ser un número'
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error(msg)
|
2017-10-06 00:10:27 -05:00
|
|
|
grid.blockEvent()
|
|
|
|
state.value = state.old
|
|
|
|
grid.editCancel()
|
|
|
|
grid.unblockEvent()
|
|
|
|
return true
|
|
|
|
}
|
2018-06-03 00:00:04 -05:00
|
|
|
|
2018-01-22 20:06:22 -06:00
|
|
|
if(cfg_invoice['with_taxes']){
|
2018-02-10 12:12:49 -06:00
|
|
|
var valor_unitario = price_without_taxes(parseFloat(state.value), row.id_product)
|
2018-06-03 00:00:04 -05:00
|
|
|
}else{
|
2018-07-10 23:34:32 -05:00
|
|
|
//~ var valor_unitario = parseFloat(state.value).round(DECIMALES)
|
|
|
|
var valor_unitario = parseFloat(state.value).round(cfg_invoice['decimales_precios'])
|
2018-01-22 20:06:22 -06:00
|
|
|
}
|
2018-06-03 00:00:04 -05:00
|
|
|
grid.blockEvent()
|
|
|
|
state.value = valor_unitario
|
|
|
|
grid.unblockEvent()
|
|
|
|
|
2017-11-12 23:27:40 -06:00
|
|
|
var cantidad = parseFloat(row['cantidad'])
|
|
|
|
var descuento = parseFloat(row['descuento'])
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:27:40 -06:00
|
|
|
if(editor.column == 'descuento'){
|
|
|
|
var descuento = parseFloat(state.value)
|
|
|
|
if(isNaN(descuento)){
|
|
|
|
msg = 'El descuento debe ser un número'
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error(msg)
|
2017-11-12 23:27:40 -06:00
|
|
|
grid.blockEvent()
|
|
|
|
state.value = state.old
|
|
|
|
grid.editCancel()
|
|
|
|
grid.unblockEvent()
|
|
|
|
return true
|
|
|
|
}
|
2018-06-03 00:00:04 -05:00
|
|
|
|
2018-07-10 23:34:32 -05:00
|
|
|
//~ descuento = descuento.round(DECIMALES)
|
|
|
|
descuento = descuento.round(cfg_invoice['decimales_precios'])
|
2017-11-12 23:27:40 -06:00
|
|
|
var cantidad = parseFloat(row['cantidad'])
|
|
|
|
var valor_unitario = parseFloat(row['valor_unitario'])
|
2018-02-23 10:41:37 -06:00
|
|
|
|
|
|
|
if(descuento>=valor_unitario){
|
|
|
|
msg = 'El descuento debe ser menor al Valor Unitario'
|
|
|
|
msg_error(msg)
|
|
|
|
grid.blockEvent()
|
|
|
|
state.value = state.old
|
|
|
|
grid.editCancel()
|
|
|
|
grid.unblockEvent()
|
|
|
|
return true
|
|
|
|
}
|
2018-06-03 00:00:04 -05:00
|
|
|
|
|
|
|
grid.blockEvent()
|
|
|
|
state.value = descuento
|
|
|
|
grid.unblockEvent()
|
|
|
|
|
2017-11-12 23:27:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var precio_final = valor_unitario - descuento
|
|
|
|
row['importe'] = (cantidad * precio_final).round(DECIMALES)
|
|
|
|
|
2017-10-06 00:10:27 -05:00
|
|
|
grid.refresh()
|
2020-04-16 22:35:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function grid_details_after_edit_stop(state, editor, ignoreUpdate){
|
|
|
|
var columns = ['', 'cantidad', 'valor_unitario', 'descuento']
|
|
|
|
if(columns.indexOf(editor.column) > 0){
|
|
|
|
calcular_impuestos()
|
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-05 15:33:25 -05:00
|
|
|
function grid_details_click(id, e, node){
|
|
|
|
if(id.column != 'delete'){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
grid.remove(id.row)
|
2017-12-12 23:36:22 -06:00
|
|
|
calcular_impuestos()
|
2017-10-05 15:33:25 -05:00
|
|
|
}
|
2017-10-06 00:10:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
function grid_details_header_click(id){
|
|
|
|
if(id.column != 'delete'){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg = '¿Estás seguro de quitar todos los productos?'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Quitar todos',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if (result){
|
|
|
|
grid.clearAll()
|
2017-12-12 23:36:22 -06:00
|
|
|
calcular_impuestos()
|
2017-10-06 00:10:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-10-10 18:49:05 -05:00
|
|
|
|
|
|
|
|
2018-02-23 23:58:13 -06:00
|
|
|
function set_invoice(row){
|
|
|
|
$$('lst_serie').setValue(row.serie)
|
|
|
|
$$('lst_tipo_comprobante').setValue(row.tipo_comprobante)
|
|
|
|
$$('lst_uso_cfdi').setValue(row.uso_cfdi)
|
|
|
|
$$('lst_metodo_pago').setValue(row.metodo_pago)
|
|
|
|
$$('lst_forma_pago').setValue(row.forma_pago)
|
|
|
|
$$('txt_condicion_pago').setValue(row.condicion_pago)
|
|
|
|
}
|
|
|
|
|
2018-02-24 17:34:55 -06:00
|
|
|
|
|
|
|
function set_products_reinvoice(values){
|
|
|
|
var rows = []
|
|
|
|
for(var product of values){
|
|
|
|
var row = product.row
|
|
|
|
rows.push(row)
|
|
|
|
|
|
|
|
var taxes = product.taxes
|
|
|
|
for(var v of taxes){
|
|
|
|
var pt = table_pt.findOne(v)
|
|
|
|
if(pt === null){
|
|
|
|
table_pt.insert(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grid.parse(rows, 'json')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-23 01:46:42 -06:00
|
|
|
function refacturar_invoice(id){
|
2018-02-23 23:58:13 -06:00
|
|
|
filters = {id: id, opt: 'reinvoice'}
|
|
|
|
|
|
|
|
webix.ajax().get('/invoices', filters, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg_error('Error al consultar')
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
cmd_new_invoice_click()
|
|
|
|
pause(500)
|
|
|
|
set_client(values.receptor)
|
|
|
|
set_invoice(values.invoice)
|
2018-02-24 17:34:55 -06:00
|
|
|
set_products_reinvoice(values.products)
|
2018-02-23 23:58:13 -06:00
|
|
|
calcular_impuestos()
|
|
|
|
}
|
|
|
|
})
|
2018-02-23 01:46:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-10 18:49:05 -05:00
|
|
|
function cmd_refacturar_click(){
|
2018-02-23 01:46:42 -06:00
|
|
|
if(gi.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = gi.getSelectedItem()
|
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una factura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (row instanceof Array){
|
|
|
|
msg_error('Selecciona solo una factura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg = '¿Estás seguro de refacturar la siguiente factura?<BR><BR>'
|
|
|
|
msg += '(' + row['serie'] + '-' + row['folio'] + ') ' + row['cliente']
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Refacturar',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if (result){
|
|
|
|
refacturar_invoice(row['id'])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2017-10-10 18:49:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_invoice_timbrar_click(){
|
|
|
|
if(gi.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = gi.getSelectedItem()
|
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una factura')
|
|
|
|
return
|
|
|
|
}
|
2018-01-16 22:04:27 -06:00
|
|
|
if (row instanceof Array){
|
|
|
|
msg_error('Selecciona solo una factura')
|
|
|
|
return
|
|
|
|
}
|
2017-10-10 18:49:05 -05:00
|
|
|
|
|
|
|
if(row.uuid){
|
|
|
|
msg_error('La factura ya esta timbrada')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = '¿Estás seguro de enviar a timbrar esta factura?'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Timbrar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
send_timbrar(row.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-10-10 22:42:11 -05:00
|
|
|
|
|
|
|
|
2017-10-16 00:02:51 -05:00
|
|
|
function enviar_correo(row){
|
|
|
|
if(!row.uuid){
|
|
|
|
msg_error('La factura no esta timbrada')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = '¿Estás seguro de enviar por correo esta factura?'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Enviar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
webix.ajax().post('/values/sendmail', {'id': row.id}, {
|
|
|
|
error:function(text, data, XmlHttpRequest){
|
|
|
|
msg = 'Ocurrio un error, consulta a soporte técnico'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success:function(text, data, XmlHttpRequest){
|
|
|
|
values = data.json();
|
|
|
|
if(values.ok){
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok(values.msg)
|
2017-10-16 00:02:51 -05:00
|
|
|
}else{
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-30 19:32:24 -06:00
|
|
|
function get_pdf(id){
|
|
|
|
window.open('/doc/pdf/' + id, '_blank')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 01:03:48 -06:00
|
|
|
function get_html(id){
|
|
|
|
window.open('/doc/html/' + id, '_blank')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-10 22:42:11 -05:00
|
|
|
function grid_invoices_click(id, e, node){
|
|
|
|
var row = this.getItem(id)
|
2017-10-15 02:30:55 -05:00
|
|
|
|
2017-10-10 22:42:11 -05:00
|
|
|
if(id.column == 'xml'){
|
|
|
|
location = '/doc/xml/' + row.id
|
2017-10-15 02:30:55 -05:00
|
|
|
}else if(id.column == 'pdf'){
|
2017-12-30 19:32:24 -06:00
|
|
|
get_pdf(row.id)
|
2018-11-19 01:03:48 -06:00
|
|
|
}else if(id.column == 'html'){
|
|
|
|
get_html(row.id)
|
2018-01-18 00:15:14 -06:00
|
|
|
}else if(id.column == 'ods'){
|
|
|
|
location = '/doc/ods/' + row.id
|
2017-10-15 02:30:55 -05:00
|
|
|
}else if(id.column == 'zip'){
|
|
|
|
location = '/doc/zip/' + row.id
|
|
|
|
}else if(id.column == 'email'){
|
2017-10-16 00:02:51 -05:00
|
|
|
enviar_correo(row)
|
2017-10-10 22:42:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-10-16 23:36:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
function send_cancel(id){
|
2018-06-03 00:00:04 -05:00
|
|
|
webix.ajax().post('invoices', {opt: 'cancel', id: id}, function(text, data){
|
2017-10-29 16:53:10 -06:00
|
|
|
var values = data.json()
|
|
|
|
if(values.ok){
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok(values.msg)
|
2017-10-29 16:53:10 -06:00
|
|
|
gi.updateItem(id, values.row)
|
|
|
|
}else{
|
2020-12-31 15:08:49 -06:00
|
|
|
msg_error('No fue posible cancelar')
|
2017-10-29 16:53:10 -06:00
|
|
|
webix.alert({
|
|
|
|
title: 'Error al Cancelar',
|
|
|
|
text: values.msg,
|
|
|
|
type: 'alert-error'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2017-10-16 23:36:10 -05:00
|
|
|
}
|
|
|
|
|
2020-01-07 00:32:48 -06:00
|
|
|
|
2017-10-16 23:36:10 -05:00
|
|
|
function cmd_invoice_cancelar_click(){
|
|
|
|
if(gi.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = gi.getSelectedItem()
|
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una factura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-16 22:04:27 -06:00
|
|
|
if (row instanceof Array){
|
|
|
|
msg_error('Selecciona solo una factura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-29 16:53:10 -06:00
|
|
|
if(row.estatus == 'Cancelada'){
|
|
|
|
msg_error('La factura ya esta cancelada')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-02-12 17:42:23 -06:00
|
|
|
msg = ''
|
|
|
|
if(!row.uuid){
|
|
|
|
msg = 'La factura NO esta timbrada, asegurate de que efectivamente NO este timbrada.<BR><BR>'
|
|
|
|
}
|
|
|
|
|
|
|
|
msg += '¿Estás seguro de enviar a cancelar esta factura?<BR><BR> \
|
2017-10-16 23:36:10 -05:00
|
|
|
ESTA ACCIÓN NO SE PUEDE DESHACER'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Cancelar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
send_cancel(row.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-10-28 00:30:42 -05:00
|
|
|
|
|
|
|
|
2019-02-16 22:38:58 -06:00
|
|
|
function get_filters_invoices(){
|
|
|
|
var filters = $$('filter_dates').getValue()
|
2019-03-04 19:22:28 -06:00
|
|
|
|
|
|
|
if(filters['start'] && !filters['end']){
|
|
|
|
msg = 'No seleccionaste la fecha final'
|
|
|
|
msg_error(msg)
|
|
|
|
}
|
|
|
|
|
2019-02-16 22:38:58 -06:00
|
|
|
filters['year'] = $$('filter_year').getValue()
|
|
|
|
filters['month'] = $$('filter_month').getValue()
|
|
|
|
filters['client'] = $$('grid_invoices').getFilter('cliente').value
|
|
|
|
return filters
|
|
|
|
}
|
2017-10-28 21:58:18 -05:00
|
|
|
|
2019-02-16 22:38:58 -06:00
|
|
|
|
|
|
|
function get_invoices(){
|
|
|
|
var filters = get_filters_invoices()
|
|
|
|
filters['by'] = 'dates'
|
2017-10-28 21:58:18 -05:00
|
|
|
|
|
|
|
var grid = $$('grid_invoices')
|
2017-11-16 01:17:22 -06:00
|
|
|
grid.showProgress({type: 'icon'})
|
|
|
|
|
2019-02-16 22:38:58 -06:00
|
|
|
webix.ajax().get('/invoices', filters, {
|
2017-10-28 21:58:18 -05:00
|
|
|
error: function(text, data, xhr) {
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Error al consultar')
|
2017-10-28 21:58:18 -05:00
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
grid.clearAll();
|
|
|
|
if (values.ok){
|
|
|
|
grid.parse(values.rows, 'json');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-28 00:30:42 -05:00
|
|
|
function filter_year_change(nv, ov){
|
2017-10-28 21:58:18 -05:00
|
|
|
get_invoices()
|
2017-10-28 00:30:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function filter_month_change(nv, ov){
|
2017-10-28 21:58:18 -05:00
|
|
|
get_invoices()
|
2017-10-28 00:30:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function filter_dates_change(range){
|
2017-10-28 22:21:39 -05:00
|
|
|
if(range.start != null && range.end != null){
|
2019-02-16 22:38:58 -06:00
|
|
|
get_invoices()
|
2017-10-28 22:21:39 -05:00
|
|
|
}
|
2017-10-28 00:30:42 -05:00
|
|
|
}
|
2017-10-28 23:37:08 -05:00
|
|
|
|
|
|
|
|
2020-01-07 00:32:48 -06:00
|
|
|
function invoice_uncancel(id){
|
|
|
|
var options = {opt: 'uncancel', id: id}
|
|
|
|
webix.ajax().put('/invoices', options, function(text, data){
|
|
|
|
var result = data.json()
|
|
|
|
if(result['result']){
|
|
|
|
gi.updateItem(id, result['values'])
|
|
|
|
msg_ok(result['msg'])
|
|
|
|
}else{
|
|
|
|
msg_error(result['msg'])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ask_invoice_uncancel(id){
|
|
|
|
var msg = 'La factura seleccionada esta Vigente en el SAT, pero Cancelada en el sistema <BR>¿Deseas cambiar su estatus?'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Cambiar estatus de factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if (result){
|
|
|
|
invoice_uncancel(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-28 23:37:08 -05:00
|
|
|
function cmd_invoice_sat_click(){
|
|
|
|
if(gi.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = gi.getSelectedItem()
|
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una factura')
|
|
|
|
return
|
|
|
|
}
|
2018-01-16 22:04:27 -06:00
|
|
|
if (row instanceof Array){
|
|
|
|
msg_error('Selecciona solo una factura')
|
|
|
|
return
|
|
|
|
}
|
2017-10-28 23:37:08 -05:00
|
|
|
|
|
|
|
if(!row.uuid){
|
|
|
|
msg_error('La factura no esta timbrada, solo es posible consultar \
|
|
|
|
el estatus en el SAT de facturas timbradas')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-07 00:32:48 -06:00
|
|
|
var options = {opt: 'statussat', id: row.id}
|
|
|
|
webix.ajax().get('/invoices', options, function(text, data){
|
|
|
|
var value = data.json()
|
|
|
|
if(value == 'Vigente'){
|
|
|
|
msg_ok(value)
|
|
|
|
}else if(value == 'uncancel'){
|
|
|
|
ask_invoice_uncancel(row.id)
|
2018-01-16 23:13:50 -06:00
|
|
|
}else{
|
2020-01-07 00:32:48 -06:00
|
|
|
msg_error(value)
|
2018-01-16 23:13:50 -06:00
|
|
|
}
|
2017-10-28 23:37:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
2017-10-30 00:03:02 -06:00
|
|
|
|
|
|
|
|
2017-11-05 00:13:48 -06:00
|
|
|
function reset_invoice(){
|
|
|
|
var form = $$('form_invoice')
|
|
|
|
var grid_totals = $$('grid_totals')
|
|
|
|
|
|
|
|
form.adjust()
|
|
|
|
form.setValues({id: 0, id_partner: 0, lbl_client: 'Ninguno'})
|
|
|
|
grid.clearAll()
|
|
|
|
grid_totals.clearAll()
|
|
|
|
grid_totals.add({id: 1, concepto: 'SubTotal', importe: 0})
|
|
|
|
|
|
|
|
table_pt.clear()
|
|
|
|
table_totals.clear()
|
2017-11-08 23:47:15 -06:00
|
|
|
$$('cmd_cfdi_relacionados').disable()
|
2017-11-05 00:13:48 -06:00
|
|
|
form.focus('search_client_name')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-30 00:03:02 -06:00
|
|
|
function cmd_prefactura_click(){
|
|
|
|
var form = this.getFormView()
|
|
|
|
|
|
|
|
if(!form.validate()) {
|
|
|
|
msg_error('Valores inválidos')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var values = form.getValues()
|
|
|
|
if(!validate_invoice(values)){
|
|
|
|
return
|
|
|
|
}
|
2017-11-05 00:13:48 -06:00
|
|
|
|
|
|
|
var rows = grid.data.getRange()
|
|
|
|
for (i = 0; i < rows.length; i++) {
|
2018-02-08 01:04:58 -06:00
|
|
|
delete rows[i]['id']
|
2017-11-05 00:13:48 -06:00
|
|
|
delete rows[i]['delete']
|
|
|
|
delete rows[i]['clave']
|
|
|
|
delete rows[i]['importe']
|
|
|
|
rows[i]['valor_unitario'] = parseFloat(rows[i]['valor_unitario'])
|
2017-11-12 23:49:53 -06:00
|
|
|
rows[i]['descuento'] = parseFloat(rows[i]['descuento'])
|
2017-11-05 00:13:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var data = new Object()
|
|
|
|
data['id'] = values.id
|
|
|
|
data['cliente'] = values.id_partner
|
|
|
|
data['productos'] = rows
|
|
|
|
data['serie'] = $$('lst_serie').getText()
|
|
|
|
data['forma_pago'] = $$('lst_forma_pago').getValue()
|
|
|
|
data['condiciones_pago'] = $$('txt_condicion_pago').getValue().trim()
|
|
|
|
data['moneda'] = $$('lst_moneda').getValue()
|
|
|
|
data['tipo_cambio'] = $$('txt_tipo_cambio').getValue()
|
|
|
|
data['tipo_comprobante'] = $$('lst_tipo_comprobante').getValue()
|
|
|
|
data['metodo_pago'] = $$('lst_metodo_pago').getValue()
|
|
|
|
data['uso_cfdi'] = $$('lst_uso_cfdi').getValue()
|
|
|
|
data['regimen_fiscal'] = $$('lst_regimen_fiscal').getValue()
|
2018-01-10 23:39:15 -06:00
|
|
|
data['notas'] = values.notas
|
2017-11-05 00:13:48 -06:00
|
|
|
|
|
|
|
if(!save_preinvoice(data)){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_invoice()
|
|
|
|
$$('tv_invoice').getTabbar().setValue('PreFacturas')
|
2017-10-30 00:03:02 -06:00
|
|
|
}
|
2017-11-02 23:24:31 -06:00
|
|
|
|
|
|
|
|
|
|
|
function lst_metodo_pago_change(nv, ov){
|
|
|
|
if(nv == 'PPD'){
|
|
|
|
$$('lst_forma_pago').setValue('99')
|
|
|
|
}
|
|
|
|
}
|
2017-11-05 00:13:48 -06:00
|
|
|
|
|
|
|
|
2017-12-13 23:58:44 -06:00
|
|
|
function lst_moneda_change(nv, ov){
|
|
|
|
if(nv == 'MXN'){
|
|
|
|
$$('txt_tipo_cambio').setValue('1.00')
|
|
|
|
$$('txt_tipo_cambio').config.readonly = true
|
|
|
|
}else{
|
|
|
|
$$('txt_tipo_cambio').config.readonly = false
|
|
|
|
}
|
|
|
|
$$('txt_tipo_cambio').refresh()
|
2018-06-03 00:00:04 -05:00
|
|
|
select_all('txt_tipo_cambio')
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function txt_tipo_cambio_lost_focus(prev){
|
|
|
|
var tipo_cambio = $$('txt_tipo_cambio').getValue()
|
|
|
|
|
|
|
|
if(isNaN(tipo_cambio * 1)){
|
|
|
|
webix.UIManager.setFocus('txt_tipo_cambio')
|
|
|
|
msg = 'El Tipo de Cambio debe ser un valor númerico'
|
|
|
|
msg_error(msg)
|
|
|
|
$$('txt_tipo_cambio').setValue('1.00')
|
|
|
|
}else{
|
|
|
|
$$('txt_tipo_cambio').setValue(parseFloat(tipo_cambio).round(4))
|
|
|
|
}
|
2017-12-13 23:58:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-05 00:13:48 -06:00
|
|
|
function get_prefacturas(){
|
|
|
|
var fy = $$('prefilter_year')
|
|
|
|
var fm = $$('prefilter_month')
|
|
|
|
|
|
|
|
var y = fy.getValue()
|
|
|
|
var m = fm.getValue()
|
|
|
|
rango = {'year': y, 'month': m}
|
|
|
|
|
|
|
|
var grid = $$('grid_preinvoices')
|
|
|
|
webix.ajax().get('/preinvoices', rango, {
|
|
|
|
error: function(text, data, xhr) {
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Error al consultar')
|
2017-11-05 00:13:48 -06:00
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
grid.clearAll();
|
|
|
|
if (values.ok){
|
|
|
|
grid.parse(values.rows, 'json')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function tb_invoice_change(nv, ov){
|
|
|
|
if(nv == 'PreFacturas'){
|
|
|
|
get_prefacturas()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function prefilter_year_change(nv, ov){
|
|
|
|
get_prefacturas()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function prefilter_month_change(nv, ov){
|
|
|
|
get_prefacturas()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function delete_preinvoice(id){
|
|
|
|
webix.ajax().del('/preinvoices', {id: id}, function(text, xml, xhr){
|
|
|
|
if(xhr.status == 200){
|
|
|
|
$$('grid_preinvoices').remove(id)
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok('PreFactura eliminada correctamente')
|
2017-11-05 00:13:48 -06:00
|
|
|
}else{
|
|
|
|
msg_error('No se pudo eliminar')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_delete_preinvoice_click(id, e, node){
|
|
|
|
var grid = $$('grid_preinvoices')
|
|
|
|
|
|
|
|
if(grid.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = grid.getSelectedItem()
|
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una prefactura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg = '¿Estás seguro de eliminar la siguiente PREFactura?<BR><BR>'
|
|
|
|
msg += '(' + row['folio'] + ') ' + row['cliente']
|
|
|
|
msg += '<BR><BR>ESTA ACCIÓN NO SE PUEDE DESHACER'
|
|
|
|
webix.confirm({
|
|
|
|
title:'Eliminar Pre Factura',
|
|
|
|
ok:'Si',
|
|
|
|
cancel:'No',
|
|
|
|
type:'confirm-error',
|
|
|
|
text:msg,
|
|
|
|
callback:function(result){
|
|
|
|
if (result){
|
|
|
|
delete_preinvoice(row['id'])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-05 21:23:37 -06:00
|
|
|
function agregar_preproducto(values){
|
|
|
|
var taxes = values.taxes
|
|
|
|
var values = values.row
|
|
|
|
var form = $$('form_invoice')
|
|
|
|
var row = grid.getItem(values.id)
|
|
|
|
|
|
|
|
values['delete'] = '-'
|
|
|
|
if (row == undefined){
|
|
|
|
grid.add(values)
|
|
|
|
} else {
|
|
|
|
values['cantidad'] = parseFloat(row.cantidad) + parseFloat(values['cantidad'])
|
2017-11-14 20:04:01 -06:00
|
|
|
values['valor_unitario'] = parseFloat(row.valor_unitario)
|
|
|
|
values['descuento'] = parseFloat(row.descuento)
|
|
|
|
var precio_final = values['valor_unitario'] - values['descuento']
|
|
|
|
values['importe'] = (precio_final * values['cantidad']).round(DECIMALES)
|
2017-11-05 21:23:37 -06:00
|
|
|
grid.updateItem(row.id, values)
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var v of taxes){
|
|
|
|
var pt = table_pt.findOne(v)
|
|
|
|
if(pt === null){
|
|
|
|
table_pt.insert(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-05 00:13:48 -06:00
|
|
|
function refacturar_preinvoice(id){
|
2017-11-05 21:23:37 -06:00
|
|
|
|
|
|
|
webix.ajax().get('/values/preproductos', {'id': id}, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg_error('Error al consultar')
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr){
|
|
|
|
var values = data.json()
|
|
|
|
set_client(values.receptor)
|
|
|
|
for(var p of values.rows){
|
|
|
|
agregar_preproducto(p)
|
|
|
|
}
|
2017-12-12 23:36:22 -06:00
|
|
|
calcular_impuestos()
|
2017-11-05 21:23:37 -06:00
|
|
|
$$('tv_invoice').getTabbar().setValue('Generar')
|
|
|
|
}
|
|
|
|
})
|
2017-11-05 00:13:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-20 11:03:21 -06:00
|
|
|
function cmd_facturar_preinvoice_click(){
|
2017-11-05 00:13:48 -06:00
|
|
|
var grid = $$('grid_preinvoices')
|
|
|
|
|
|
|
|
if(grid.count() == 0){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var row = grid.getSelectedItem()
|
|
|
|
if (row == undefined){
|
|
|
|
msg_error('Selecciona una prefactura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var msg = '¿Estás seguro de facturar la siguiente PREFactura?<BR><BR>'
|
|
|
|
msg += '(' + row['folio'] + ') ' + row['cliente']
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Generar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if (result){
|
|
|
|
refacturar_preinvoice(row['id'])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-11-05 19:53:27 -06:00
|
|
|
|
|
|
|
|
|
|
|
function enviar_prefactura(id){
|
|
|
|
msg = '¿Estás seguro de enviar por correo esta prefactura?'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Enviar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
2017-12-31 00:17:20 -06:00
|
|
|
webix.ajax().post('/values/enviarprefac', {'id': id.row}, {
|
2017-11-05 19:53:27 -06:00
|
|
|
error:function(text, data, XmlHttpRequest){
|
|
|
|
msg = 'Ocurrio un error, consulta a soporte técnico'
|
|
|
|
msg_error(msg)
|
|
|
|
},
|
|
|
|
success:function(text, data, XmlHttpRequest){
|
|
|
|
values = data.json();
|
|
|
|
if(values.ok){
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok(values.msg)
|
2017-11-05 19:53:27 -06:00
|
|
|
}else{
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-20 01:33:02 -06:00
|
|
|
function generate_pdf(id){
|
|
|
|
webix.ajax().get('/values/canopenpre', {id: id}, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var value = data.json();
|
|
|
|
//~ if(value){
|
|
|
|
window.open('/doc/pre/' + id, '_blank')
|
|
|
|
//~ }else{
|
|
|
|
//~ msg_ok('Generando prefactura...')
|
|
|
|
//~ }
|
|
|
|
}
|
|
|
|
})
|
2017-11-05 19:53:27 -06:00
|
|
|
|
2018-01-20 01:33:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function grid_preinvoices_click(id, e, node){
|
2017-11-05 19:53:27 -06:00
|
|
|
if(id.column == 'pdf'){
|
2018-01-27 02:45:45 -06:00
|
|
|
//~ generate_pdf(id.row)
|
|
|
|
window.open('/doc/pre/' + id, '_blank')
|
2017-11-05 19:53:27 -06:00
|
|
|
}else if(id.column == 'email'){
|
2017-12-31 00:17:20 -06:00
|
|
|
enviar_prefactura(id)
|
2017-11-05 19:53:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-11-06 23:34:43 -06:00
|
|
|
|
|
|
|
|
2017-11-08 23:47:15 -06:00
|
|
|
function get_facturas_por_cliente(){
|
|
|
|
var values = $$('form_invoice').getValues()
|
|
|
|
var id = values.id_partner
|
|
|
|
|
|
|
|
var y = $$('filter_cfdi_year').getValue()
|
|
|
|
var m = $$('filter_cfdi_month').getValue()
|
|
|
|
|
|
|
|
var ids = []
|
|
|
|
var rows = $$('grid_relacionados').data.getRange()
|
|
|
|
for (i = 0; i < rows.length; i++) {
|
|
|
|
ids.push(rows[i]['id'])
|
|
|
|
}
|
|
|
|
|
|
|
|
filters = {
|
|
|
|
'year': y,
|
|
|
|
'month': m,
|
|
|
|
'id_cliente': id,
|
|
|
|
'cfdis': ids,
|
2017-11-12 18:50:41 -06:00
|
|
|
'anticipo': $$('chk_relacionados_anticipo').getValue(),
|
2017-11-08 23:47:15 -06:00
|
|
|
'folio': $$('filter_cfdi_folio').getValue(),
|
|
|
|
'uuid': $$('filter_cfdi_uuid').getValue(),
|
|
|
|
'opt': 'relacionados'
|
|
|
|
}
|
|
|
|
|
|
|
|
var grid = $$('grid_cfdi_cliente')
|
|
|
|
|
|
|
|
webix.ajax().get('/invoices', filters, {
|
|
|
|
error: function(text, data, xhr) {
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_error('Error al consultar')
|
2017-11-08 23:47:15 -06:00
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
grid.clearAll();
|
|
|
|
if (values.ok){
|
|
|
|
grid.parse(values.rows, 'json');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function get_info_cfdi_relacionados(){
|
|
|
|
|
|
|
|
webix.ajax().get('/values/tiporelacion', {key: true}, function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
$$('lst_tipo_relacion').getList().parse(values)
|
|
|
|
$$('lst_tipo_relacion').setValue(tipo_relacion)
|
|
|
|
})
|
|
|
|
|
|
|
|
query = table_relaciones.chain().data()
|
|
|
|
$$('grid_relacionados').parse(query)
|
|
|
|
get_facturas_por_cliente()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-06 23:34:43 -06:00
|
|
|
function cmd_cfdi_relacionados_click(){
|
2017-11-08 23:47:15 -06:00
|
|
|
var d = new Date()
|
|
|
|
ui_invoice.init()
|
|
|
|
var fy = $$('filter_cfdi_year')
|
|
|
|
var fm = $$('filter_cfdi_month')
|
|
|
|
|
|
|
|
fy.blockEvent()
|
|
|
|
fm.blockEvent()
|
|
|
|
|
|
|
|
$$('lbl_cfdi_cliente').setValue($$('lbl_client').getValue())
|
|
|
|
data = $$('filter_year').getList().data
|
|
|
|
fy.getList().data.sync(data)
|
|
|
|
fy.setValue(d.getFullYear())
|
|
|
|
fm.setValue(d.getMonth() + 1)
|
|
|
|
|
|
|
|
fy.unblockEvent()
|
|
|
|
fm.unblockEvent()
|
|
|
|
|
|
|
|
get_info_cfdi_relacionados()
|
|
|
|
|
|
|
|
$$('win_cfdi_relacionados').show()
|
2017-11-06 23:34:43 -06:00
|
|
|
}
|
2017-11-08 23:47:15 -06:00
|
|
|
|
|
|
|
|
|
|
|
function cmd_limpiar_relacionados_click(){
|
|
|
|
msg = '¿Estás seguro de quitar todas las relaciones<BR><BR>'
|
|
|
|
msg += 'ESTA ACCION NO SE PUEDE DESHACER'
|
|
|
|
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Limpiar relaciones',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
$$('lst_tipo_relacion').setValue('')
|
|
|
|
$$('grid_relacionados').clearAll()
|
|
|
|
table_relaciones.clear()
|
|
|
|
tipo_relacion = ''
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok('Las relaciones han sido eliminadas')
|
2017-11-08 23:47:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_guardar_relacionados_click(){
|
|
|
|
var grid = $$('grid_relacionados')
|
|
|
|
var value = $$('lst_tipo_relacion').getValue()
|
|
|
|
|
|
|
|
if(value == '' || value == '-'){
|
|
|
|
msg_error('Selecciona el tipo de relación')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(grid.count() == 0){
|
|
|
|
msg_error('Agrega al menos un CFDI a relacionar')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = grid.data.getRange()
|
|
|
|
table_relaciones.clear()
|
|
|
|
table_relaciones.insert(data)
|
|
|
|
tipo_relacion = value
|
2017-11-25 20:26:15 -06:00
|
|
|
msg_ok('Relaciones guardadas correctamente')
|
2017-11-08 23:47:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_filter_relacionados_click(){
|
|
|
|
get_facturas_por_cliente()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function filter_cfdi_year_change(nv, ov){
|
|
|
|
cmd_filter_relacionados_click()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function filter_cfdi_month_change(nv, ov){
|
|
|
|
cmd_filter_relacionados_click()
|
|
|
|
}
|
|
|
|
|
2017-11-12 18:50:41 -06:00
|
|
|
|
|
|
|
function lst_tipo_relacion_change(nv, ov){
|
|
|
|
$$('chk_relacionados_anticipo').setValue(0)
|
|
|
|
$$('chk_relacionados_anticipo').disable()
|
|
|
|
if(nv=='07'){
|
|
|
|
$$('chk_relacionados_anticipo').enable()
|
|
|
|
$$('chk_relacionados_anticipo').setValue(1)
|
|
|
|
cmd_filter_relacionados_click()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:56:45 -06:00
|
|
|
|
2018-02-22 18:27:05 -06:00
|
|
|
function lst_tipo_comprobante_change(nv, ov){
|
2018-03-01 00:03:53 -06:00
|
|
|
if(nv=='T'){
|
|
|
|
grid.eachRow(function(row){
|
|
|
|
var p = grid.getItem(row)
|
|
|
|
p.descuento = 0.0
|
|
|
|
p.importe = (p.cantidad * p.valor_unitario).round(DECIMALES)
|
|
|
|
grid.updateItem(row, p)
|
|
|
|
})
|
|
|
|
}
|
2018-02-22 18:27:05 -06:00
|
|
|
if(nv=='T' || ov=='T'){
|
|
|
|
calcular_impuestos()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-12 21:56:45 -06:00
|
|
|
function lst_serie_change(nv, ov){
|
2017-11-12 22:06:06 -06:00
|
|
|
query = table_series.chain().find({id: nv}).data()[0]
|
|
|
|
if(query.usarcon){
|
|
|
|
$$('lst_tipo_comprobante').setValue(query.usarcon)
|
|
|
|
$$('lst_tipo_comprobante').config.readonly = true
|
|
|
|
}else{
|
|
|
|
$$('lst_tipo_comprobante').config.readonly = false
|
|
|
|
}
|
|
|
|
$$('lst_tipo_comprobante').refresh()
|
2017-11-12 21:56:45 -06:00
|
|
|
}
|
2017-11-12 22:06:06 -06:00
|
|
|
|
2017-12-29 04:09:02 -06:00
|
|
|
|
|
|
|
function cmd_cfdi_notes_click(){
|
|
|
|
win_invoice_notes.init()
|
2018-01-10 23:21:37 -06:00
|
|
|
var values = $$('form_invoice').getValues()
|
|
|
|
$$('invoice_notes').setValue(values.notas)
|
|
|
|
$$('win_invoice_notes').show()
|
|
|
|
to_end('invoice_notes')
|
2018-01-16 23:13:50 -06:00
|
|
|
cfg_invoice['notes'] = false
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function save_invoice_notes(notes){
|
|
|
|
var row = $$('grid_invoices').getSelectedId()
|
|
|
|
|
|
|
|
webix.ajax().post('/values/invoicenotes', {id: row.id, notes: notes}, {
|
|
|
|
error:function(text, data, XmlHttpRequest){
|
|
|
|
},
|
|
|
|
success:function(text, data, XmlHttpRequest){
|
|
|
|
values = data.json();
|
|
|
|
if(values.ok){
|
|
|
|
msg_ok(values.msg)
|
|
|
|
}else{
|
|
|
|
msg_error(values.msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-12-29 04:09:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 23:21:37 -06:00
|
|
|
function cmd_invoice_save_note_click(){
|
|
|
|
var value = $$('invoice_notes').getValue()
|
2018-01-16 23:13:50 -06:00
|
|
|
if(cfg_invoice['notes']){
|
|
|
|
save_invoice_notes(value)
|
|
|
|
}else{
|
|
|
|
$$('form_invoice').setValues({notas: value}, true)
|
|
|
|
}
|
2018-01-10 23:21:37 -06:00
|
|
|
$$('win_invoice_notes').close()
|
|
|
|
|
2018-01-02 18:24:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_invoice_report_pdf_click(){
|
2018-07-05 23:52:09 -05:00
|
|
|
var d = new Date()
|
|
|
|
var ds = d.toISOString().slice(0,10).replace(/-/g, "_")
|
|
|
|
|
2018-01-02 18:24:55 -06:00
|
|
|
webix.toPDF($$('grid_invoices'), {
|
|
|
|
ignore: {'xml': true, 'pdf': true, 'zip': true, 'mail': true},
|
2018-07-05 23:52:09 -05:00
|
|
|
filename: 'Reporte_de_Facturas_' + ds,
|
2018-01-02 18:24:55 -06:00
|
|
|
width: 612,
|
|
|
|
height: 792,
|
2018-07-05 23:52:09 -05:00
|
|
|
//~ autowidth: true,
|
|
|
|
filterHTML: true,
|
|
|
|
fontSize: 8,
|
|
|
|
padding: 5,
|
|
|
|
header:{
|
|
|
|
textAlign: 'center',
|
|
|
|
fontSize: 9,
|
|
|
|
},
|
|
|
|
table:{
|
|
|
|
fontSize: 8,
|
|
|
|
},
|
|
|
|
row:{
|
|
|
|
padding: 0,
|
|
|
|
},
|
2018-01-02 18:24:55 -06:00
|
|
|
columns:{
|
|
|
|
index: true,
|
2018-07-05 23:52:09 -05:00
|
|
|
serie: {width: 40},
|
|
|
|
folio: {width: 30},
|
|
|
|
fecha: {width: 95},
|
|
|
|
tipo_comprobante: {width: 20},
|
|
|
|
estatus: {width: 50},
|
|
|
|
total_mn: {width: 70},
|
|
|
|
cliente: {width: 200},
|
2018-01-02 18:24:55 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_invoice_report_xls_click(){
|
|
|
|
webix.toExcel($$('grid_invoices'), {
|
|
|
|
filename: 'Reporte_de_Facturas',
|
|
|
|
name: 'Facturas',
|
|
|
|
ignore: {'xml': true, 'pdf': true, 'zip': true, 'mail': true},
|
|
|
|
rawValues: true,
|
|
|
|
})
|
2018-01-16 22:04:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function grid_invoices_on_select_change(){
|
|
|
|
var g = $$('grid_invoices')
|
|
|
|
var rows = g.getSelectedItem(true)
|
|
|
|
var total = 0
|
|
|
|
|
|
|
|
for (i = 0; i < rows.length; i++) {
|
2018-01-16 23:13:50 -06:00
|
|
|
if(typeof(rows[i].total_mn) == 'string'){
|
|
|
|
total += rows[i].total_mn.to_float()
|
|
|
|
}else{
|
|
|
|
total += rows[i].total_mn
|
|
|
|
}
|
2018-01-16 22:04:27 -06:00
|
|
|
}
|
|
|
|
g.getColumnConfig('cliente').footer[0].text = webix.i18n.priceFormat(total)
|
|
|
|
g.refreshColumns()
|
2018-01-16 23:13:50 -06:00
|
|
|
$$('cmd_admin_invoice_notes').disable()
|
|
|
|
if(rows.length==1){
|
|
|
|
$$('cmd_admin_invoice_notes').enable()
|
|
|
|
}
|
2018-01-16 22:04:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function grid_invoices_on_header_click(id){
|
|
|
|
if(id.column != 'index'){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var g = $$('grid_invoices')
|
|
|
|
var rows = g.getSelectedItem(true)
|
|
|
|
if(rows.length){
|
|
|
|
g.unselectAll()
|
|
|
|
}else{
|
|
|
|
g.selectAll()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:13:50 -06:00
|
|
|
|
|
|
|
function get_invoice_notes(row){
|
|
|
|
webix.ajax().sync().get('/values/invoicenotes', {id: row.id}, function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
return values.notes
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_admin_invoice_notes_click(){
|
|
|
|
var row = $$('grid_invoices').getSelectedId()
|
|
|
|
win_invoice_notes.init()
|
|
|
|
webix.ajax().sync().get('/values/invoicenotes', {id: row.id}, function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
$$('invoice_notes').setValue(values.notes)
|
|
|
|
$$('win_invoice_notes').show()
|
|
|
|
to_end('invoice_notes')
|
|
|
|
})
|
|
|
|
cfg_invoice['notes'] = true
|
2018-01-19 22:16:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_import_invoice_click(){
|
|
|
|
win_import_invoice.init()
|
|
|
|
$$('win_import_invoice').show()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cmd_upload_invoice_click(){
|
|
|
|
var form = $$('form_upload_invoice')
|
|
|
|
|
|
|
|
var values = form.getValues()
|
|
|
|
|
|
|
|
if(!$$('lst_upload_invoice').count()){
|
|
|
|
$$('win_import_invoice').close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if($$('lst_upload_invoice').count() > 1){
|
|
|
|
msg = 'Selecciona solo un archivo'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var template = $$('up_invoice').files.getItem($$('up_invoice').files.getFirstId())
|
|
|
|
|
|
|
|
if(template.type.toLowerCase() != 'ods'){
|
|
|
|
msg = 'Archivo inválido.\n\nSe requiere un archivo ODS'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = '¿Estás seguro de importar este archivo?'
|
|
|
|
webix.confirm({
|
|
|
|
title: 'Importar Factura',
|
|
|
|
ok: 'Si',
|
|
|
|
cancel: 'No',
|
|
|
|
type: 'confirm-error',
|
|
|
|
text: msg,
|
|
|
|
callback:function(result){
|
|
|
|
if(result){
|
|
|
|
$$('up_invoice').send()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function add_import_product_taxes(taxes){
|
|
|
|
for(var v of taxes){
|
|
|
|
var pt = table_pt.findOne(v)
|
|
|
|
if(pt === null){
|
|
|
|
table_pt.insert(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function up_invoice_upload_complete(response){
|
|
|
|
if(response.status != 'server'){
|
|
|
|
msg = 'Ocurrio un error al subir el archivo'
|
|
|
|
msg_error(msg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
msg = 'Archivo subido correctamente.\n\nComenzando importación.'
|
|
|
|
msg_ok(msg)
|
|
|
|
$$('win_import_invoice').close()
|
|
|
|
|
|
|
|
webix.ajax().get('/values/importinvoice', {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg_error('Error al consultar')
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr){
|
|
|
|
var values = data.json()
|
|
|
|
if (values.ok){
|
|
|
|
for(var p of values.rows){
|
|
|
|
add_import_product_taxes(p.taxes)
|
|
|
|
}
|
|
|
|
grid.clearAll()
|
|
|
|
grid.parse(values.rows, 'json')
|
|
|
|
grid.refresh()
|
|
|
|
calcular_impuestos()
|
|
|
|
}else{
|
|
|
|
webix.alert({
|
|
|
|
title: 'Error al importar',
|
|
|
|
text: values.msg,
|
|
|
|
type: 'alert-error',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-13 12:05:44 -06:00
|
|
|
|
|
|
|
function cmd_invoice_verify_sat_click(){
|
|
|
|
var rows = gi.getSelectedItem(true)
|
|
|
|
|
|
|
|
if (rows.length == 0){
|
|
|
|
msg_error('Selecciona una factura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows.length > 1){
|
|
|
|
msg_error('Selecciona solo una factura')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!rows[0].uuid){
|
|
|
|
msg_error('La factura no esta timbrada, solo es posible verificar \
|
|
|
|
en el SAT, facturas timbradas')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
webix.ajax().get('/values/verifysat', {id: rows[0].id}, function(text, data){
|
|
|
|
var values = data.json()
|
|
|
|
window.open(values.url, '_blank')
|
|
|
|
})
|
2018-02-20 11:03:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-15 00:05:55 -05:00
|
|
|
function grid_invoices_on_subview_create(view, item){
|
|
|
|
var values = {'opt': 'detalle', 'id': item.id}
|
|
|
|
webix.ajax().get('/invoices', values, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg_error('Error al consultar')
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
view.parse(data.json(), 'json')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-20 11:03:21 -06:00
|
|
|
|
|
|
|
|
2018-06-15 00:05:55 -05:00
|
|
|
function cmd_preinvoice_generate_delete_click(){
|
|
|
|
}
|
2019-01-17 22:00:07 -06:00
|
|
|
|
|
|
|
|
|
|
|
function txt_folio_custom_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 validate_folio_exists(folio){
|
|
|
|
var serie = $$('lst_serie').getText()
|
|
|
|
var values = {'opt': 'foliocustom', 'folio': folio, 'serie': serie}
|
|
|
|
webix.ajax().get('/invoices', values, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg_error('Error al consultar')
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var result = data.json()
|
|
|
|
if(result.ok){
|
|
|
|
msg_error(result.msg)
|
|
|
|
focus('txt_folio_custom')
|
|
|
|
}else{
|
|
|
|
msg_ok(result.msg)
|
|
|
|
}
|
|
|
|
return result.ok
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function txt_folio_custom_lost_focus(prev){
|
|
|
|
if(prev.getValue()){
|
|
|
|
validate_folio_exists(prev.getValue())
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 17:51:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
function search_by(value){
|
|
|
|
var filters = get_filters_invoices()
|
|
|
|
filters['by'] = 'notes'
|
|
|
|
filters['notes'] = value
|
|
|
|
|
|
|
|
|
|
|
|
var grid = $$('grid_invoices')
|
|
|
|
grid.showProgress({type: 'icon'})
|
|
|
|
|
|
|
|
webix.ajax().get('/invoices', filters, {
|
|
|
|
error: function(text, data, xhr) {
|
|
|
|
msg_error('Error al consultar')
|
|
|
|
},
|
|
|
|
success: function(text, data, xhr) {
|
|
|
|
var values = data.json();
|
|
|
|
grid.clearAll();
|
|
|
|
if (values.ok){
|
|
|
|
grid.parse(values.rows, 'json');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function search_by_key_press(code, e){
|
|
|
|
var value = this.getValue().trim()
|
|
|
|
if(code == 13 && value.length > 3){
|
|
|
|
search_by(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function search_by_click(){
|
|
|
|
var value = this.getValue().trim()
|
|
|
|
if(value.length > 3){
|
|
|
|
search_by(value)
|
|
|
|
}
|
|
|
|
}
|
2020-03-01 23:18:26 -06:00
|
|
|
|
|
|
|
|
|
|
|
function get_leyendas_fiscales(){
|
|
|
|
webix.ajax().get('/leyendasfiscales', {'opt': 'active'}, {
|
|
|
|
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()
|
|
|
|
var grid = $$('grid_leyendas_fiscales')
|
|
|
|
grid.clearAll()
|
|
|
|
grid.parse(values)
|
|
|
|
grid.refresh()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|