Files
SIG/General/SaldosIniciales.aspx.vb

4019 lines
212 KiB
VB.net

Option Strict On
Option Explicit On
Imports System.Data
Imports System.Math
Imports Extensiones
Imports GemBox.Spreadsheet
Imports log4net.Filter
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 = Now.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 = False
Dim ErrorExcel = 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" 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 = "4" Then
' If Not dt.Columns(15).ColumnName = "ImpuestoLocal" Then
' Alert("El nombre de la diesciseisava columna debe ser 'ImpuestoLocal'. Favor de corregirlo", TipoMensaje.MsgError)
' Exit Sub
' End If
' If Not dt.Columns(16).ColumnName = "Amort.Ant" Then
' Alert("El nombre de la diescisieteava columna debe ser 'Amort.Ant'. Favor de corregirlo", TipoMensaje.MsgError)
' Exit Sub
' 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
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 = "Descripcion" 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 = "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(5).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
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
If ObjGral.GetMedidas(UsuarioActual.CveEmpresa) Then
DtMedidas = ObjGral.DtResultados.Copy
End If
If ObjGral.GetRimTamanios(UsuarioActual.CveEmpresa) Then
DtRinTamaño = ObjGral.DtResultados.Copy
End If
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.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 = Row("IEPS").ToString().ToDecimal
Dim Tamaño As String = Row("Tamaño").ToString().Trim
Dim SATClavePS As String = Row("Código SAT").ToString().Trim
Dim Clasificacion2 As String = If(dt.Columns.Contains("Servicio"), Row("Servicio").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 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, "", -1, "-1", -1, "-1", -1, "-1",
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
If ObjUM.GetUnidadesMedida(UsuarioActual.CveEmpresa) 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.GetRimTamanios(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, "", -1, "-1", -1, "-1", -1, "-1", 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, "", CodigoBarras, Descripcion, Precio, -1, RetIVA, False, -1, True, True, True, UsuarioActual.CveUsuario, CvePS, -1, -1, CveSATPS,
CveTipoPS:=CveTipoPS, CveMarca:=CveMarca, CveMedida:=CveMedida, CveRinTamaño:=CveRinTamaño,
CveModelo:=CveModelo, Litraje:=Litraje, IEPSPorcentaje:=IEPS, CveClasificacion2:=CveClasificacion2, CveTamaño:=CveTamaño, AplicaSerie:=AplicaSerie) 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, "", 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) <= 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: <b>{0}</b> Productos/Servicios correctamente. <br>Se Actualizaron: <b>{1}</b> Productos/Servicios ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion)
Else
Alert(String.Format("Se agregaron: <b>{0}</b> 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.<br>")
ErrorProv = True
End If
End If
Next
For Each Row As DataRow In dt.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.<br>")
ErrorProv = True
End If
Next
If Not ErrorProv Then
dt.AcceptChanges()
Else
Alert($"Errores detectados <br>{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.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.<br>")
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.<br>")
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.<br>")
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.<br>")
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.<br>")
ErrorProv = True
End If
End If
If ErrorProv Then
Alert($"Errores detectados <br>{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, -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "", -1, "",
-1, "", -1, "", -1, "", CveProveedorClasificacion, -1, "", "", False, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CP:=CodigoPostal, CveRegimenFiscal:=CveRegimenFiscal,
CveTipoProveedor:=TipoProveedor, CveMonedaPreferente:=CveMoneda, DIOTCveTipoTercero:=DIOTCveTipoTercero, DIOTCveTipoOperacion:=DIOTCveTipoOperacion) Then
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, "-1", "-1", NumeroCuenta, ClabeInter, "-1", "-1", "-1", "-1", 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, -1,
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: <b>{0}</b> Proveedores correctamente. <br>Se Omitieron: <b>{1}</b> Proveedores ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion)
Else
Alert(String.Format("Se agregaron: <b>{0}</b> 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 NumRow As Integer = 0
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($"Cliente {RazonSocial} cuenta {CuentaContable} no encontrada.<br>")
ErrorClientes = True
End If
End If
Next
If Not ErrorClientes Then
dt.AcceptChanges()
Else
Alert($"Errores detectados <br>{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()
Dim RazonSocial As String = Row("RazonSocial").ToString()
Dim RFC As String = Row("RFC").ToString().Trim
Dim Calle As String = Row("Calle").ToString()
Dim NumExt As Decimal = Row("Número exterior").ToString().ToDecimal
Dim Colonia As String = Row("Colonia").ToString()
Dim CodigoPostal As String = Row("Código Postal").ToString()
Dim Poblacion As String = Row("Población").ToString()
Dim Estado As String = Row("Estado").ToString().Trim
Dim Pais As String = Row("Pais").ToString()
Dim Telefono As String = Row("Teléfono").ToString().Replace("-", "").Replace(" ", "").Replace("(", "").Replace(")", "")
Dim Contacto As String = Row("Contacto").ToString()
Dim Vendedor As String = Row("Vendedor").ToString()
Dim Clasificacion As String = Row("ClasificacionCliente").ToString()
Dim CveCliente As Integer = GlobalDTCliente(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero()
Dim CveVendedor As Integer = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero()
Dim CveClasificación As Integer = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", $"Clasificacion = '{Clasificacion}'").ToString().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 = Row("Limite Credito").ToString().ToDecimal
Dim CobranzaCorreo As String = Row("CorreoPagos").ToString()
Dim PlazoCobranza As Integer = Row("Plazo Cobranza").ToString().ToEntero()
Dim DìaVisita As String = If(dt.Columns.Contains("Dia Pago"), Row("Dia Pago").ToString(), "")
Dim DiasPagoEspecifico As String = If(dt.Columns.Contains("Dìa Visita"), Row("Dìa Visita").ToString(), "")
Dim CobranzaContacto As String = If(dt.Columns.Contains("Encargado Pagoa"), Row("Encargado Pago").ToString(), "")
Dim CobranzaTelefono As String = Row("Celular Contacto").ToString().Replace("-", "").Replace(" ", "").Replace("(", "").Replace(")", "")
Dim CveUsoCFDI As Integer = If(Row("UsoCFDI").ToString() = "", -1, GlobalDTSATUsosCFDI().FiltroPrimeroValor("CveUsoCFDI", String.Format("UsoCFDI = '{0}'", Row("UsoCFDI").ToString())).ToEntero())
Dim CveCuentaContable As Integer = Row("CveCuentaContable").ToString().ToEntero()
' CobranzaContacto = Regex.Replace(CobranzaContacto, "[^0-9]", "")
'Telefono
If Telefono.Trim.Length > 10 Then
Telefono = ""
End If
If CobranzaTelefono.Trim.Length > 10 Then
CobranzaTelefono = ""
End If
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
'Dim RazonSocial As String = Row("RazonSocial").ToString()
'Contacto
If CveCliente > 0 Then
ExisteCliente = True
Contador = Contador + 1
'If Not ObjClientes.UpdateCliente(RazonSocial, RazonSocial, Calle, "", "", Colonia, "", "", Estado, RFC, CodigoPostal, "", "", Contacto, "", "", "", "", -1, False, 1, -1, False, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", -1, -1, -1,
' "-1", -1, -1, -1, -1, "0", -1, "0", 0, "", 0, "", 0, "", 0, "", "", "", "", 0, "", 1, False, "", "", "", False, "", "", "", "", "", False, "", "", "", False, 0, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", "", False, -1) Then
' ErrorClientes = True
' RFC.GuardaLog
' Exit For
'End If
Else
Dim CveSATEstado As Integer = GlobalDTGralEstados("MEX").FiltroPrimeroValor("CveSATEstado", String.Format(" NombreEstado ='{0}'", Estado.ToUpper)).ToEntero()
If Not ObjClientes.AddCliente(RazonSocial, RazonSocial, Calle, NumExt.ToString(), "", Colonia, Poblacion, Poblacion, Estado, Pais, RFC, CodigoPostal, Telefono, Contacto, "", "", "", "", "", -1, False, 0, 0, False, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", CveVendedor, PlazoCobranza, -1,
"-1", "-1", -1, "-1", -1, "0", -1, "0", 0, "", 0, "", 0, "", 0, "", "", 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) Then
ErrorClientes = True
RFC.GuardaLog
Exit For
End If
If CveCuentaContable > 0 Then
Dim ObjConta As New ClsContabilidad(ObjClientes.IniciaTransacSQL)
If Not ObjConta.AddCuentasAsignaciones(1, UsuarioActual.CveEmpresa, CveCuentaContable, -1,
-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: <b>{0}</b> Clientes correctamente. <br>Se Omitieron: <b>{1}</b> Clientes ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion)
Else
Alert(String.Format("Se agregaron: <b>{0}</b> 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 = New DataTable
Dim NoEncontrados = 0
Dim Encontrados As Integer = 0
DtProveedores = GlobalDTCompProveedores(UsuarioActual.CveEmpresa)
Dim RFC As String = ""
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(-1, CveEmpresa:=UsuarioActual.CveEmpresa)
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
RFC = Row("RFC").ToString().Trim
Dim Serie As String = Row("Serie").ToString()
Dim Folio As String = Row("Folio").ToString()
Dim Fecha As Date = Row("Fecha").ToString().ToDate
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 TipoDocto As String = Row("Tipo Documento").ToString()
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
Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal
Dim IEPS As Decimal = Row("IEPS").ToString().ToDecimal
Dim Moneda As String = Row("Moneda").ToString()
Dim TipoCambio As String = Row("Tipo Cambio").ToString()
Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate
Dim CveMoneda As Integer = 1
Dim CveProveedorSucursal As Integer = Row("CveProveedorSucursal").ToString().ToEntero()
Dim PorcentajeIVA As String = Row("PorcentajeIVA").ToString()
Dim ImpuestosLocales As Decimal = If(dt.Columns.Contains("ImpuestosLocales"), Row("ImpuestosLocales").ToString(), "0").ToDecimal
Dim RetIVAPorcentaje As Decimal = Row("RetIVAPorcentaje").ToString().ToDecimal
Dim RetISRPorcentaje As Decimal = Row("RetISRPorcentaje").ToString().ToDecimal
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
TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESOS", "INGRESO", "ING", "FACTURA"), "Fac", "NC").ToString()
'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") Then
CveMoneda = 2
End If
'Si no se especifica TC, se manda como pesos.
If TipoCambio = "" Then TipoCambio = "1"
'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
'Compra
If Not ObjCompras.AddCompra(TipoDocto, "", Serie, Folio, Folio2, CveProveedor.ToEntero(), SubTotal, 0, 0, IVA, RetIVA, RetISR, IEPS, 0, 0, Total, Fecha, CveMoneda, TipoCambio.ToDouble, FechaVencimiento,
False, CodProvee, 1, CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveProveedorSucursal:=CveProveedorSucursal,
NumeroReembolso:=Transaccion, PorcentajeIVA:=PorcentajeIVA.ToDecimal, TotalOriginal:=Total) Then
ErrorCompras = True
Exit For
End If
CveCompra = ObjCompras.CveCompra
'Compra Detalle
If Not ObjCompras.AddCompraDetalle(CveCompra, CveUnidadMedida, CvePS, Sucursal.ToEntero(), -1, 0, 1, SubTotal, 0.16D, SubTotal, 0, "Carga Inicial", -1, IVAPorcentaje:=PorcentajeIVA.ToDecimal, RetIVAPorcentaje:=RetIVAPorcentaje, RetISRPorcentaje:=RetISRPorcentaje) Then
ErrorCompras = True
Exit For
End If
Dim ConceptoContablePago As Integer = 17
If TipoDocto = "NC" Then ConceptoContablePago = 60
'PrePólizaDetalle
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Folio, IIf(TipoDocto = "Fac", 5, 18).ToString().ToEntero(), String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=Total, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, SubTotal, Folio, 6, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=SubTotal, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For
If IVA > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, IVA, Folio, 14, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=IVA, CveSubProyecto:=Sucursal.ToEntero(), CveClasificacion:=CveClasificacion, PorcentajeImpuesto:=PorcentajeIVA.ToDecimal) Then ErrorCompras = True : Exit For
End If
If IEPS > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, IEPS, Folio, 25, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=IEPS, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For
If RetIVA > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, RetIVA, Folio, 15, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=RetIVA, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For
If RetISR > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, RetISR, Folio, 16, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=RetISR, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For
If ImpuestosLocales > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImpuestosLocales, Folio, 27, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=ImpuestosLocales, CveSubProyecto:=Sucursal.ToEntero()) Then ErrorCompras = True : Exit For
'Saldo
If Saldo < Total Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, $"{Folio} SALDO INICIAL", 17, Folio, Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=Total - Saldo) Then ErrorCompras = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, $"{Folio} SALDO INICIAL", 95, Folio, Fecha, -1, -1, CveCompra:=CveCompra, CveProveedor:=CveProveedor, ImporteMX:=Total - Saldo) Then ErrorCompras = True : Exit For
End If
Encontrados = Encontrados + 1
Next
If Not ErrorCompras Then
If Contador > 0 Then
Alert(String.Format("Se agregaron: <b>{0}</b> Compras correctamente.<br>Se Omitieron: <b>{1}</b> Compras ya que ya se encuentran registradas.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion)
Else
Alert(String.Format("Se agregaron: <b>{0}</b> Compras correctamente.", NumRows), TipoMensaje.MsgInformacion)
End If
Alert(String.Format("Se agregaron: <b>{0}</b> Compras correctamente. RFC:{1} ", Encontrados, RFC), TipoMensaje.MsgInformacion)
ObjCompras.Commit()
TxtExcel.Text = ""
UpDatos.Update()
Else
Alert(String.Format("NO Se agregaron: <b>{0}</b> 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
#Region "C L I E N T E S - F A C T U R A S"
Dim ObjVentas As New ClsVentas
Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL())
Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL())
Dim ErrorVentas As Boolean = False
Dim CveVenta As Integer
Dim DtClientes = New DataTable
'Dim ExisteVenta As Boolean = False
'Dim Contador As Integer = 0
DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1)
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")
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(-1, CveEmpresa:=UsuarioActual.CveEmpresa)
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
Dim Serie As String = Row("Serie").ToString()
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 Double = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDouble, 0.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 Double = Row("Ret ISR").ToString().ToDouble
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 'Row("IEPS").ToString().ToDecimal
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 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()
'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"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "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ÓLARES", "DOLARES", "USD") Then
CveMoneda = 2
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") Then
GuardaLog(Serie & "-" & Folio)
If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDouble,
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) Then
ErrorVentas = True
Exit For
End If
CveVenta = ObjVentas.CveVenta
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) Then
ErrorVentas = True
Exit For
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
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, Folio.ToString(), 4, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, ImporteMX:=SubTotal, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Folio.ToString(), ConceptoContable, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=Total, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For
If IVA > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, Folio.ToString(), 13, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IVA, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For
End If
'If IEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio.ToString(), 38, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) Then ErrorVentas = True : Exit For
If RetIVA > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetIVA, Folio.ToString(), 8, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=RetIVA, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For
End If
If ImpuestoLocal > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, Folio.ToString(), 27, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=ImpuestoLocal, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For
End If
If UsaComplementaria Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Folio.ToString(), 203, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, ImporteMX:=Total * TipoCambio.ToDecimal - 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, Folio.ToString(), ConceptoContablePago, Folio.ToString(), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=Total - Saldo, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Folio.ToString(), 95, Folio.ToString(), Fecha, -1, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=Total - Saldo, 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, Folio.ToString(), 30, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Folio.ToString(), 66, String.Format("{0}-{1}", Serie, Folio), Fecha, -1, -1, CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For
End If
Encontrados = Encontrados + 1
Else
NoEncontrados = NoEncontrados + 1
StrRFCNoencontrados.AppendFormat("{0}<br/>", RFC)
ErrorVentas = True
Exit For
End If
Next
If Not ErrorVentas Then
Alert(String.Format("Se agregaron: <b>{0}</b> Ventas correctamente. <b>{1} no encontrados</b><br/>{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion)
ObjVentas.Commit()
TxtExcel.Text = ""
UpDatos.Update()
Else
Alert(String.Format("Error al registrar : <b>{0}</b> Ventas correctamente. <b>{1} no encontrados</b><br/>{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError)
ObjVentas.RollBack()
End If
ObjVentas.Dispose()
#End Region
' 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
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("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($"Activo Fijo {Codigo} {Descripcion} cuenta {CuentaContable} no encontrada.<br>")
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.<br>")
ErrorAF = True
End If
End If
Next
If Not ErrorAF Then
dt.AcceptChanges()
Else
Alert($"Errores detectados <br>{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 de compra").ToString().ToDecimal
Dim FechaAF As Date = Row("Fecha de compra").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(-1, CveEmpresa:=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("CveCuentaContable").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, CtaDepreciacion, CveEstadoActivoFijo,
CtaDepreciacion, 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, -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, -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: <b>{0}</b> Activos Fijos correctamente. <br>Se Omitieron: <b>{1}</b> Activos Fijos ya que ya se encontraban registrados.", NumRows - Contador, Contador), TipoMensaje.MsgInformacion)
ObjAF.Commit()
TxtExcel.Text = ""
UpDatos.Update()
Else
Alert(String.Format("Se agregaron: <b>{0}</b> 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 = 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 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("-", "")
Dim TipoCuenta As String = Row("TipoCuenta").ToString().Trim
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 = ObjConta.AddCuenta(CveCuentaPadre, Cuenta.Replace("-", ""), NombreCuenta, TipoCuenta, 1, 1, CveEmpresaParam:=UsuarioActual.CveEmpresa, CveAgrupadorSAT:=CveAgrupadorSAT)
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, Now.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} </br>")
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, Now, "") 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(-1, -1, CveEmpresa:=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} </br>")
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 </br>")
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, "", 95, Concepto, Now.ToDate, -1, -1, ImporteMX:=Importe, 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("<br/><br/>Prepóliza: <b><a href = ""/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={0}"" class=""texto"" target=""_blank"" >Prepóliza</a></b>", 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)
Dim AlmacenRef As DataTable = GlobalDTAlmacen(UsuarioActual.CveEmpresa)
Dim contadorMovimientos As Integer = 0
Dim listadoMovimientos As String = ""
Dim mensajeError As String = ""
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 <a href='/Inventarios/EntradasSalidas.aspx?CveMovimiento={movimientoCabecera}' target='_blank' style='color:blue'>{ObjMovimientos.Folio}</a><br/>"
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")}' AND CveEmpresa = {UsuarioActual.CveEmpresa}")
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, "")
If Not ObjMovimientos.AddMovimientoDetalle(movimientoCabecera, Cantidad, CveUM, CvePS, (Valor / Cantidad), -1, -1, Serie:=Serie) Then
mensajeError = "No se logró generar el detalle del movimiento"
Throw New Exception()
End If
Else
mensajeError = $"La unidad de medida no se reconoce para el producto servicio:{nuevaEntrada("CodigoPS")}"
Throw New Exception()
End If
Else
mensajeError = $"No se encontró el producto o servicio con código ""{nuevaEntrada("CodigoPS")}"""
Throw New Exception()
End If
Next
If contadorMovimientos = 0 Then
mensajeError = $"No se encontraros registros del almacen: ""{almacenActual}"""
Throw New Exception()
Exit For
End If
Else
mensajeError = $"No se registró el encabezado ""{almacenActual}"""
Throw New Exception()
Exit For
End If
Else
mensajeError = $"No se encontró el almacén con nombre ""{almacenActual}"""
Throw New Exception()
Exit For
End If
Next
Catch ex As Exception
If mensajeError = "" Then
mensajeError = "Error técnico, informar a soporte" & ex.Message
End If
ObjMovimientos.RollBack()
End Try
If mensajeError = "" Then
ObjMovimientos.Commit()
Alert($"Se cargaron correctamente {contadorMovimientos} movimientos<br/><br/>{listadoMovimientos}")
Else
Alert(mensajeError, 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 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}.<br/>")
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}.<br/>")
ErrorProceso = True
End If
Next
If ErrorProceso Then
Alert($"Cuentas no encontradas.<br/>{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 conusltar 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 = DTClasificaiones.FiltroPrimeroValor("CveClasificacion", $"Clasificacion='{Clasificacion}'").ToEntero()
If CveClasificaionTemp > 0 Then
CveClasificacion = CveClasificaionTemp
End If
If Not CveClasificacion > 0 Then
If ObjClasificaciones.AddClasificaciones(Clasificacion, "", -1, "-1", -1, "-1", -1, "-1", 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", -1, "-1", -1, "-1", -1, "-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, 0, 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, FolioStr.ToString(), 30, FolioStr, Fecha, -1, -1, CveIE:=CveIE, Contabilizable:=False, ImporteMX:=ImporteMX, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Importe, FolioStr.ToString(), 95, FolioStr, Fecha, -1, -1, CveIE:=CveIE, Contabilizable:=False, ImporteMX:=ImporteMX, 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, FolioStr.ToString(), 30, FolioStr, Fecha, -1, -1, CveIE:=CveIE, CveProveedor:=CveProveedor, Contabilizable:=False, ImporteMX:=ImporteMX, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Importe, FolioStr.ToString(), 10, FolioStr, Fecha, -1, -1, CveIE:=CveIE, CveProveedor:=CveProveedor, Contabilizable:=False, ImporteMX:=ImporteMX, 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
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
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, FolioStr.ToString(), 30, FolioStr, Fecha, -1, -1, CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False, ImporteMX:=ImporteMX, ImporteME:=ImporteME, TipoCambio:=TipoCambio) Then ErrorProceso = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Importe, FolioStr.ToString(), 66, FolioStr, Fecha, -1, -1, CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False, ImporteMX:=ImporteMX, 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, -1,
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"
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.<br>")
ErrorValidacion = True
End If
End If
Next
If Not ErrorValidacion Then
dt.AcceptChanges()
Else
Alert($"Errores detectados <br>{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 = GlobalDTRHPuestos(UsuarioActual.CveEmpresa)
dtpuestos.CaseSensitive = False
If ObjRH.GetRegistrosPatronales(-1, UsuarioActual.CveEmpresa, -1) Then
dtregistrospatronales = ObjRH.DtResultados
dtregistrospatronales.CaseSensitive = False
dTSubProyectos = GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, -1)
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()
Dim Codigo As String = Row("Código").ToString()
Dim ApellidoPaterno As String = Row("Apellido Paterno").ToString()
Dim ApellidoMaterno As String = Row("Apellido Materno").ToString()
Dim Nombre As String = Row("Nombre").ToString()
Dim CorreoElectronico As String = Row("Correo Electronico").ToString()
Dim FechaIngreso As String = Row("Fecha Ingreso").ToString()
Dim FechaBaja As String = Row("Fecha Baja").ToString()
Dim NumeroSS As String = Row("Numero SS").ToString()
Dim AltaIMSS As String = Row("Alta IMSS").ToString()
Dim SalarioDiario As String = Row("Salario Diario").ToString()
Dim Direccion As String = Row("Dirección").ToString()
Dim FechaNacimiento As String = Row("Fecha Nacimiento").ToString()
Dim LugarNacimiento As String = Row("Lugar Nacimiento").ToString()
Dim Sexo As String = Row("Sexo").ToString()
Dim CodigoPostal As String = Row("Código Postal").ToString()
Dim Ciudad As String = Row("Ciudad").ToString()
Dim EstadoCivil As String = Row("Estado Civil").ToString().ToUpper
Dim Telefono As String = Row("Teléfono").ToString()
Dim Celular As String = Row("Celular").ToString()
Dim RFC As String = Row("RFC").ToString()
Dim CURP As String = Row("CURP").ToString()
Dim ClabeInterbancaria As String = Row("CLABE").ToString()
Dim EstatusPersonal As String = Row("Estatus Personal").ToString().ToUpper
Dim SubProyecto As String = Row("SubProyecto").ToString().ToUpper
'Nuevas
Dim Estado As String = Row("Estado").ToString()
Dim NombrePadre As String = Row("Nombre Padre").ToString()
Dim NombreMadre As String = Row("Nombre Madre").ToString()
Dim Puesto As String = Row("Puesto").ToString()
Dim Turno As String = Row("Turno").ToString()
Dim TipoContrato As String = Row("Tipo Contrato").ToString()
Dim Departamento As String = Row("Departamento").ToString()
Dim TipoPeriodo As String = Row("Tipo Periodo").ToString()
Dim Escolaridad As String = Row("Escolaridad").ToString()
Dim SDI As String = Row("SDI").ToString()
Dim MetodoPago As String = Row("Metodo Pago").ToString()
Dim Nominista As String = Row("Nominista").ToString()
Dim CveCuentaContable As Integer = Row("CveCuentaContable").ToString().ToEntero()
Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal
Dim TipoTrabajador As String = Row("Tipo Trabajador").ToString()
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
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}").ToString().ToEntero()
Else
CveSubProyecto = dTSubProyectos.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{SubProyecto}'").ToString().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
CveDepartamento = -1
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 = GlobalDTMetodosPago().FiltroPrimeroValor("CveMetodoPago", $"CveMetodoPago = {CveMetodoPago}").ToString().ToEntero()
Else
CveMetodoPago = GlobalDTMetodosPago().FiltroPrimeroValor("CveMetodoPago", $"ClaveSAT = '{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, -1).FiltroPrimeroValor("CveUsuario", $"CveUsuario = {CveUsuarioNomina}").ToString().ToEntero()
Else
CveUsuarioNomina = GlobalDTUsuarios(-1, -1).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.Contains("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, "", "", "", CodigoPostal, Ciudad, CveEstado, Telefono, "", Celular, RFC, CURP, "", NombrePadre, NombreMadre, -1, CveSATRiesgoPuesto, CveSATRegimenContratacion, -1, CveSubProyecto, "", -1,
ClabeInterbancaria, "", CveJornada, CveJornada, "", -1, "", 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, -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, FolioStr.ToString(), 30, FolioStr, Fecha, -1, -1, CveIE:=CveIE, CvePersonal:=CvePersonal, Contabilizable:=False, ImporteMX:=Saldo) Then ErrorRH = True : Exit For
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Saldo, FolioStr.ToString(), 28, FolioStr, Fecha, -1, -1, CveIE:=CveIE, CvePersonal:=CvePersonal, Contabilizable:=False, ImporteMX:=Saldo) 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: <b>{0}</b> Empleados correctamente. <br>Se Omitieron: <b>{1}</b> Empleados ya que ya se encontraban registrados.", ContadorAgregados, Contador), TipoMensaje.MsgInformacion)
ObjRH.Commit()
TxtExcel.Text = ""
UpDatos.Update()
Else
Alert(String.Format("Se agregaron: <b>{0}</b> Empleados correctamente.", NumRows), 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 = 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 = 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 = 0
Dim rowmetodopago = 0
crow = 1
ccol = ccol + 1
Catalogos.Cell(crow, ccol).Value = "Metodo pago"
For Each row As DataRow In GlobalDTMetodosPago.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 = 0
Dim rowsubproyecto = 0
crow = 1
ccol = ccol + 1
Catalogos.Cell(crow, ccol).Value = "subproyecto"
Dim dtsubproyecto = If(Not UsuarioActual.TienePermisoProceso(110), GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, 1), GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 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.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