From 40e0bdb971777767fecf9953fd5226101184dc06 Mon Sep 17 00:00:00 2001 From: rrene Date: Tue, 21 Jan 2025 18:18:03 -0700 Subject: [PATCH] =?UTF-8?q?--=20separaci=C3=B3n=20de=20registro=20de=20ven?= =?UTF-8?q?tas=20y=20ventasdetalle,=20en=20un=20sub=20--=20marcado=20=20de?= =?UTF-8?q?=20la=20venta=20en=20esdevolucionventa=20=3D=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- General/SaldosIniciales.aspx.vb | 1654 ++++++++++++------------------- 1 file changed, 654 insertions(+), 1000 deletions(-) diff --git a/General/SaldosIniciales.aspx.vb b/General/SaldosIniciales.aspx.vb index 160061279..6f44e2d57 100644 --- a/General/SaldosIniciales.aspx.vb +++ b/General/SaldosIniciales.aspx.vb @@ -2176,1009 +2176,11 @@ Partial Class General_SaldosIniciales '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 NoEncontrados As Integer = 0 - Dim Encontrados As Integer = 0 - Dim StrRFCNoencontrados As New StringBuilder - Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") - If drr Is Nothing Then - Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Dim ObjVentas As New ClsVentas - Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) - Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) - Dim ErrorVentas As Boolean = False - Dim CveVenta As Integer - Dim DtClientes As New DataTable - 'Dim ExisteVenta As Boolean = False - 'Dim Contador As Integer = 0 - DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() - Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() - Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() - - If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True - ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True - If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True - Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) - - 'For Each drt As DataRow In dt.FiltraParametros("RFC <> ''", DistinctColumns:={"RFC"}).Rows - ' Dim RFC As String = drt("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - ' Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - ' If CveCliente <= 0 Then - ' Dim OBJ As New ClsClientes - ' OBJ.AgregarClienteNoFrecuente(RFC, RFC, "", "", "", "", "", 26, RFC, "", "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", -1, -1) - ' OBJ.Dispose() - ' End If - 'Next - 'GlobalDTCliente(UsuarioActual.CveEmpresa) = Nothing - 'DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CountRow As Integer = 1 - For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows - Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") - Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim - Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - Dim Serie As String = Row("Serie").ToString().Trim - Dim Folio As Integer = Row("Folio").ToString().ToEntero() - Dim Fecha As Date = Row("Fecha").ToString().ToDate - Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate - Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) - Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) - Dim SubTotal As Decimal = Row("SubTotal").ToString().ToDecimal - Dim IVA As Decimal = Row("IVA").ToString().ToDecimal - Dim Total As Decimal = Row("Total").ToString().ToDecimal - Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal - Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - Dim RetIVA As Decimal = Row("Ret IVA").ToString().ToDecimal - Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal - Dim Moneda As String = Row("Moneda").ToString() - Dim TipoCambio As String = Row("Tipo Cambio").ToString() - Dim CveMoneda As Integer = 1 - Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "") - Dim CveVendedor As Integer = 0 - - Dim IEPS As Decimal = 0 - - If RblFormato.SelectedValue = "17" Then - IEPS = Row("IEPS").ToString().ToDecimal - End If - - Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() - Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), Row("Folio Fiscal").ToString(), "") - Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) - Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") - - GuardaLog(Sucursal + "-" + Row("Folio").ToString()) - 'Temporalmente SE BORRARA - Dim Transaccion As String = "" ' Row("Transaccion2").ToString() - Dim Folio2 As String = "" ' Row("Folio2").ToString() - Dim CodCliente As String = "" 'Row("CodCliente2").ToString() - - Dim IEPSDetalle As Decimal = 0 - Dim CantidadDetalle As Decimal = 0 - Dim PUDetalle As Decimal = 0 - Dim IVADetalle As Decimal = 0 - Dim PorcentajeIEPS As Decimal = 0 - - If IEPS > 0 Then - PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) - End If - - If RblFormato.SelectedValue = "17" Then - - Dim CodigoDetalle As String = Row("Codigo").ToString - If CodigoDetalle.Trim.Length > 0 Then - Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") - - If DrDetalles IsNot Nothing Then - CvePS = DrDetalles("CvePS").ToString().ToEntero() - CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() - CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() - Else - Alert($"El código del producto no se encontro, error en registro {CountRow}") - ErrorVentas = True - End If - Else - Alert($"El código es requerido, error en registro {CountRow}") - ErrorVentas = True - End If - - IEPSDetalle = Row("IEPS").ToString.ToDecimal - CantidadDetalle = Row("Cantidad").ToString.ToDecimal - PUDetalle = Row("PU").ToString.ToDecimal - IVADetalle = Row("IVA").ToString.ToDecimal - - If CantidadDetalle = 0 Then - Alert($"No se especifico la cantidad, error en registro {CountRow}") - ErrorVentas = True - End If - - End If - - If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then - - Dim ObjCliente As New ClsClientes - If ObjCliente.GetSucursales(CveCliente) Then - If ObjCliente.DtResultados.Rows.Count > 0 Then - CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero - End If - End If - - ObjCliente.Dispose() - End If - - - 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For - TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", IIf(TipoDocto.ToUpper.Contiene("ANTICIPO", "ANTICIPOS", "ANT"), "Ant", "Rem"))).ToString() - 'PrePóliza - Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Vendedor <> "" Then - CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() - If Not CveVendedor > 0 Then CveVendedor = 0 - Else - CveVendedor = 0 - End If - - 'Moneda - If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then - CveMoneda = 1 - TipoCambio = "1" - ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then - CveMoneda = 2 - - If TipoCambio.Trim.ToDecimal < 10 Then - - If UsuarioActual.CveEmpresa.Contiene(13, 83) Then - TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() - Else - TipoCambio = GlobalTipoCambio(Fecha).ToString() - End If - - End If - - End If - - 'Si no se especifica TC, se manda como pesos. - If TipoCambio = "" Then TipoCambio = "1" - - If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 - - If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then - FechaVencimiento = Fecha - End If - - - 'Venta - If CveCliente > 0 Then - - - If TipoDocto.Contiene("Ing", "Egs", "Rem", "Ant") Then - GuardaLog(Serie & "-" & Folio) - If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, - 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, - UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), - CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, - PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then - ErrorVentas = True - Exit For - End If - CveVenta = ObjVentas.CveVenta - - If RblFormato.SelectedValue = "17" Then - - Dim TotalDetalles As Decimal = SubTotal - If PUDetalle > 0 Then - TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle - End If - - If Math.Abs(TotalDetalles - Total) > 0.01 Then - ErrorVentas = True - Alert($"Registro {CountRow} El total no councide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) - Exit For - End If - - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, - PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then - ErrorVentas = True - Exit For - End If - - Else - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then - ErrorVentas = True - Exit For - End If - End If - - Dim ConceptoContable As Integer = 1 - Dim ConceptoContablePago As Integer = 2 - If TipoDocto = "Egs" Then - ConceptoContable = 12 - ConceptoContablePago = 91 - End If - - If FolioFiscal <> "" Then - If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then - ErrorVentas = True - Exit For - End If - End If - - Dim UsaComplementaria As Boolean = False - - If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True - - 'PrePólizaDetalle - Dim tCveConcepto As Integer = 4 - If TipoDocto = "Ant" Then tCveConcepto = 3 - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, tCveConcepto, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - - If IVA > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If IEPS > 0 Then - 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - If RetIVA > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If RetISR > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If ImpuestoLocal > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - - If UsaComplementaria Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - 'Saldo - If Saldo < Total Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - - - Else - 'ANTICIPOS - Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, - 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - Encontrados = Encontrados + 1 - - Else - NoEncontrados = NoEncontrados + 1 - StrRFCNoencontrados.AppendFormat("{0}
", RFC) - ErrorVentas = True - Exit For - End If - - CountRow = CountRow + 1 - Next - If Not ErrorVentas Then - Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) - ObjVentas.Commit() - TxtExcel.Text = "" - UpDatos.Update() - Else - Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) - ObjVentas.RollBack() - End If - ObjVentas.Dispose() - - + RegistraVentas(dt, False) ElseIf RblFormato.SelectedValue = "17" Then - Dim NoEncontrados As Integer = 0 - Dim VentasAgregadas As Integer = 0 - Dim Encontrados As Integer = 0 - Dim StrRFCNoencontrados As New StringBuilder - Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") - If drr Is Nothing Then - Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) - Exit Sub - End If - Dim ObjVentas As New ClsVentas - Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) - Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) - Dim ErrorVentas As Boolean = False - Dim CveVenta As Integer - Dim CvePrePoliza As Integer - Dim DtClientes As New DataTable - 'Dim ExisteVenta As Boolean = False - 'Dim Contador As Integer = 0 - DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() - Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() - Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() - - If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True - ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True - If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True - Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) - - 'For Each drt As DataRow In dt.FiltraParametros("RFC <> ''", DistinctColumns:={"RFC"}).Rows - ' Dim RFC As String = drt("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - ' Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - ' If CveCliente <= 0 Then - ' Dim OBJ As New ClsClientes - ' OBJ.AgregarClienteNoFrecuente(RFC, RFC, "", "", "", "", "", 26, RFC, "", "", "", -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, "", -1, -1) - ' OBJ.Dispose() - ' End If - 'Next - 'GlobalDTCliente(UsuarioActual.CveEmpresa) = Nothing - 'DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) - Dim CountRow As Integer = 1 - Dim LastSerieFolioTipoDoc As String = String.Empty - Dim EsDetalle As Boolean = False - - If UsuarioActual.CveEmpresa = 189 Then - - Dim DTFoliosFiscales As DataTable = dt.FiltraParametros("[Folio Fiscal] <> ''", "", {"Folio Fiscal"}) - - For Each drFolioFiscal As DataRow In DTFoliosFiscales.Rows - Dim FolioFiscalActual As String = drFolioFiscal("Folio Fiscal").ToString - Dim DRVentaActual As DataRow = dt.FiltroPrimero($"[Folio Fiscal] = '{FolioFiscalActual}'") - - Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{DRVentaActual("Sucursal").ToString()}'") - Dim TipoDocto As String = DRVentaActual("Tipo Documento").ToString().Trim - Dim RFC As String = DRVentaActual("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - Dim Serie As String = DRVentaActual("Serie").ToString().Trim - Dim Folio As Integer = DRVentaActual("Folio").ToString().ToEntero() - Dim Fecha As Date = DRVentaActual("Fecha").ToString().ToDate - Dim FechaVencimiento As Date = DRVentaActual("Fecha Vencimiento").ToString().ToDate - Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), DRVentaActual("ImpuestoLocal").ToString().ToDecimal, 0D) - Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), DRVentaActual("Amort.Ant").ToString().ToDecimal, 0) - Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - - If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then - EsDetalle = True - Else - LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" - EsDetalle = False - End If - - Dim SubTotal As Decimal = 0 - Dim IVA As Decimal = 0 - Dim Total As Decimal = 0 - Dim Saldo As Decimal = 0 - Dim RetIVA As Decimal = 0 - Dim RetISR As Decimal = 0 - Dim IEPS As Decimal = 0 - - SubTotal = DRVentaActual("SubTotal").ToString().ToDecimal - IVA = DRVentaActual("IVA").ToString().ToDecimal - Total = DRVentaActual("Total").ToString().ToDecimal - Saldo = DRVentaActual("Saldo").ToString().ToDecimal - RetIVA = DRVentaActual("Ret IVA").ToString().ToDecimal - RetISR = DRVentaActual("Ret ISR").ToString().ToDecimal - IEPS = DRVentaActual("IEPS").ToString().ToDecimal - - Dim Moneda As String = DRVentaActual("Moneda").ToString() - Dim TipoCambio As String = DRVentaActual("Tipo Cambio").ToString() - Dim CveMoneda As Integer = 1 - Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), DRVentaActual("Vendedor").ToString(), "") - Dim CveVendedor As Integer = 0 - - Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() - 'Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), DRVentaActual("Folio Fiscal").ToString(), "") - Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(DRVentaActual("PorcentajeIVA").ToString().ToDecimal, 2), 0) - Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(DRVentaActual("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(DRVentaActual("PorcentajeRetISR").ToString().ToDecimal, 4), 0) - Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), DRVentaActual("Pedido").ToString(), "") - - GuardaLog(Sucursal + "-" + DRVentaActual("Folio").ToString()) - 'Temporalmente SE BORRARA - Dim Transaccion As String = "" ' Row("Transaccion2").ToString() - Dim Folio2 As String = "" ' Row("Folio2").ToString() - Dim CodCliente As String = "" 'Row("CodCliente2").ToString() - - TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() - - 'Dim CantidadDetalle As Decimal = 0 - 'Dim PUDetalle As Decimal = 0 - 'Dim IVADetalle As Decimal = 0 - Dim PorcentajeIEPS As Decimal = 0 - - - Dim TotalDetalles As Decimal = 0 - For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows - Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle - Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal - Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal - Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal - TotalDetalles += (CantidadDetalle * PuDetalle) + IVADetalle + IEPSDetalle - Next - - - If IEPS > 0 Then - PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(DRVentaActual("PorcentajeIEPS").ToString().ToDecimal, 4), 0) - End If - - If Math.Abs(TotalDetalles - Total) > 0.01 Then - ErrorVentas = True - Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) - Exit For - End If - - If Vendedor <> "" Then - CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() - If Not CveVendedor > 0 Then CveVendedor = 0 - Else - CveVendedor = 0 - End If - - If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then - CveMoneda = 1 - TipoCambio = "1" - ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then - CveMoneda = 2 - - If TipoCambio.Trim.ToDecimal < 10 Then - - If UsuarioActual.CveEmpresa.Contiene(13, 83) Then - TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() - Else - TipoCambio = GlobalTipoCambio(Fecha).ToString() - End If - - End If - - End If - - If TipoCambio = "" Then TipoCambio = "1" - - If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 - - If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then - FechaVencimiento = Fecha - End If - - If Not ErrorVentas Then - CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If Not CvePrePoliza > 0 Then - ErrorVentas = True - End If - End If - Dim VentayaRegistrada As Boolean = False - If Not ErrorVentas Then - 'Venta - If CveCliente > 0 Then - - If TipoDocto.Contiene("Ing", "Egs", "Rem") Then - GuardaLog(Serie & "-" & Folio) - CveVenta = 0 - Dim contador As Integer = 0 - 'verificar si existe la venta, si existe obtener el cveventa y limpiar su contenido para carga de lo nuevo. - If ObjVentas.GetVentas(UsuarioActual.CveEmpresa, TipoDocto, Serie, Folio, "-1", -1, -1, -1, -1, "2000-01-01", Now.ToShortDateString, FolioFiscalActual, CveUsuarioConsulta:=100) Then - If ObjVentas.DtResultados.Rows.Count > 0 Then - contador = 1 - CveVenta = ObjVentas.DtResultados.FiltroPrimeroValor("CveVenta").ToEntero - VentayaRegistrada = True - VentasAgregadas += 1 - 'limpieza de las partidas - If ObjVentas.GetVentaDetalle(CveVenta) Then - For Each dr As DataRow In ObjVentas.DtResultados.Rows - ObjVentas.RemoveVentasDetalle(CveVenta, dr("CveVentaDetalle").ToString.ToEntero) - Next - End If - - End If - End If - If Not EsDetalle AndAlso CveVenta = 0 Then - If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, - 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, - UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), - CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, - PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then - ErrorVentas = True - Exit For - Else - VentasAgregadas += 1 - End If - CveVenta = ObjVentas.CveVenta - End If - - For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows - - Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle - Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal - Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal - Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal - Dim PorcentajeIEPSDetalle = dRowDetalle("PorcentajeIEPS").ToString.ToDecimal - - Dim CodigoDetalle As String = dRowDetalle("Codigo").ToString - If CodigoDetalle.Trim.Length > 0 Then - Dim DrDetalles As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") - - If DrDetalles IsNot Nothing Then - CvePS = DrDetalles("CvePS").ToString().ToEntero() - CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() - CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() - Else - Alert($"El código del producto no se encontro, error en registro {CountRow}") - ErrorVentas = True - End If - Else - Alert($"El código es requerido, error en registro {CountRow}") - ErrorVentas = True - End If - - If Not ErrorVentas Then - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PuDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, - PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=0, IEPS:=IEPSDetalle, PorcentajeRetISR:=0, PorcentajeIEPS:=PorcentajeIEPSDetalle, - EstatusAlmacen:=2) Then - ErrorVentas = True - Exit For - End If - End If - - Next - - If Not VentayaRegistrada Then - Dim ConceptoContable As Integer = 1 - Dim ConceptoContablePago As Integer = 2 - If TipoDocto = "Egs" Then - ConceptoContable = 12 - ConceptoContablePago = 91 - End If - - If FolioFiscalActual <> "" Then - If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscalActual, CveVenta, UsuarioActual.CveEmpresa) Then - ErrorVentas = True - Exit For - End If - End If - - Dim UsaComplementaria As Boolean = False - - If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True - - 'PrePólizaDetalle - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - - If IVA > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If IEPS > 0 Then - 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - If RetIVA > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If RetISR > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If ImpuestoLocal > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If UsaComplementaria Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - 'Saldo - If Saldo < Total Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - End If - - If Not ErrorVentas Then - VentasAgregadas += VentasAgregadas - End If - - Else - - 'ANTICIPOS - Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - '_______________________________________________________________ - - Else - NoEncontrados = NoEncontrados + 1 - StrRFCNoencontrados.AppendFormat("{0}
", RFC) - 'ErrorVentas = True - 'Exit For - End If - End If - - - Next - Else - For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows - - Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") - Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim - Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") - Dim Serie As String = Row("Serie").ToString().Trim - Dim Folio As Integer = Row("Folio").ToString().ToEntero() - Dim Fecha As Date = Row("Fecha").ToString().ToDate - Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate - Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) - Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) - Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() - - If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then - EsDetalle = True - Else - LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" - EsDetalle = False - End If - - Dim SubTotal As Decimal = 0 - Dim IVA As Decimal = 0 - Dim Total As Decimal = 0 - Dim Saldo As Decimal = 0 - Dim RetIVA As Decimal = 0 - Dim RetISR As Decimal = 0 - Dim IEPS As Decimal = 0 - - If UsuarioActual.CveEmpresa = 189 AndAlso Not EsDetalle Then - - For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}' AND Serie = '{Row("Serie").ToString()}' AND [Tipo Documento] = '{Row("Tipo Documento").ToString()}' ").Rows - SubTotal += item("SubTotal").ToString().ToDecimal - IVA += item("IVA").ToString().ToDecimal - Total += item("Total").ToString().ToDecimal - Saldo += item("Saldo").ToString().ToDecimal - RetIVA += item("Ret IVA").ToString().ToDecimal - RetISR += item("Ret ISR").ToString().ToDecimal - IEPS += item("IEPS").ToString().ToDecimal - Next - - Else - SubTotal = Row("SubTotal").ToString().ToDecimal - IVA = Row("IVA").ToString().ToDecimal - Total = Row("Total").ToString().ToDecimal - Saldo = Row("Saldo").ToString().ToDecimal - RetIVA = Row("Ret IVA").ToString().ToDecimal - RetISR = Row("Ret ISR").ToString().ToDecimal - IEPS = Row("IEPS").ToString().ToDecimal - End If - - 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 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, 2), 0) - Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) - Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) - Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") - - GuardaLog(Sucursal + "-" + Row("Folio").ToString()) - 'Temporalmente SE BORRARA - Dim Transaccion As String = "" ' Row("Transaccion2").ToString() - Dim Folio2 As String = "" ' Row("Folio2").ToString() - Dim CodCliente As String = "" 'Row("CodCliente2").ToString() - - Dim IEPSDetalle As Decimal = 0 - Dim CantidadDetalle As Decimal = 0 - Dim PUDetalle As Decimal = 0 - Dim IVADetalle As Decimal = 0 - Dim PorcentajeIEPS As Decimal = 0 - - If IEPS > 0 Then - PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) - End If - - If RblFormato.SelectedValue = "17" Then - - Dim CodigoDetalle As String = Row("Codigo").ToString - If CodigoDetalle.Trim.Length > 0 Then - Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") - - If DrDetalles IsNot Nothing Then - CvePS = DrDetalles("CvePS").ToString().ToEntero() - CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() - CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() - Else - Alert($"El código del producto no se encontro, error en registro {CountRow}") - ErrorVentas = True - End If - Else - Alert($"El código es requerido, error en registro {CountRow}") - ErrorVentas = True - End If - - IEPSDetalle = Row("IEPS").ToString.ToDecimal - CantidadDetalle = Row("Cantidad").ToString.ToDecimal - PUDetalle = Row("PU").ToString.ToDecimal - IVADetalle = Row("IVA").ToString.ToDecimal - - If CantidadDetalle = 0 Then - Alert($"No se especifico la cantidad, error en registro {CountRow}") - ErrorVentas = True - End If - - End If - - If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then - - Dim ObjCliente As New ClsClientes - If ObjCliente.GetSucursales(CveCliente) Then - If ObjCliente.DtResultados.Rows.Count > 0 Then - CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero - End If - End If - - ObjCliente.Dispose() - End If - - - 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For - TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() - 'PrePóliza - If Not EsDetalle Then - CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - End If - - If Vendedor <> "" Then - CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() - If Not CveVendedor > 0 Then CveVendedor = 0 - Else - CveVendedor = 0 - End If - - 'Moneda - If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then - CveMoneda = 1 - TipoCambio = "1" - ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then - CveMoneda = 2 - - If TipoCambio.Trim.ToDecimal < 10 Then - - If UsuarioActual.CveEmpresa.Contiene(13, 83) Then - TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() - Else - TipoCambio = GlobalTipoCambio(Fecha).ToString() - End If - - End If - - End If - - 'Si no se especifica TC, se manda como pesos. - If TipoCambio = "" Then TipoCambio = "1" - - If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 - - If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then - FechaVencimiento = Fecha - End If - - - 'Venta - If CveCliente > 0 Then - - If TipoDocto.Contiene("Ing", "Egs", "Rem") Then - GuardaLog(Serie & "-" & Folio) - If Not EsDetalle Then - If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, - 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, - UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), - CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, - PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then - ErrorVentas = True - Exit For - Else - VentasAgregadas += 1 - End If - CveVenta = ObjVentas.CveVenta - End If - - If Not EsDetalle Then - SubTotal = Row("SubTotal").ToString().ToDecimal - IVA = Row("IVA").ToString().ToDecimal - Total = Row("Total").ToString().ToDecimal - Saldo = Row("Saldo").ToString().ToDecimal - RetIVA = Row("Ret IVA").ToString().ToDecimal - RetISR = Row("Ret ISR").ToString().ToDecimal - IEPS = Row("IEPS").ToString().ToDecimal - End If - - If RblFormato.SelectedValue = "17" Then - - Dim TotalDetalles As Decimal = SubTotal - If PUDetalle > 0 Then - TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle - End If - - If Math.Abs(TotalDetalles - Total) > 0.01 Then - ErrorVentas = True - Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) - Exit For - End If - - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, - PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then - ErrorVentas = True - Exit For - End If - - Else - If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then - ErrorVentas = True - Exit For - End If - End If - - - - Dim ConceptoContable As Integer = 1 - Dim ConceptoContablePago As Integer = 2 - If TipoDocto = "Egs" Then - ConceptoContable = 12 - ConceptoContablePago = 91 - End If - - If FolioFiscal <> "" Then - If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then - ErrorVentas = True - Exit For - End If - End If - - Dim UsaComplementaria As Boolean = False - - If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True - - If Not EsDetalle Then - - SubTotal = 0 - IVA = 0 - Total = 0 - Saldo = 0 - RetIVA = 0 - RetISR = 0 - For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}' AND Serie = '{Row("Serie").ToString()}' AND [Tipo Documento] = '{Row("Tipo Documento").ToString()}' ").Rows - SubTotal += item("SubTotal").ToString().ToDecimal - IVA += item("IVA").ToString().ToDecimal - Total += item("Total").ToString().ToDecimal - Saldo += item("Saldo").ToString().ToDecimal - RetIVA += item("Ret IVA").ToString().ToDecimal - RetISR += item("Ret ISR").ToString().ToDecimal - IEPS += item("IEPS").ToString().ToDecimal - Next - - 'PrePólizaDetalle - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - - If IVA > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If IEPS > 0 Then - 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - - End If - - If RetIVA > 0 Then - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If RetISR > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - If ImpuestoLocal > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - - If UsaComplementaria Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - - 'Saldo - If Saldo < Total Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - End If - - Else - - If Not EsDetalle Then - - SubTotal = 0 - IVA = 0 - Total = 0 - Saldo = 0 - RetIVA = 0 - RetISR = 0 - For Each item As DataRow In dt.FiltraParametros($"RFC <> '' AND Folio = '{Row("Folio").ToString()}' AND Serie = '{Row("Serie").ToString()}' AND [Tipo Documento] = '{Row("Tipo Documento").ToString()}' ").Rows - SubTotal += item("SubTotal").ToString().ToDecimal - IVA += item("IVA").ToString().ToDecimal - Total += item("Total").ToString().ToDecimal - Saldo += item("Saldo").ToString().ToDecimal - RetIVA += item("Ret IVA").ToString().ToDecimal - RetISR += item("Ret ISR").ToString().ToDecimal - IEPS += item("IEPS").ToString().ToDecimal - Next - - 'ANTICIPOS - Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, - 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For - End If - End If - Encontrados = Encontrados + 1 - - Else - NoEncontrados = NoEncontrados + 1 - StrRFCNoencontrados.AppendFormat("{0}
", RFC) - 'ErrorVentas = True - 'Exit For - End If - - CountRow = CountRow + 1 - Next - End If - - '********************************************************************************************************************************************************************************** - - If Not ErrorVentas Then - - If UsuarioActual.CveEmpresa = 189 Then - Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", VentasAgregadas, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) - Else - Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) - End If - - - ObjVentas.Commit() - TxtExcel.Text = "" - UpDatos.Update() - Else - Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) - ObjVentas.RollBack() - End If - ObjVentas.Dispose() -#End Region + RegistraVentas(dt, True) ' R H - P E R S O N A L ElseIf RblFormato.SelectedValue = "6" Then @@ -3762,6 +2764,658 @@ Partial Class General_SaldosIniciales End If End If + End Sub + + Private Sub RegistraVentas(dt As DataTable, OpcionDetallada As Boolean) + + If Not OpcionDetallada Then + + Dim NoEncontrados As Integer = 0 + Dim Encontrados As Integer = 0 + Dim StrRFCNoencontrados As New StringBuilder + Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") + If drr Is Nothing Then + Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Dim ObjVentas As New ClsVentas + Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) + Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) + Dim ObjInv As New ClsInventarios(ObjVentas.IniciaTransacSQL()) + Dim ErrorVentas As Boolean = False + Dim CveVenta As Integer + Dim DtClientes As New DataTable + 'Dim ExisteVenta As Boolean = False + 'Dim Contador As Integer = 0 + DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) + Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() + Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() + Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() + + If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True + ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True + If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True + Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) + + Dim CountRow As Integer = 1 + For Each Row As DataRow In dt.FiltraParametros("RFC <> ''").Rows + Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{Row("Sucursal").ToString()}'") + Dim TipoDocto As String = Row("Tipo Documento").ToString().Trim + Dim RFC As String = Row("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") + Dim Serie As String = Row("Serie").ToString().Trim + Dim Folio As Integer = Row("Folio").ToString().ToEntero() + Dim Fecha As Date = Row("Fecha").ToString().ToDate + Dim FechaVencimiento As Date = Row("Fecha Vencimiento").ToString().ToDate + Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), Row("ImpuestoLocal").ToString().ToDecimal, 0D) + Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), Row("Amort.Ant").ToString().ToDecimal, 0) + Dim SubTotal As Decimal = Row("SubTotal").ToString().ToDecimal + Dim IVA As Decimal = Row("IVA").ToString().ToDecimal + Dim Total As Decimal = Row("Total").ToString().ToDecimal + Dim Saldo As Decimal = Row("Saldo").ToString().ToDecimal + Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() + Dim RetIVA As Decimal = Row("Ret IVA").ToString().ToDecimal + Dim RetISR As Decimal = Row("Ret ISR").ToString().ToDecimal + Dim Moneda As String = Row("Moneda").ToString() + Dim TipoCambio As String = Row("Tipo Cambio").ToString() + Dim CveMoneda As Integer = 1 + Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), Row("Vendedor").ToString(), "") + Dim CveVendedor As Integer = 0 + + Dim IEPS As Decimal = 0 + + If RblFormato.SelectedValue = "17" Then + IEPS = Row("IEPS").ToString().ToDecimal + End If + + Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() + Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), Row("Folio Fiscal").ToString(), "") + Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString().ToDecimal, 4), 0) + Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(Row("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) + Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(Row("PorcentajeRetISR").ToString().ToDecimal, 4), 0) + Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), Row("Pedido").ToString(), "") + + GuardaLog(Sucursal + "-" + Row("Folio").ToString()) + 'Temporalmente SE BORRARA + Dim Transaccion As String = "" ' Row("Transaccion2").ToString() + Dim Folio2 As String = "" ' Row("Folio2").ToString() + Dim CodCliente As String = "" 'Row("CodCliente2").ToString() + + Dim IEPSDetalle As Decimal = 0 + Dim CantidadDetalle As Decimal = 0 + Dim PUDetalle As Decimal = 0 + Dim IVADetalle As Decimal = 0 + Dim PorcentajeIEPS As Decimal = 0 + + If IEPS > 0 Then + PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(Row("PorcentajeIEPS").ToString().ToDecimal, 4), 0) + End If + + If RblFormato.SelectedValue = "17" Then + + Dim CodigoDetalle As String = Row("Codigo").ToString + If CodigoDetalle.Trim.Length > 0 Then + Dim DrDetalles As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") + + If DrDetalles IsNot Nothing Then + CvePS = DrDetalles("CvePS").ToString().ToEntero() + CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() + CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() + Else + Alert($"El código del producto no se encontro, error en registro {CountRow}") + ErrorVentas = True + End If + Else + Alert($"El código es requerido, error en registro {CountRow}") + ErrorVentas = True + End If + + IEPSDetalle = Row("IEPS").ToString.ToDecimal + CantidadDetalle = Row("Cantidad").ToString.ToDecimal + PUDetalle = Row("PU").ToString.ToDecimal + IVADetalle = Row("IVA").ToString.ToDecimal + + If CantidadDetalle = 0 Then + Alert($"No se especifico la cantidad, error en registro {CountRow}") + ErrorVentas = True + End If + + End If + + If dt.Columns.Contains("Cliente Sucursal") AndAlso Row("Cliente Sucursal").ToString() <> "" Then + + Dim ObjCliente As New ClsClientes + If ObjCliente.GetSucursales(CveCliente) Then + If ObjCliente.DtResultados.Rows.Count > 0 Then + CveClienteSucursal = ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "SucursalCliente = '" & Row("Cliente Sucursal").ToString().Trim & "'").ToEntero + End If + End If + + ObjCliente.Dispose() + End If + + + 'If Not CveCliente > 0 Then Alert(String.Format("No se encontró el cliente con el RFC: {0}", {RFC}), TipoMensaje.MsgError) : ErrorVentas = True : RFC.GuardaLog : Exit For + TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", IIf(TipoDocto.ToUpper.Contiene("ANTICIPO", "ANTICIPOS", "ANT"), "Ant", "Rem"))).ToString() + 'PrePóliza + Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, 1, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If Vendedor <> "" Then + CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() + If Not CveVendedor > 0 Then CveVendedor = 0 + Else + CveVendedor = 0 + End If + + 'Moneda + If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then + CveMoneda = 1 + TipoCambio = "1" + ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then + CveMoneda = 2 + + If TipoCambio.Trim.ToDecimal < 10 Then + + If UsuarioActual.CveEmpresa.Contiene(13, 83) Then + TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() + Else + TipoCambio = GlobalTipoCambio(Fecha).ToString() + End If + + End If + + End If + + 'Si no se especifica TC, se manda como pesos. + If TipoCambio = "" Then TipoCambio = "1" + + If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 + + If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then + FechaVencimiento = Fecha + End If + + + 'Venta + If CveCliente > 0 Then + + + If TipoDocto.Contiene("Ing", "Egs", "Rem", "Ant") Then + GuardaLog(Serie & "-" & Folio) + If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, + 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, + UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), + CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, + PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then + ErrorVentas = True + Exit For + End If + CveVenta = ObjVentas.CveVenta + + If Not ErrorVentas Then + If Not ObjInv.ActualizarEsDevolucionVenta(CveVenta, 2) Then + ErrorVentas = True + Exit For + End If + End If + + If RblFormato.SelectedValue = "17" Then + + Dim TotalDetalles As Decimal = SubTotal + If PUDetalle > 0 Then + TotalDetalles = (CantidadDetalle * PUDetalle) + IVA - RetIVA - RetISR + IEPSDetalle + End If + + If Math.Abs(TotalDetalles - Total) > 0.01 Then + ErrorVentas = True + Alert($"Registro {CountRow} El total no coincide con el calculo de los detalles, total: {Total.ToString("###,###,###.00")} calculo detatalles: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) + Exit For + End If + + If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PUDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, + PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=IEPSDetalle, PorcentajeRetISR:=PorcentajeRetISR, PorcentajeIEPS:=PorcentajeIEPS) Then + ErrorVentas = True + Exit For + End If + + Else + If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, 1, CveUnidadMedida, SubTotal, IVA, SubTotal * PorcentajeIVA, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=RetIVA, IEPS:=0) Then + ErrorVentas = True + Exit For + End If + End If + + Dim ConceptoContable As Integer = 1 + Dim ConceptoContablePago As Integer = 2 + If TipoDocto = "Egs" Then + ConceptoContable = 12 + ConceptoContablePago = 91 + End If + + If FolioFiscal <> "" Then + If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscal, CveVenta, UsuarioActual.CveEmpresa) Then + ErrorVentas = True + Exit For + End If + End If + + Dim UsaComplementaria As Boolean = False + + If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True + + 'PrePólizaDetalle + Dim tCveConcepto As Integer = 4 + If TipoDocto = "Ant" Then tCveConcepto = 3 + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, tCveConcepto, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + + If IVA > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If IEPS > 0 Then + 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + + If RetIVA > 0 Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If RetISR > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If ImpuestoLocal > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If UsaComplementaria Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + 'Saldo + If Saldo < Total Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + Else + 'ANTICIPOS + Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, + 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + Encontrados = Encontrados + 1 + + Else + NoEncontrados = NoEncontrados + 1 + StrRFCNoencontrados.AppendFormat("{0}
", RFC) + ErrorVentas = True + Exit For + End If + + CountRow = CountRow + 1 + Next + If Not ErrorVentas Then + Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) + ObjVentas.Commit() + TxtExcel.Text = "" + UpDatos.Update() + Else + Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) + ObjVentas.RollBack() + End If + ObjVentas.Dispose() + + Else + + Dim NoEncontrados As Integer = 0 + Dim VentasAgregadas As Integer = 0 + Dim Encontrados As Integer = 0 + Dim StrRFCNoencontrados As New StringBuilder + Dim drr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero("AplicaParaVenta = 1") + If drr Is Nothing Then + Alert("No existen productos para venta. favor de crear uno e intentar de nuevo", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Dim ObjVentas As New ClsVentas + Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) + Dim ObjIE As New ClsBancos(ObjVentas.IniciaTransacSQL()) + Dim ObjInv As New ClsInventarios(ObjVentas.IniciaTransacSQL()) + Dim ErrorVentas As Boolean = False + Dim CveVenta As Integer + Dim CvePrePoliza As Integer + Dim DtClientes As New DataTable + 'Dim ExisteVenta As Boolean = False + 'Dim Contador As Integer = 0 + DtClientes = GlobalDTCliente(UsuarioActual.CveEmpresa, Estatus:=-1) + Dim CvePS As Integer = drr("CvePS").ToString().ToEntero() + Dim CveUnidadMedida As Integer = drr("CveUnidadMedida").ToString().ToEntero() + Dim CveClasificacion As Integer = drr("CveClasificacion").ToString().ToEntero() + + If Not CvePS > 0 Then Alert(String.Format("No se encontró el Producto Servicio"), TipoMensaje.MsgError) : ErrorVentas = True + ' If Not CveSucursal > 0 Then Alert("No se encontró la sucursal.", TipoMensaje.MsgError) : ErrorVentas = True + If Not CveUnidadMedida > 0 Then Alert(String.Format("No se encontró la Unidad de Medida."), TipoMensaje.MsgError) : ErrorVentas = True + Dim dtsubp As DataTable = GlobalDTSubProyectos(UsuarioActual.CveEmpresa) + + Dim CountRow As Integer = 1 + Dim LastSerieFolioTipoDoc As String = String.Empty + Dim EsDetalle As Boolean = False + + + + Dim DTFoliosFiscales As DataTable = dt.FiltraParametros("[Folio Fiscal] <> ''", "", {"Folio Fiscal"}) + + For Each drFolioFiscal As DataRow In DTFoliosFiscales.Rows + Dim FolioFiscalActual As String = drFolioFiscal("Folio Fiscal").ToString + Dim DRVentaActual As DataRow = dt.FiltroPrimero($"[Folio Fiscal] = '{FolioFiscalActual}'") + + Dim Sucursal As String = dtsubp.FiltroPrimeroValor("CveSubProyecto", $"SubProyecto = '{DRVentaActual("Sucursal").ToString()}'") + Dim TipoDocto As String = DRVentaActual("Tipo Documento").ToString().Trim + Dim RFC As String = DRVentaActual("RFC").ToString().Trim.Replace("-", "").Replace(" ", "") + Dim Serie As String = DRVentaActual("Serie").ToString().Trim + Dim Folio As Integer = DRVentaActual("Folio").ToString().ToEntero() + Dim Fecha As Date = DRVentaActual("Fecha").ToString().ToDate + Dim FechaVencimiento As Date = DRVentaActual("Fecha Vencimiento").ToString().ToDate + Dim ImpuestoLocal As Decimal = If(dt.Columns.Contains("ImpuestoLocal"), DRVentaActual("ImpuestoLocal").ToString().ToDecimal, 0D) + Dim Amortizacion As Decimal = If(dt.Columns.Contains("Amort.Ant"), DRVentaActual("Amort.Ant").ToString().ToDecimal, 0) + Dim CveCliente As Integer = DtClientes.FiltroPrimeroValor("CveCliente", $"RFC = '{RFC}'").ToString().ToEntero() + + If LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" AndAlso UsuarioActual.CveEmpresa = 189 Then + EsDetalle = True + Else + LastSerieFolioTipoDoc = $"{Serie}{Folio}{TipoDocto}" + EsDetalle = False + End If + + Dim SubTotal As Decimal = 0 + Dim IVA As Decimal = 0 + Dim Total As Decimal = 0 + Dim Saldo As Decimal = 0 + Dim RetIVA As Decimal = 0 + Dim RetISR As Decimal = 0 + Dim IEPS As Decimal = 0 + + SubTotal = DRVentaActual("SubTotal").ToString().ToDecimal + IVA = DRVentaActual("IVA").ToString().ToDecimal + Total = DRVentaActual("Total").ToString().ToDecimal + Saldo = DRVentaActual("Saldo").ToString().ToDecimal + RetIVA = DRVentaActual("Ret IVA").ToString().ToDecimal + RetISR = DRVentaActual("Ret ISR").ToString().ToDecimal + IEPS = DRVentaActual("IEPS").ToString().ToDecimal + + Dim Moneda As String = DRVentaActual("Moneda").ToString() + Dim TipoCambio As String = DRVentaActual("Tipo Cambio").ToString() + Dim CveMoneda As Integer = 1 + Dim Vendedor As String = If(dt.Columns.Contains("Vendedor"), DRVentaActual("Vendedor").ToString(), "") + Dim CveVendedor As Integer = 0 + + Dim CveClienteSucursal As Integer = 0 'Row("CveClienteSucursal").ToString().ToEntero() + 'Dim FolioFiscal As String = If(dt.Columns.Contains("Folio Fiscal"), DRVentaActual("Folio Fiscal").ToString(), "") + Dim PorcentajeIVA As Decimal = If(dt.Columns.Contains("PorcentajeIVA"), Round(DRVentaActual("PorcentajeIVA").ToString().ToDecimal, 2), 0) + Dim PorcentajeRetIVA As Decimal = If(dt.Columns.Contains("PorcentajeRetIVA"), Round(DRVentaActual("PorcentajeRetIVA").ToString().ToDecimal, 4), 0) + Dim PorcentajeRetISR As Decimal = If(dt.Columns.Contains("PorcentajeRetISR"), Round(DRVentaActual("PorcentajeRetISR").ToString().ToDecimal, 4), 0) + Dim PedidoContrato As String = If(dt.Columns.Contains("Pedido"), DRVentaActual("Pedido").ToString(), "") + + GuardaLog(Sucursal + "-" + DRVentaActual("Folio").ToString()) + 'Temporalmente SE BORRARA + Dim Transaccion As String = "" ' Row("Transaccion2").ToString() + Dim Folio2 As String = "" ' Row("Folio2").ToString() + Dim CodCliente As String = "" 'Row("CodCliente2").ToString() + + TipoDocto = IIf(TipoDocto.ToUpper.Contiene("INGRESO", "INGRESOS", "ING", "FACTURA", "FACTURAS"), "Ing", IIf(TipoDocto.ToUpper.Contiene("EGRESO", "EGRESOS", "EGS"), "Egs", "Rem")).ToString() + + 'Dim CantidadDetalle As Decimal = 0 + 'Dim PUDetalle As Decimal = 0 + 'Dim IVADetalle As Decimal = 0 + Dim PorcentajeIEPS As Decimal = 0 + + + Dim TotalDetalles As Decimal = 0 + For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows + Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle + Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal + Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal + Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal + TotalDetalles += (CantidadDetalle * PuDetalle) + IVADetalle + IEPSDetalle + Next + + + If IEPS > 0 Then + PorcentajeIEPS = If(dt.Columns.Contains("PorcentajeIEPS"), Round(DRVentaActual("PorcentajeIEPS").ToString().ToDecimal, 4), 0) + End If + + If Math.Abs(TotalDetalles - Total) > 0.01 Then + ErrorVentas = True + Alert($"Registro {CountRow} El total no coincide con el acumulado de los detalles, total: {Total.ToString("###,###,###.00")} detatalle: {TotalDetalles.ToString("###,###,###.00")}", TipoMensaje.MsgAdvertencia) + Exit For + End If + + If Vendedor <> "" Then + CveVendedor = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=-1).FiltroPrimeroValor("CveVendedor", $"Vendedor = '{Vendedor}'").ToString().ToEntero() + If Not CveVendedor > 0 Then CveVendedor = 0 + Else + CveVendedor = 0 + End If + + If Moneda.ToUpper.Contiene("PESOS", "PESO", "MXN") Then + CveMoneda = 1 + TipoCambio = "1" + ElseIf Moneda.ToUpper.Contiene("DÓLAR", "DÓLARES", "DOLARES", "USD") Then + CveMoneda = 2 + + If TipoCambio.Trim.ToDecimal < 10 Then + + If UsuarioActual.CveEmpresa.Contiene(13, 83) Then + TipoCambio = GlobalTipoCambio(Fecha.AddDays(-1)).ToString() + Else + TipoCambio = GlobalTipoCambio(Fecha).ToString() + End If + + End If + + End If + + If TipoCambio = "" Then TipoCambio = "1" + + If Not CveClienteSucursal > 0 Then CveClienteSucursal = -1 + + If FechaVencimiento = "".ToDate Or FechaVencimiento < "1900/01/01".ToDate Then + FechaVencimiento = Fecha + End If + + If Not ErrorVentas Then + CvePrePoliza = ObjConta.AddPrePolizas("Venta/SaldoInicial", 1, Total, Total, CveMoneda, Fecha, String.Format("{0}-{1}", Serie, Folio), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If Not CvePrePoliza > 0 Then + ErrorVentas = True + End If + End If + Dim VentayaRegistrada As Boolean = False + If Not ErrorVentas Then + 'Venta + If CveCliente > 0 Then + + If TipoDocto.Contiene("Ing", "Egs", "Rem") Then + GuardaLog(Serie & "-" & Folio) + CveVenta = 0 + Dim contador As Integer = 0 + 'verificar si existe la venta, si existe obtener el cveventa y limpiar su contenido para carga de lo nuevo. + If ObjVentas.GetVentas(UsuarioActual.CveEmpresa, TipoDocto, Serie, Folio, "-1", -1, -1, -1, -1, "2000-01-01", Now.ToShortDateString, FolioFiscalActual, CveUsuarioConsulta:=100) Then + If ObjVentas.DtResultados.Rows.Count > 0 Then + contador = 1 + CveVenta = ObjVentas.DtResultados.FiltroPrimeroValor("CveVenta").ToEntero + VentayaRegistrada = True + VentasAgregadas += 1 + 'limpieza de las partidas + If ObjVentas.GetVentaDetalle(CveVenta) Then + For Each dr As DataRow In ObjVentas.DtResultados.Rows + ObjVentas.RemoveVentasDetalle(CveVenta, dr("CveVentaDetalle").ToString.ToEntero) + Next + End If + + End If + End If + If Not EsDetalle AndAlso CveVenta = 0 Then + If Not ObjVentas.AddVenta(TipoDocto, Folio, CveCliente.ToEntero(), CveClienteSucursal, SubTotal, 0, Amortizacion, IVA, RetIVA, RetISR, Total, CveMoneda, TipoCambio.ToDecimal, + 0, 0, 0, FechaVencimiento, Fecha, "", "", Fecha, CveVendedor, Folio2, "", "", 0, 0, 0, "-1".ToDate, "-1".ToDate, "-1".ToDate, -1, 0, CvePrePoliza, + UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Serie:=Serie, CveSubProyecto:=Sucursal.ToEntero(), CveSubProyectoEjecucion:=Sucursal.ToEntero(), + CveSubProyectoCobranza:=Sucursal.ToEntero(), IEPS:=IEPS, ObservacionesAlmacen:=Transaccion, Entrega:=CodCliente, ImpuestoLocal:=ImpuestoLocal, + PedidoContrato:=PedidoContrato, CveMetodoPago33:=3) Then + ErrorVentas = True + Exit For + Else + VentasAgregadas += 1 + End If + CveVenta = ObjVentas.CveVenta + End If + + If Not ErrorVentas Then + If Not ObjInv.ActualizarEsDevolucionVenta(CveVenta, 2) Then + ErrorVentas = True + Exit For + End If + End If + + For Each dRowDetalle As DataRow In dt.FiltraParametros($"[Folio Fiscal]='{FolioFiscalActual}'").Rows + + Dim CantidadDetalle As Decimal = dRowDetalle("Cantidad").ToString.ToDecimal 'digo PU IVADetalle + Dim PuDetalle As Decimal = dRowDetalle("PU").ToString.ToDecimal + Dim IVADetalle As Decimal = dRowDetalle("IVADetalle").ToString.ToDecimal + Dim IEPSDetalle As Decimal = dRowDetalle("IEPS").ToString.ToDecimal + Dim PorcentajeIEPSDetalle = dRowDetalle("PorcentajeIEPS").ToString.ToDecimal + + Dim CodigoDetalle As String = dRowDetalle("Codigo").ToString + If CodigoDetalle.Trim.Length > 0 Then + Dim DrDetalles As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimero($"Codigo = '{CodigoDetalle}'") + + If DrDetalles IsNot Nothing Then + CvePS = DrDetalles("CvePS").ToString().ToEntero() + CveUnidadMedida = DrDetalles("CveUnidadMedida").ToString().ToEntero() + CveClasificacion = DrDetalles("CveClasificacion").ToString().ToEntero() + Else + Alert($"El código del producto no se encontro, error en registro {CountRow}") + ErrorVentas = True + End If + Else + Alert($"El código es requerido, error en registro {CountRow}") + ErrorVentas = True + End If + + If Not ErrorVentas Then + If Not ObjVentas.AddVentaDetalle(CveVenta, CvePS, CantidadDetalle, CveUnidadMedida, PuDetalle, IVADetalle, TotalDetalles, "Saldo Inicial", 0, 0, Sucursal.ToEntero(), 0, + PorcentajeIVA:=PorcentajeIVA, PorcentajeRetIVA:=PorcentajeRetIVA, ImporteRetIVA:=0, IEPS:=IEPSDetalle, PorcentajeRetISR:=0, PorcentajeIEPS:=PorcentajeIEPSDetalle, + EstatusAlmacen:=1) Then + ErrorVentas = True + Exit For + End If + End If + + Next + + If Not VentayaRegistrada Then + Dim ConceptoContable As Integer = 1 + Dim ConceptoContablePago As Integer = 2 + If TipoDocto = "Egs" Then + ConceptoContable = 12 + ConceptoContablePago = 91 + End If + + If FolioFiscalActual <> "" Then + If Not ObjVentas.UpdateVentaFolioFiscal(FolioFiscalActual, CveVenta, UsuarioActual.CveEmpresa) Then + ErrorVentas = True + Exit For + End If + End If + + Dim UsaComplementaria As Boolean = False + + If UsuarioActual.CveEmpresa.Contiene(119, 158) Then UsaComplementaria = True + + 'PrePólizaDetalle + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, SubTotal, SubTotal, 4, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, CveSubProyecto:=Sucursal.ToEntero(), PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, ConceptoContable, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + + If IVA > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, IVA, 13, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If IEPS > 0 Then + 'AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, Folio, 38, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=IEPS) + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, IEPS, 38, Folio.ToString, String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + + If RetIVA > 0 Then + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 8, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If RetISR > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, RetISR, RetISR, 9, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeRetISR, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If ImpuestoLocal > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImpuestoLocal, ImpuestoLocal, 27, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, PorcentajeImpuesto:=PorcentajeIVA, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + If UsaComplementaria Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total * TipoCambio.ToDecimal - Total, Total * TipoCambio.ToDecimal - Total, 203, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteME:=Total, TipoCambio:=TipoCambio.ToDecimal, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + + 'Saldo + If Saldo < Total Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total - Saldo, Total - Saldo, ConceptoContablePago, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, CveVentaAmortizacion:=CveVenta, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total - Saldo, Total - Saldo, 95, Folio.ToString(), Folio.ToString(), CveVenta:=CveVenta, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + End If + End If + + If Not ErrorVentas Then + VentasAgregadas += VentasAgregadas + End If + + Else + + 'ANTICIPOS + Dim CveIE As Integer = ObjIE.AddBancos_IE(1, 1, Fecha, Folio.ToString(), "", Total, 1, 1, "Anticipo Cliente", "", False, False, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Total, Total, 30, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Total, Total, 66, Folio.ToString(), String.Format("{0}-{1}", Serie, Folio), CveIE:=CveIE, CveCliente:=CveCliente, Contabilizable:=False) Then ErrorVentas = True : Exit For + + End If + + '_______________________________________________________________ + + Else + NoEncontrados = NoEncontrados + 1 + StrRFCNoencontrados.AppendFormat("{0}
", RFC) + 'ErrorVentas = True + 'Exit For + End If + End If + + Next + + '********************************************************************************************************************************************************************************** + + If Not ErrorVentas Then + ObjVentas.Commit() + + Alert(String.Format("Se agregaron: {0} Ventas correctamente. {1} no encontrados
{2} ", VentasAgregadas, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgInformacion) + TxtExcel.Text = "" + UpDatos.Update() + Else + Alert(String.Format("Error al registrar : {0} Ventas correctamente. {1} no encontrados
{2} ", Encontrados, NoEncontrados, StrRFCNoencontrados), TipoMensaje.MsgError) + ObjVentas.RollBack() + End If + ObjVentas.Dispose() + End If + + End Sub