Option Strict On Option Explicit On Imports System.Data Imports System.Math Imports ADSNetLibrary.SIGAPI.Models.OC.Response Imports ClosedXML.Excel Imports DocumentFormat.OpenXml.Drawing.Diagrams Imports Extensiones Partial Class General_SaldosIniciales Inherits ClsPaginas Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then TxtFecha.Text = NowADS().ToShortDateString End If End Sub Protected Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcel.Click If TxtExcel.getfiles().Archivos.Count > 0 Then Dim file As Archivo = TxtExcel.getfiles().Archivos(0) Dim Directorio As String = Server.MapPath("~") & file.path Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV") CargarArchivo(Directorio, file.filename, Tipo) Else Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError) End If End Sub Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String) Dim dt As New DataTable Dim ErrorArchivo As Boolean = False Dim ErrorExcel As Boolean = False dt = ReadExcelFile(Ruta + FileName, True) If Not ErrorArchivo Then If RblFormato.SelectedValue = "1" Then If Not dt.Columns(0).ColumnName = "Codigo" Then Alert("El nombre de la primera columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "RazonSocial" Then Alert("El nombre de la segunda columna debe ser 'Fecha'.Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "RFC" Then Alert("El nombre de la tercera columna debe ser 'RFC'.Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Calle" Then Alert("El nombre de la cuarta columna debe ser 'Calle'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Número exterior" Then Alert("El nombre de la quinta columna debe ser 'Número exterior' .Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "Colonia" Then Alert("El nombre de la sexta columna debe ser 'Colonia'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "Código postal" Then Alert("El nombre de la séptima columna debe ser 'Código postal'.Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(7).ColumnName = "Población" Then Alert("El nombre de la octava columna debe ser 'Población'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(8).ColumnName = "Estado" Then Alert("El nombre de la novena columna debe ser 'Estado'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(9).ColumnName = "Teléfono" Then Alert("El nombre de la décima columna debe ser 'Teléfono'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(10).ColumnName = "Contacto" Then Alert("El nombre de la onceava columna debe ser 'Contacto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(11).ColumnName = "Celular Contacto" Then Alert("El nombre de la doceava columna debe ser 'Celular Contacto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(12).ColumnName = "Limite Credito" Then Alert("El nombre de la treceava columna debe ser 'Limite Credito'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(13).ColumnName = "Plazo Cobranza" Then Alert("El nombre de la catorceava columna debe ser 'Plazo Cobranza'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(14).ColumnName.ToUpper = "BANCO" Then Alert("El nombre de la quinceava columna debe ser 'Banco'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(15).ColumnName.ToUpper = "N° CUENTA" Then Alert("El nombre de la dieciseisava columna debe ser 'N° Cuenta'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(16).ColumnName.ToUpper = "CLABE INTER" Then Alert("El nombre de la diecisieteava columna debe ser 'Clabe Inter'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(17).ColumnName.ToUpper = "TIPOPROVEEDOR" Then Alert("El nombre de la columna 18 debe ser 'TipoProveedor'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(18).ColumnName.ToUpper = "CUENTACONTABLE" Then Alert("El nombre de la columna 19 debe ser 'CuentaContable'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(19).ColumnName.ToUpper = "MONEDA PREFERENTE" Then Alert("El nombre de la columna 20 debe ser 'Moneda Preferente'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(20).ColumnName.ToUpper = "CLASIFICACIÓN PROVEEDOR" Then Alert("El nombre de la columna 21 debe ser 'Clasificación Proveedor'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(21).ColumnName.ToUpper = "REGIMEN FISCAL" Then Alert("El nombre de la columna 22 debe ser 'CuentaContable'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(22).ColumnName.ToUpper = "TIPO TERCERO" Then Alert("El nombre de la columna 23 debe ser 'Tipo Tercero'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(23).ColumnName.ToUpper = "TIPO OPERACIÓN" Then Alert("El nombre de la columna 24 debe ser 'Tipo Operación'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ElseIf RblFormato.SelectedValue = "2" Then If Not dt.Columns(0).ColumnName = "Codigo" Then Alert("El nombre de la primera columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "RazonSocial" Then Alert("El nombre de la segunda columna debe ser 'Fecha'.Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "RFC" Then Alert("El nombre de la tercera columna debe ser 'RFC'.Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Calle" Then Alert("El nombre de la cuarta columna debe ser 'Calle'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Número exterior" Then Alert("El nombre de la quinta columna debe ser 'Número exterior' .Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "Colonia" Then Alert("El nombre de la sexta columna debe ser 'Colonia'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "Código postal" Then Alert("El nombre de la séptima columna debe ser 'Código postal'.Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(7).ColumnName = "Población" Then Alert("El nombre de la octava columna debe ser 'Población'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(8).ColumnName = "Estado" Then Alert("El nombre de la novena columna debe ser 'Estado'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(9).ColumnName = "Teléfono" Then Alert("El nombre de la décima columna debe ser 'Teléfono'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(10).ColumnName = "Contacto" Then Alert("El nombre de la onceava columna debe ser 'Contacto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(11).ColumnName = "Celular Contacto" Then Alert("El nombre de la doceava columna debe ser 'Celular Contacto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(12).ColumnName = "Limite Credito" Then Alert("El nombre de la treceava columna debe ser 'Limite Credito'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(13).ColumnName = "Plazo Cobranza" Then Alert("El nombre de la treceava columna debe ser 'Plazo Cobranza'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If 'If Not dt.Columns(14).ColumnName = "Vendedor" Then ' Alert("El nombre de la catorceava columna debe ser 'Es distribuidor'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(15).ColumnName = "Clasificación" Then ' Alert("El nombre de la catorceava columna debe ser 'Es distribuidor'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(16).ColumnName = "Es distribuidor" Then ' Alert("El nombre de la catorceava columna debe ser 'Es distribuidor'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If ElseIf RblFormato.SelectedValue = "3" Or RblFormato.SelectedValue = "4" Or RblFormato.SelectedValue = "17" Or RblFormato.SelectedValue = "18" Then If Not dt.Columns(0).ColumnName = "Sucursal" Then Alert("El nombre de la primera columna debe ser 'Sucursal'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "RFC" Then Alert("El nombre de la segunda columna debe ser 'RFC'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Serie" Then Alert("El nombre de la tercera columna debe ser 'Serie'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Folio" Then Alert("El nombre de la cuarta columna debe ser 'Folio'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Fecha" Then Alert("El nombre de la quinta columna debe ser 'Fecha'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName.ToLower = "subtotal" Then Alert("El nombre de la sexta columna debe ser 'SubTotal'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "IVA" Then Alert("El nombre de la séptima columna debe ser 'IVA'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(7).ColumnName = "Total" Then Alert("El nombre de la octava columna debe ser 'Total'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(8).ColumnName = "Saldo" Then Alert("El nombre de la novena columna debe ser 'Saldo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(9).ColumnName = "Tipo Documento" Then Alert("El nombre de la décima columna debe ser 'Tipo Documento'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(10).ColumnName.ToLower.Contiene("ret iva", "ret iva") Then Alert("El nombre de la onceava columna debe ser 'Ret IVA'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(11).ColumnName.ToLower = "ret isr" Then Alert("El nombre de la doceava columna debe ser 'Ret ISR'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(12).ColumnName = "Moneda" Then Alert("El nombre de la treceava columna debe ser 'Moneda'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(13).ColumnName.Contiene("Tipo Cambio", "Tipo de Cambio") Then Alert("El nombre de la catorceava columna debe ser 'Tipo Cambio'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(14).ColumnName = "Fecha Vencimiento" Then Alert("El nombre de la quinceava columna debe ser 'Fecha Vencimiento'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If RblFormato.SelectedValue = "3" Or RblFormato.SelectedValue = "18" Then If Not dt.Columns(15).ColumnName = "PorcentajeIVA" Then Alert("El nombre de la quinceava columna debe ser 'PorcentajeIVA'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(16).ColumnName = "ImpuestosLocales" Then Alert("El nombre de la quinceava columna debe ser 'ImpuestosLocales'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If RblFormato.SelectedValue = "18" Then If Not dt.Columns(18).ColumnName = "Cantidad" Then Alert("El nombre de la Decimoctava columna debe ser 'Cantidad'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(19).ColumnName = "Codigo" Then Alert("El nombre de la Decimonovena columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(20).ColumnName = "PU" Then Alert("El nombre de la Vigésima columna debe ser 'PU'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(21).ColumnName = "IVADetalle" Then Alert("El nombre de la Vigésimo primera columna debe ser 'IVADetalle'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(22).ColumnName = "IEPS" Then Alert("El nombre de la Vigésimo segunda columna debe ser 'IEPS'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If End If End If If RblFormato.SelectedValue = "4" Or RblFormato.SelectedValue = "17" Then If Not dt.Columns(15).ColumnName = "Folio Fiscal" Then Alert("El nombre de la decimosexta columna debe ser 'Folio Fiscalo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(16).ColumnName = "PorcentajeIVA" Then Alert("El nombre de la decimoséptima columna debe ser 'PorcentajeIVA'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If RblFormato.SelectedValue = "17" Then If Not dt.Columns(17).ColumnName = "Vendedor" Then Alert("El nombre de la Decimoctava columna debe ser 'Vendedor'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(18).ColumnName = "Cantidad" Then Alert("El nombre de la Decimonovena columna debe ser 'Cantidad'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(19).ColumnName = "Codigo" Then Alert("El nombre de la Vigésima columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(20).ColumnName = "PU" Then Alert("El nombre de la Vigésimo primera columna debe ser 'PU'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(21).ColumnName = "IVADetalle" Then Alert("El nombre de la Vigésimo segunda columna debe ser 'IVADetalle'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(22).ColumnName = "IEPS" Then Alert("El nombre de la Vigésimo tercera columna debe ser 'IEPS'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If End If End If ElseIf RblFormato.SelectedValue = "5" Then If Not dt.Columns(0).ColumnName = "Codigo" Then Alert("El nombre de la primera columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Descripcion" Then Alert("El nombre de la segunda columna debe ser 'Descripcion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Tipo" Then Alert("El nombre de la terera columna debe ser 'Tipo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Código Barras" Then Alert("El nombre de la cuarta columna debe ser 'Código Barras'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Unidad Medida" Then Alert("El nombre de la quinta columna debe ser 'Unidad Medida'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "Clasificacion" Then Alert("El nombre de la sexta columna debe ser 'Clasificacion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "Marca" Then Alert("El nombre de la séptima columna debe ser 'Marca'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(7).ColumnName = "AplicaSerie" Then Alert("El nombre de la octava columna debe ser 'AplicaSerie'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(8).ColumnName = "Precio" Then Alert("El nombre de la novena columna debe ser 'Precio'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If 'If Not dt.Columns(9).ColumnName = "IEPS" Then ' Alert("El nombre de la décima columna debe ser 'IEPS'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(10).ColumnName = "Tamaño" Then ' Alert("El nombre de la onceava columna debe ser 'Tamaño'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(11).ColumnName = "Código SAT" Then ' Alert("El nombre de la doceava columna debe ser 'Código SAT'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(12).ColumnName = "Servicio" Then ' Alert("El nombre de la treceava columna debe ser 'Servicio'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(13).ColumnName = "Conversion Unidad" Then ' Alert("El nombre de la catorceava columna debe ser 'Conversion Unidad'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If ElseIf RblFormato.SelectedValue = "6" Then If Not validaRHPersonal(dt) Then Exit Sub End If ElseIf RblFormato.SelectedValue = "7" Then If Not dt.Columns(0).ColumnName = "Código" Then Alert("El nombre de la primera columna debe ser 'Código'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Descripción" Then Alert("El nombre de la segunda columna debe ser 'Descripción'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Tipo" Then Alert("El nombre de la tercera columna debe ser 'Tipo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "SubTipo" Then Alert("El nombre de la tercera columna debe ser 'SubTipo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Valor" Then Alert("El nombre de la tercera columna debe ser 'Valor'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "Fecha" Then Alert("El nombre de la tercera columna debe ser 'Fecha'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "No. Serie" Then Alert("El nombre de la tercera columna debe ser 'No. Serie'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(7).ColumnName = "Año" Then Alert("El nombre de la tercera columna debe ser 'Año'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(8).ColumnName = "Cuenta Contable" Then Alert("El nombre de la tercera columna debe ser 'Cuenta Contable'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(9).ColumnName = "Estado" Then Alert("El nombre de la tercera columna debe ser 'Estado'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(10).ColumnName = "Proyecto" Then Alert("El nombre de la tercera columna debe ser 'Proyecto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(11).ColumnName = "SubProyecto" Then Alert("El nombre de la tercera columna debe ser 'SubProyecto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(12).ColumnName = "Cliente" Then Alert("El nombre de la tercera columna debe ser 'Cliente'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(13).ColumnName = "Observaciones" Then Alert("El nombre de la tercera columna debe ser 'Observaciones'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(14).ColumnName = "Cuenta Depreciación" Then Alert("El nombre de la tercera columna debe ser 'Cuenta Depreciación'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(15).ColumnName = "% Depreciación" Then Alert("El nombre de la tercera columna debe ser '% Depreciación'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(16).ColumnName = "Cuenta Depreciación Acumulada" Then Alert("El nombre de la tercera columna debe ser 'Cuenta Depreciación Acumulada'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If 'If Not dt.Columns(3).ColumnName = "Linea" Then ' Alert("El nombre de la cuarta columna debe ser 'Linea'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(4).ColumnName = "Codigo Barras" Then ' Alert("El nombre de la sexta columna debe ser 'Codigo Barras'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(5).ColumnName = "Clasificacion" Then ' Alert("El nombre de la séptima columna debe ser 'Clasificacion'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(6).ColumnName = "Marca" Then ' Alert("El nombre de la octava columna debe ser 'Marca'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(7).ColumnName = "Modelo" Then ' Alert("El nombre de la novena columna debe ser 'Modelo'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(8).ColumnName = "Medida" Then ' Alert("El nombre de la décima columna debe ser 'Medida'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(9).ColumnName = "Tamaño de Rin" Then ' Alert("El nombre de la onceava columna debe ser 'Tamaño de Rin'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(10).ColumnName = "CODIGO SAT" Then ' Alert("El nombre de la diesciseisava columna debe ser 'CODIGO SAT'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If 'If Not dt.Columns(11).ColumnName = "Clave Unidad" Then ' Alert("El nombre de la diescisieteava columna debe ser 'Clave Unidad'. Favor de corregirlo", TipoMensaje.MsgError) ' Exit Sub 'End If ElseIf RblFormato.SelectedValue = "9" Then If Not dt.Columns(0).ColumnName = "Cuenta" Then Alert("El nombre de la primera columna debe ser 'Cuenta'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "NombreCuenta" Then Alert("El nombre de la segunda columna debe ser 'NombreCuenta'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "TipoCuenta" Then Alert("El nombre de la tercera columna debe ser 'TipoCuenta'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "CuentaPadre" Then Alert("El nombre de la cuarta columna debe ser 'CuentaPadre'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "AgrupadorSAT" Then Alert("El nombre de la quinta columna debe ser 'AgrupadorSAT'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ElseIf RblFormato.SelectedValue = "12" Then If Not dt.Columns(0).ColumnName = "CodigoPS" Then Alert("El nombre de la primera columna debe ser 'CodigoPS'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Almacen" Then Alert("El nombre de la segunda columna debe ser 'Almacen'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Existencia" Then Alert("El nombre de la tercera columna debe ser 'Existencia'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Valor" Then Alert("El nombre de la cuarta columna debe ser 'Valor'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ElseIf RblFormato.SelectedValue = "13" Then 'ANTICIPO PROVEEDORES If Not dt.Columns(0).ColumnName = "RFC" Then Alert("El nombre de la primera columna debe ser 'RFC'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Descripcion" Then Alert("El nombre de la segunda columna debe ser 'Descripcion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Fecha" Then Alert("El nombre de la tercera columna debe ser 'Fecha'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Importe" Then Alert("El nombre de la cuarta columna debe ser 'Importe'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Moneda" Then Alert("El nombre de la cuarta columna debe ser 'Moneda'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "TipoCambio" Then Alert("El nombre de la cuarta columna debe ser 'TipoCambio'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "CuentaContable" Then Alert("El nombre de la cuarta columna debe ser 'CuentaContable'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ElseIf RblFormato.SelectedValue = "14" Then 'ANTICIPO CLIENTES If Not dt.Columns(0).ColumnName = "RFC" Then Alert("El nombre de la primera columna debe ser 'RFC'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Descripcion" Then Alert("El nombre de la segunda columna debe ser 'Descripcion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Fecha" Then Alert("El nombre de la tercera columna debe ser 'Fecha'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Importe" Then Alert("El nombre de la cuarta columna debe ser 'Importe'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Moneda" Then Alert("El nombre de la cuarta columna debe ser 'Moneda'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "TipoCambio" Then Alert("El nombre de la cuarta columna debe ser 'TipoCambio'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "CuentaContable" Then Alert("El nombre de la cuarta columna debe ser 'CuentaContable'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ElseIf RblFormato.SelectedValue = "15" Then 'BANCOS If Not dt.Columns(0).ColumnName = "CuentaBancaria" Then Alert("El nombre de la primera columna debe ser 'CuentaBancaria'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Banco" Then Alert("El nombre de la primera columna debe ser 'Banco'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Importe" Then Alert("El nombre de la segunda columna debe ser 'Importe'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Moneda" Then Alert("El nombre de la segunda columna debe ser 'Moneda'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "TipoCambio" Then Alert("El nombre de la segunda columna debe ser 'TipoCambio'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(5).ColumnName = "Fecha" Then Alert("El nombre de la cuarta columna debe ser 'Fecha'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(6).ColumnName = "Descripcion" Then Alert("El nombre de la cuarta columna debe ser 'Descripcion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(7).ColumnName = "CuentaContable" Then Alert("El nombre de la tercera columna debe ser 'CuentaContable'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ElseIf RblFormato.SelectedValue = "16" Then 'CLASIFICACIONES If Not dt.Columns(0).ColumnName = "Clasificacion" Then Alert("El nombre de la primera columna debe ser 'Clasificacion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Categoria" Then Alert("El nombre de la segunda columna debe ser 'Categoria'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "UsoClasificacion" Then Alert("El nombre de la segunda columna debe ser 'UsoClasificacion'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "CuentaContableIngreso" Then Alert("El nombre de la segunda columna debe ser 'CuentaContableIngreso'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "CuentaContableGasto" Then Alert("El nombre de la cuarta columna debe ser 'CuentaContableGasto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If End If End If dt.TableName = "Datos" Dim NumRows As Integer = dt.Rows.Count Dim DTCuentasContables As New DataTable If UsuarioActual.Empresa.TipoContabilizacion = 1 Or UsuarioActual.CveEmpresa.Contiene(172, 174) Then Dim ObjConta As New ClsContabilidad If ObjConta.GetCuentas(-1, "-1", -1, UsuarioActual.CveEmpresa) Then DTCuentasContables = ObjConta.DtResultados End If ObjConta.Dispose() End If If Not ErrorArchivo Then 'P R O D U C T O S / S E R V I C I O S If RblFormato.SelectedValue = "5" Then #Region "P R O D U C T O S / S E R V I C I O S" Dim ObjPS As New ClsProductosServicios Dim ObjGral As New ClsGenerales(ObjPS.IniciaTransacSQL()) Dim ObjClas As New ClsClasificaciones(ObjPS.IniciaTransacSQL()) Dim ObjVenta As New ClsVentas(ObjPS.IniciaTransacSQL()) Dim ObjUM As New ClsUnidadesMedida(ObjPS.IniciaTransacSQL()) Dim ErrorPS As Boolean = False Dim ExistePS As Boolean = False Dim Contador As Integer = 0 Dim DtMarcas As DataTable = Nothing Dim DtMedidas As DataTable = Nothing Dim DtRinTamaño As DataTable = Nothing Dim DtModelos As DataTable = Nothing Dim DTPS As DataTable = Nothing If ObjPS.GetMarcas(UsuarioActual.CveEmpresa) Then DtMarcas = ObjPS.DtResultados.Copy End If DtMedidas = GlobalDTPSMedidas(UsuarioActual.CveEmpresa) DtRinTamaño = GlobalDTPSRinTamaños(UsuarioActual.CveEmpresa) If ObjGral.GetModelos(UsuarioActual.CveEmpresa) Then DtModelos = ObjGral.DtResultados.Copy End If If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then DTPS = ObjPS.DtResultados End If Dim NuevaClasificacion As Boolean = False For Each Row As DataRow In dt.FiltraParametros("Descripcion <> ''").Rows Dim Codigo As String = Row("Codigo").ToString() Dim Descripcion As String = Row("Descripcion").ToString() Dim TipoPS As String = Row("Tipo").ToString().Trim.ToUpper Dim CodigoBarras As String = Row("Código Barras").ToString() Dim UnidadMedida As String = Row("Unidad Medida").ToString().Trim Dim Clasificacion As String = Row("Clasificacion").ToString().Trim Dim Marca As String = Row("Marca").ToString().Trim Dim AplicaSerie As Boolean = If(Row("AplicaSerie").ToString().Trim.ToUpper.Contiene("1", "SI"), True, False) Dim Precio As Double = Row("Precio").ToString().ToDouble Dim IEPS As Decimal = If(Row.Table.Columns.Contains("IEPS"), Row("IEPS").ToString().Trim.ToDecimal, -1) Dim Tamaño As String = If(Row.Table.Columns.Contains("Tamaño"), Row("Tamaño").ToString().Trim, "") Dim SATClavePS As String = Row("Código SAT").ToString().Trim Dim Clasificacion2 As String = If(dt.Columns.Contains("Clasificacion2"), Row("Clasificacion2").ToString().Trim, "") Dim Litraje As Double = If(dt.Columns.Contains("Conversion Unidad"), Row("Conversion Unidad").ToString().ToDouble, 0) Dim RinTamaño As String = If(Row.Table.Columns.Contains("Tamaño de Rin"), Row("Tamaño de Rin").ToString().Trim, "") Dim Medida As String = If(Row.Table.Columns.Contains("Medida"), Row("Medida").ToString().Trim, "") Dim SATClaveUnidadMedida As String = If(Row.Table.Columns.Contains("Clave Unidad"), Row("Clave Unidad").ToString().Trim, "") Dim Linea As String = If(Row.Table.Columns.Contains("Linea"), Row("Linea").ToString().Trim, "") Dim Modelo As String = If(Row.Table.Columns.Contains("Modelo"), Row("Modelo").ToString().Trim, "") Dim RetIVA As Decimal = If(Row.Table.Columns.Contains("RetIVA"), Row("RetIVA").ToString().Trim.ToDecimal, 0D) Dim NumeroParte As String = If(Row.Table.Columns.Contains("NumeroParte"), Row("NumeroParte").ToString().Trim, "") Dim CvePS As Integer = DTPS.FiltroPrimeroValor("CvePS", $"Codigo = '{Codigo}'").ToString().ToEntero() Dim CveTipoPS As Integer = If(TipoPS.ToUpper = "PRODUCTO", 2, 1) Dim CveClasificacion As Integer = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{Clasificacion}'").ToString().ToEntero() Dim CveUnidadMedida As Integer = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUnidadMedida", $"UnidadMedida = '{UnidadMedida}' OR Abreviatura = '{UnidadMedida}'").ToString().ToEntero() Dim CveSATPS As Integer = ClsPaginas.GlobalDTPSATPS("-1", CodigoSAT:=SATClavePS).FiltroPrimeroValor("CveSATPS", "").ToEntero() Dim CveTamaño As Integer = GlobalDTAcumTamaños(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTamaño", $"Tamaño = '{Tamaño}' ").ToString().ToEntero() Dim CveClasificacion2 As Integer = GlobalDTClasificaciones2(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{Clasificacion2}'").ToString().ToEntero() Dim CveClasificacionDetalle As Integer = GlobalDTClasificacionesDetalle(UsuarioActual.CveEmpresa, -1).FiltroPrimeroValor("CveClasificacionDetalle", $"ClasificacionDetalle = '{Linea}'").ToString().ToEntero() If Not CveClasificacion > 0 AndAlso Clasificacion <> "" Then If ObjClas.AddClasificaciones(Clasificacion, "", GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveCategoria", "").ToString().ToEntero(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then GlobalDTClasificaciones(UsuarioActual.CveEmpresa) = Nothing CveClasificacion = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{Clasificacion}'").ToString().ToEntero() NuevaClasificacion = True End If End If If Not CveUnidadMedida > 0 AndAlso UnidadMedida <> "" Then If ObjUM.AddUnidadMedida(UnidadMedida, UnidadMedida, "", "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).ToEntero() > 0 Then GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) = Nothing CveUnidadMedida = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUnidadMedida", $"UnidadMedida = '{UnidadMedida}'").ToString().ToEntero() End If End If Dim CveMarca As Integer = -1 If Marca <> "" AndAlso DtMarcas IsNot Nothing Then CveMarca = DtMarcas.FiltroPrimeroValor("CveMarca", $"Marca = '{Marca}'").ToString().ToEntero() If Not CveMarca > 0 Then If ObjPS.AddMarcas(Marca, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then If ObjPS.GetMarcas(UsuarioActual.CveEmpresa) Then DtMarcas = ObjPS.DtResultados.Copy CveMarca = DtMarcas.FiltroPrimeroValor("CveMarca", $"Marca = '{Marca}'").ToString().ToEntero() End If End If End If End If Dim CveMedida As Integer = -1 If Medida <> "" AndAlso DtMedidas IsNot Nothing Then CveMedida = DtMedidas.FiltroPrimeroValor("CveMedida", $"Medida = '{Medida}'").ToString().ToEntero() If Not CveMedida > 0 Then If ObjGral.AddMedidas(CveClasificacion, "", Medida, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then If ObjGral.GetMedidas(UsuarioActual.CveEmpresa) Then DtMedidas = ObjGral.DtResultados.Copy CveMedida = DtMedidas.FiltroPrimeroValor("CveMedida", $"Medida = '{Medida}'").ToString().ToEntero() End If End If End If End If Dim CveRinTamaño As Integer = -1 If RinTamaño <> "" AndAlso DtRinTamaño IsNot Nothing Then CveRinTamaño = DtRinTamaño.FiltroPrimeroValor("CveRinTamaño", $"RinTamaño = '{RinTamaño}'").ToString().ToEntero() If Not CveRinTamaño > 0 Then If ObjGral.AddRimTamanios(CveClasificacion, "", RinTamaño, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then If ObjGral.GetRinTamanios(UsuarioActual.CveEmpresa) Then DtRinTamaño = ObjGral.DtResultados.Copy CveRinTamaño = DtRinTamaño.FiltroPrimeroValor("CveRinTamaño", $"RinTamaño = '{RinTamaño}'").ToString().ToEntero() End If End If End If End If Dim CveModelo As Integer = -1 If Modelo <> "" AndAlso DtModelos IsNot Nothing Then CveModelo = DtModelos.FiltroPrimeroValor("CveModelo", $"Modelo = '{Modelo}'").ToString().ToEntero() If Not CveModelo > 0 Then If ObjGral.AddModelos(CveMarca, "", Modelo, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then If ObjGral.GetModelos(UsuarioActual.CveEmpresa) Then DtModelos = ObjGral.DtResultados.Copy CveModelo = DtModelos.FiltroPrimeroValor("CveModelo", $"Modelo = '{Modelo}'").ToString().ToEntero() End If End If End If End If If Not CveClasificacion2 > 0 AndAlso Clasificacion2 <> "" Then Dim CveCategoria As Integer If ObjGral.GetCategorias(UsuarioActual.CveEmpresa, 4) Then CveCategoria = ObjGral.DtResultados.FiltroPrimeroValor("CveCategoria", "").ToEntero() End If If Not CveCategoria > 0 Then If ObjGral.AddCategorias(Clasificacion2, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 4) Then If ObjGral.GetCategorias(UsuarioActual.CveEmpresa, 4) Then CveCategoria = ObjGral.DtResultados.FiltroPrimeroValor("CveCategoria", "").ToEntero() End If End If End If If ObjClas.GetClasificaciones(UsuarioActual.CveEmpresa) Then CveClasificacion2 = ObjClas.DtResultados.FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{ Clasificacion2.Trim }'").ToEntero() End If If CveClasificacion2 = 0 Then If ObjClas.AddClasificaciones(Clasificacion2, "", CveCategoria, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then If ObjClas.GetClasificaciones(Tipo:=4) Then Application("GlobalDTClasificaciones2") = ObjClas.DtResultados CveClasificacion2 = GlobalDTClasificaciones2(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{Clasificacion2}'").ToString().ToEntero() End If End If End If If Not CveClasificacion > 0 AndAlso Clasificacion <> "" Then Alert("No se encontró la Clasificación: " + Clasificacion, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If Not CveUnidadMedida > 0 AndAlso UnidadMedida <> "" Then Alert("No se encontró la Unidad de Medida: " + UnidadMedida, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If Not CveSATPS > 0 AndAlso SATClavePS <> "" Then Alert("No se encontró la Clve SAT PS: " + SATClavePS, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If Not CveMarca > 0 AndAlso Marca <> "" Then Alert("No se encontró la Marca: " + Marca, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If Not CveMedida > 0 AndAlso Medida <> "" Then Alert("No se encontró la Media: " + Medida, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If Not CveRinTamaño > 0 AndAlso RinTamaño <> "" Then Alert("No se encontró el Tamaño: " + RinTamaño, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If Not CveModelo > 0 AndAlso Modelo <> "" Then Alert("No se encontró el Modelo: " + Modelo, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For 'If Not CveClasificacion2 > 0 AndAlso Clasificacion2 <> "" Then Alert("No se encontró la Serie: " + Clasificacion2, TipoMensaje.MsgAdvertencia) : ErrorPS = True : Exit For If CvePS > 0 Then If Not ObjPS.UpdatePS(CveClasificacion, 1, CveUnidadMedida, Codigo, NumeroParte, CodigoBarras, Descripcion, Precio, -1, RetIVA, False, -1, True, True, True, UsuarioActual.CveUsuario, CvePS, -1, -1, CveSATPS, UsuarioActual.CveEmpresa, CveTipoPS:=CveTipoPS, CveMarca:=CveMarca, CveMedida:=CveMedida, CveRinTamaño:=CveRinTamaño, CveModelo:=CveModelo, Litraje:=Litraje, IEPSPorcentaje:=IEPS, CveClasificacion2:=CveClasificacion2, CveTamaño:=CveTamaño, AplicaSerie:=AplicaSerie, CveObjetoImpuesto:=2) Then 'If Not ObjPS.UpdatePS(CveClasificacion, 1, CveUnidadMedida, Codigo, "", CodigoBarras, Descripcion, 0, 1, 1, False, 0, True, True, True, UsuarioActual.CveUsuario, CvePS, -1, -1, CveSATPS, ' CveTipoPS:=CveTipoPS, CveMarca:=CveMarca, CveTamaño:=CveTamaño, CveMedida:=CveMedida) Then ErrorPS = True Codigo.GuardaLog Exit For Else Contador += 1 End If Else 'If Codigo.Length > 0 Then If ObjPS.AddPS(CveClasificacion, 1, CveUnidadMedida, Codigo, NumeroParte, CodigoBarras, Descripcion, Precio, -1, RetIVA, False, 0, False, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, 1, CveTipoPS:=CveTipoPS, CveSATPS:=CveSATPS, CveMarca:=CveMarca, CveTamaño:=CveTamaño, CveMedida:=CveMedida, CveRinTamaño:=CveRinTamaño, CveModelo:=CveModelo, Litraje:=Litraje, IEPSPorcentaje:=IEPS, CveClasificacion2:=CveClasificacion2, CveClasificacionDetalle:=CveClasificacionDetalle, AplicaSerie:=AplicaSerie, CveObjetoImpuesto:=2) <= 0 Then 'If ObjPS.AddPS(CveClasificacion, 1, CveUnidadMedida, Codigo, "", "", Descripcion, 0, 0, 0, False, 0, False, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, 1, ' CveTipoPS:=CveTipoPS, CveSATPS:=CveSATPS, CveMarca:=CveMarca, CveTamaño:=CveTamaño, CveMedida:=CveMedida) <= 0 Then ErrorPS = True Codigo.GuardaLog Exit For 'Else ' If ObjPS.GetPS(-1, -1, UsuarioActual.CveEmpresa) Then ' DTPS = ObjPS.DtResultados ' End If End If 'End If End If Next If Not ErrorPS Then ObjPS.Commit() GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) = Nothing 'If ObjPS.GetPSSimplificado(-1) Then Application("GlobalDTPSSimplificado") = ObjPS.DtResultados.AsEnumerable() If Contador > 0 Then Alert(String.Format("Se agregaron: {0} Productos/Servicios correctamente.
Se Actualizaron: {1} Productos/Servicios ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion) Else Alert(String.Format("Se agregaron: {0} Productos/Servicios correctamente.", NumRows), TipoMensaje.MsgInformacion) End If TxtExcel.Text = "" UpDatos.Update() Else ObjPS.RollBack() If NuevaClasificacion Then GlobalDTClasificaciones(UsuarioActual.CveEmpresa) = Nothing End If End If ObjPS.Dispose() ObjGral.Dispose() ObjClas.Dispose() ObjVenta.Dispose() ObjUM.Dispose() #End Region 'P R O V E E D O R E S ElseIf RblFormato.SelectedValue = "1" Then #Region "P R O V E E D O R E S" Dim ObjProv As New ClsCompProveedores Dim ErrorProv As Boolean = False Dim Contador As Integer = 0 Dim ExisteProveedor As Boolean = False If Not dt.Columns.Contains("CveCuentaContable") Then dt.Columns.Add("CveCuentaContable", GetType(Integer)) End If Dim sbErrores As New StringBuilder For Each Row As DataRow In dt.Rows Dim RazonSocial As String = Row("RazonSocial").ToString() Dim CuentaContable As String = Row("CuentaContable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then Dim CveCuentaContable As Integer = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then Row("CveCuentaContable") = CveCuentaContable Else sbErrores.AppendLine($"Proveedor {RazonSocial} cuenta {CuentaContable} no encontrada.
") ErrorProv = True End If End If Next For Each Row As DataRow In dt.FiltraParametros("RazonSocial <> ''").Rows Dim RazonSocial As String = Row("RazonSocial").ToString() If Not (Row("TipoProveedor").ToString().Trim.ToUpper).Contiene("PROVEEDOR", "ACREEDOR") Then sbErrores.AppendLine($"Proveedor {RazonSocial} TipoProveedor {Row("TipoProveedor")} invalido.
") ErrorProv = True End If Next If Not ErrorProv Then dt.AcceptChanges() Else Alert($"Errores detectados
{sbErrores.ToString()}", TipoMensaje.MsgAdvertencia) ObjProv.Dispose() Exit Sub End If Dim DTClasificaciones As New DataTable Using ObjClasificaciones As New ClsClasificaciones If ObjClasificaciones.GetClasificaciones(UsuarioActual.CveEmpresa) Then DTClasificaciones = ObjClasificaciones.DtResultados End If End Using ObjProv.IniciaTransacSQL() For Each Row As DataRow In dt.FiltraParametros("RazonSocial <> ''").Rows Dim Codigo As String = Row("Codigo").ToString() Dim RazonSocial As String = Row("RazonSocial").ToString() If RazonSocial.Trim.Length = 0 Then Continue For End If Dim RFC As String = Row("RFC").ToString().Trim Dim Dirrecion As String = $"{ Row("Población").ToString()}, { Row("Estado").ToString()} , Colonia { Row("Colonia").ToString()}, {Row("Calle").ToString()} #{Row("Número exterior").ToString()}" 'Dim NumExt As String = Row("Número exterior").ToString() ' Dim Colonia As String = Row("Colonia").ToString() Dim CodigoPostal As Integer = Row("Código Postal").ToString().ToEntero() ' Dim Poblacion As String = Row("Población").ToString() 'Dim Estado As String = Row("Estado").ToString() Dim Telefono As String = Row("Teléfono").ToString() Dim ContactoMail As String = Row("Contacto").ToString() Dim CelularContacto As String = Row("Celular Contacto").ToString() Dim LimiteCredito As Double = Row("Limite Credito").ToString().ToDouble Dim PlazoCobranza As Integer = Row("Plazo Cobranza").ToString().ToEntero() Dim Banco As String = Row("Banco").ToString() Dim NumeroCuenta As String = Row("N° CUENTA").ToString().Replace("-", "").Replace(" ", "") Dim ClabeInter As String = Row("Clabe Inter").ToString().Replace("-", "").Replace(" ", "") Dim CveProveedor As Integer = GlobalDTCompProveedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveProveedor", $"RFC = '{RFC}'").ToString().ToEntero() Dim CveProveedor2 As Integer = GlobalDTCompProveedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveProveedor", $"RazonSocial = '{RazonSocial}'").ToString().ToEntero() Dim CveProveedor3 As Integer = 0 Dim CveCuentaContable As Integer = Row("CveCuentaContable").ToString().ToEntero() Dim TipoProveedor As Integer = If(Row("TipoProveedor").ToString().ToUpper = "PROVEEDOR", 1, 2) Dim CveConceptoCuentaAsiganaciones As Integer = If(TipoProveedor = 1, 5, 305) If Codigo.Trim.Length > 0 Then CveProveedor3 = GlobalDTCompProveedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveProveedor", $"Codigo = '{Codigo}'").ToString().ToEntero() End If Dim CodigoRegimenFiscal As String = Row("Regimen Fiscal").ToString() Dim ProveedorClasificacion As String = Row("Clasificación Proveedor").ToString() Dim Moneda As String = Row("Moneda Preferente").ToString() Dim DIOTTipoTercero As String = Row("Tipo Tercero").ToString().Trim.ToUpper Dim DIOTipoOperacion As String = Row("Tipo Operación").ToString() Dim CveMoneda As Integer = -1 Dim CveProveedorClasificacion As Integer = -1 Dim CveRegimenFiscal As Integer = 0 Dim DIOTCveTipoTercero As Integer = 0 Dim DIOTCveTipoOperacion As Integer = 0 If DIOTTipoTercero.Length > 0 Then Select Case DIOTTipoTercero Case "PROVEEDOR NACIONAL" DIOTCveTipoTercero = 1 Exit Select Case "PROVEEDOR EXTRANJERO" DIOTCveTipoTercero = 2 Exit Select Case "ACCIONISTAS, SOCIOS O INTEGRANTES" DIOTCveTipoTercero = 3 Exit Select Case "RETENCIONES (EXCEPTO PROVEEDORES)" DIOTCveTipoTercero = 4 Exit Select Case "PROVEEDOR NACIONAL GLOBAL" DIOTCveTipoTercero = 5 Exit Select Case "PROVEEDOR EXTRANJERO GLOBAL" DIOTCveTipoTercero = 6 Exit Select Case "EGRESOS VARIOS" DIOTCveTipoTercero = 7 Case Else DIOTCveTipoTercero = 0 Exit Select End Select If Not DIOTCveTipoTercero > 0 Then sbErrores.AppendLine($"Proveedor {RazonSocial} Tipo Tercero {DIOTTipoTercero} invalida.
") ErrorProv = True End If End If If DIOTipoOperacion.Length > 0 Then Select Case DIOTipoOperacion Case "03", "3" DIOTCveTipoOperacion = 1 Exit Select Case "06", "6" DIOTCveTipoOperacion = 2 Exit Select Case "85" DIOTCveTipoOperacion = 3 Exit Select Case Else DIOTCveTipoOperacion = 0 Exit Select End Select If Not DIOTCveTipoOperacion > 0 Then sbErrores.AppendLine($"Proveedor {RazonSocial} Tipo Operación {DIOTipoOperacion} invalida.
") ErrorProv = True End If End If If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN", "MONEDA NACIONAL") Then CveMoneda = 1 ElseIf Moneda.ToUpper.Contiene("DOLARES", "DOLAR", "USD", "DÓLARES") Then CveMoneda = 2 Else sbErrores.AppendLine($"Proveedor {RazonSocial} Moneda {Moneda} invalida.
") ErrorProv = True End If If ProveedorClasificacion.Trim.Length > 0 Then CveProveedorClasificacion = GlobalDTProveedorClasificacion(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveProveedorClasificacion", $"ProveedorClasificacion = '{ProveedorClasificacion}'").ToString().ToEntero() If Not CveProveedorClasificacion > 0 Then sbErrores.AppendLine($"Proveedor {RazonSocial} Proveedor Clasificacion {ProveedorClasificacion} invalida.
") ErrorProv = True End If End If If CodigoRegimenFiscal.Trim.Length > 0 Then CveRegimenFiscal = GlobalDTRegimenesFiscales.FiltroPrimeroValor("CveRegimenFiscal", $"CodigoRegimenFiscal= '{CodigoRegimenFiscal}' ").ToEntero() If Not CveRegimenFiscal > 0 Then sbErrores.AppendLine($"Proveedor {RazonSocial} Codigo RegimenFiscal {CodigoRegimenFiscal} invalido.
") ErrorProv = True End If End If If ErrorProv Then Alert($"Errores detectados
{sbErrores.ToString()}", TipoMensaje.MsgAdvertencia) Exit For End If If CveProveedor > 0 Or CveProveedor2 > 0 Or CveProveedor3 > 0 Then Contador = Contador + 1 'If Not ObjProv.UpdateProveedor(Codigo, RazonSocial, RazonSocial, RazonSocial, RFC, Calle, Telefono, ' Contacto, "", Telefono, LimiteCredito, PlazoCobranza, "", 0, 0, 0, -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", ' -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, -1, True, "", "", False, CveProveedor) Then ' ErrorProv = True ' Exit For 'End If Else Telefono = Telefono.Replace("-", "").Replace("(", "").Replace(")", "").Trim CelularContacto = CelularContacto.Replace("-", "").Replace("(", "").Replace(")", "").Trim Telefono = If(Telefono.Length > 10, "", Telefono) CelularContacto = If(CelularContacto.Length > 10, "", Telefono) If Not ObjProv.AddProveedor(Codigo, RazonSocial, RazonSocial, RazonSocial, RFC, Dirrecion, Telefono, "", ContactoMail, CelularContacto, LimiteCredito, PlazoCobranza, "", 0, 0, 0, CveProveedorClasificacion, -1, "", "", False, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CP:=CodigoPostal, CveRegimenFiscal:=CveRegimenFiscal, CveTipoProveedor:=TipoProveedor, CveMonedaPreferente:=CveMoneda, DIOTCveTipoTercero:=DIOTCveTipoTercero, DIOTCveTipoOperacion:=DIOTCveTipoOperacion) Then Alert("." & RFC) ErrorProv = True Exit For Else Dim ErrorCuentaDeposito As Boolean = False 'RESTRICCIONES GENERALES 'QUE TENGA ALGUN DATO DE TIPO DE CUENTA If NumeroCuenta.Trim.Length = 0 AndAlso ClabeInter.Trim.Length = 0 Then ErrorCuentaDeposito = True End If 'SI CLABE TIENE ALGO DEBE TENER UNA LOGITUD EXACTA DE 18 If ClabeInter.Trim.Length <> 0 AndAlso ClabeInter.Trim.Length <> 18 Then ErrorCuentaDeposito = True End If If Not ErrorCuentaDeposito Then Dim ObjGrales As New ClsGenerales(ObjProv.IniciaTransacSQL) If Not ObjGrales.AddCuentasDepositos(Banco, "", "", NumeroCuenta, ClabeInter, "", "", "", "", UsuarioActual.CveUsuario, 1, UsuarioActual.CveEmpresa, CveProveedor:=ObjProv.CveProveedor) Then 'ErrorProv = True End If End If If CveCuentaContable > 0 Then Dim ObjConta As New ClsContabilidad(ObjProv.IniciaTransacSQL) If Not ObjConta.AddCuentasAsignaciones(CveConceptoCuentaAsiganaciones, UsuarioActual.CveEmpresa, CveCuentaContable, ObjProv.CveProveedor, -1, -1, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=-1, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorProv = True End If End If End If End If Next If Not ErrorProv Then ObjProv.Commit() If ObjProv.GetProveedores(ClsCompProveedores.TipoConsulta.ParaGlobalDT, -1, "-1", "-1", "-1", "-1", "-1", "-1", "-1", -1, -1) Then Application("GlobalDTCompProveedores") = ObjProv.DtResultados If Contador > 0 Then Alert(String.Format("Se agregaron: {0} Proveedores correctamente.
Se Omitieron: {1} Proveedores ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion) Else Alert(String.Format("Se agregaron: {0} Proveedores correctamente.", NumRows), TipoMensaje.MsgInformacion) End If TxtExcel.Text = "" UpDatos.Update() Else ObjProv.RollBack() End If ObjProv.Dispose() #End Region ' C L I E N T E S ElseIf RblFormato.SelectedValue = "2" Then #Region "C L I E N T E S" Dim ObjClientes As New ClsClientes Dim ErrorClientes As Boolean = False Dim ExisteCliente As Boolean = False Dim Contador As Integer = 0 Dim CountRFCGenerico As Integer = 0 Dim NumRow As Integer = 0 If Not dt.Columns.Contains("CveCuentaContable") Then dt.Columns.Add("CveCuentaContable", GetType(Integer)) End If Dim sbErrores As New StringBuilder Dim CveCuentaContable As Integer If dt.Columns.Contains("CuentaContable") Then For Each Row As DataRow In dt.Rows Dim RazonSocial As String = Row("RazonSocial").ToString() Dim CuentaContable As String = Row("CuentaContable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then CveCuentaContable = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then Row("CveCuentaContable") = CveCuentaContable Else sbErrores.AppendLine($"Cliente {RazonSocial} cuenta {CuentaContable} no encontrada.
") ErrorClientes = True End If End If Next End If If Not ErrorClientes Then dt.AcceptChanges() Else Alert($"Errores detectados
{sbErrores.ToString()}", TipoMensaje.MsgAdvertencia) ObjClientes.Dispose() Exit Sub End If ObjClientes.IniciaTransacSQL() For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows NumRow = NumRow + 1 Dim Codigo As String = Row("Codigo").ToString().Trim Dim RazonSocial As String = Row("RazonSocial").ToString().Trim Dim RFC As String = Row("RFC").ToString().Trim Dim Calle As String = Row("Calle").ToString().Trim Dim NumExt As String = Row("Número exterior").ToString().Trim Dim NumInt As String = If(dt.Columns.Contains("Número interior"), Row("Número interior").ToString(), "").Trim Dim Colonia As String = Row("Colonia").ToString().Trim Dim CodigoPostal As String = Row("Código Postal").ToString().Trim Dim Poblacion As String = Row("Población").ToString().Trim Dim Estado As String = Row("Estado").ToString().Trim Dim Pais As String = If(dt.Columns.Contains("Pais"), Row("Pais").ToString(), "").Trim Dim Telefono As String = Row("Teléfono").ToString().Replace("-", "").Replace(" ", "").Replace("(", "").Replace(")", "").Trim Dim Contacto As String = If(dt.Columns.Contains("Contacto"), Row("Contacto").ToString(), "").Trim Dim Correo As String = If(dt.Columns.Contains("Correo"), Row("Correo").ToString(), "").Trim Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "").Trim Dim Clasificacion As String = If(dt.Columns.Contains("ClasificacionCliente"), Row("ClasificacionCliente").ToString(), "").Trim Dim CveCliente As Integer = -1 'GlobalDTCliente(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() Dim EsRFCGenerico As Boolean = If(RFC.ToUpper = "XAXX010101000" Or RFC.ToUpper = "XEXX010101000" Or RFC.ToUpper = "AAA010101AAA", True, False) 'If CveCliente <= 0 And Not EsRFCGenerico Then ' If ObjClientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa:=UsuarioActual.CveEmpresa, Estatus:=-1) Then ' CveCliente = ObjClientes.DtResultados.Copy().FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() ' End If 'End If Dim CveVendedor As Integer = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() Dim CveClasificación As Integer = GlobalDTClienteClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClienteClasificacion", $"ClienteClasificacion = '{Clasificacion}'").ToEntero() Dim EsDistribuidor As Boolean = If(dt.Columns.Contains("Es distribuidor"), If(Row("Es distribuidor").ToString().ToUpper = "SI", True, False), False) Dim CargoUsado As Boolean = If(dt.Columns.Contains("Cargo Usados"), If(Row("Cargo Usados").ToString().ToUpper = "SI", True, False), False) Dim BonificacionUsado As Boolean = If(dt.Columns.Contains("EmitirBon Usado"), If(Row("EmitirBon Usado").ToString().ToUpper = "SI", True, False), False) Dim LimiteCredito As Decimal = If(dt.Columns.Contains("Limite Credito"), Row("Limite Credito").ToString(), "").ToDecimal Dim CobranzaCorreo As String = If(dt.Columns.Contains("CorreoPagos"), Row("CorreoPagos").ToString(), "").Trim Dim PlazoCobranza As Integer = If(dt.Columns.Contains("Plazo Cobranza"), Row("Plazo Cobranza").ToString(), "").ToEntero Dim DìaVisita As String = If(dt.Columns.Contains("Dia Pago"), Row("Dia Pago").ToString(), "").Trim Dim DiasPagoEspecifico As String = If(dt.Columns.Contains("Dìa Visita"), Row("Dìa Visita").ToString(), "").Trim Dim CobranzaContacto As String = If(dt.Columns.Contains("Encargado Pago"), Row("Encargado Pago").ToString(), "").Trim Dim CobranzaTelefono As String = If(dt.Columns.Contains("Celular Contacto"), Row("Celular Contacto").ToString(), "").Replace("-", "").Replace(" ", "").Replace("(", "").Replace(")", "").Trim Dim CveUsoCFDI As Integer = If(Row("UsoCFDI").ToString() = "", -1, GlobalDTSATUsosCFDI().FiltroPrimeroValor("CveUsoCFDI", String.Format("UsoCFDI = '{0}' OR UsoCFDIDescripcion = '{0}'", Row("UsoCFDI").ToString())).ToEntero()) Dim CuentaContable As String = If(dt.Columns.Contains("CuentaContable"), Row("CuentaContable").ToString(), "").Trim Dim RegimenSociedad As String = If(dt.Columns.Contains("RegimenSociedad"), Row("RegimenSociedad").ToString(), "").Trim Dim Pagina As String = If(dt.Columns.Contains("Pagina"), Row("Pagina").ToString(), "").Trim Dim CodigoRegimenFiscal As String = Row("RegimenFiscal").ToString.Trim Dim CveRegimenFiscal As Integer = 0 Dim TipoPersona As Boolean = If(RFC.Length = 12, True, False) If CodigoRegimenFiscal.Trim.Length > 0 Then CveRegimenFiscal = GlobalDTRegimenesFiscales.FiltroPrimeroValor("CveRegimenFiscal", $"CodigoRegimenFiscal= '{CodigoRegimenFiscal}' ").ToEntero() If Not CveRegimenFiscal > 0 Then sbErrores.AppendLine($"Proveedor {RazonSocial} Código RegimenFiscal {CodigoRegimenFiscal} invalido.
") End If End If CuentaContable = CuentaContable.Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then CveCuentaContable = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable <= 0 Then sbErrores.AppendLine($"Cliente {RazonSocial} cuenta {CuentaContable} no encontrada.
") ErrorClientes = True End If End If 'Telefono If Telefono.Trim.Length > 10 Then Telefono = "" If CobranzaTelefono.Trim.Length > 10 Then CobranzaTelefono = "" Dim FormaPago As String = If(dt.Columns.Contains("Forma Pago"), Row("Forma Pago").ToString(), "") Dim CveFormaPago33 As Integer = 99 Select Case FormaPago Case "01" CveFormaPago33 = 1 Exit Select Case "02" CveFormaPago33 = 2 Exit Select Case "03" CveFormaPago33 = 3 Exit Select Case "04" CveFormaPago33 = 4 Exit Select Case "05" CveFormaPago33 = 5 Exit Select Case "06" CveFormaPago33 = 6 Exit Select Case "08" CveFormaPago33 = 7 Exit Select Case "12" CveFormaPago33 = 8 Exit Select Case "13" CveFormaPago33 = 9 Exit Select Case "14" CveFormaPago33 = 10 Exit Select Case "15" CveFormaPago33 = 11 Exit Select Case "17" CveFormaPago33 = 12 Exit Select Case "23" CveFormaPago33 = 13 Exit Select Case "24" CveFormaPago33 = 14 Exit Select Case "25" CveFormaPago33 = 15 Exit Select Case "26" CveFormaPago33 = 16 Exit Select Case "27" CveFormaPago33 = 17 Exit Select Case "28" CveFormaPago33 = 18 Exit Select Case "29" CveFormaPago33 = 19 Exit Select Case "99" CveFormaPago33 = 20 Exit Select Case "30" CveFormaPago33 = 21 Exit Select Case "31" CveFormaPago33 = 22 Exit Select Case Else CveFormaPago33 = 99 End Select 'Contacto If CveCliente > 0 Then ExisteCliente = True 'PermiteCredito As Boolean, CveSubProyecto As Integer, CveClienteCorporativo As Integer, Dim CveSATEstado As Integer = GlobalDTGralEstados("-1").FiltroPrimeroValor("CveSATEstado", String.Format(" NombreEstado ='{0}'", Estado.ToUpper)).ToEntero() CveSATEstado = If(CveSATEstado > 0, CveSATEstado, -1) Dim PermiteCredito As Boolean = If(LimiteCredito > 0, True, False) If EsRFCGenerico Then CountRFCGenerico = CountRFCGenerico + 1 End If Codigo = If(Codigo.Trim.Length = 0, "-1", Codigo) If Not EsRFCGenerico AndAlso Not ObjClientes.UpdateCliente(RazonSocial, RazonSocial, Calle, NumExt.ToString(), NumInt, Colonia, Poblacion, Poblacion, Estado, Pais, RFC, CodigoPostal, Telefono, Contacto, Correo, "-1", "-1", Pagina, "-1", -1, False, -1, -1, False, True, "-1", CveVendedor, PlazoCobranza, -1, "-1", "-1", "-1", Codigo, LimiteCredito, False, "-1", "-1", "-1", False, "-1", "-1", "-1", "-1", "-1", False, "-1", UsuarioActual.CveUsuario, CveCliente, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "-1", "-1", PermiteCredito, -1, -1, EsDistribuidor:=EsDistribuidor, CveClienteClasificacion:=CveClasificación, CargoUsado:=CargoUsado, BonificacionUsado:=BonificacionUsado, CobranzaContacto:=CobranzaContacto, CobranzaCorreo:=CobranzaCorreo, DiasEspecifico:=DiasPagoEspecifico, DiasRevision:=DìaVisita, CobranzaTelefono:=CobranzaTelefono, CveFormaPago:=CveFormaPago33, CveUsoCFDI:=CveUsoCFDI, CveSATEstado:=CveSATEstado, CveAdminTrayecto:=0, RegimenSociedad:=RegimenSociedad, CveRegimenFiscal:=CveRegimenFiscal, TipoPersona:=TipoPersona) Then ErrorClientes = True RFC.GuardaLog Exit For Else If EsRFCGenerico Then CountRFCGenerico = CountRFCGenerico + 1 Else Contador = Contador + 1 End If End If If CveCuentaContable > 0 Then Dim ObjConta As New ClsContabilidad(ObjClientes.IniciaTransacSQL) If Not ObjConta.AddCuentasAsignaciones(1, UsuarioActual.CveEmpresa, CveCuentaContable, -1, ObjClientes.CveCliente, -1, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=-1, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorClientes = True End If End If Else Dim CveSATEstado As Integer = GlobalDTGralEstados("-1").FiltroPrimeroValor("CveSATEstado", String.Format(" NombreEstado ='{0}'", Estado.ToUpper)).ToEntero() CveSATEstado = If(CveSATEstado > 0, CveSATEstado, 26) If Not ObjClientes.AddCliente(RazonSocial, RazonSocial, Calle, NumExt.ToString(), NumInt, Colonia, Poblacion, Poblacion, Estado, Pais, RFC, CodigoPostal, Telefono, Contacto, Correo, "", "", Pagina, "", -1, False, 0, 0, False, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", CveVendedor, PlazoCobranza, -1, "-1", "-1", "-1", Codigo, LimiteCredito, False, "", "", "", False, "", "", "", "", "", False, "", "", "", False, 0, -1, EsDistribuidor:=EsDistribuidor, CveClienteClasificacion:=CveClasificación, CargoUsado:=CargoUsado, BonificacionUsado:=BonificacionUsado, CobranzaContacto:=CobranzaContacto, CobranzaCorreo:=CobranzaCorreo, DiasEspecifico:=DiasPagoEspecifico, DiasRevision:=DìaVisita, CobranzaTelefono:=CobranzaTelefono, CveFormaPago:=CveFormaPago33, CveUsoCFDI:=CveUsoCFDI, CveSATEstado:=CveSATEstado, CveAdminTrayecto:=0, RegimenSociedad:=RegimenSociedad, CveRegimenFiscal:=CveRegimenFiscal, TipoPersona:=TipoPersona) Then ErrorClientes = True RFC.GuardaLog Exit For Else GlobalDTCliente(UsuarioActual.CveEmpresa) = Nothing End If If CveCuentaContable > 0 Then Dim ObjConta As New ClsContabilidad(ObjClientes.IniciaTransacSQL) If Not ObjConta.AddCuentasAsignaciones(1, UsuarioActual.CveEmpresa, CveCuentaContable, -1, ObjClientes.CveCliente, -1, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=-1, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorClientes = True End If End If End If Next If Not ErrorClientes Then ObjClientes.Commit() 'If ObjClientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, -1) Then Application("GlobalDTCliente") = ObjClientes.DtResultados GlobalDTCliente(UsuarioActual.CveEmpresa) = Nothing If Contador > 0 Then Alert(String.Format("Se agregaron: {0} Clientes correctamente.
Se Omitieron: {1} Clientes ya que ya se encontraban registrados. RFC Genericos Omitidos {2}", NumRows - Contador, Contador, CountRFCGenerico), TipoMensaje.MsgInformacion) Else Alert(String.Format("Se agregaron: {0} Clientes correctamente.", NumRows), TipoMensaje.MsgInformacion) End If TxtExcel.Text = "" UpDatos.Update() Else ObjClientes.RollBack() End If ObjClientes.Dispose() #End Region 'P R O V E E D O R E S - F A C T U R A S ElseIf RblFormato.SelectedValue = "3" Then #Region "P R O V E E D O R E S - F A C T U R A S" Dim ObjCompras As New ClsCompras Dim ErrorCompras As Boolean = False Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) Dim CveCompra As Integer 'Dim Contador As Integer = 0 Dim ExisteCompra As Boolean = False Dim DtProveedores As New DataTable Dim NoEncontrados As Integer = 0 Dim Encontrados As Integer = 0 Dim RFC As String = "" Try DtProveedores = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("CveTipoPS = 1") Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) Dim CountRow As Integer = 1 For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") RFC = Row("RFC").ToString().Trim Dim Serie As String = Row("Serie").ToString().Trim Dim Folio As String = Row("Folio").ToString().Trim Dim Fecha As Date = Row("Fecha").ToString().ToDate Dim SubTotal As Decimal = Row("SubTotal").ToString().ToDecimal Dim IVA As Decimal = Row("IVA").ToString().ToDecimal.RoundSQL Dim Total As Decimal = Row("Total").ToString().ToDecimal.RoundSQL Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal.RoundSQL Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim.ToUpper Dim CveProveedor As Integer = DtProveedores.FiltroPrimeroValor("CveProveedor", $"RFC = '{RFC}'").ToString().ToEntero() GuardaLog(Sucursal + " - " + Row("Sucursal").ToString()) Dim RetIVA As Decimal = Row("Ret IVA").ToString().ToDecimal.RoundSQL Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal.RoundSQL Dim IEPS As Decimal = If(dt.Columns.Contains("IEPS"), Row("IEPS").ToString(), "0").ToDecimal.RoundSQL Dim Moneda As String = Row("Moneda").ToString() Dim TipoCambio As String = If(dt.Columns.Contains("Tipo Cambio"), Row("Tipo Cambio").ToString(), "1") Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate Dim CveMoneda As Integer = 1 Dim CveProveedorSucursal As Integer = If(dt.Columns.Contains("CveProveedorSucursal"), Row("CveProveedorSucursal").ToString(), "0").ToEntero Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Row("PorcentajeIVA").ToString(), "0").ToDecimal Dim ImpuestosLocales As Decimal = If(dt.Columns.Contains("ImpuestosLocales"), Row("ImpuestosLocales").ToString(), "0").ToDecimal Dim RetIVAPorcentaje As Decimal = If(dt.Columns.Contains("RetIVAPorcentaje"), Row("RetIVAPorcentaje").ToString(), "0").ToDecimal Dim RetISRPorcentaje As Decimal = If(dt.Columns.Contains("RetISRPorcentaje"), Row("RetISRPorcentaje").ToString(), "0").ToDecimal Dim CveSubProyecto As Integer = GlobalDTSubProyectos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", String.Format("SubProyecto='{0}'", If(dt.Columns.Contains("SubProyecto"), Row("SubProyecto").ToString(), ""))).ToEntero If CveSubProyecto = 0 Then CveSubProyecto = GlobalDTSubProyectos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto").ToEntero If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorCompras = True If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorCompras = True If Not CveProveedor > 0 Then Alert(String.Format("No se encontró el Proveedor con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorCompras = True : Exit For If Not CveProveedorSucursal > 0 Then CveProveedorSucursal = -1 If PorcentajeIVA > 0 AndAlso IVA = 0 Then PorcentajeIVA = 0 Dim RetIVAConcepto As String = If(dt.Columns.Contains("RetIVAConcepto"), Row("RetIVAConcepto").ToString(), "").ToUpper Dim RetISRConcepto As String = If(dt.Columns.Contains("RetISRConcepto"), Row("RetISRConcepto").ToString(), "").ToUpper Dim CveRetIVAConcepto As Integer = If(RetIVAConcepto = "HONORARIOS", 1, If(RetIVAConcepto = "FLETES", 2, If(RetIVAConcepto = "ARRENDAMIENTO", 4, -1))) Dim CveRetISRConcepto As Integer = If(RetISRConcepto = "HONORARIOS", 1, If(RetISRConcepto = "ARRENDAMIENTO", 2, If(RetISRConcepto = "RESICO", 4, -1))) TipoDocto = IIf(TipoDocto.Contiene("INGRESOS", "INGRESO", "ING", "FACTURA", "FACTURAS", ""), "Fac", "NC").ToString() 'RMF. falta validación de totales. 'Temporalmente SE BORRARA Dim Transaccion As String = "" 'Row("Transaccion2").ToString() Dim Folio2 As String = "" 'Row("Folio2").ToString() Dim CodProvee As String = "" 'Row("CodProvee2").ToString() 'Moneda If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN", "MONEDA NACIONAL") Then CveMoneda = 1 ElseIf Moneda.ToUpper.Contiene("DOLARES", "DOLAR", "USD", "DÓLARES", "DÓLAR") Then CveMoneda = 2 End If 'Si no se especifica TC, se manda como pesos. If TipoCambio = "" Then TipoCambio = "1" If CveMoneda = 2 AndAlso TipoCambio = "1" Then TipoCambio = GlobalTipoCambio(Fecha).ToString End If Dim IEPSDetalle As Decimal = 0 Dim CantidadDetalle As Decimal = 0 Dim PUDetalle As Decimal = 0 Dim IVADetalle As Decimal = 0 If RblFormato.SelectedValue = "18" Then Dim CodigoDetalle As String = Row("Codigo").ToString If CodigoDetalle.Trim.Length > 0 Then Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") If DrDetalles IsNot Nothing Then CvePS = DrDetalles("CvePS").ToString().ToEntero() CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() Else Alert($"El código del producto no se encontro, error en registro {CountRow}") ErrorCompras = True End If Else Alert($"El código es requerido, error en registro {CountRow}") ErrorCompras = True End If IEPSDetalle = Row("IEPS").ToString.ToDecimal CantidadDetalle = Row("Cantidad").ToString.ToDecimal PUDetalle = Row("PU").ToString.ToDecimal IVADetalle = Row("IVA").ToString.ToDecimal If CantidadDetalle = 0 Then Alert($"No se especifico la cantidad, error en registro {CountRow}") ErrorCompras = True End If End If 'PrePóliza Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Compras/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorCompras = True Exit For End If If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then FechaVencimiento = Fecha End If If Not ObjCompras.AddCompra(TipoDocto, "", Serie, Folio, Folio2, CveProveedor.ToEntero(), SubTotal + ImpuestosLocales, 0, 0, IVA, RetIVA, RetISR, IEPS, 0, 0, Total, Fecha, CveMoneda, TipoCambio.ToDecimal, FechaVencimiento, False, CodProvee, 1, CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveProveedorSucursal:=CveProveedorSucursal, NumeroReembolso:=Transaccion, PorcentajeIVA:=PorcentajeIVA, TotalOriginal:=Total, CveSubProyecto:=CveSubProyecto, CveRetIVAConcepto:=CveRetIVAConcepto, CveRetISRConcepto:=CveRetISRConcepto) Then ErrorCompras = True Exit For End If CveCompra = ObjCompras.CveCompra 'Compra Detalle If RblFormato.SelectedValue = "18" Then Dim TotalDetalles As Decimal = SubTotal If PUDetalle > 0 Then TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle End If If Math.Abs(TotalDetalles - Total) > 0.01 Then ErrorCompras = True Alert($"Registro {CountRow} El total no councide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) Exit For End If If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, CveSubProyecto, -1, 0, CantidadDetalle, PUDetalle, (CantidadDetalle * PUDetalle) * PorcentajeIVA, TotalDetalles, 0, "Carga Inicial", -1, IVAPorcentaje:=PorcentajeIVA, RetIVAPorcentaje:=RetIVAPorcentaje, RetISRPorcentaje:=RetISRPorcentaje, IEPSPS:=IEPSDetalle) Then ErrorCompras = True Exit For End If Else If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, CveSubProyecto, -1, 0, 1, SubTotal, SubTotal * PorcentajeIVA, SubTotal, 0, "Carga Inicial", -1, IVAPorcentaje:=PorcentajeIVA, RetIVAPorcentaje:=RetIVAPorcentaje, RetISRPorcentaje:=RetISRPorcentaje) Then ErrorCompras = True Exit For End If End If If ImpuestosLocales > 0 Then 'se agrega como parte de la partida, sin iva. If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, CveSubProyecto, -1, 0, 1, ImpuestosLocales, ImpuestosLocales, ImpuestosLocales, 0, "Carga Inicial", -1, IVAPorcentaje:=0, RetIVAPorcentaje:=0, RetISRPorcentaje:=0) Then ErrorCompras = True Exit For End If End If Dim ConceptoContablePago As Integer = 17 If TipoDocto = "NC" Then ConceptoContablePago = 60 'PrePólizaDetalle If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, IIf(TipoDocto = "Fac", 5, 18).ToString().ToEntero(), Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, SubTotal, SubTotal, 6, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If IVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, IVA, IVA, 14, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), CveClasificacion:=CveClasificacion, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorCompras = True : Exit For End If If IEPS > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, IEPS, IEPS, 25, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If RetIVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, RetIVA, RetIVA, 15, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If RetISR > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, RetISR, RetISR, 16, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For 'If ImpuestosLocales > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImpuestosLocales, ImpuestosLocales, 27, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For 'Saldo If Saldo < Total Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveCompra:=CveCompra, CveProveedor:=CveProveedor, Contabilizable:=False) Then ErrorCompras = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveCompra:=CveCompra, CveProveedor:=CveProveedor, Contabilizable:=False) Then ErrorCompras = True : Exit For End If Encontrados = Encontrados + 1 CountRow = CountRow + 1 Next Catch ex As Exception OnError("Ocurrió un error al cargar los datos", ex) ErrorCompras = True End Try If Not ErrorCompras Then 'If Encontrados > 0 Then ' Alert(String.Format("Se agregaron: {0} Compras correctamente.
Se Omitieron: {1} Compras ya que ya se encuentran registradas.", Encontrados, NumRows - 1 - Encontrados), TipoMensaje.MsgInformacion) 'Else ' Alert(String.Format("Se agregaron: {0} Compras correctamente.", Encontrados), TipoMensaje.MsgInformacion) 'End If Alert(String.Format("Se agregaron: {0} Compras correctamente.", Encontrados), TipoMensaje.MsgInformacion) 'Alert(String.Format("Se agregaron: {0} Compras correctamente. RFC:{1} ", Encontrados, RFC), TipoMensaje.MsgInformacion) ObjCompras.Commit() TxtExcel.Text = "" UpDatos.Update() Else Alert(String.Format("NO Se agregaron: {0} Compras.", NumRows), TipoMensaje.MsgError) ObjCompras.RollBack() End If ObjCompras.Dispose() ElseIf RblFormato.SelectedValue = "18" Then Dim ObjCompras As New ClsCompras Dim ErrorCompras As Boolean = False Dim ObjConta As New ClsContabilidad(ObjCompras.IniciaTransacSQL()) Dim CveCompra As Integer Dim CvePrePoliza As Integer 'Dim Contador As Integer = 0 Dim ExisteCompra As Boolean = False Dim DtProveedores As New DataTable Dim NoEncontrados As Integer = 0 Dim Encontrados As Integer = 0 Dim RFC As String = "" Try DtProveedores = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("") Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) If UsuarioActual.CveEmpresa = 189 Then For Each Row As DataRow In dt.Rows Dim SubTotal = Row("SubTotal").ToString().ToDecimal.RoundSQL Dim IVA = Row("IVA").ToString().ToDecimal.RoundSQL Dim Total = Row("Total").ToString().ToDecimal.RoundSQL Dim Cantidad = Row("Cantidad").ToString.ToDecimal Dim PU = Row("PU").ToString.ToDecimal If Total - SubTotal - IVA <> 0 Then Row("PU") = (Total - IVA) / Cantidad Row("SubTotal") = Row("PU").ToString.ToDecimal * Cantidad PU = Row("PU").ToString.ToDecimal SubTotal = Row("SubTotal").ToString().ToDecimal.RoundSQL End If If ((Cantidad * PU) - SubTotal) <> 0 Then Row("PU") = SubTotal / Cantidad End If Next dt.AcceptChanges() End If Dim CountRow As Integer = 1 Dim LastSerieFolioTipoDoc As String = String.Empty Dim EsDetalle As Boolean = False For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") RFC = Row("RFC").ToString().Trim Dim Serie As String = Row("Serie").ToString().Trim Dim Folio As String = Row("Folio").ToString().Trim Dim Fecha As Date = Row("Fecha").ToString().ToDate Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim.ToUpper Dim CveProveedor As Integer = 0 If UsuarioActual.CveEmpresa = 189 Then CveProveedor = DtProveedores.FiltroPrimeroValor("CveProveedor", $"RazonSocial = '{RFC}'").ToString().ToEntero() Else CveProveedor = DtProveedores.FiltroPrimeroValor("CveProveedor", $"RFC = '{RFC}'").ToString().ToEntero() End If GuardaLog(Sucursal + " - " + Row("Sucursal").ToString()) Dim Moneda As String = Row("Moneda").ToString() Dim TipoCambio As String = If(dt.Columns.Contains("Tipo Cambio"), Row("Tipo Cambio").ToString(), "1") Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate Dim CveMoneda As Integer = 1 Dim CveProveedorSucursal As Integer = If(dt.Columns.Contains("CveProveedorSucursal"), Row("CveProveedorSucursal").ToString(), "0").ToEntero Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Row("PorcentajeIVA").ToString(), "0").ToDecimal.RoundSQL Dim ImpuestosLocales As Decimal = If(dt.Columns.Contains("ImpuestosLocales"), Row("ImpuestosLocales").ToString(), "0").ToDecimal Dim RetIVAPorcentaje As Decimal = If(dt.Columns.Contains("RetIVAPorcentaje"), Row("RetIVAPorcentaje").ToString(), "0").ToDecimal Dim RetISRPorcentaje As Decimal = If(dt.Columns.Contains("RetISRPorcentaje"), Row("RetISRPorcentaje").ToString(), "0").ToDecimal Dim CveSubProyecto As Integer = GlobalDTSubProyectos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", String.Format("SubProyecto='{0}'", If(dt.Columns.Contains("SubProyecto"), Row("SubProyecto").ToString(), ""))).ToEntero If CveSubProyecto = 0 Then CveSubProyecto = GlobalDTSubProyectos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto").ToEntero If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorCompras = True If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorCompras = True If UsuarioActual.CveEmpresa = 189 Then If Not CveProveedor > 0 Then Alert(String.Format("No se encontró el Proveedor con la razon social: {0}", {RFC}), TipoMensaje.MsgError) : ErrorCompras = True : Exit For Else If Not CveProveedor > 0 Then Alert(String.Format("No se encontró el Proveedor con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorCompras = True : Exit For End If If Not CveProveedorSucursal > 0 Then CveProveedorSucursal = -1 If LastSerieFolioTipoDoc = $"{Folio}" AndAlso UsuarioActual.CveEmpresa = 189 Then EsDetalle = True Else LastSerieFolioTipoDoc = $"{Folio}" EsDetalle = False End If Dim SubTotal As Decimal = 0 Dim IVA As Decimal = 0 Dim Total As Decimal = 0 Dim Saldo As Decimal = 0 Dim RetIVA As Decimal = 0 Dim RetISR As Decimal = 0 Dim IEPS As Decimal = 0 If UsuarioActual.CveEmpresa = 189 AndAlso Not EsDetalle Then For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}'").Rows SubTotal += item("SubTotal").ToString().ToDecimal.RoundSQL IVA += item("IVA").ToString().ToDecimal.RoundSQL Total += item("Total").ToString().ToDecimal.RoundSQL Saldo += item("Saldo").ToString().ToDecimal.RoundSQL RetIVA += item("Ret IVA").ToString().ToDecimal.RoundSQL RetISR += item("Ret ISR").ToString().ToDecimal.RoundSQL IEPS += If(dt.Columns.Contains("IEPS"), Row("IEPS").ToString(), "0").ToDecimal.RoundSQL Next Else SubTotal = Row("SubTotal").ToString().ToDecimal.RoundSQL IVA = Row("IVA").ToString().ToDecimal.RoundSQL Total = Row("Total").ToString().ToDecimal.RoundSQL Saldo = Row("Saldo").ToString().ToDecimal.RoundSQL RetIVA = Row("Ret IVA").ToString().ToDecimal.RoundSQL RetISR = Row("Ret ISR").ToString().ToDecimal.RoundSQL IEPS = If(dt.Columns.Contains("IEPS"), Row("IEPS").ToString(), "0").ToDecimal.RoundSQL End If If PorcentajeIVA > 0 AndAlso IVA = 0 Then PorcentajeIVA = 0 Dim RetIVAConcepto As String = If(dt.Columns.Contains("RetIVAConcepto"), Row("RetIVAConcepto").ToString(), "").ToUpper Dim RetISRConcepto As String = If(dt.Columns.Contains("RetISRConcepto"), Row("RetISRConcepto").ToString(), "").ToUpper Dim CveRetIVAConcepto As Integer = If(RetIVAConcepto = "HONORARIOS", 1, If(RetIVAConcepto = "FLETES", 2, If(RetIVAConcepto = "ARRENDAMIENTO", 4, -1))) Dim CveRetISRConcepto As Integer = If(RetISRConcepto = "HONORARIOS", 1, If(RetISRConcepto = "ARRENDAMIENTO", 2, If(RetISRConcepto = "RESICO", 4, -1))) TipoDocto = IIf(TipoDocto.Contiene("INGRESOS", "INGRESO", "ING", "FACTURA", "FACTURAS", ""), "Fac", "NC").ToString() 'RMF. falta validación de totales. 'Temporalmente SE BORRARA Dim Transaccion As String = "" 'Row("Transaccion2").ToString() Dim Folio2 As String = "" 'Row("Folio2").ToString() Dim CodProvee As String = "" 'Row("CodProvee2").ToString() 'Moneda If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN", "MONEDA NACIONAL") Then CveMoneda = 1 ElseIf Moneda.ToUpper.Contiene("DOLARES", "DOLAR", "USD", "DÓLARES", "DÓLAR") Then CveMoneda = 2 End If 'Si no se especifica TC, se manda como pesos. If TipoCambio = "" Then TipoCambio = "1" If CveMoneda = 2 AndAlso TipoCambio = "1" Then TipoCambio = GlobalTipoCambio(Fecha).ToString End If Dim IEPSDetalle As Decimal = 0 Dim CantidadDetalle As Decimal = 0 Dim PUDetalle As Decimal = 0 Dim IVADetalle As Decimal = 0 If RblFormato.SelectedValue = "18" Then Dim CodigoDetalle As String = Row("Codigo").ToString If CodigoDetalle.Trim.Length > 0 Then Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") If DrDetalles IsNot Nothing Then CvePS = DrDetalles("CvePS").ToString().ToEntero() CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() Else Alert($"El código del producto no se encontro, error en registro {CountRow}") ErrorCompras = True End If Else Alert($"El código es requerido, error en registro {CountRow}") ErrorCompras = True End If IEPSDetalle = Row("IEPS").ToString.ToDecimal CantidadDetalle = Row("Cantidad").ToString.ToDecimal PUDetalle = Row("PU").ToString.ToDecimal IVADetalle = Row("IVA").ToString.ToDecimal If CantidadDetalle = 0 Then Alert($"No se especifico la cantidad, error en registro {CountRow}") ErrorCompras = True End If End If 'PrePóliza If Not EsDetalle Then CvePrePoliza = ObjConta.AddPrePolizas("Compras/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorCompras = True Exit For End If End If If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then FechaVencimiento = Fecha End If If Not EsDetalle Then If Not ObjCompras.AddCompra(TipoDocto, "", Serie, Folio, Folio2, CveProveedor.ToEntero(), SubTotal + ImpuestosLocales, 0, 0, IVA, RetIVA, RetISR, IEPS, 0, 0, Total, Fecha, CveMoneda, TipoCambio.ToDecimal, FechaVencimiento, False, CodProvee, 1, CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveProveedorSucursal:=CveProveedorSucursal, NumeroReembolso:=Transaccion, PorcentajeIVA:=PorcentajeIVA, TotalOriginal:=Total, CveSubProyecto:=CveSubProyecto, CveRetIVAConcepto:=CveRetIVAConcepto, CveRetISRConcepto:=CveRetISRConcepto) Then ErrorCompras = True Exit For End If CveCompra = ObjCompras.CveCompra SubTotal = Row("SubTotal").ToString().ToDecimal IVA = Row("IVA").ToString().ToDecimal Total = Row("Total").ToString().ToDecimal Saldo = Row("Saldo").ToString().ToDecimal RetIVA = Row("Ret IVA").ToString().ToDecimal RetISR = Row("Ret ISR").ToString().ToDecimal IEPS = Row("IEPS").ToString().ToDecimal End If 'Compra Detalle If RblFormato.SelectedValue = "18" Then Dim TotalDetalles As Decimal = SubTotal If PUDetalle > 0 Then TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle End If If Math.Abs(TotalDetalles - Total) > 0.01 Then ErrorCompras = True Alert($"Registro {CountRow} El total no councide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) Exit For End If If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, CveSubProyecto, -1, 0, CantidadDetalle, PUDetalle, (CantidadDetalle * PUDetalle) * PorcentajeIVA, TotalDetalles, 0, "Carga Inicial", -1, IVAPorcentaje:=PorcentajeIVA, RetIVAPorcentaje:=RetIVAPorcentaje, RetISRPorcentaje:=RetISRPorcentaje, IEPSPS:=IEPSDetalle) Then ErrorCompras = True Exit For End If Else If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, CveSubProyecto, -1, 0, 1, SubTotal, SubTotal * PorcentajeIVA, SubTotal, 0, "Carga Inicial", -1, IVAPorcentaje:=PorcentajeIVA, RetIVAPorcentaje:=RetIVAPorcentaje, RetISRPorcentaje:=RetISRPorcentaje) Then ErrorCompras = True Exit For End If End If If ImpuestosLocales > 0 Then 'se agrega como parte de la partida, sin iva. If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, CveSubProyecto, -1, 0, 1, ImpuestosLocales, ImpuestosLocales, ImpuestosLocales, 0, "Carga Inicial", -1, IVAPorcentaje:=0, RetIVAPorcentaje:=0, RetISRPorcentaje:=0) Then ErrorCompras = True Exit For End If End If Dim ConceptoContablePago As Integer = 17 If TipoDocto = "NC" Then ConceptoContablePago = 60 If Not EsDetalle Then SubTotal = 0 IVA = 0 Total = 0 Saldo = 0 RetIVA = 0 RetISR = 0 IEPS = 0 For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}'").Rows SubTotal += item("SubTotal").ToString().ToDecimal.RoundSQL IVA += item("IVA").ToString().ToDecimal.RoundSQL Total += item("Total").ToString().ToDecimal.RoundSQL Saldo += item("Saldo").ToString().ToDecimal.RoundSQL RetIVA += item("Ret IVA").ToString().ToDecimal.RoundSQL RetISR += item("Ret ISR").ToString().ToDecimal.RoundSQL IEPS += If(dt.Columns.Contains("IEPS"), Row("IEPS").ToString(), "0").ToDecimal.RoundSQL Next 'PrePólizaDetalle If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, IIf(TipoDocto = "Fac", 5, 18).ToString().ToEntero(), Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, SubTotal, SubTotal, 6, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If IVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, IVA, IVA, 14, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), CveClasificacion:=CveClasificacion, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorCompras = True : Exit For End If If IEPS > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, IEPS, IEPS, 25, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If RetIVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, RetIVA, RetIVA, 15, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For If RetISR > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, RetISR, RetISR, 16, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero(), Contabilizable:=False) Then ErrorCompras = True : Exit For 'If ImpuestosLocales > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImpuestosLocales, ImpuestosLocales, 27, Folio, String.Format("{0}-{1}", Serie, Folio), CveCompra:=CveCompra, CveProveedor:=CveProveedor, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For 'Saldo If Saldo < Total Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveCompra:=CveCompra, CveProveedor:=CveProveedor, Contabilizable:=False) Then ErrorCompras = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveCompra:=CveCompra, CveProveedor:=CveProveedor, Contabilizable:=False) Then ErrorCompras = True : Exit For End If End If Encontrados = Encontrados + 1 CountRow = CountRow + 1 Next Catch ex As Exception OnError("Ocurrió un error al cargar los datos", ex) ErrorCompras = True End Try If Not ErrorCompras Then 'If Encontrados > 0 Then ' Alert(String.Format("Se agregaron: {0} Compras correctamente.
Se Omitieron: {1} Compras ya que ya se encuentran registradas.", Encontrados, NumRows - 1 - Encontrados), TipoMensaje.MsgInformacion) 'Else ' Alert(String.Format("Se agregaron: {0} Compras correctamente.", Encontrados), TipoMensaje.MsgInformacion) 'End If Alert(String.Format("Se agregaron: {0} Compras correctamente.", Encontrados), TipoMensaje.MsgInformacion) 'Alert(String.Format("Se agregaron: {0} Compras correctamente. RFC:{1} ", Encontrados, RFC), TipoMensaje.MsgInformacion) ObjCompras.Commit() TxtExcel.Text = "" UpDatos.Update() Else Alert(String.Format("NO Se agregaron: {0} Compras.", NumRows), TipoMensaje.MsgError) ObjCompras.RollBack() End If ObjCompras.Dispose() #End Region 'C L I E N T E S - F A C T U R A S ElseIf RblFormato.SelectedValue = "4" Then RegistraVentas(dt, False) ElseIf RblFormato.SelectedValue = "17" Then RegistraVentas(dt, True) ' R H - P E R S O N A L ElseIf RblFormato.SelectedValue = "6" Then UpPersonal(dt, DTCuentasContables) ' A F - A C T I V O F I J O ElseIf RblFormato.SelectedValue = "7" Then #Region " A F - A C T I V O F I J O" Dim ErrorAF As Boolean = False If Not dt.Columns.Contains("CveCuentaContable") Then dt.Columns.Add("CveCuentaContable", GetType(Integer)) End If If Not dt.Columns.Contains("CveCuentaContableDepreciacion") Then dt.Columns.Add("CveCuentaContableDepreciacion", GetType(Integer)) End If If Not dt.Columns.Contains("CveCuentaContableDepreciacionAcum") Then dt.Columns.Add("CveCuentaContableDepreciacionAcum", GetType(Integer)) End If Dim sbErrores As New StringBuilder For Each Row As DataRow In dt.Rows Dim Codigo As String = Row("Código").ToString() Dim Descripcion As String = Row("Descripción").ToString() Dim CuentaContable As String = Row("Cuenta Contable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then Dim CveCuentaContable As Integer = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then Row("CveCuentaContable") = CveCuentaContable Else sbErrores.AppendLine($"Activo Fijo {Codigo} {Descripcion} cuenta {CuentaContable} no encontrada.
") ErrorAF = True End If End If CuentaContable = Row("Cuenta Depreciación").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then Dim CveCuentaContable As Integer = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then Row("CveCuentaContableDepreciacion") = CveCuentaContable Else sbErrores.AppendLine($"Activo Fijo {Codigo} {Descripcion} cuenta {CuentaContable} no encontrada.
") ErrorAF = True End If End If CuentaContable = Row("Cuenta Depreciación Acumulada").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then Dim CveCuentaContable As Integer = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then Row("CveCuentaContableDepreciacionAcum") = CveCuentaContable Else sbErrores.AppendLine($"Activo Fijo {Codigo} {Descripcion} cuenta {CuentaContable} no encontrada.
") ErrorAF = True End If End If Next If Not ErrorAF Then dt.AcceptChanges() Else Alert($"Errores detectados
{sbErrores.ToString()}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjAF As New ClsAF ObjAF.IniciaTransacSQL() Dim ObjConta As New ClsContabilidad(ObjAF.IniciaTransacSQL) Try Dim Contador As Integer = 0 Dim NumRow As Integer = 0 For Each Row As DataRow In dt.FiltraParametros("Descripción <> ''").Rows Dim Codigo As String = Row("Código").ToString() Dim Descripcion As String = Row("Descripción").ToString() Dim TipoAF As String = Row("Tipo").ToString().Trim Dim SubTipo As String = Row("SubTipo").ToString().Trim Dim Valor As Decimal = Row("Valor").ToString().ToDecimal Dim FechaAF As Date = Row("Fecha").ToString().ToDate Dim NumeroSerie As String = Row("No. Serie").ToString() Dim Año As Integer = Row("Año").ToString().ToEntero() Dim CuentaContable As String = Row("Cuenta Contable").ToString() Dim Estado As String = Row("Estado").ToString() Dim Proyecto As String = Row("Proyecto").ToString() Dim SubProyecto As String = Row("SubProyecto").ToString() Dim Cliente As String = Row("Cliente").ToString() Dim Observaciones As String = Row("Observaciones").ToString() Dim CtaDepreciacion As Integer = Row("Cuenta Depreciación").ToString().ToEntero() Dim PorcentajeDepreciacion As Decimal = Row("% Depreciación").ToString().ToDecimal 'CLAVES Dim CveAF As Integer = GlobalDTActivoFijos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveActivoFijo", $"Codigo = '{Codigo}'").ToString().ToEntero() Dim CveSubTipoAF As Integer = GlobalDTSubTipoActivoFijo(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubTipoActivoFijo", $"TipoActivoFijo = '{TipoAF}'").ToString().ToEntero() Dim CveSubProyecto As Integer = GlobalDTSubProyectos(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{SubProyecto}'").ToString().ToEntero() Dim CveEstadoActivoFijo As Integer = GlobalDTEstadoActivoFijo().FiltroPrimeroValor("CveEstadoActivoFijo", $"EstadoActivoFijo = '{Estado}'").ToString().ToEntero() Dim CveCliente As Integer = GlobalDTCliente(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveCliente", $"Nombre = '{Cliente}'").ToString().ToEntero() Dim CveCuentaContable As Integer = Row("CveCuentaContable").ToString().ToEntero() Dim CveCuentaContableDepreciacion As Integer = Row("CveCuentaContableDepreciacion").ToString().ToEntero() Dim CveCuentaContableDepreciacionAcum As Integer = Row("CveCuentaContableDepreciacionAcum").ToString().ToEntero() 'VALIDACIONES If Not CveSubTipoAF > 0 Then Alert($"No se encontró el SubTipo: {TipoAF} Descripcion: {Descripcion} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorAF = True : Exit For If Not CveSubProyecto > 0 Then Alert($"No se encontró el SubProyecto: {SubProyecto} Descripcion: {Descripcion} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorAF = True : Exit For If Not CveEstadoActivoFijo > 0 Then Alert($"No se encontró el Estado: {Estado} Descripcion: {Descripcion} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorAF = True : Exit For If Not CveCliente > 0 Then CveCliente = -1 If CveAF > 0 Then Contador = Contador + 1 Else CveAF = ObjAF.AddActivosFijos(Codigo, Descripcion, Valor, FechaAF, CveSubTipoAF, -1, NumeroSerie, Año, CveSubProyecto, CveEstadoActivoFijo, PorcentajeDepreciacion, Observaciones, CveCliente, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If CveAF > 0 Then If CveCuentaContable > 0 Then If Not ObjConta.AddCuentasAsignaciones(49, UsuarioActual.CveEmpresa, CveCuentaContable, -1, -1, -1, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=CveAF, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorAF = True End If End If If CveCuentaContableDepreciacion > 0 Then If Not ObjConta.AddCuentasAsignaciones(101, UsuarioActual.CveEmpresa, CveCuentaContableDepreciacion, -1, -1, -1, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=CveAF, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorAF = True End If End If If CveCuentaContableDepreciacion > 0 Then If Not ObjConta.AddCuentasAsignaciones(270, UsuarioActual.CveEmpresa, CveCuentaContableDepreciacionAcum, -1, -1, -1, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=CveAF, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorAF = True End If End If Else ErrorAF = True Exit For End If End If NumRow = NumRow + 1 Next If Not ErrorAF Then If Contador > 0 Then Alert(String.Format("Se agregaron: {0} Activos Fijos correctamente.
Se Omitieron: {1} Activos Fijos ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion) ObjAF.Commit() TxtExcel.Text = "" UpDatos.Update() GlobalDTActivoFijos(UsuarioActual.CveEmpresa) = Nothing Else Alert(String.Format("Se agregaron: {0} Activos Fijos correctamente.", NumRows), TipoMensaje.MsgInformacion) ObjAF.Commit() TxtExcel.Text = "" UpDatos.Update() End If Else ObjAF.RollBack() End If Catch ex As Exception GuardaLog($"Ocurrio un error al agregar Activo Fijo: {ex}") ObjAF.RollBack() Finally ObjAF.Dispose() ObjConta.Dispose() End Try #End Region ' C U E N T A S C O N T A B L E S ElseIf RblFormato.SelectedValue = "8" Then Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) ObjConta.IniciaTransacSQL() Try Dim TieneError As Boolean = False Dim ContadorUpdate As Integer = 0 Dim ContadorError As Integer = 0 Dim NombreCuenta As String = "" Dim CuentaPadre As String = "" For Each Row As DataRow In dt.Rows NombreCuenta = Row("NombreCuenta").ToString() CuentaPadre = Row("CuentaPadre").ToString() Dim Cuenta As String = Row("Cuenta").ToString() Dim TipoCuenta As String = Row("TipoCuenta").ToString() Dim AgrupadorSAT As String = Row("AgrupadorSAT").ToString() Dim CveCuentaPadre As Integer = -1 If NombreCuenta <> "" Then If ObjConta.GetCuentas(-1, CuentaPadre.Replace("-", ""), -1) Then If ObjConta.DtResultados.Rows.Count > 0 Then CveCuentaPadre = ObjConta.DtResultados().FiltroPrimeroValor("Id").ToEntero() Else TieneError = True Exit For End If Else TieneError = True Exit For End If Dim IdNew As Integer = ObjConta.AddCuenta(Cuenta.Replace("-", ""), NombreCuenta, TipoCuenta, 1, 0, 1, 0, "", 0, CveCuentaPadre, AgrupadorSAT.ToEntero()) If IdNew > 0 Then ContadorUpdate = ContadorUpdate + 1 Else TieneError = True ContadorError = ContadorError + 1 Exit For End If End If Next If Not TieneError Then ObjConta.Commit() Else Alert($"No pudimos agregar la cuenta: {NombreCuenta} - Cuenta Padre: {CuentaPadre}", TipoMensaje.MsgError) ObjConta.RollBack() End If Alert($"Se agregaron {ContadorUpdate} Cuentas Correctamente y se omitieron: {ContadorError} cuentas.") Catch ex As Exception ObjConta.RollBack() End Try ObjConta.Dispose() 'C U E N T A S C O N T A B L E S - C O N T A S I G ElseIf RblFormato.SelectedValue = "9" Then Dim ObjConta As New ClsContabilidad ObjConta.IniciaTransacSQL() Try Dim TieneError As Boolean = False Dim ContadorUpdate As Integer = 0 Dim ContadorError As Integer = 0 Dim NombreCuenta As String = "" Dim CuentaPadre As String = "" Dim CodigoVinculacion As String = "" Dim AgrupadoresSAT As DataTable = New DataTable If ObjConta.GetAgrupadoresSAT() Then AgrupadoresSAT = ObjConta.DtResultados End If If AgrupadoresSAT.Rows.Count > 0 Then For Each Row As DataRow In dt.Rows Dim Cuenta As String = Row("Cuenta").ToString().Trim.Replace("-", "") If Cuenta <> "" Then NombreCuenta = Row("NombreCuenta").ToString().Trim CuentaPadre = Row("CuentaPadre").ToString().Trim.Replace("-", "") CodigoVinculacion = If(dt.Columns.Contains("CodigoVinculacion"), Row("CodigoVinculacion").ToString().Trim, "") Dim TipoCuenta As String = Row("TipoCuenta").ToString().Trim.ToUpper Dim AgrupadorSAT As String = Row("AgrupadorSAT").ToString().Trim Dim CveCuentaPadre As Integer = -1 Dim CveAgrupadorSAT As Integer = If(AgrupadorSAT = "0", -1, AgrupadoresSAT.FiltroPrimeroValor("CveAgrupadorSAT", String.Format("CodigoNombre LIKE '%{0}%'", AgrupadorSAT)).ToEntero()) If Not CuentaPadre = "" Then If ObjConta.GetCuentas(-1, CuentaPadre.Replace("-", ""), -1, UsuarioActual.CveEmpresa) Then If ObjConta.DtResultados.Rows.Count > 0 Then CveCuentaPadre = ObjConta.DtResultados().FiltroPrimeroValor("Id").ToEntero() Else TieneError = True Exit For End If Else TieneError = True Exit For End If Else CveCuentaPadre = -2 End If Dim IdNew As Integer = ObjConta.AddCuenta(CveCuentaPadre, Cuenta.Replace("-", ""), NombreCuenta, TipoCuenta, 1, 1, CveEmpresaParam:=UsuarioActual.CveEmpresa, CveAgrupadorSAT:=CveAgrupadorSAT, CodigoVinculacion:=CodigoVinculacion) If IdNew > 0 Then ContadorUpdate = ContadorUpdate + 1 Else TieneError = True ContadorError = ContadorError + 1 Exit For End If End If Next Else Alert("No se tienen asociados Agrupadores para esta empresa") TieneError = True End If If Not TieneError Then ObjConta.Commit() Alert($"Se agregaron {ContadorUpdate} Cuentas Correctamente y se omitieron: {ContadorError} cuentas.") Else Alert($"No pudimos agregar la cuenta en ContaSIG: {NombreCuenta} - Cuenta Padre: {CuentaPadre}", TipoMensaje.MsgError) ObjConta.RollBack() End If Catch ex As Exception ObjConta.RollBack() End Try ObjConta.Dispose() ElseIf RblFormato.SelectedValue = "10" Then Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) ObjConta.IniciaTransacSQL() Try Dim TieneError As Boolean = False Dim ContadorUpdate As Integer = 0 Dim ContadorError As Integer = 0 Dim NombreCuenta As String = "" Dim IdPoliza As Integer = 0 Dim Cuenta As String = "" Dim Reporte As New StringBuilder IdPoliza = ObjConta.AddPoliza(1, "Saldos Iniciales", 0, 0, 100, NowADS().ToDate) For Each Row As DataRow In dt.Rows NombreCuenta = Row("NombreCuenta").ToString() Cuenta = Row("Cuenta").ToString() Dim TipoCuenta As String = Row("TipoCuenta").ToString() Dim Importe As Double = Row("Importe").ToString().ToDouble Dim IdCuenta As Integer = -1 Dim CargoAbono As Boolean = True Dim YaExiste As Boolean = False If ObjConta.GetCuentas(-1, Cuenta.Replace("-", ""), 1) Then If ObjConta.DtResultados.Rows.Count > 0 Then IdCuenta = ObjConta.DtResultados().FiltroPrimeroValor("Id").ToEntero() TipoCuenta = ObjConta.DtResultados().FiltroPrimeroValor("Tipo") Else Reporte.AppendLine($"{Cuenta} - {NombreCuenta} - {Importe}
") TieneError = True YaExiste = True End If Else TieneError = True Exit For End If If TipoCuenta.Contiene("A", "C", "E") Then CargoAbono = False End If If YaExiste = False Then If IdCuenta > 0 Then If Not ObjConta.AddMovimiento(IdPoliza, IdCuenta, CargoAbono, Importe, "", "Saldos Iniciales", -1, NowADS(), "") Then TieneError = True Exit For End If Else IdCuenta = -2 End If End If Next If Not TieneError Then ObjConta.Commit() Alert($"Se agregó la póliza {IdPoliza}") Else Alert($"No encontraron las siguientes cuentas: {Reporte.ToString()} ", TipoMensaje.MsgError) ObjConta.RollBack() End If Catch ex As Exception ObjConta.RollBack() End Try ObjConta.Dispose() ElseIf RblFormato.SelectedValue = "11" Then Dim ObjConta As New ClsContabilidad() ObjConta.IniciaTransacSQL() Try Dim TieneError As Boolean = False Dim ContadorUpdate As Integer = 0 Dim ContadorError As Integer = 0 Dim NombreCuenta As String = "" Dim CvePrePoliza As Integer = 0 Dim Cuenta As String = "" Dim Reporte As New StringBuilder Dim SubProTemp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) CvePrePoliza = ObjConta.AddPrePolizas("SI", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Saldos Iniciales", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) For Each Row As DataRow In dt.FiltraParametros("Cuenta <> '' ").Rows NombreCuenta = Row("NombreCuenta").ToString() Cuenta = Row("Cuenta").ToString() Dim Importe As Decimal = If(Row("Cargo").ToString().ToDecimal <> 0, Row("Cargo").ToString().ToDecimal, Row("Abono").ToString().ToDecimal) Dim Concepto As String = Row("Concepto").ToString() Dim IdCuenta As Integer = -1 Dim CveSubProyecto As Integer = -1 Dim TipoMovto As Boolean = If(Row("Cargo").ToString().ToDecimal <> 0, False, True) Dim YaExiste As Boolean = False Dim DataTemp As DataTable Dim Afectable As Boolean = False Cuenta = Cuenta.Replace(" ", "") If ObjConta.GetCuentas(-1, Cuenta.Replace("-", "").Trim, -1, UsuarioActual.CveEmpresa) Then If ObjConta.DtResultados.Rows.Count > 0 Then IdCuenta = ObjConta.DtResultados().FiltroPrimeroValor("CveCuenta").ToEntero() Afectable = ObjConta.DtResultados().FiltroPrimeroValor("Afectable") = "True" Else Reporte.AppendLine($"{Cuenta} - {NombreCuenta} - {Importe}
") TieneError = True YaExiste = True End If Else TieneError = True Exit For End If Dim SubP As String = Row("SubProyecto").ToString().Trim If SubP <> "" AndAlso SubP <> "-" Then DataTemp = SubProTemp.FiltraParametros(String.Format("SubProyecto = '{0}'", SubP)) CveSubProyecto = DataTemp.FiltroPrimeroValor("CveSubProyecto", "").ToEntero() If CveSubProyecto <= 0 Then Reporte.AppendLine($"'{SubP}' - no se encontró en los subproyectos
") TieneError = True Exit For End If End If 'If TipoCuenta.Contiene("A", "C", "E") Then ' CargoAbono = False 'End If If YaExiste = False AndAlso Afectable Then If IdCuenta > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Importe, Importe, 95, "", Concepto, CveSubProyecto:=CveSubProyecto, CveCuenta:=IdCuenta) Then TieneError = True Reporte.Append(NombreCuenta) NombreCuenta.GuardaLog Exit For End If Else IdCuenta = -2 End If End If Next If Not TieneError Then ObjConta.Commit() Alert(String.Format("

Prepóliza: Prepóliza", CvePrePoliza, ObjConta.ContaFolio)) Alert($"Se agregó la póliza {ObjConta.ContaFolio}") Else Alert($"No encontraron las siguientes cuentas: {Reporte.ToString()} ", TipoMensaje.MsgError) ObjConta.RollBack() End If Catch ex As Exception Alert(ex.Message) ObjConta.RollBack() End Try ObjConta.Dispose() ElseIf RblFormato.SelectedValue = "12" Then Dim ObjMovimientos As New ClsInventarios ObjMovimientos.IniciaTransacSQL() Dim ProductosServiciosRef As DataTable = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, Estatus:=-1) Dim AlmacenRef As DataTable = GlobalDTAlmacen(UsuarioActual.CveEmpresa) Dim contadorMovimientos As Integer = 0 Dim listadoMovimientos As String = "" Dim mensajeError As New StringBuilder Dim Fecha As DateTime = (TxtFecha.Text).ToDate Try For Each almacenSinRepetir As DataRow In dt.FiltraParametros("Almacen <> ''", DistinctColumns:={"Almacen"}).Rows Dim almacenActual As String = almacenSinRepetir("Almacen").ToString().Trim Dim CveAlmacen As Integer = AlmacenRef.FiltroPrimeroValor("CveAlmacen", $"Almacen = '{almacenActual}'").ToEntero() If CveAlmacen > 0 Then Dim movimientoCabecera As Integer = ObjMovimientos.AddMovimiento(CveAlmacen, DdlConceptoAlmacen.SelectedValue.ToEntero(), 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1) listadoMovimientos += $"movimiento con folio {ObjMovimientos.Folio}
" If movimientoCabecera > 0 Then For Each nuevaEntrada As DataRow In dt.FiltraParametros($"TRIM(Almacen) = '{almacenActual}'").Rows contadorMovimientos += 1 'Dim RowPS As DataRow = ProductosServiciosRef.FiltroPrimero($"Codigo = '{nuevaEntrada("CodigoPS").ToString.Trim}' ") Dim RowPS As DataRow = ProductosServiciosRef.FiltroPrimero($"Codigo = '{nuevaEntrada("CodigoPS").ToString.Trim(" "c)}' ") If RowPS IsNot Nothing Then Dim CvePS As Integer = RowPS("CvePS").ToString().ToEntero() Dim CveUM As Integer = RowPS("CveUnidadMedida").ToString().ToEntero() If CveUM > 0 Then Dim Cantidad As Decimal = nuevaEntrada("Existencia").ToString().ToDecimal Dim Valor As Decimal = nuevaEntrada("Valor").ToString().ToDecimal Dim Serie As String = If(dt.Columns.Contains("Serie"), nuevaEntrada("Serie").ToString().Trim, "") Dim Lote As String = If(dt.Columns.Contains("Lote"), nuevaEntrada("Lote").ToString().Trim, "-1") Dim FechaCaducidad As Date = If(dt.Columns.Contains("FechaCaducidad"), nuevaEntrada("FechaCaducidad").ToString().Trim.ToDate, MinFecha) Dim PU As Decimal = If(Valor = 0, 0, (Valor / Cantidad)) If Cantidad > 0 Then If Not ObjMovimientos.AddMovimientoDetalle(movimientoCabecera, Cantidad, CveUM, CvePS, PU, -1, -1, Serie:=Serie, Lote:=Lote, FechaCaducidad:=FechaCaducidad) Then mensajeError.Append("No se logró generar el detalle del movimiento") Throw New Exception() End If End If Else mensajeError.Append($"La unidad de medida no se reconoce para el producto servicio:{nuevaEntrada("CodigoPS")}") Throw New Exception() End If Else mensajeError.Append($"No se encontró el producto o servicio con código ""{nuevaEntrada("CodigoPS")}""
") ' Throw New Exception() End If Next If contadorMovimientos = 0 Then mensajeError.Append($"No se encontraros registros del almacen: ""{almacenActual}""") Throw New Exception() Exit For End If Else mensajeError.Append($"No se registró el encabezado ""{almacenActual}""") Throw New Exception() Exit For End If Else mensajeError.Append($"No se encontró el almacén con nombre ""{almacenActual}""") Throw New Exception() Exit For End If Next Catch ex As Exception If mensajeError.ToString = "" Then mensajeError.Append("Error técnico, informar a soporte" & ex.Message) End If ObjMovimientos.RollBack() End Try If mensajeError.ToString = "" Then ObjMovimientos.Commit() Alert($"Se cargaron correctamente {contadorMovimientos} movimientos

{listadoMovimientos}") Else Alert(mensajeError.ToString, TipoMensaje.MsgError) ObjMovimientos.RollBack() End If ObjMovimientos.Dispose() ProductosServiciosRef.Dispose() AlmacenRef.Dispose() ElseIf RblFormato.SelectedValue = "13" Then ProcesaAnticipoProveedor(dt, DTCuentasContables) ElseIf RblFormato.SelectedValue = "14" Then ProcesaAnticipoCliente(dt, DTCuentasContables) ElseIf RblFormato.SelectedValue = "15" Then ProcesaBancos(dt, DTCuentasContables) ElseIf RblFormato.SelectedValue = "16" Then ProcesaClasificaciones(dt, DTCuentasContables) End If End If End Sub Private Sub RegistraVentas(dt As DataTable, OpcionDetallada As Boolean) If Not OpcionDetallada Then Dim NoEncontrados As Integer = 0 Dim Encontrados As Integer = 0 Dim StrRFCNoencontrados As New StringBuilder Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") If drr Is Nothing Then Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjVentas As New ClsVentas Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) Dim ObjInv As New ClsInventarios(ObjVentas.IniciaTransacSQL()) Dim ErrorVentas As Boolean = False Dim CveVenta As Integer Dim DtClientes As New DataTable 'Dim ExisteVenta As Boolean = False 'Dim Contador As Integer = 0 DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) Dim CountRow As Integer = 1 For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") Dim Serie As String = Row("Serie").ToString().Trim Dim Folio As Integer = Row("Folio").ToString().ToEntero() Dim Fecha As Date = Row("Fecha").ToString().ToDate Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) Dim SubTotal As Decimal = Row("SubTotal").ToString().ToDecimal Dim IVA As Decimal = Row("IVA").ToString().ToDecimal Dim Total As Decimal = Row("Total").ToString().ToDecimal Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() Dim RetIVA As Decimal = Row("Ret IVA").ToString().ToDecimal Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal Dim Moneda As String = Row("Moneda").ToString() Dim TipoCambio As String = Row("Tipo Cambio").ToString() Dim CveMoneda As Integer = 1 Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "") Dim CveVendedor As Integer = 0 Dim IEPS As Decimal = 0 If RblFormato.SelectedValue = "17" Then IEPS = Row("IEPS").ToString().ToDecimal End If Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), Row("Folio Fiscal").ToString(), "") Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString().ToDecimal, 4), 0) Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") GuardaLog(Sucursal + "-" + Row("Folio").ToString()) 'Temporalmente SE BORRARA Dim Transaccion As String = "" ' Row("Transaccion2").ToString() Dim Folio2 As String = "" ' Row("Folio2").ToString() Dim CodCliente As String = "" 'Row("CodCliente2").ToString() Dim IEPSDetalle As Decimal = 0 Dim CantidadDetalle As Decimal = 0 Dim PUDetalle As Decimal = 0 Dim IVADetalle As Decimal = 0 Dim PorcentajeIEPS As Decimal = 0 If IEPS > 0 Then PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) End If If RblFormato.SelectedValue = "17" Then Dim CodigoDetalle As String = Row("Codigo").ToString If CodigoDetalle.Trim.Length > 0 Then Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") If DrDetalles IsNot Nothing Then CvePS = DrDetalles("CvePS").ToString().ToEntero() CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() Else Alert($"El código del producto no se encontro, error en registro {CountRow}") ErrorVentas = True End If Else Alert($"El código es requerido, error en registro {CountRow}") ErrorVentas = True End If IEPSDetalle = Row("IEPS").ToString.ToDecimal CantidadDetalle = Row("Cantidad").ToString.ToDecimal PUDetalle = Row("PU").ToString.ToDecimal IVADetalle = Row("IVA").ToString.ToDecimal If CantidadDetalle = 0 Then Alert($"No se especifico la cantidad, error en registro {CountRow}") ErrorVentas = True End If End If If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then Dim ObjCliente As New ClsClientes If ObjCliente.GetSucursales(CveCliente) Then If ObjCliente.DtResultados.Rows.Count > 0 Then CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero End If End If ObjCliente.Dispose() End If 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", IIf(TipoDocto.ToUpper.Contiene("ANTICIPO", "ANTICIPOS", "ANT"), "Ant", "Rem"))).ToString() 'PrePóliza Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Vendedor <> "" Then CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() If Not CveVendedor > 0 Then CveVendedor = 0 Else CveVendedor = 0 End If 'Moneda If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then CveMoneda = 1 TipoCambio = "1" ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then CveMoneda = 2 If TipoCambio.Trim.ToDecimal < 10 Then If UsuarioActual.CveEmpresa.Contiene(13, 83) Then TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() Else TipoCambio = GlobalTipoCambio(Fecha).ToString() End If End If End If 'Si no se especifica TC, se manda como pesos. If TipoCambio = "" Then TipoCambio = "1" If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then FechaVencimiento = Fecha End If 'Venta If CveCliente > 0 Then If TipoDocto.Contiene("Ing", "Egs", "Rem", "Ant") Then GuardaLog(Serie & "-" & Folio) If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then ErrorVentas = True Exit For End If CveVenta = ObjVentas.CveVenta If Not ErrorVentas Then If Not ObjInv.ActualizarEsDevolucionVenta(CveVenta, 2) Then ErrorVentas = True Exit For End If End If If RblFormato.SelectedValue = "17" Then Dim TotalDetalles As Decimal = SubTotal If PUDetalle > 0 Then TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle End If If Math.Abs(TotalDetalles - Total) > 0.01 Then ErrorVentas = True Alert($"Registro {CountRow} El total no coincide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) Exit For End If If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then ErrorVentas = True Exit For End If Else If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then ErrorVentas = True Exit For End If End If Dim ConceptoContable As Integer = 1 Dim ConceptoContablePago As Integer = 2 If TipoDocto = "Egs" Then ConceptoContable = 12 ConceptoContablePago = 91 End If If FolioFiscal <> "" Then If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then ErrorVentas = True Exit For End If End If Dim UsaComplementaria As Boolean = False If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True 'PrePólizaDetalle Dim tCveConcepto As Integer = 4 If TipoDocto = "Ant" Then tCveConcepto = 3 If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, tCveConcepto, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For If IVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If IEPS > 0 Then 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If RetIVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If RetISR > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If ImpuestoLocal > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If UsaComplementaria Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For End If 'Saldo If Saldo < Total Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For End If Else 'ANTICIPOS Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For End If Encontrados = Encontrados + 1 Else NoEncontrados = NoEncontrados + 1 StrRFCNoencontrados.AppendFormat("{0}
", RFC) ErrorVentas = True Exit For End If CountRow = CountRow + 1 Next If Not ErrorVentas Then Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) ObjVentas.Commit() TxtExcel.Text = "" UpDatos.Update() Else Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) ObjVentas.RollBack() End If ObjVentas.Dispose() Else Dim NoEncontrados As Integer = 0 Dim VentasAgregadas As Integer = 0 Dim Encontrados As Integer = 0 Dim StrRFCNoencontrados As New StringBuilder Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") If drr Is Nothing Then Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjVentas As New ClsVentas Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) Dim ObjInv As New ClsInventarios(ObjVentas.IniciaTransacSQL()) Dim ErrorVentas As Boolean = False Dim CveVenta As Integer Dim CvePrePoliza As Integer Dim DtClientes As New DataTable 'Dim ExisteVenta As Boolean = False 'Dim Contador As Integer = 0 DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) Dim CountRow As Integer = 1 Dim LastSerieFolioTipoDoc As String = String.Empty Dim EsDetalle As Boolean = False Dim DTFoliosFiscales As DataTable = dt.FiltraParametros("[Folio Fiscal] <> ''", "", {"Folio Fiscal"}) For Each drFolioFiscal As DataRow In DTFoliosFiscales.Rows Dim FolioFiscalActual As String = drFolioFiscal("Folio Fiscal").ToString Dim DRVentaActual As DataRow = dt.FiltroPrimero($"[Folio Fiscal] = '{FolioFiscalActual}'") Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{DRVentaActual("Sucursal").ToString()}'") Dim TipoDocto As String = DRVentaActual("Tipo Documento").ToString().Trim Dim RFC As String = DRVentaActual("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") Dim Serie As String = DRVentaActual("Serie").ToString().Trim Dim Folio As Integer = DRVentaActual("Folio").ToString().ToEntero() Dim Fecha As Date = DRVentaActual("Fecha").ToString().ToDate Dim FechaVencimiento As Date = DRVentaActual("Fecha Vencimiento").ToString().ToDate Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), DRVentaActual("ImpuestoLocal").ToString().ToDecimal, 0D) Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), DRVentaActual("Amort.Ant").ToString().ToDecimal, 0) Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then EsDetalle = True Else LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" EsDetalle = False End If Dim SubTotal As Decimal = 0 Dim IVA As Decimal = 0 Dim Total As Decimal = 0 Dim Saldo As Decimal = 0 Dim RetIVA As Decimal = 0 Dim RetISR As Decimal = 0 Dim IEPS As Decimal = 0 SubTotal = DRVentaActual("SubTotal").ToString().ToDecimal IVA = DRVentaActual("IVA").ToString().ToDecimal Total = DRVentaActual("Total").ToString().ToDecimal Saldo = DRVentaActual("Saldo").ToString().ToDecimal RetIVA = DRVentaActual("Ret IVA").ToString().ToDecimal RetISR = DRVentaActual("Ret ISR").ToString().ToDecimal IEPS = DRVentaActual("IEPS").ToString().ToDecimal Dim Moneda As String = DRVentaActual("Moneda").ToString() Dim TipoCambio As String = DRVentaActual("Tipo Cambio").ToString() Dim CveMoneda As Integer = 1 Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), DRVentaActual("Vendedor").ToString(), "") Dim CveVendedor As Integer = 0 Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() 'Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), DRVentaActual("Folio Fiscal").ToString(), "") Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(DRVentaActual("PorcentajeIVA").ToString().ToDecimal, 2), 0) Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(DRVentaActual("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(DRVentaActual("PorcentajeRetISR").ToString().ToDecimal, 4), 0) Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), DRVentaActual("Pedido").ToString(), "") GuardaLog(Sucursal + "-" + DRVentaActual("Folio").ToString()) 'Temporalmente SE BORRARA Dim Transaccion As String = "" ' Row("Transaccion2").ToString() Dim Folio2 As String = "" ' Row("Folio2").ToString() Dim CodCliente As String = "" 'Row("CodCliente2").ToString() TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() 'Dim CantidadDetalle As Decimal = 0 'Dim PUDetalle As Decimal = 0 'Dim IVADetalle As Decimal = 0 Dim PorcentajeIEPS As Decimal = 0 Dim TotalDetalles As Decimal = 0 For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal TotalDetalles += (CantidadDetalle * PuDetalle) + IVADetalle + IEPSDetalle Next If IEPS > 0 Then PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(DRVentaActual("PorcentajeIEPS").ToString().ToDecimal, 4), 0) End If If Math.Abs(TotalDetalles - Total) > 0.01 Then ErrorVentas = True Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) Exit For End If If Vendedor <> "" Then CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() If Not CveVendedor > 0 Then CveVendedor = 0 Else CveVendedor = 0 End If If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then CveMoneda = 1 TipoCambio = "1" ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then CveMoneda = 2 If TipoCambio.Trim.ToDecimal < 10 Then If UsuarioActual.CveEmpresa.Contiene(13, 83) Then TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() Else TipoCambio = GlobalTipoCambio(Fecha).ToString() End If End If End If If TipoCambio = "" Then TipoCambio = "1" If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then FechaVencimiento = Fecha End If If Not ErrorVentas Then CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorVentas = True End If End If Dim VentayaRegistrada As Boolean = False If Not ErrorVentas Then 'Venta If CveCliente > 0 Then If TipoDocto.Contiene("Ing", "Egs", "Rem") Then GuardaLog(Serie & "-" & Folio) CveVenta = 0 Dim contador As Integer = 0 'verificar si existe la venta, si existe obtener el cveventa y limpiar su contenido para carga de lo nuevo. If ObjVentas.GetVentas(UsuarioActual.CveEmpresa, TipoDocto, Serie, Folio, "-1", -1, -1, -1, -1, "2000-01-01", Now.ToShortDateString, FolioFiscalActual, CveUsuarioConsulta:=100) Then If ObjVentas.DtResultados.Rows.Count > 0 Then contador = 1 CveVenta = ObjVentas.DtResultados.FiltroPrimeroValor("CveVenta").ToEntero VentayaRegistrada = True VentasAgregadas += 1 'limpieza de las partidas If ObjVentas.GetVentaDetalle(CveVenta) Then For Each dr As DataRow In ObjVentas.DtResultados.Rows ObjVentas.RemoveVentasDetalle(CveVenta, dr("CveVentaDetalle").ToString.ToEntero) Next End If End If End If If Not EsDetalle AndAlso CveVenta = 0 Then If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then ErrorVentas = True Exit For Else VentasAgregadas += 1 End If CveVenta = ObjVentas.CveVenta End If If Not ErrorVentas Then If Not ObjInv.ActualizarEsDevolucionVenta(CveVenta, 2) Then ErrorVentas = True Exit For End If End If For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal Dim PorcentajeIEPSDetalle = dRowDetalle("PorcentajeIEPS").ToString.ToDecimal Dim CodigoDetalle As String = dRowDetalle("Codigo").ToString If CodigoDetalle.Trim.Length > 0 Then Dim DrDetalles As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") If DrDetalles IsNot Nothing Then CvePS = DrDetalles("CvePS").ToString().ToEntero() CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() Else Alert($"El código del producto no se encontro, error en registro {CountRow}") ErrorVentas = True End If Else Alert($"El código es requerido, error en registro {CountRow}") ErrorVentas = True End If If Not ErrorVentas Then If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PuDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=0, IEPS:=IEPSDetalle, PorcentajeRetISR:=0, PorcentajeIEPS:=PorcentajeIEPSDetalle, EstatusAlmacen:=1) Then ErrorVentas = True Exit For End If End If Next If Not VentayaRegistrada Then Dim ConceptoContable As Integer = 1 Dim ConceptoContablePago As Integer = 2 If TipoDocto = "Egs" Then ConceptoContable = 12 ConceptoContablePago = 91 End If If FolioFiscalActual <> "" Then If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscalActual, CveVenta, UsuarioActual.CveEmpresa) Then ErrorVentas = True Exit For End If End If Dim UsaComplementaria As Boolean = False If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True 'PrePólizaDetalle If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For If IVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If IEPS > 0 Then 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If RetIVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If RetISR > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If ImpuestoLocal > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For End If If UsaComplementaria Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For End If 'Saldo If Saldo < Total Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For End If End If If Not ErrorVentas Then VentasAgregadas += VentasAgregadas End If Else 'ANTICIPOS Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For End If '_______________________________________________________________ Else NoEncontrados = NoEncontrados + 1 StrRFCNoencontrados.AppendFormat("{0}
", RFC) 'ErrorVentas = True 'Exit For End If End If Next '********************************************************************************************************************************************************************************** If Not ErrorVentas Then ObjVentas.Commit() Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", VentasAgregadas, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) TxtExcel.Text = "" UpDatos.Update() Else Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) ObjVentas.RollBack() End If ObjVentas.Dispose() End If End Sub Private Sub ProcesaClasificaciones(dt As DataTable, dTCuentasContables As DataTable) Dim ErrorProceso As Boolean = False Dim SBMensajesCuentasNoEncontradas As New StringBuilder For Each dRow As DataRow In dt.FiltraParametros(" LEN(Clasificacion) > 0 ").Rows Dim Clasificacion As String = dRow("Clasificacion").ToString().Trim.Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim CuentaContableIngreso As String = dRow("CuentaContableIngreso").ToString().Trim.Replace("-", "").Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim CuentaContableGasto As String = dRow("CuentaContableGasto").ToString().Trim.Replace("-", "").Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim CveCuentaContableIngreso As Integer = dTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContableIngreso}'").ToEntero() Dim CveCuentaContableGasto As Integer = dTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContableGasto}'").ToEntero() If CuentaContableIngreso.Trim.Length > 0 AndAlso CveCuentaContableIngreso <= 0 Then SBMensajesCuentasNoEncontradas.AppendLine($"Clasificación {Clasificacion} no se encontro la cuenta de ingreso {CuentaContableIngreso}.
") ErrorProceso = True End If If CuentaContableGasto.Trim.Length > 0 AndAlso CveCuentaContableGasto <= 0 Then SBMensajesCuentasNoEncontradas.AppendLine($"Clasificación {Clasificacion} no se encontro la cuenta de gasto {CuentaContableGasto}.
") ErrorProceso = True End If Next If ErrorProceso Then Alert($"Cuentas no encontradas.
{SBMensajesCuentasNoEncontradas.ToString}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjClasificaciones As New ClsClasificaciones Dim ObjConta As New ClsContabilidad(ObjClasificaciones.IniciaTransacSQL) Dim Contador As Integer = 0 Dim DTClasificaiones As New DataTable 'If ObjClasificaciones.GetClasificaciones(UsuarioActual.CveEmpresa) Then ' DTClasificaiones = ObjClasificaciones.DtResultados 'End If 'If Not DTClasificaiones.Rows.Count > 0 Then ' ObjConta.Dispose() ' Alert("Error a consultar clasificaciones.", TipoMensaje.MsgAdvertencia) ' Exit Sub 'End If DTClasificaiones.CaseSensitive = False For Each dRow As DataRow In dt.FiltraParametros(" LEN(Clasificacion) > 0 ").Rows Dim Clasificacion As String = dRow("Clasificacion").ToString().Trim.Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim Categoria As String = dRow("Categoria").ToString().Trim.Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim UsoClasificacion As String = dRow("UsoClasificacion").ToString().Trim.ToUpper.Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim CuentaContableIngreso As String = dRow("CuentaContableIngreso").ToString().Trim.Replace("-", "").Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim CuentaContableGasto As String = dRow("CuentaContableGasto").ToString().Trim.Replace("-", "").Replace("\r\n", "").Replace(vbCrLf, "").Replace(vbCr, "") Dim CveClasificacion As Integer = -1 Dim CveUsoClasificacion As Integer = -1 Dim CveCategoria As Integer = -1 CveCategoria = GlobalDTGralCategorias(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveCategoria", $" Categoria = '{Categoria}' ").ToEntero() If Not CveCategoria > 0 Then CveCategoria = GlobalDTGralCategorias(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveCategoria", "").ToEntero() If Not CveCategoria > 0 Then Alert($"Clasificación {Clasificacion} la categoria {Categoria} no es valida.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If End If If UsoClasificacion = "INGRESOS" Then CveUsoClasificacion = 1 ElseIf UsoClasificacion = "GASTO" Then CveUsoClasificacion = 2 ElseIf UsoClasificacion = "INGRESOS/GASTO" Then CveUsoClasificacion = 3 End If If Not CveUsoClasificacion > 0 Then Alert($"Clasificación {Clasificacion} el uso {UsoClasificacion} no es valido.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If Dim CveCuentaContableIngreso As Integer = dTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContableIngreso}'").ToEntero() Dim CveCuentaContableGasto As Integer = dTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContableGasto}'").ToEntero() 'If CuentaContableIngreso.Trim.Length > 0 AndAlso CveCuentaContableIngreso <= 0 Then ' Alert($"Clasificación {Clasificacion} no se encontro la cuenta de ingreso {CuentaContableIngreso}.", TipoMensaje.MsgAdvertencia) ' ErrorProceso = True 'End If 'If CuentaContableGasto.Trim.Length > 0 AndAlso CveCuentaContableGasto <= 0 Then ' Alert($"Clasificación {Clasificacion} no se encontro la cuenta de gasto {CuentaContableGasto}.", TipoMensaje.MsgAdvertencia) ' ErrorProceso = True 'End If Dim CveClasificaionTemp As Integer = DTClasificaiones.FiltroPrimeroValor("CveClasificacion", $"Clasificacion='{Clasificacion}'").ToEntero() If CveClasificaionTemp > 0 Then CveClasificacion = CveClasificaionTemp End If If Not CveClasificacion > 0 Then If ObjClasificaciones.AddClasificaciones(Clasificacion, "", CveCategoria, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, RequiereSerieLote:=0, UsoClasificacion:=CveUsoClasificacion, CveSATPS:=-1, RequiereAFCompra:=False, RequiereAFInsumo:=False, RequierePersonal:=False, EsAcumulador:=False, TopVentas:=False, TopCompras:=False, PrecioBaseCosto:=-1) Then CveClasificacion = ObjClasificaciones.CveClasificacion If CveClasificacion > 0 Then If ObjClasificaciones.GetClasificaciones(UsuarioActual.CveEmpresa) Then DTClasificaiones = ObjClasificaciones.DtResultados End If Else ErrorProceso = True End If Else ErrorProceso = True End If Else If Not ObjClasificaciones.UpdateClasificacion(Clasificacion, "-1", True, True, CveCategoria, UsuarioActual.CveUsuario, CveClasificacion, UsoClasificacion:=CveUsoClasificacion) Then ErrorProceso = True End If End If If Not ErrorProceso Then If CveCuentaContableIngreso > 0 Then If Not AsignacionCuenta(ObjConta, 4, CveCuentaContableIngreso, -1, -1, -1, -1, UsuarioActual.CveEmpresa, CveClasificacion, OpActualizarClasificacion:=True) Then ErrorProceso = True Alert("Se presento un error al guardar en asignaciones", TipoMensaje.MsgAdvertencia) Exit For End If End If If CveCuentaContableGasto > 0 Then If Not AsignacionCuenta(ObjConta, 6, CveCuentaContableGasto, -1, -1, -1, -1, UsuarioActual.CveEmpresa, CveClasificacion, OpActualizarClasificacion:=True) Then ErrorProceso = True Alert("Se presento un error al guardar en asignaciones", TipoMensaje.MsgAdvertencia) Exit For End If End If End If Contador = Contador + 1 Next If Not ErrorProceso Then ObjClasificaciones.Commit() Alert($"Se agregaron {Contador} Clasificaciones.") Else ObjClasificaciones.RollBack() End If ObjClasificaciones.Dispose() End Sub Private Sub ProcesaBancos(DTBancos As DataTable, DTCuentasContables As DataTable) Dim ErrorProceso As Boolean = False Dim ObjConta As New ClsContabilidad() Dim ObjBancos As New ClsBancos(ObjConta.IniciaTransacSQL) If Not DTBancos.Columns.Contains("CveCuentaContable") Then DTBancos.Columns.Add("CveCuentaContable", GetType(Integer)) End If Dim Contador As Integer = 0 For Each dRow As DataRow In DTBancos.Rows Dim Fecha As Date = dRow("Fecha").ToString().ToDate Dim Importe As Decimal = dRow("Importe").ToString().ToDecimal Dim Descripcion As String = dRow("Descripcion").ToString() Dim Banco As String = dRow("Banco").ToString() Dim NumCuenta As String = dRow("CuentaBancaria").ToString().Trim Dim ImporteMX As Decimal = 0 Dim ImporteME As Decimal = 0 Dim Moneda As String = dRow("Moneda").ToString() Dim CveMoneda As Integer Dim TipoCambio As Decimal = dRow("TipoCambio").ToString().ToDecimal If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then CveMoneda = 1 TipoCambio = 1 ElseIf Moneda.ToUpper.Contiene("DÓLARES", "DOLARES", "USD") Then CveMoneda = 2 End If If CveMoneda.Contiene(1, 2) Then If CveMoneda = 2 Then If TipoCambio = 0 Then Alert($"Registro {Contador + 1} moneda en dólares sin tipo de cambio especificado.") ErrorProceso = True Exit For Else ImporteMX = Importe * TipoCambio ImporteME = Importe End If Else ImporteMX = Importe ImporteME = 0 End If Else Alert($"Registro {Contador + 1} moneda ({Moneda}) no valida.") ErrorProceso = True Exit For End If Dim CveTipoTransaccion As Integer = 3 ' tipo transaccion, cheque recibido Dim CveCuentaBancaria As Integer = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa, Estatus:=-1).FiltroPrimeroValor("CveCuenta", $" NumCuenta = '{NumCuenta}'").ToEntero() If Not CveCuentaBancaria > 0 Then ' se registrará primero Dim CveBanco As Integer = GlobalDTBancos().FiltroPrimeroValor("CveBanco", String.Format("CveEmpresa = {0} AND Banco = '{1}'", UsuarioActual.CveEmpresa, Banco)).ToEntero() If CveBanco > 0 Then Dim CveTipoCuenta As Integer = 2 'tipo de cheques If NumCuenta.ToLower.Contains("caja chica") Then CveTipoCuenta = 1 ' cuando es caja chica If ObjBancos.AddBancosCuentas(CveBanco, 2, NumCuenta, "", CveMoneda, 1, 1, 1, 9999999, 0, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", False, False) Then CveCuentaBancaria = ObjBancos.TCveCuenta Else Alert($"No se detecto cuenta Bancaria {NumCuenta}", TipoMensaje.MsgAdvertencia) ErrorProceso = True : Exit For End If Else Alert($"No se detecto cuenta Bancaria {NumCuenta}", TipoMensaje.MsgAdvertencia) ErrorProceso = True : Exit For End If End If If ImporteMX < 0 Then CveTipoTransaccion = 2 'salida de dinero, concepto de transferencia realizada Dim FolioStr As String = "" FolioStr = CStr(ObjBancos.GetNextFolio(CveCuentaBancaria, CveTipoTransaccion)) Dim CveCuentaContable As Integer = 0 Dim CuentaContable As String = dRow("CuentaContable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then CveCuentaContable = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then dRow("CveCuentaContable") = CveCuentaContable Else Alert($"Cuenta Bancaria {NumCuenta} cuenta contable {CuentaContable} no encontrada.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If If Not ErrorProceso Then DTBancos.AcceptChanges() End If End If If CveCuentaContable > 0 AndAlso Not AsignacionCuenta(ObjConta, 30, CveCuentaContable, CveCuentaBancaria, -1, -1, -1, UsuarioActual.CveEmpresa, -1) Then ErrorProceso = True Alert("Se presento un error al guardar en asignaciones", TipoMensaje.MsgAdvertencia) Exit For End If If Importe <> 0 Then Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Bancos/SaldoInicial", 66, Importe, Importe, CveMoneda, Fecha, FolioStr, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorProceso = True : Exit For End If Dim CveIE As Integer = ObjBancos.AddBancos_IE(CveCuentaBancaria, CveTipoTransaccion, Fecha, FolioStr.ToString(), "", Importe, CveMoneda, TipoCambio, Descripcion, "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Importe, ImporteMX, 30, FolioStr.ToString(), FolioStr, CveIE:=CveIE, Contabilizable:=False, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Importe, ImporteMX, 95, FolioStr.ToString(), FolioStr, CveIE:=CveIE, Contabilizable:=False, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For End If Contador = Contador + 1 Next If Not ErrorProceso Then Alert($"Se agregaron {Contador} Movimientos.") ObjBancos.Commit() Else ObjBancos.RollBack() End If ObjBancos.Dispose() End Sub Private Sub ProcesaAnticipoProveedor(DtAnticipoProveedor As DataTable, DTCuentasContables As DataTable) Dim ErrorProceso As Boolean = False Dim CveCuentaBancaria As Integer = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa, Estatus:=1).FiltroPrimeroValor("CveCuenta", "").ToEntero() If Not CveCuentaBancaria > 0 Then Alert("No se detecto una cuenta Bancaria", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjConta As New ClsContabilidad() Dim ObjBancos As New ClsBancos(ObjConta.IniciaTransacSQL) If Not DtAnticipoProveedor.Columns.Contains("CveCuentaContable") Then DtAnticipoProveedor.Columns.Add("CveCuentaContable", GetType(Integer)) End If Dim Contador As Integer = 0 For Each dRow As DataRow In DtAnticipoProveedor.Rows Dim Fecha As Date = dRow("Fecha").ToString().ToDate Dim Importe As Decimal = dRow("Importe").ToString().ToDecimal Dim ImporteMX As Decimal = 0 Dim ImporteME As Decimal = 0 Dim Descripcion As String = dRow("Descripcion").ToString() Dim RFC As String = dRow("RFC").ToString() Dim Moneda As String = dRow("Moneda").ToString() Dim CveMoneda As Integer Dim TipoCambio As Decimal = dRow("TipoCambio").ToString().ToDecimal If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then CveMoneda = 1 TipoCambio = 1 ElseIf Moneda.ToUpper.Contiene("DÓLARES", "DOLARES", "USD") Then CveMoneda = 2 End If If CveMoneda.Contiene(1, 2) Then If CveMoneda = 2 Then If TipoCambio = 0 Then Alert($"Registro {Contador + 1} moneda en dólares sin tipo de cambio especificado.") ErrorProceso = True Exit For Else ImporteMX = Importe * TipoCambio ImporteME = Importe End If Else ImporteMX = Importe ImporteME = 0 End If Else Alert($"Registro {Contador + 1} moneda ({Moneda}) no valida.") ErrorProceso = True Exit For End If Dim FolioStr As String = "" FolioStr = CStr(ObjBancos.GetNextFolio(CveCuentaBancaria, 1) + Contador) Dim CveProveedor As Integer = GlobalDTCompProveedores(CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveProveedor", $" RFC = '{RFC}' ").ToEntero() If Not CveProveedor > 0 Then Alert($"No se encontro Proveedor con RFC: {RFC}.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If Dim CveCuentaContable As Integer = 0 Dim CuentaContable As String = dRow("CuentaContable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then CveCuentaContable = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then dRow("CveCuentaContable") = CveCuentaContable Else Alert($"RFC {RFC} cuenta {CuentaContable} no encontrada.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If If Not ErrorProceso Then DtAnticipoProveedor.AcceptChanges() End If End If If Not AsignacionCuenta(ObjConta, 10, CveCuentaContable, -1, CveProveedor, -1, -1, UsuarioActual.CveEmpresa, -1) Then ErrorProceso = True Alert("Se presento un error al guardar en asignaciones", TipoMensaje.MsgAdvertencia) Exit For End If Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Anticipo/Proveedor/SaldoInicial", 12, Importe, Importe, CveMoneda, Fecha, FolioStr, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorProceso = True Exit For End If Dim CveIE As Integer = ObjBancos.AddBancos_IE(CveCuentaBancaria, 1, Fecha, FolioStr.ToString(), "", Importe, CveMoneda, TipoCambio, Descripcion, "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Importe, ImporteMX, 30, FolioStr.ToString(), FolioStr, CveIE:=CveIE, CveProveedor:=CveProveedor, Contabilizable:=False, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Importe, ImporteMX, 10, FolioStr.ToString(), FolioStr, CveIE:=CveIE, CveProveedor:=CveProveedor, Contabilizable:=False, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For Contador = Contador + 1 Next If Not ErrorProceso Then Alert($"Se agregaron {Contador} Anticipos.") ObjBancos.Commit() Else ObjBancos.RollBack() End If ObjBancos.Dispose() End Sub Private Sub ProcesaAnticipoCliente(DTAnticipoCliente As DataTable, DTCuentasContables As DataTable) Dim ErrorProceso As Boolean = False Dim CveCuentaBancaria As Integer = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa, Estatus:=1).FiltroPrimeroValor("CveCuenta", "").ToEntero() If Not CveCuentaBancaria > 0 Then Alert("No se detecto una cuenta Bancaria", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjConta As New ClsContabilidad() Dim ObjBancos As New ClsBancos(ObjConta.IniciaTransacSQL) If Not DTAnticipoCliente.Columns.Contains("CveCuentaContable") Then DTAnticipoCliente.Columns.Add("CveCuentaContable", GetType(Integer)) End If Dim Contador As Integer = 0 For Each dRow As DataRow In DTAnticipoCliente.Rows Dim Fecha As Date = dRow("Fecha").ToString().ToDate Dim Importe As Decimal = dRow("Importe").ToString().ToDecimal Dim ImporteMX As Decimal = 0 Dim ImporteME As Decimal = 0 Dim Descripcion As String = dRow("Descripcion").ToString() Dim RFC As String = dRow("RFC").ToString() Dim Moneda As String = dRow("Moneda").ToString() Dim CveMoneda As Integer Dim TipoCambio As Decimal = dRow("TipoCambio").ToString().ToDecimal If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then CveMoneda = 1 TipoCambio = 1 ElseIf Moneda.ToUpper.Contiene("DÓLARES", "DOLARES", "USD") Then CveMoneda = 2 End If If CveMoneda.Contiene(1, 2) Then If CveMoneda = 2 Then If TipoCambio = 0 Then Alert($"Registro {Contador + 1} moneda en dólares sin tipo de cambio especificado.") ErrorProceso = True Exit For Else ImporteMX = Importe * TipoCambio ImporteME = Importe End If Else ImporteMX = Importe ImporteME = 0 End If Else Alert($"Registro {Contador + 1} moneda ({Moneda}) no valida.") ErrorProceso = True Exit For End If Dim FolioStr As String = "" FolioStr = CStr(ObjBancos.GetNextFolio(CveCuentaBancaria, 3) + Contador) Dim CveCliente As Integer = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=1).FiltroPrimeroValor("CveCliente", $" RFC = '{RFC}' ").ToEntero() If Not CveCliente > 0 Then Alert($"No se encontro cliente con RFC: {RFC}.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If 'Dim RazonSocial As String = Row("RazonSocial").ToString() Dim CveCuentaContable As Integer = 0 Dim CuentaContable As String = dRow("CuentaContable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then CveCuentaContable = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then dRow("CveCuentaContable") = CveCuentaContable Else Alert($"RFC {RFC} cuenta {CuentaContable} no encontrada.", TipoMensaje.MsgAdvertencia) ErrorProceso = True Exit For End If If Not ErrorProceso Then DTAnticipoCliente.AcceptChanges() End If If Not AsignacionCuenta(ObjConta, 66, CveCuentaContable, -1, -1, CveCliente, -1, UsuarioActual.CveEmpresa, -1) Then ErrorProceso = True Alert("Se presento un error al guardar en asignaciones", TipoMensaje.MsgAdvertencia) Exit For End If End If Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Anticipo/Cliente/SaldoInicial", 24, Importe, Importe, CveMoneda, Fecha, FolioStr, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorProceso = True Exit For End If Dim CveIE As Integer = ObjBancos.AddBancos_IE(CveCuentaBancaria, 3, Fecha, FolioStr.ToString(), "", Importe, CveMoneda, TipoCambio, Descripcion, "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Importe, ImporteMX, 30, FolioStr.ToString(), FolioStr, CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Importe, ImporteMX, 66, FolioStr.ToString(), FolioStr, CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For Contador = Contador + 1 Next If Not ErrorProceso Then Alert($"Se agregaron {Contador} Anticipos.") ObjBancos.Commit() Else ObjBancos.RollBack() End If ObjBancos.Dispose() End Sub Private Function AsignacionCuenta(ObjContabilidad As ClsContabilidad, CveConceptoContable As Integer, CveCuentaContable As Integer, CveBancoCuenta As Integer, CveProveedor As Integer, CveCliente As Integer, CvePersonal As Integer, CveEmpresa As Integer, CveClasificacion As Integer, Optional OpActualizarClasificacion As Boolean = False) As Boolean Dim Respuesta As Boolean = False If ObjContabilidad.AddCuentasAsignaciones(CveConceptoContable, CveEmpresa, CveCuentaContable, CveProveedor, CveCliente, CvePersonal, CveClasificacion, -1, 0, CveBancoCuenta:=CveBancoCuenta, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=-1, CveTipoGasto:=-1, RegeneraCuenta:=False, OpActualizarClasificacion:=OpActualizarClasificacion) Then Respuesta = True End If Return Respuesta End Function Protected Sub BtnDescargar_Click(sender As Object, e As EventArgs) Handles BtnDescargar.Click Dim Directorio As String = "" If RblFormato.SelectedValue = "1" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoProveedor.xlsx" ElseIf RblFormato.SelectedValue = "2" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoClientes.xlsx" ElseIf RblFormato.SelectedValue = "3" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoProveedores-Facturas.xlsx" ElseIf RblFormato.SelectedValue = "4" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoClientes-Facturas.xlsx" ElseIf RblFormato.SelectedValue = "5" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoPS.xlsx" ElseIf RblFormato.SelectedValue = "6" Then 'Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoRH-Personal.xlsx" LnkCargaMasiva_Click(Nothing, Nothing) ElseIf RblFormato.SelectedValue = "7" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoAF-ActivosFijos.xlsx" ElseIf RblFormato.SelectedValue = "8" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoContabilidad.xlsx" ElseIf RblFormato.SelectedValue = "9" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoContabilidad.xlsx" ElseIf RblFormato.SelectedValue = "11" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoPrePoliza.xlsx" ElseIf RblFormato.SelectedValue = "12" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoAlmacen.xlsx" ElseIf RblFormato.SelectedValue = "13" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoAnticipoProveedor.xlsx" ElseIf RblFormato.SelectedValue = "14" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoAnticipoCliente.xlsx" ElseIf RblFormato.SelectedValue = "15" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoBancos.xlsx" ElseIf RblFormato.SelectedValue = "16" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoClasificaciones.xlsx" ElseIf RblFormato.SelectedValue = "17" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoClientes-Facturas-Detalles.xlsx" ElseIf RblFormato.SelectedValue = "18" Then Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SaldosIniciales\FormatoProveedores-Facturas-Detalles.xlsx" End If If Not (Directorio = "") Then Dim Archivo As New IO.FileInfo(Directorio) If Archivo.Exists Then Response.Clear() Response.ClearHeaders() Response.ClearContent() Response.AddHeader("Content-Disposition", "attachment; filename=" + Archivo.Name) Response.AddHeader("Content-Length", Archivo.Length.ToString()) Response.ContentType = "text/plain" Response.Flush() Response.TransmitFile(Archivo.FullName) Response.End() End If End If End Sub Public Function validaRHPersonal(dt As DataTable) As Boolean Return True If Not dt.Columns(0).ColumnName = "Código" Then Alert("El nombre de la primera columna debe ser 'Código'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(1).ColumnName = "Apellido Paterno" Then Alert("El nombre de la segunda columna debe ser 'Apellido Paterno'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(2).ColumnName = "Apellido Materno" Then Alert("El nombre de la tercera columna debe ser 'Apellido Materno'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(3).ColumnName = "Nombre" Then Alert("El nombre de la cuarta columna debe ser 'Nombre'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(4).ColumnName = "Correo Electronico" Then Alert("El nombre de la quinta columna debe ser 'Correo Electronico'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(5).ColumnName = "Fecha Nacimiento" Then Alert("El nombre de la sexta columna debe ser 'Fecha Nacimiento'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(6).ColumnName = "Sexo" Then Alert("El nombre de la séptima columna debe ser 'Sexo'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(7).ColumnName = "Lugar Nacimiento" Then Alert("El nombre de la octava columna debe ser 'Lugar Nacimiento'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(8).ColumnName = "Dirección" Then Alert("El nombre de la novena columna debe ser 'Dirección'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(9).ColumnName = "Ciudad" Then Alert("El nombre de la décima columna debe ser 'Ciudad'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(10).ColumnName = "Estado Civil" Then Alert("El nombre de la onceava columna debe ser 'Estado Civil'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(11).ColumnName = "Teléfono" Then Alert("El nombre de la doceava columna debe ser 'Teléfono'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(12).ColumnName = "Celular" Then Alert("El nombre de la treceava columna debe ser 'Celular'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(13).ColumnName = "RFC" Then Alert("El nombre de la catorceava columna debe ser 'RFC'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(14).ColumnName = "CURP" Then Alert("El nombre de la quinceava columna debe ser 'CURP'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(15).ColumnName = "Numero SS" Then Alert("El nombre de la diesciseisava columna debe ser 'Numero SS'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(16).ColumnName = "CLABE" Then Alert("El nombre de la diescisieteava columna debe ser 'CLABE'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(17).ColumnName = "Fecha Ingreso" Then Alert("El nombre de la dieciochoava columna debe ser 'Fecha Ingreso'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(18).ColumnName = "Fecha Baja" Then Alert("El nombre de la diecinueveava columna debe ser 'Fecha Baja'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(19).ColumnName = "Alta IMSS" Then Alert("El nombre de la veinteava columna debe ser 'Alta IMSS'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(20).ColumnName = "Salario Diario" Then Alert("El nombre de la veinteunava columna debe ser 'Salario Diario'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(21).ColumnName = "Código Postal" Then Alert("El nombre de la veintedosava columna debe ser 'Código Postal'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(22).ColumnName = "Estatus Personal" Then Alert("El nombre de la veintetresava columna debe ser 'Estatus Personal'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(23).ColumnName = "Estado" Then Alert("El nombre de la veintecuatroava columna debe ser 'Estado'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(24).ColumnName = "Nombre Padre" Then Alert("El nombre de la veintecincoava columna debe ser 'Nombre Padre'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(25).ColumnName = "Nombre Madre" Then Alert("El nombre de la veinteseisava columna debe ser 'Nombre Madre'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(26).ColumnName = "Puesto" Then Alert("El nombre de la veintesieteava columna debe ser 'Puesto'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(27).ColumnName = "Turno" Then Alert("El nombre de la veinteochaava columna debe ser 'Turno'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(28).ColumnName = "Tipo Contrato" Then Alert("El nombre de la veintenueveava columna debe ser 'Tipo Contrato'. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(29).ColumnName = "Departamento" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(30).ColumnName = "Tipo Periodo" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(31).ColumnName = "Escolaridad" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(32).ColumnName = "Salario Diario" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(33).ColumnName = "Tipo Salario" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(34).ColumnName = "Salario variable" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(35).ColumnName = "Sindicalizado" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(36).ColumnName = "SubProyecto" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(37).ColumnName = "RegimenContratacion" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(38).ColumnName = "Area Geografica" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(39).ColumnName = "Prima vacacional" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(40).ColumnName = "Dias aguinaldo" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(41).ColumnName = "Metodo Pago" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(42).ColumnName = "SDI" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(43).ColumnName = "Nominista" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If If Not dt.Columns(44).ColumnName = "Registro Patronal" Then Alert("El nombre de la veintenueveava columna debe ser ''. Favor de corregirlo", TipoMensaje.MsgError) Return False End If End Function Protected Sub UpPersonal(dt As DataTable, DTCuentasContables As DataTable) Dim ErrorValidacion As Boolean = False If Not dt.Columns.Contains("CveCuentaContable") Then dt.Columns.Add("CveCuentaContable", GetType(Integer)) End If Dim sbErrores As New StringBuilder For Each Row As DataRow In dt.Rows Dim ApellidoPaterno As String = Row("Apellido Paterno").ToString() Dim ApellidoMaterno As String = Row("Apellido Materno").ToString() Dim Nombre As String = Row("Nombre").ToString() Dim CuentaContable As String = Row("CuentaContable").ToString().Trim.Replace("-", "").Replace(" ", "") If CuentaContable.Length > 0 Then Dim CveCuentaContable As Integer = DTCuentasContables.FiltroPrimeroValor("CveCuenta", $"Codigo ='{CuentaContable}'").ToEntero() If CveCuentaContable > 0 Then Row("CveCuentaContable") = CveCuentaContable Else sbErrores.AppendLine($"Empleado {Nombre} {ApellidoPaterno} {ApellidoMaterno} cuenta {CuentaContable} no encontrada.
") ErrorValidacion = True End If End If Next If Not ErrorValidacion Then dt.AcceptChanges() Else Alert($"Errores detectados
{sbErrores.ToString()}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim NumRows As Integer = 0 Dim dtregistrospatronales As New DataTable Dim dTSubProyectos As New DataTable Dim dTDepartamentos As New DataTable Dim dTTurno As New DataTable Dim ObjRH As New ClsRH Dim dtTipoTrabajador As New DataTable If (ObjRH.TiposTrabajadorGet(-1, UsuarioActual.CveEmpresa)) Then dtTipoTrabajador = ObjRH.DtResultados End If Dim dtpuestos As DataTable = GlobalDTRHPuestos(UsuarioActual.CveEmpresa) dtpuestos.CaseSensitive = False If ObjRH.GetRegistrosPatronales(-1, UsuarioActual.CveEmpresa, -1) Then dtregistrospatronales = ObjRH.DtResultados dtregistrospatronales.CaseSensitive = False dTSubProyectos = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) dTDepartamentos = GlobalDTDepartamentos(UsuarioActual.CveEmpresa) dTTurno = GlobalDTTurno(UsuarioActual.CveEmpresa) dTSubProyectos.CaseSensitive = False dTDepartamentos.CaseSensitive = False dTTurno.CaseSensitive = False End If Try ObjRH.IniciaTransacSQL() Dim ErrorRH As Boolean = False Dim Contador As Integer = 0 Dim ContadorAgregados As Integer = 0 Dim NumRow As Integer = 0 For Each Row As DataRow In dt.Rows Dim myarraystr As String() Dim RegistroPatronal As String = Row("Registro Patronal").ToString().ToUpper().Trim Dim Codigo As String = Row("Código").ToString().Trim Dim ApellidoPaterno As String = Row("Apellido Paterno").ToString().Trim Dim ApellidoMaterno As String = Row("Apellido Materno").ToString().Trim Dim Nombre As String = Row("Nombre").ToString().Trim Dim CorreoElectronico As String = Row("Correo Electronico").ToString().Trim Dim FechaIngreso As String = Row("Fecha Ingreso").ToString().Trim Dim FechaBaja As String = Row("Fecha Baja").ToString().Trim Dim NumeroSS As String = Row("Numero SS").ToString().Trim Dim AltaIMSS As String = Row("Alta IMSS").ToString().Trim Dim SalarioDiario As String = Row("Salario Diario").ToString().Trim Dim Direccion As String = Row("Dirección").ToString().Trim Dim FechaNacimiento As String = Row("Fecha Nacimiento").ToString().Trim Dim LugarNacimiento As String = Row("Lugar Nacimiento").ToString().Trim Dim Sexo As String = Row("Sexo").ToString().Trim Dim CodigoPostal As String = Row("Código Postal").ToString().Trim Dim Colonia As String = Row("Colonia").ToString().Trim Dim NumExterior As String = Row("NumExterior").ToString().Trim Dim Ciudad As String = Row("Ciudad").ToString().Trim Dim EstadoCivil As String = Row("Estado Civil").ToString().ToUpper.Trim Dim Telefono As String = Row("Teléfono").ToString().Trim Dim Celular As String = Row("Celular").ToString().Trim Dim RFC As String = Row("RFC").ToString().Trim Dim CURP As String = Row("CURP").ToString().Trim Dim ClabeInterbancaria As String = Row("CLABE").ToString().Trim Dim EstatusPersonal As String = Row("Estatus Personal").ToString().ToUpper.Trim Dim SubProyecto As String = Row("SubProyecto").ToString().ToUpper.Trim 'Nuevas Dim Estado As String = Row("Estado").ToString().Trim Dim NombrePadre As String = Row("Nombre Padre").ToString().Trim Dim NombreMadre As String = Row("Nombre Madre").ToString().Trim Dim Puesto As String = Row("Puesto").ToString().Trim Dim Turno As String = Row("Turno").ToString().Trim Dim TipoContrato As String = Row("Tipo Contrato").ToString().Trim Dim Departamento As String = Row("Departamento").ToString().Trim Dim TipoPeriodo As String = Row("Tipo Periodo").ToString().Trim Dim Escolaridad As String = Row("Escolaridad").ToString().Trim Dim SDI As String = Row("SDI").ToString().Trim Dim MetodoPago As String = Row("Metodo Pago").ToString().Trim Dim Nominista As String = Row("Nominista").ToString().Trim Dim CveCuentaContable As Integer = Row("CveCuentaContable").ToString().ToEntero() Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal Dim TipoTrabajador As String = Row("Tipo Trabajador").ToString().Trim Dim NombreCompleto As String = $"{Nombre} {ApellidoPaterno} {ApellidoMaterno}" If NombreCompleto.Trim.Replace(" ", "") = String.Empty Then Continue For End If 'CLAVES Dim CveGenero As Integer = 0 Dim CveEstadoCivil As Integer = 0 Dim CveEstatusPersonal As Integer = 0 ' Dim CveSucursal As Integer = GlobalDTSucursales(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSucursal").ToString().ToEntero() Dim CveRegistroPatronal As Integer Dim CvePuesto As Integer Dim CveTurno As Integer Dim CveDepartamento As Integer Dim CveEstado As Integer Dim CveTipoContrato As Integer Dim CveTipoPeriodo As Integer Dim CveEscolaridad As Integer Dim CveMetodoPago As Integer Dim CveUsuarioNomina As Integer Dim CveSubProyecto As Integer Dim CveTipoTrabajador As Integer myarraystr = Puesto.Split(":"c) If (myarraystr.Length > 1) Then CvePuesto = myarraystr(0).ToEntero() CvePuesto = dtpuestos.FiltroPrimeroValor("CvePuesto", $"(CvePuesto) = ({CvePuesto})").ToString().ToEntero() Else CvePuesto = dtpuestos.FiltroPrimeroValor("CvePuesto", $"(Puesto) = ('{Puesto}')").ToString().ToEntero() End If If CvePuesto <= 0 Then Dim ObjRH2 As New ClsRH ObjRH2.AddPuesto(Puesto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) ObjRH2.Dispose() GlobalDTRHPuestos(UsuarioActual.CveEmpresa) = Nothing dtpuestos = GlobalDTRHPuestos(UsuarioActual.CveEmpresa) CvePuesto = dtpuestos.FiltroPrimeroValor("CvePuesto", $"(Puesto) = ('{Puesto}')").ToString().ToEntero() End If CveTipoTrabajador = dtTipoTrabajador.FiltroPrimeroValor("CveTipoTrabajador", $"(TipoTrabajador) = ('{TipoTrabajador}')").ToString().ToEntero() If CveTipoTrabajador = 0 Then CveTipoTrabajador = -1 End If CveRegistroPatronal = dtregistrospatronales.FiltroPrimeroValor("CveRegistroPatronal", $"(RegistroPatronal) = ('{RegistroPatronal}')").ToString().ToEntero() If CvePuesto = 0 Then CvePuesto = -1 End If myarraystr = Turno.Split(":"c) If (myarraystr.Length > 1) Then CveTurno = myarraystr(0).ToEntero() CveTurno = dTTurno.FiltroPrimeroValor("CveTurno", $"CveTurno = {CveTurno}").ToString().ToEntero() Else CveTurno = dTTurno.FiltroPrimeroValor("CveTurno", $"Turno = '{Turno}'").ToString().ToEntero() End If If CveTurno = 0 Then CveTurno = -1 End If myarraystr = SubProyecto.Split(":"c) If (myarraystr.Length > 1) Then CveSubProyecto = myarraystr(0).ToEntero() CveSubProyecto = dTSubProyectos.FiltroPrimeroValor("CveSubProyecto", $"CveSubProyecto = {CveSubProyecto}").ToEntero() Else CveSubProyecto = dTSubProyectos.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{SubProyecto}'").ToEntero() End If If CveSubProyecto = 0 Then CveSubProyecto = -1 End If myarraystr = Departamento.Split(":"c) If (myarraystr.Length > 1) Then CveDepartamento = myarraystr(0).ToEntero() CveDepartamento = dTDepartamentos.FiltroPrimeroValor("CveDepartamento", $"CveDepartamento = {CveDepartamento}").ToString().ToEntero() Else CveDepartamento = dTDepartamentos.FiltroPrimeroValor("CveDepartamento", $"Departamento = '{Departamento}'").ToString().ToEntero() End If If CveDepartamento <= 0 Then Dim ObjRH2 As New ClsRH ObjRH2.AddDepartamento(Departamento, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) ObjRH2.Dispose() CveDepartamento = dTDepartamentos.FiltroPrimeroValor("CveDepartamento", $"Departamento = '{Departamento}'").ToString().ToEntero() End If myarraystr = Estado.Split(":"c) If (myarraystr.Length > 1) Then CveEstado = myarraystr(0).ToEntero() CveEstado = GlobalDTGralEstados("MEX").FiltroPrimeroValor("CveEstado", $"CveEstado = {CveEstado}").ToString().ToEntero() Else CveEstado = GlobalDTGralEstados("MEX").FiltroPrimeroValor("CveEstado", $"NombreEstado = '{Estado}'").ToString().ToEntero() End If If CveEstado = 0 Then CveEstado = -1 End If myarraystr = TipoContrato.Split(":"c) If (myarraystr.Length > 1) Then CveTipoContrato = myarraystr(0).ToEntero() CveTipoContrato = GlobalDTTiposContrato().FiltroPrimeroValor("CveTipoContrato", $"CveTipoContrato = {CveTipoContrato}").ToString().ToEntero() Else CveTipoContrato = GlobalDTTiposContrato().FiltroPrimeroValor("CveTipoContrato", $"TipoContrato = '{TipoContrato}'").ToString().ToEntero() End If If CveTipoContrato = 0 Then CveTipoContrato = -1 myarraystr = TipoContrato.Split("-"c) If (myarraystr.Length > 1) Then CveTipoContrato = myarraystr(0).Trim().ToEntero() End If If CveTipoContrato = 0 Then CveTipoContrato = -1 End If End If myarraystr = TipoPeriodo.Split(":"c) If (myarraystr.Length > 1) Then CveTipoPeriodo = myarraystr(0).ToEntero() CveTipoPeriodo = GlobalDTTipoPeriodo().FiltroPrimeroValor("CveTipoPeriodo", $"CveTipoPeriodo = {CveTipoPeriodo}").ToString().ToEntero() Else CveTipoPeriodo = GlobalDTTipoPeriodo().FiltroPrimeroValor("CveTipoPeriodo", $"TipoPeriodo = '{TipoPeriodo}'").ToString().ToEntero() End If If CveTipoPeriodo = 0 Then CveTipoPeriodo = -1 End If myarraystr = Escolaridad.Split(":"c) If (myarraystr.Length > 1) Then CveEscolaridad = myarraystr(0).ToEntero() CveEscolaridad = GlobalDTEscolaridad().FiltroPrimeroValor("CveEscolaridad", $"CveEscolaridad = {CveEscolaridad}").ToString().ToEntero() Else CveEscolaridad = GlobalDTEscolaridad().FiltroPrimeroValor("CveEscolaridad", $"Escolaridad = '{Escolaridad}'").ToString().ToEntero() End If 'If CveEscolaridad = 0 Then ' CveEscolaridad = -1 'End If myarraystr = MetodoPago.Split(":"c) If (myarraystr.Length > 1) Then CveMetodoPago = myarraystr(0).ToEntero() CveMetodoPago = GlobalDTVtaMetodoPago().FiltroPrimeroValor("CveMetodoPago", $"CveMetodoPago = {CveMetodoPago}").ToString().ToEntero() Else CveMetodoPago = GlobalDTVtaMetodoPago().FiltroPrimeroValor("CveMetodoPago", $"ClaveMetodoPagoSAT = '{MetodoPago}'").ToString().ToEntero() End If If CveMetodoPago = 0 Then CveMetodoPago = -1 End If myarraystr = Nominista.Split(":"c) If (myarraystr.Length > 1) Then CveUsuarioNomina = myarraystr(0).ToEntero() CveUsuarioNomina = GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUsuario", $"CveUsuario = {CveUsuarioNomina}").ToString().ToEntero() Else CveUsuarioNomina = GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveUsuario", $"Nombre = '{Nominista}'").ToString().ToEntero() End If If CveUsuarioNomina = 0 Then CveUsuarioNomina = -1 End If Dim FechaIn As Date Dim FechaFn As Date Dim FechaNac As Date FechaIn = If(IsDate(FechaIngreso), FechaIngreso.ToDate, MinFecha) FechaFn = If(IsDate(FechaBaja), FechaBaja.ToDate, MinFecha) FechaNac = If(IsDate(FechaNacimiento), FechaNacimiento.ToDate, MinFecha) 'VALIDACIONES ' If Not CveSucursal > 0 Then Alert("La Empresa no cuenta con Sucursal, es necesario dar una Sucursal de alta.", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveDepartamento > 0 Then Alert($"No se encontró el Departamento: {Departamento} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) ErrorRH = True Exit For End If If Not CveRegistroPatronal > 0 Then Alert($"No se encontró el Registropatronal: {RegistroPatronal} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CvePuesto > 0 Then Alert($"No se encontró el Puesto: {Puesto} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveTurno > 0 Then Alert($"No se encontró el turno: {Turno} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveEstado > 0 Then Alert($"No se encontró el Estado: {Estado} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveTipoContrato > 0 Then Alert($"No se encontró el Tipo Contrato: {TipoContrato} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveTipoPeriodo > 0 Then Alert($"No se encontró el Tipo Periodo: {TipoPeriodo} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For 'If Not CveEscolaridad > 0 Then Alert($"No se encontró el Escolaridad: {Escolaridad} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveMetodoPago > 0 Then Alert($"No se encontró el Método de Pago: {MetodoPago} Renglón: {NumRow}: ", TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For If Not CveUsuarioNomina > 0 Then CveUsuarioNomina = -1 'Alert("No se encontró el Nominista: " + Nominista + " Renglón: " + NumRow, TipoMensaje.MsgAdvertencia) : ErrorRH = True : Exit For Dim CvePersonal As Integer = GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePersonal", $"NombreCompletoNombre = '{NombreCompleto}'").ToString().ToEntero() If Not (CvePersonal > 0) Then CvePersonal = GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePersonal", $"CURP = '{CURP}'").ToString().ToEntero() End If 'PENDIENTES POR MEJORAR Dim CveSATRegimenContratacion As Integer = 1 Dim CveSATRiesgoPuesto As Integer = 1 Dim CveJornada As Integer = 1 If Sexo.ToUpper.Contiene("Masculino", "1: Masculino") Then CveGenero = 1 Else CveGenero = 2 If AltaIMSS.ToUpper.Contiene("SI", "1") Then AltaIMSS = "True" Else AltaIMSS = "False" myarraystr = EstadoCivil.Split(":"c) If (myarraystr.Length > 1) Then CveEstadoCivil = myarraystr(0).ToEntero() End If If CveEstadoCivil = 0 Then CveEstadoCivil = 1 End If 'Select Case EstadoCivil ' Case "SOLTERO" ' CveEstadoCivil = 1 ' Case "CASADO" ' CveEstadoCivil = 2 ' Case "DIVORCIADO" ' CveEstadoCivil = 3 ' Case "UNIÓN LIBRE" ' CveEstadoCivil = 4 ' Case "VIUDO" ' CveEstadoCivil = 5 ' Case Else ' CveEstadoCivil = 1 'End Select myarraystr = EstatusPersonal.Split(":"c) If (myarraystr.Length > 0) Then CveEstatusPersonal = myarraystr(0).ToEntero() End If If CveEstatusPersonal = 0 Then CveEstatusPersonal = 1 End If 'Select Case EstatusPersonal ' Case "ACTIVO" ' CveEstatusPersonal = 1 ' Case "INACTIVO" ' CveEstatusPersonal = 2 ' Case "REINGRESO" ' CveEstatusPersonal = 5 ' Case Else ' CveEstatusPersonal = 1 'End Select If CvePersonal > 0 Then Contador = Contador + 1 Else If SalarioDiario.ToDouble > SDI.ToDouble Then SDI = SalarioDiario End If If Not ObjRH.AddPersonal(Codigo, ApellidoPaterno, ApellidoMaterno, Nombre, CorreoElectronico, FechaIn, CveTipoPeriodo, NumeroSS, CBool(AltaIMSS), SalarioDiario.ToDouble, SalarioDiario.ToDouble, SDI.ToDouble, SDI.ToDouble, -1, -1, -1, CveMetodoPago, FechaIn, FechaFn.ToString(), CveTipoContrato, Direccion, CveTurno, CvePuesto, CveDepartamento, -1, CveEscolaridad, CveEstadoCivil, CveGenero, -1, FechaBaja, CveEstatusPersonal, FechaNac, LugarNacimiento, Direccion, NumExterior, "", Colonia, CodigoPostal, Ciudad, CveEstado, Telefono, "", Celular, RFC, CURP, "", NombrePadre, NombreMadre, -1, CveSATRiesgoPuesto, CveSATRegimenContratacion, -1, CveSubProyecto, "", -1, ClabeInterbancaria, "", CveJornada, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveUsuarioNomina, "", CveRegistroPatronal:=CveRegistroPatronal, CveTipoTrabajador:=CveTipoTrabajador) Then If (ObjRH.noguardoXcurpb) Then Else ErrorRH = True Exit For End If Else ContadorAgregados = ContadorAgregados + 1 End If If CveCuentaContable > 0 Then Dim ObjConta As New ClsContabilidad(ObjRH.IniciaTransacSQL) If Not ObjConta.AddCuentasAsignaciones(28, UsuarioActual.CveEmpresa, CveCuentaContable, -1, -1, ObjRH.CvePersonal, -1, -1, 0, CveBancoCuenta:=-1, CveConceptoNomina:=-1, CveSubProyecto:=-1, CveActivoFijo:=-1, CveTipoGasto:=-1, RegeneraCuenta:=False) Then ErrorRH = True Exit For End If End If If Saldo > 0 Then If Not CveCuentaContable > 0 Then Alert($"Personal {NombreCompleto} tiene saldo pero no se especifico cuenta contable.") ErrorRH = True Exit For End If Dim CveCuentaBancaria As Integer = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa, Estatus:=1).FiltroPrimeroValor("CveCuenta", "").ToEntero() If Not CveCuentaBancaria > 0 Then Alert("No se detecto una cuenta Bancaria", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjConta As New ClsContabilidad(ObjRH.IniciaTransacSQL) Dim ObjBancos As New ClsBancos(ObjRH.IniciaTransacSQL) Dim Fecha As Date = TxtFecha.Text.ToDate Dim FolioStr As String = "" FolioStr = CStr(ObjBancos.GetNextFolio(CveCuentaBancaria, 3) + Contador) Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Saldo/Personal/SaldoInicial", 23, Saldo, Saldo, 1, Fecha, FolioStr, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not CvePrePoliza > 0 Then ErrorRH = True Exit For End If Dim CveIE As Integer = ObjBancos.AddBancos_IE(CveCuentaBancaria, 3, Fecha, FolioStr.ToString(), "", Saldo, 1, 1, "Saldo Inicial", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, Saldo, 30, FolioStr.ToString(), FolioStr, CveIE:=CveIE, CvePersonal:=CvePersonal, Contabilizable:=False) Then ErrorRH = True : Exit For If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Saldo, Saldo, 28, FolioStr.ToString(), FolioStr, CveIE:=CveIE, CvePersonal:=CvePersonal, Contabilizable:=False) Then ErrorRH = True : Exit For End If End If NumRow = NumRow + 1 Next If Not ErrorRH Then If Contador > 0 Then Alert(String.Format("Se agregaron: {0} Empleados correctamente.
Se Omitieron: {1} Empleados ya que ya se encontraban registrados.", ContadorAgregados, Contador), TipoMensaje.MsgInformacion) ObjRH.Commit() TxtExcel.Text = "" UpDatos.Update() Else Alert(String.Format("Se agregaron: {0} Empleados correctamente.", ContadorAgregados), TipoMensaje.MsgInformacion) ObjRH.Commit() TxtExcel.Text = "" UpDatos.Update() End If Else ObjRH.RollBack() End If Catch ex As Exception GuardaLog($"Ocurrio un error al insertar el personal.: {ex}") ObjRH.RollBack() Finally ObjRH.Dispose() End Try End Sub Protected Sub LnkCargaMasiva_Click(sender As Object, e As EventArgs) Dim wb As ClosedXML.Excel.XLWorkbook = New ClosedXML.Excel.XLWorkbook() Dim libro As IXLWorksheet = wb.AddWorksheet("Personal") Dim crow As Integer = 1 Dim ccol As Integer = 1 Dim colLugarNacimiento As Integer = 1 Dim rowLugarNacimiento As Integer = 1 #Region "Regimen de contratación" Dim Catalogos As IXLWorksheet = wb.AddWorksheet("Catalogos") crow = 1 ccol = 1 Dim colRegimenContratacion As Integer = 1 Dim rowRegimenContratacion As Integer = 1 Catalogos.Cell(crow, ccol).Value = "Regimen de contratación" For Each row As DataRow In GlobalDTNomSatRegimenContratacion.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveSATRegimenContratacion"), row("RegimenContratacion")) Next colRegimenContratacion = ccol rowRegimenContratacion = crow #End Region #Region "Estado civil" Dim colEstadoCivil As Integer = 1 Dim rowEstadoCivil As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Estado civil" For Each row As DataRow In GlobalDTEstadoCivil.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveEstadoCivil"), row("EstadoCivil")) Next colEstadoCivil = ccol rowEstadoCivil = crow #End Region #Region "Escolaridad" Dim colEscolaridad As Integer = 1 Dim rowEscolaridad As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Escolaridad" For Each row As DataRow In GlobalDTEscolaridad.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveEscolaridad"), row("Escolaridad")) Next colEscolaridad = ccol rowEscolaridad = crow #End Region #Region "Tipo Periodo" Dim colTipoPeriodo As Integer = 1 Dim rowTipoPeriodo As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Tipo Periodo" For Each row As DataRow In GlobalDTTipoPeriodo.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveTipoPeriodo"), row("TipoPeriodo")) Next colTipoPeriodo = ccol rowTipoPeriodo = crow #End Region #Region "Estatus" Dim colEstatusPersonal As Integer = 1 Dim rowEstatusPersonal As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Estatus" For Each row As DataRow In GlobalDTEstatusPersonal.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveEstatusPersonal"), row("EstatusPersonal")) Next colEstatusPersonal = ccol rowEstatusPersonal = crow #End Region #Region "Tipo Contratro" Dim colTipoContrato As Integer = 1 Dim rowTipoContrato As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Tipo Contratro" For Each row As DataRow In GlobalDTTiposContrato.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}", row("TipoContrato")) Next colTipoContrato = ccol rowTipoContrato = crow #End Region #Region "Departamento" Dim colDepartamento As Integer = 1 Dim rowDepartamento As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Departamento" For Each row As DataRow In GlobalDTDepartamentos(UsuarioActual.CveEmpresa).Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveDepartamento"), row("Departamento")) Next colDepartamento = ccol rowDepartamento = crow #End Region #Region "Turno" Dim colTurno As Integer = 1 Dim rowTurno As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Turno" For Each row As DataRow In GlobalDTTurno(UsuarioActual.CveEmpresa).Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveTurno"), row("Turno")) Next colTurno = ccol rowTurno = crow #End Region #Region "Puesto" Dim colPuesto As Integer = 1 Dim rowPuesto As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Puesto" For Each row As DataRow In GlobalDTRHPuestos(UsuarioActual.CveEmpresa).Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CvePuesto"), row("Puesto")) Next colPuesto = ccol rowPuesto = crow #End Region #Region "Estado" Dim colEstado As Integer = 1 Dim rowEstado As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Estado" For Each row As DataRow In GlobalDTGralEstados("MEX").Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveEstado"), row("NombreEstado")) Next colEstado = ccol rowEstado = crow #End Region #Region "Tipo salario" Dim colTipoSalario As Integer = 1 Dim rowTipoSalario As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Tipo salario" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "1: Salario fijo" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "2: Salario variable" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "3: Salario mixto" colTipoSalario = ccol rowTipoSalario = crow #End Region #Region "Genero" Dim colSexo As Integer = 1 Dim rowSexo As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Genero" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "1: Masculino" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "2: Femenino" colSexo = ccol rowSexo = crow #End Region #Region "Sindicalizado" Dim colsindicalizado As Integer = 1 Dim rowsindicalizado As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Sindicalizado" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "1: Sí" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "0: No" colsindicalizado = ccol rowsindicalizado = crow #End Region #Region "Area geografica" Dim colAreaGeografica As Integer = 1 Dim rowAreaGeografica As Integer = 1 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Area geografica" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "A" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "B" crow = crow + 1 Catalogos.Cell(crow, ccol).Value = "C" colAreaGeografica = ccol rowAreaGeografica = crow #End Region #Region "Metodo pago" Dim colmetodopago As Integer = 0 Dim rowmetodopago As Integer = 0 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "Metodo pago" For Each row As DataRow In GlobalDTVtaMetodoPago.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveMetodoPago"), row("MetodoPago")) Next colmetodopago = ccol rowmetodopago = crow #End Region #Region "subproyecto" Dim colsubproyecto As Integer = 0 Dim rowsubproyecto As Integer = 0 crow = 1 ccol = ccol + 1 Catalogos.Cell(crow, ccol).Value = "subproyecto" Dim dtsubproyecto As DataTable = If(Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(UsuarioActual.CveEmpresa, Estatus:=1)) For Each row As DataRow In dtsubproyecto.Rows crow = crow + 1 Catalogos.Cell(crow, ccol).Value = String.Format("{0}: {1}", row("CveSubProyecto"), row("SubProyecto")) Next colsubproyecto = ccol rowsubproyecto = crow #End Region Catalogos.Range(1, 1, 1, ccol).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189)) Catalogos.Range(1, 1, 1, ccol).Style.Font.FontColor = ClosedXML.Excel.XLColor.White crow = 1 ccol = 1 libro.Cell(crow, ccol).Value = "Código" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Apellido Paterno" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Apellido Materno" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Nombre" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Correo Electronico" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Fecha Nacimiento" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Sexo" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colSexo, rowSexo, colSexo), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Lugar Nacimiento" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Dirección" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Ciudad" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Estado Civil" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colEstadoCivil, rowEstadoCivil, colEstadoCivil), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Teléfono" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Celular" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "RFC" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "CURP" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Numero SS" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "CLABE" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Fecha Ingreso" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Fecha Baja" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Alta IMSS" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Código Postal" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Estatus Personal" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colEstatusPersonal, rowEstatusPersonal, colEstatusPersonal), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Estado" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colEstado, rowEstado, colEstado), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Nombre Padre" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Nombre Madre" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Puesto" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colPuesto, rowPuesto, colPuesto), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Turno" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colTurno, rowTurno, colTurno), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Tipo Contrato" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colTipoContrato, rowTipoContrato, colTipoContrato), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Departamento" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colDepartamento, rowDepartamento, colDepartamento), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Tipo Periodo" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colTipoPeriodo, rowTipoPeriodo, colTipoPeriodo), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Escolaridad" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colEscolaridad, rowEscolaridad, colEscolaridad), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Salario Diario" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Tipo Salario" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colTipoSalario, rowTipoSalario, colTipoSalario), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Salario variable" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Sindicalizado" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colsindicalizado, rowsindicalizado, colsindicalizado), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "SubProyecto" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colsubproyecto, rowsubproyecto, colsubproyecto), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "RegimenContratacion" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colRegimenContratacion, rowRegimenContratacion, colRegimenContratacion), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Area Geografica" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colAreaGeografica, rowAreaGeografica, colAreaGeografica), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Prima vacacional" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Dias aguinaldo" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Metodo Pago" : libro.Range(crow + 1, ccol, 50000, ccol).SetDataValidation().List(Catalogos.Range(2, colmetodopago, rowmetodopago, colmetodopago), True) : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "SDI" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Nominista" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Registro Patronal" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "CuentaContable" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Saldo" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "Tipo Trabajador" : ccol = ccol + 1 libro.Cell(crow, ccol).Value = "RegistroPatronal" : ccol = ccol + 1 ' libro.Range(crow, 1, crow, ccol - 1).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189)) libro.Range(crow, 1, crow, ccol - 1).Style.Font.FontColor = ClosedXML.Excel.XLColor.White Catalogos.ColumnsUsed().AdjustToContents() libro.ColumnsUsed().AdjustToContents() 'AreaGeografica ABC 'GlobalDTMetodosPago MetodoPago" DataValueField="CveMetodoPago Dim fs As System.IO.Stream = New System.IO.MemoryStream() wb.SaveAs(fs) fs.Position = 0 Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream() Using input As System.IO.Stream = fs input.CopyTo(memoryStream) End Using memoryStream.Position = 0 Response.Clear() Response.Buffer = True Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" Response.AddHeader("content-disposition", String.Format("attachment;filename=SaldosInicialesRH.xlsx", "")) Response.BinaryWrite(memoryStream.ToArray()) Response.[End]() End Sub End Class