diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index b2e9e897d..2a0131d71 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -5105,6 +5105,12 @@ Namespace Modelos Dim ValidaVirtual = True Dim DtPSVirtual As New DataTable("DtTamanios") + Dim tCveAlmacen As Integer = -1 + + If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + tCveAlmacen = ObjInventario.DtResultados.FiltroPrimeroValor("CveAlmacen").ToEntero() + End If + If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa, CveMovimientoRelacionado:=CveMovimientoRelacionado) Then DtPSVirtual = ObjInventario.DtResultados End If @@ -5113,7 +5119,7 @@ Namespace Modelos Dim CveAlmacenVirtual As Integer = -1 Dim CveMovimientoRelacionadoVirtual As Integer = CveMovimiento - CveAlmacenVirtual = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 24).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() + CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 AndAlso CveAlmacenVirtual > 0 AndAlso CveConceptoMovimientoVirtual > 0 Then CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, CveConceptoMovimientoVirtual, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, -1, -1, diff --git a/Ashx/E141.ashx b/Ashx/E141.ashx index dd8ea7fcf..51b154202 100644 --- a/Ashx/E141.ashx +++ b/Ashx/E141.ashx @@ -1,14 +1,13 @@ <%@ WebHandler Language="VB" Class="E141" %> -Imports System -Imports System.Web +Option Strict On +Option Explicit On + Imports System.Data Imports System.Net.Http -Imports System.Net Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports Extensiones -Imports System.IO Public Class E141 : Implements IHttpHandler @@ -50,7 +49,7 @@ Public Class E141 : Implements IHttpHandler Public ReadOnly Property TokenAutorizacion As String Get If EsProduccion Then - Return "$2y$10$AGCCDbEoGEpd0ys89fuBXedtWlunwUeLRlo4MdeLyxDvJF4GwpL7a" + Return "$2y$10$8Mk3YeIkJESilIwD.U5dG.SsA4JloycJKbaGls8TNEw/AKBE1qane" Else Return "$2y$10$8Mk3YeIkJESilIwD.U5dG.SsA4JloycJKbaGls8TNEw/AKBE1qane" End If @@ -60,7 +59,7 @@ Public Class E141 : Implements IHttpHandler Public ReadOnly Property URLBase As String Get If EsProduccion Then - Return "https://services.fidelityapps.mx/" + Return "https://econollantas-pruebas.fidelityapps.mx" Else Return "https://econollantas-pruebas.fidelityapps.mx/" End If @@ -68,11 +67,11 @@ Public Class E141 : Implements IHttpHandler End Property Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest - context.Response.ContentType = "application/json" - Dim retorno As String = "no se encontro la variable" + Dim retorno As String = "" Try Dim Params = If(context.Request("P") = Nothing, "", context.Request("P").ToString()) + 'DESCARGA DEL PDF If Not String.IsNullOrEmpty(Params) Then Dim UrlParametros As Hashtable = Parametros(Decripta(Params)) @@ -80,41 +79,54 @@ Public Class E141 : Implements IHttpHandler If Not String.IsNullOrEmpty(File) Then ImprimirbytesPDF(context, DescargarFactura(File), File) End If + Else - End If + Dim Metodo = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) + 'OBTENER EXISTENCIAS + If Metodo = "GetExistencia" Then + context.Response.ContentType = "application/json" - Dim Metodo = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) + Dim Codigo = If(context.Request("Sku") = Nothing, "", context.Request("Sku").ToString()) + retorno = GetExistencia(context, Codigo) - Dim FiltrarTodos = If(context.Request("FiltrarTodos") = Nothing, "", context.Request("FiltrarTodos").ToString()) + Else + context.Response.ContentType = "text/html" - If Metodo = "CrearActualizarProductos" Then - retorno = CrearActualizarProductos(If(FiltrarTodos = "1", True, False)) - End If + Dim FiltrarTodos = If(context.Request("FiltrarTodos") = Nothing, "", context.Request("FiltrarTodos").ToString()) - If Metodo = "ActualizarPrecios" Then - retorno = ActualizarPrecios(If(FiltrarTodos = "1", True, False)) - End If + Dim respuesta As Boolean = False - If Metodo = "ActualizarExistencias" Then - retorno = ActualizarExistencias(If(FiltrarTodos = "1", True, False)) - End If + 'TAREAS PROGRAMADAS + Select Case Metodo + Case "CrearActualizarProductos" + respuesta = CrearActualizarProductos(If(FiltrarTodos = "1", True, False)) + Case "ActualizarPrecios" + respuesta = ActualizarPrecios(If(FiltrarTodos = "1", True, False)) + Case "ActualizarExistencias" + respuesta = ActualizarExistencias() + Case "ActualizarVendedores" + respuesta = ActualizarVendedores(If(FiltrarTodos = "1", True, False)) + End Select - If Metodo = "ActualizarVendedores" Then - retorno = ActualizarVendedores(If(FiltrarTodos = "1", True, False)) - End If + If respuesta Then + retorno = "True" + Else + retorno = "False" + End If + + End If + + context.Response.Write(retorno) - If Metodo = "GetExistencia" Then - Dim Codigo = If(context.Request("Sku") = Nothing, "", context.Request("Sku").ToString()) - retorno = GetExistencia(context, Codigo) End If Catch ex As Exception + context.Response.ContentType = "text/html" retorno = ex.ToString() ex.GuardaLog(ex.ToString()) + context.Response.Write(retorno) End Try - - context.Response.Write(retorno) End Sub Private Function GetExistencia(ByVal context As HttpContext, Codigo As String) As String @@ -157,17 +169,23 @@ Public Class E141 : Implements IHttpHandler Using ObjPS As New ClsProductosServicios() If ObjPS.GetExistenciasEmpresa(Codigo, CveEmpresa) Then Dim ArrayPS As New JArray - For Each RowPS As DataRow In ObjPS.DtResultados.Rows - Dim producto As New JObject( - New JProperty("sku", RowPS("Codigo")), - New JProperty("stock", RowPS("Existencia")) - ) - ArrayPS.Add(producto) - Next + If ObjPS.DtResultados.Rows.Count > 0 Then + For Each RowPS As DataRow In ObjPS.DtResultados.Rows + Dim producto As New JObject( + New JProperty("sku", RowPS("Codigo")), + New JProperty("stock", RowPS("Existencia")) + ) + ArrayPS.Add(producto) + Next + respuesta.isSuccess = True + respuesta.message = "La existencia se obtuvo correctamente" + Else + respuesta.isSuccess = True + respuesta.message = "No se encontro ningun producto" + End If respuesta.products = ArrayPS - respuesta.isSuccess = True - respuesta.message = "La existencia se obtuvo correctamente" + Else respuesta.isSuccess = False respuesta.message = "Ocurrió un error al obtener la existencia" @@ -182,6 +200,7 @@ Public Class E141 : Implements IHttpHandler Dim Retorno As String = "{}" Try Using httpClient = New HttpClient() + httpClient.Timeout = New TimeSpan(0, 5, 0) Using request = New HttpRequestMessage(HttpMethod.Post, New Uri(url)) request.Headers.Add("token", TokenAutorizacion) @@ -233,12 +252,10 @@ Public Class E141 : Implements IHttpHandler ' Return Retorno 'End Function #Region "C R E A C I Ó N / A C T U A L I Z A C I Ó N - P R O D U C T O S" - Private Function CrearActualizarProductos(Todos As Boolean) As String - Return EnviarInformacion($"{Me.URLBase}api/services/products/import", GetProductosModificados(Todos)) - End Function - Private Function GetProductosModificados(Todos As Boolean) As String - Dim Retorno As String = "{}" + Private Function CrearActualizarProductos(Todos As Boolean) As Boolean + Dim Retorno As Boolean = False + Dim CountPeticiones As Integer = 0, CountPeticionesExitosas As Integer = 0 Dim DtPS As DataTable = Nothing Using ObjPS As New ClsProductosServicios @@ -250,59 +267,124 @@ Public Class E141 : Implements IHttpHandler If DtPS IsNot Nothing Then - Dim ArrayPS As New JArray - For Each RowPS As DataRow In DtPS.Rows + If DtPS.Rows.Count > 0 AndAlso DtPS.Rows.Count = 1 Then + Dim Dt As DataTable = DtPS.FiltraPorIndices(0, 0) + Dim payload = New JObject() - Dim PSData As String() = RowPS("PS").ToString().Split(" ".ToCharArray()) + payload.Add(New JProperty("products", GenerarPayloadProductos(Dt))) - Dim Measurement As String = "", Size As String = "", alt_code As String = "" + Dim resp = EnviarInformacion($"{Me.URLBase}api/services/products/import", payload.ToString()) - If PSData.Length > 0 Then - Measurement = PSData(0) + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If End If - If PSData.Length > 1 Then - Size = PSData(1) - End If + Else + Dim TotalIndex As Integer = DtPS.Rows.Count - 1 + Dim TotaRegistrosPorPeticion As Integer = 500 + Dim PrevIndex As Integer = 0 + Dim CurrentIndex As Integer = 0 - alt_code = String.Concat(Measurement, Size) + While PrevIndex < TotalIndex + CurrentIndex += TotaRegistrosPorPeticion - Dim producto As New JObject( - New JProperty("clasificacion", RowPS("Clasificacion")), - New JProperty("category", "Prod"), - New JProperty("pza", RowPS("Unidad")), - New JProperty("sku", RowPS("Codigo")), - New JProperty("name", RowPS("PS")), - New JProperty("measurement", Measurement), - New JProperty("size", Size), - New JProperty("brand", RowPS("Marca")), - New JProperty("price", RowPS("Precio")), - New JProperty("active", RowPS("Estado")), - New JProperty("user", RowPS("UsuarioModifico")), - New JProperty("alt_code", alt_code), - New JProperty("short_description", ""), - New JProperty("description", ""), - New JProperty("currency", 1), - New JProperty("promo_price", RowPS("PrecioPromocion")) - ) + If CurrentIndex > TotalIndex Then + CurrentIndex = TotalIndex + End If - ArrayPS.Add(producto) - Next - Retorno = New JObject(New JProperty("products", ArrayPS)).ToString() + Dim Dt As DataTable = DtPS.FiltraPorIndices(PrevIndex, CurrentIndex) + Dim payload = New JObject() + + 'If Not EsProduccion Then + ' payload.Add(New JProperty("deleteNotIncluded", True)) + 'End If + + payload.Add(New JProperty("products", GenerarPayloadProductos(Dt))) + + PrevIndex = CurrentIndex + + Dim resp = EnviarInformacion($"{Me.URLBase}api/services/products/import", payload.ToString()) + + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If + End If + + Threading.Thread.Sleep(3000) + End While + End If + + End If + + If CountPeticionesExitosas = CountPeticiones Then + Retorno = True End If Return Retorno End Function + + Private Function GenerarPayloadProductos(DtPS As DataTable) As JArray + Dim ArrayPS As New JArray + For Each RowPS As DataRow In DtPS.Rows + + Dim PSData As String() = RowPS("PS").ToString().Split(" ".ToCharArray()) + + Dim Measurement As String = "", Size As String = "", alt_code As String = "" + + If PSData.Length > 0 Then + Measurement = PSData(0) + End If + + If PSData.Length > 1 Then + Size = PSData(1) + End If + + alt_code = String.Concat(Measurement, Size) + + Dim producto As New JObject( + New JProperty("clasificacion", RowPS("Clasificacion")), + New JProperty("category", "Prod"), + New JProperty("pza", RowPS("Unidad")), + New JProperty("sku", RowPS("Codigo")), + New JProperty("name", RowPS("PS")), + New JProperty("measurement", Measurement), + New JProperty("size", Size), + New JProperty("brand", RowPS("Marca")), + New JProperty("price", RowPS("Precio")), + New JProperty("active", RowPS("Estado")), + New JProperty("user", RowPS("UsuarioModifico")), + New JProperty("alt_code", alt_code), + New JProperty("short_description", ""), + New JProperty("description", ""), + New JProperty("currency", 1), + New JProperty("promo_price", RowPS("PrecioPromocion")) + ) + + ArrayPS.Add(producto) + Next + + Return ArrayPS + End Function #End Region #Region "A C T U A L I Z A R - P R E C I O S" - Private Function ActualizarPrecios(Todos As Boolean) As String - Return EnviarInformacion($"{Me.URLBase}api/services/products/price-import", GetPreciosModificados(Todos)) - End Function + 'Private Function ActualizarPrecios(Todos As Boolean) As String + ' Return EnviarInformacion($"{Me.URLBase}api/services/products/price-import", GetPreciosModificados(Todos)) + 'End Function - Private Function GetPreciosModificados(Todos As Boolean) As String - Dim Retorno As String = "{}" + Private Function ActualizarPrecios(Todos As Boolean) As Boolean + Dim Retorno As Boolean = False + Dim CountPeticiones As Integer = 0, CountPeticionesExitosas As Integer = 0 Dim DtPS As DataTable = Nothing Using ObjPS As New ClsProductosServicios @@ -314,32 +396,90 @@ Public Class E141 : Implements IHttpHandler If DtPS IsNot Nothing Then - Dim ArrayPS As New JArray - For Each RowPS As DataRow In DtPS.Rows + If DtPS.Rows.Count > 0 AndAlso DtPS.Rows.Count = 1 Then + Dim Dt As DataTable = DtPS.FiltraPorIndices(0, 0) + Dim payload = New JObject() - Dim producto As New JObject( - New JProperty("sku", RowPS("Codigo")), - New JProperty("price", RowPS("Precio")), - New JProperty("promo_price", RowPS("PrecioPromocion")) - ) + payload.Add(New JProperty("products", GenerarPayloadPrecios(Dt))) + + + Dim resp = EnviarInformacion($"{Me.URLBase}api/services/products/price-import", payload.ToString()) + + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If + End If + + Else + Dim TotalIndex As Integer = DtPS.Rows.Count - 1 + Dim TotaRegistrosPorPeticion As Integer = 500 + Dim PrevIndex As Integer = 0 + Dim CurrentIndex As Integer = 0 + + While PrevIndex < TotalIndex + CurrentIndex += TotaRegistrosPorPeticion + + If CurrentIndex > TotalIndex Then + CurrentIndex = TotalIndex + End If + + Dim Dt As DataTable = DtPS.FiltraPorIndices(PrevIndex, CurrentIndex) + Dim payload = New JObject() + + payload.Add(New JProperty("products", GenerarPayloadPrecios(Dt))) + + PrevIndex = CurrentIndex + + Dim resp = EnviarInformacion($"{Me.URLBase}api/services/products/price-import", payload.ToString()) + + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If + End If + + Threading.Thread.Sleep(3000) + End While + End If - ArrayPS.Add(producto) - Next - Retorno = New JObject(New JProperty("products", ArrayPS)).ToString() End If Return Retorno End Function + + Private Function GenerarPayloadPrecios(DtPS As DataTable) As JArray + Dim ArrayPS As New JArray + For Each RowPS As DataRow In DtPS.Rows + + Dim producto As New JObject( + New JProperty("sku", RowPS("Codigo")), + New JProperty("price", RowPS("Precio")), + New JProperty("promo_price", RowPS("PrecioPromocion")) + ) + + ArrayPS.Add(producto) + Next + + Return ArrayPS + End Function #End Region #Region "A C T U A L I Z A R - E X I S T E N C I A S" - Private Function ActualizarExistencias() As String - Return EnviarInformacion($"{Me.URLBase}api/services/products/stock", GetPSExistencias()) - End Function + 'Private Function ActualizarExistencias() As String + ' Return EnviarInformacion($"{Me.URLBase}api/services/products/stock", GetPSExistencias()) + 'End Function - Private Function GetPSExistencias() As String - Dim Retorno As String = "{}" + Private Function ActualizarExistencias() As Boolean + Dim Retorno As Boolean = False + Dim CountPeticiones As Integer = 0, CountPeticionesExitosas As Integer = 0 Dim DtPS As DataTable = Nothing Using ObjPS As New ClsProductosServicios @@ -350,34 +490,90 @@ Public Class E141 : Implements IHttpHandler End Using If DtPS IsNot Nothing Then + If DtPS.Rows.Count > 0 AndAlso DtPS.Rows.Count = 1 Then - Dim ArrayPS As New JArray - For Each RowPS As DataRow In DtPS.Rows + Dim Dt As DataTable = DtPS.FiltraPorIndices(0, 0) + Dim payload = New JObject() - Dim producto As New JObject( - New JProperty("sku", RowPS("Codigo")), - New JProperty("branch_office_code", "01"), - New JProperty("stock", RowPS("Existencia")) - ) + payload.Add(New JProperty("stock", GenerarPayloadExistencias(Dt))) - ArrayPS.Add(producto) - Next - Retorno = New JObject(New JProperty("stock", ArrayPS)).ToString() + Dim resp = EnviarInformacion($"{Me.URLBase}api/services/products/stock", payload.ToString()) + + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If + End If + + Else + Dim TotalIndex As Integer = DtPS.Rows.Count - 1 + Dim TotaRegistrosPorPeticion As Integer = 500 + Dim PrevIndex As Integer = 0 + Dim CurrentIndex As Integer = 0 + + While PrevIndex < TotalIndex + CurrentIndex += TotaRegistrosPorPeticion + + If CurrentIndex > TotalIndex Then + CurrentIndex = TotalIndex + End If + + Dim Dt As DataTable = DtPS.FiltraPorIndices(PrevIndex, CurrentIndex) + Dim payload = New JObject() + + payload.Add(New JProperty("stock", GenerarPayloadExistencias(Dt))) + + PrevIndex = CurrentIndex + + Dim resp = EnviarInformacion($"{Me.URLBase}api/services/products/stock", payload.ToString()) + + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If + End If + + Threading.Thread.Sleep(3000) + End While + End If + End If + + If CountPeticionesExitosas = CountPeticiones Then + Retorno = True End If Return Retorno End Function + + Private Function GenerarPayloadExistencias(DtPS As DataTable) As JArray + Dim ArrayPS As New JArray + For Each RowPS As DataRow In DtPS.Rows + + Dim producto As New JObject( + New JProperty("sku", RowPS("Codigo")), + New JProperty("branch_office_code", "01"), + New JProperty("stock", RowPS("Existencia").ToString()) + ) + + ArrayPS.Add(producto) + Next + + Return ArrayPS + End Function #End Region #Region "A C T U A L I Z A R - E X I S T E N C I A S" - Private Function ActualizarVendedores(Todos As Boolean) As String - Return EnviarInformacion($"{Me.URLBase}api/v1/sellers/import", GetVendedores(Todos)) - End Function - - Private Function GetVendedores(Todos As Boolean) As String - Dim Retorno As String = "{}" + Private Function ActualizarVendedores(Todos As Boolean) As Boolean + Dim Retorno As Boolean = False + Dim CountPeticiones As Integer = 0, CountPeticionesExitosas As Integer = 0 Dim DtVendedores As DataTable = Nothing Using ObjPS As New ClsProductosServicios @@ -410,6 +606,11 @@ Public Class E141 : Implements IHttpHandler Apellido = String.Concat(VendedorData(0), " ", VendedorData(1)) End Select + If VendedorData.Length > 4 Then + Nombre = String.Concat(VendedorData(VendedorData.Length - 1), " ", VendedorData(VendedorData.Length)) + Apellido = String.Concat(VendedorData(0), " ", VendedorData(1)) + End If + Dim vendedor As New JObject( New JProperty("email", RowVendedor("Correo")), New JProperty("password", RowVendedor("Correo")), @@ -426,7 +627,19 @@ Public Class E141 : Implements IHttpHandler ArrayVendedores.Add(vendedor) Next - Retorno = New JObject(New JProperty("sellers", ArrayVendedores)).ToString() + + Dim payload = New JObject(New JProperty("sellers", ArrayVendedores)).ToString() + + Dim resp = EnviarInformacion($"{Me.URLBase}api/v1/sellers/import", payload) + + CountPeticiones += 1 + + If IsValidJson(resp) Then + Dim respuesta = JObject.Parse(resp) + If respuesta("status").ToString() = "success" Then + CountPeticionesExitosas += 1 + End If + End If End If Return Retorno @@ -495,4 +708,28 @@ Public Class E141 : Implements IHttpHandler Return URLParametros End Function + Private Shared Function IsValidJson(ByVal strInput As String) As Boolean + If String.IsNullOrWhiteSpace(strInput) Then + Return False + End If + + strInput = strInput.Trim() + + If (strInput.StartsWith("{") AndAlso strInput.EndsWith("}")) OrElse (strInput.StartsWith("[") AndAlso strInput.EndsWith("]")) Then + + Try + Dim obj = JToken.Parse(strInput) + Return True + Catch jex As JsonReaderException + Console.WriteLine(jex.Message) + Return False + Catch ex As Exception + Console.WriteLine(ex.ToString()) + Return False + End Try + Else + Return False + End If + End Function + End Class \ No newline at end of file diff --git a/Inventarios/EntregaAlmacen.aspx.vb b/Inventarios/EntregaAlmacen.aspx.vb index 21afcd47b..1ec5937e6 100644 --- a/Inventarios/EntregaAlmacen.aspx.vb +++ b/Inventarios/EntregaAlmacen.aspx.vb @@ -2663,7 +2663,12 @@ Partial Class Inventarios_EntregaAlmacen ' COMIENZA: VIRTUAL If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Dev") AndAlso UsuarioActual.Empresa.Funcionalidad(573) = "1" AndAlso CveMovimiento > 0 Then - Dim DtPSVirtual As New DataTable("DtTamanios") + Dim DtPSVirtual As New DataTable("DtTamanios") + Dim tCveAlmacen As Integer = -1 + + If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + tCveAlmacen = ObjInventario.DtResultados.FiltroPrimeroValor("CveAlmacen").ToEntero() + End If If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa) Then DtPSVirtual = ObjInventario.DtResultados @@ -2685,7 +2690,7 @@ Partial Class Inventarios_EntregaAlmacen Dim CveAlmacenVirtual As Integer = -1 Dim CveMovimientoRelacionadoVirtual As Integer = CveMovimiento Dim ValidaVirtual As Boolean = False - CveAlmacenVirtual = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 24).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() + CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() If TipoMovimiento = 1 Then CveConceptoMovimientoVirtual = 37 diff --git a/Inventarios/RecepcionAlmacen.aspx.vb b/Inventarios/RecepcionAlmacen.aspx.vb index 8215bcfc2..579a324c4 100644 --- a/Inventarios/RecepcionAlmacen.aspx.vb +++ b/Inventarios/RecepcionAlmacen.aspx.vb @@ -2702,6 +2702,12 @@ Partial Class Inventarios_RecepcionAlmacen Dim DtPSVirtual As New DataTable("DtTamanios") + Dim tCveAlmacen As Integer = -1 + + If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + tCveAlmacen = ObjInventario.DtResultados.FiltroPrimeroValor("CveAlmacen").ToEntero() + End If + If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa) Then DtPSVirtual = ObjInventario.DtResultados End If @@ -2711,7 +2717,7 @@ Partial Class Inventarios_RecepcionAlmacen Dim CveTipoAlmacenFiltro As Integer = If(CveTipoCompra = 9, 25, 24) - Dim CveAlmacenVirutal As Integer = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoAlmacenFiltro).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() + Dim CveAlmacenVirutal As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirutal, If(TipoMovimiento > 1, 13, 2), 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, CveMovimientoRelacionado:=CveMovimiento, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="RA/G4") FolioVirtual = ObjInventario.Folio diff --git a/Inventarios/TraspasoAlmacen.aspx.vb b/Inventarios/TraspasoAlmacen.aspx.vb index 25ad54a68..434eaf4fb 100644 --- a/Inventarios/TraspasoAlmacen.aspx.vb +++ b/Inventarios/TraspasoAlmacen.aspx.vb @@ -686,6 +686,9 @@ Partial Class Inventarios_TraspasoAlmacen Dim CveSubProyectoOrigen, CveSubProyectoDestino As Integer Dim IdCtaContableOrigen, IdCtaContableDestino As Integer + Dim CveAlmacenVirtualSalida As Integer = -1 + Dim CveAlmacenVirtualEntrada As Integer = -1 + DrAlmO = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacenOrigen.SelectedValue.ToEntero).FiltroPrimero("") DrAlmD = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacenDestino.SelectedValue.ToEntero).FiltroPrimero("") @@ -694,11 +697,14 @@ Partial Class Inventarios_TraspasoAlmacen TipoAlmacenOrigen = DrAlmO("CveTipoAlmacen").ToString.ToEntero CveSubProyectoOrigen = DrAlmO("CveSubProyecto").ToString.ToEntero IdCtaContableOrigen = DrAlmO("IdCtaContable").ToString.ToEntero + CveAlmacenVirtualSalida = DrAlmO("CveAlmacenVirtual").ToString.ToEntero + CveSucursalDestino = DrAlmD("CveSubProyecto").ToString.ToEntero TipoAlmacenDestino = DrAlmD("CveTipoAlmacen").ToString.ToEntero CveSubProyectoDestino = DrAlmD("CveSubProyecto").ToString.ToEntero - IdCtaContableDestino = DrAlmO("IdCtaContable").ToString.ToEntero + IdCtaContableDestino = DrAlmD("IdCtaContable").ToString.ToEntero + CveAlmacenVirtualEntrada = DrAlmD("CveAlmacenVirtual").ToString.ToEntero End If @@ -863,7 +869,11 @@ Partial Class Inventarios_TraspasoAlmacen 'VIRTUAL SALIDA If RealizarMovimientoVirtual Then - Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveSubProyectoOrigen).FiltroPrimeroValor("CveAlmacenVirtual", "").ToEntero() + 'If TipoAlmacenOrigen = 27 Then + ' CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, 25).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyectoOrigen}").ToEntero() + 'Else + ' CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, 24).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyectoOrigen}").ToEntero() + 'End If Dim dtvirtual As DataTable = Nothing @@ -889,7 +899,7 @@ Partial Class Inventarios_TraspasoAlmacen End If Else ErrorMovInv = True - End If + End If End If AlmacenEntrada = If(ChkTransitorio.Checked, DdlAlmacenTransitorio.SelectedValue.ToEntero, DdlAlmacenDestino.SelectedValue.ToEntero) @@ -955,70 +965,70 @@ Partial Class Inventarios_TraspasoAlmacen Else ErrorMovInv = True - End If + End If + End If + Dim Concepto As String = TxtObservaciones.Text + If Concepto = "" Then Concepto = "Traspaso" + 'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO: + If Not ErrorMovInv Then + Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/TraspasoAlmacen", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + + Dim resultado As DataTable = ObjInventario.DtResultados + Dim importe As Decimal = resultado.SUMD("Total").RoundSQL + 'Dim IdCtaContableSalida As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", DdlAlmacenOrigen.SelectedValue.ToEntero)).ToEntero + 'Dim IdCtaContableEntrada As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", DdlAlmacenDestino.SelectedValue.ToEntero)).ToEntero + Dim Contabilizable As Boolean = True + + If IdCtaContableOrigen = IdCtaContableDestino And TipoAlmacenDestino <> 26 Then Contabilizable = False + + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContableOrigen, -1, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable, ImporteMX:=importe) Then + ErrorMovInv = True End If - Dim Concepto As String = TxtObservaciones.Text - If Concepto = "" Then Concepto = "Traspaso" - 'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO: - If Not ErrorMovInv Then - Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/TraspasoAlmacen", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - Dim resultado As DataTable = ObjInventario.DtResultados - Dim importe As Decimal = resultado.SUMD("Total").RoundSQL - 'Dim IdCtaContableSalida As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", DdlAlmacenOrigen.SelectedValue.ToEntero)).ToEntero - 'Dim IdCtaContableEntrada As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", DdlAlmacenDestino.SelectedValue.ToEntero)).ToEntero - Dim Contabilizable As Boolean = True + 'si el tipo de almacen de entrada es Almacen sin costo, se registra al costo, la salida. + If TipoAlmacenOrigen <> 26 AndAlso TipoAlmacenDestino = 26 Then - If IdCtaContableOrigen = IdCtaContableDestino And TipoAlmacenDestino <> 26 Then Contabilizable = False - - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContableOrigen, -1, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable, ImporteMX:=importe) Then - ErrorMovInv = True - End If - - 'si el tipo de almacen de entrada es Almacen sin costo, se registra al costo, la salida. - If TipoAlmacenOrigen <> 26 AndAlso TipoAlmacenDestino = 26 Then - - Dim tCveClasificacion As Integer = DtMovimientos.MAX("CveClasificacion").ToEntero - Dim dr As DataRow = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=tCveClasificacion).FiltroPrimero("") - Dim IdCuentaCostos As Integer = -1 - If dr IsNot Nothing Then - IdCuentaCostos = dr("IdCuentaCostos").ToString.ToEntero - End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, TxtObservaciones.Text, 69, TxtObservaciones.Text, Fecha, IdCuentaCostos, -1, CveClasificacion:=tCveClasificacion, CveSubProyecto:=CveSubProyectoOrigen, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable, ImporteMX:=importe) Then - ErrorMovInv = True - End If - Contabilizable = False - importe = 0 - End If - - If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContableDestino, -1, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable, ImporteMX:=importe) Then - ErrorMovInv = True - End If + Dim tCveClasificacion As Integer = DtMovimientos.MAX("CveClasificacion").ToEntero + Dim dr As DataRow = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=tCveClasificacion).FiltroPrimero("") + Dim IdCuentaCostos As Integer = -1 + If dr IsNot Nothing Then + IdCuentaCostos = dr("IdCuentaCostos").ToString.ToEntero End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, TxtObservaciones.Text, 69, TxtObservaciones.Text, Fecha, IdCuentaCostos, -1, CveClasificacion:=tCveClasificacion, CveSubProyecto:=CveSubProyectoOrigen, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable, ImporteMX:=importe) Then + ErrorMovInv = True + End If + Contabilizable = False + importe = 0 + End If + + If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContableDestino, -1, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable, ImporteMX:=importe) Then + ErrorMovInv = True End If End If + End If + End If Else - If Not ErrorMovInv Then - Dim Concepto As String = TxtObservaciones.Text - If Concepto = "" Then Concepto = "Traspaso" - Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/TraspasoAlmacen2", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then + If Not ErrorMovInv Then + Dim Concepto As String = TxtObservaciones.Text + If Concepto = "" Then Concepto = "Traspaso" + Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/TraspasoAlmacen2", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then - Dim resultado As DataTable = ObjInventario.DtResultados - Dim importe As Decimal = resultado.SUMD("Total").RoundSQL - Dim IdCtaContable As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", DdlAlmacenTransitorio.SelectedValue.ToEntero)).ToEntero + Dim resultado As DataTable = ObjInventario.DtResultados + Dim importe As Decimal = resultado.SUMD("Total").RoundSQL + Dim IdCtaContable As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", String.Format("CveAlmacen = {0}", DdlAlmacenTransitorio.SelectedValue.ToEntero)).ToEntero - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContable, -1, CveMovimientoAlmacen:=CveMovimientoSalida, ImporteMX:=importe, Contabilizable:=False) Then - ErrorMovInv = True - End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContable, -1, CveMovimientoAlmacen:=CveMovimientoSalida, ImporteMX:=importe, Contabilizable:=False) Then + ErrorMovInv = True + End If - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContable, -1, CveMovimientoAlmacen:=CveMovimientoEntrada, ImporteMX:=importe, Contabilizable:=False) Then - ErrorMovInv = True - End If + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContable, -1, CveMovimientoAlmacen:=CveMovimientoEntrada, ImporteMX:=importe, Contabilizable:=False) Then + ErrorMovInv = True End If End If End If + End If @@ -1688,6 +1698,14 @@ Partial Class Inventarios_TraspasoAlmacen Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=GvDatosRecepcion.Rows(0).DataKey("CveAlmacenSalida").ToEntero).FiltroPrimeroValor("CveAlmacenVirtual", "").ToEntero() + 'SI EL ALMACEN ORIGEN ES DE APOPYO LOGISTICO EL ALMACEN VIRTUAL DEBE SER DE APOYO LOGISTICO + 'Dim CveAlmacenVirtual As Integer = -1 + 'If CveTipoAlmacenOrigen = 27 Then + ' CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $" CveTipoAlmacen =25 AND CveSubProyecto={CveSubProyecto}").ToEntero() + 'Else + ' CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $" CveTipoAlmacen =24 AND CveSubProyecto={CveSubProyecto}").ToEntero() + 'End If + If CveAlmacenVirtual > 0 Then Dim dtvirtual As DataTable = Nothing @@ -2833,7 +2851,7 @@ Partial Class Inventarios_TraspasoAlmacen Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) - Dim excelFile As ExcelFile = ExcelFile.Load(flatFilePath) + Dim excelFile As ExcelFile = excelFile.Load(flatFilePath) Dim unnamed As Integer = 0 Dim cols As Integer diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 62bac30a1..7f0fbdb3d 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -5176,6 +5176,10 @@ Partial Class Ventas DdlAlmacenAsignado.DataBind() DdlAlmacenAsignado.SelectedValueExist(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto = {DdlSubProyectoDatos.SelectedValue}").ToString().ToEntero()) End If + Else + ddlAlmacen.DataSource = Nothing + ddlAlmacen.DataBind() + End If UpINV.Update() End Sub @@ -13355,7 +13359,7 @@ Partial Class Ventas - End If + End If End Sub Protected Sub BtnAceptarAnticipos_Click(sender As Object, e As System.EventArgs) Handles BtnAceptarAnticipos.Click Anticipos() @@ -18025,7 +18029,7 @@ Partial Class Ventas CveMovimientoEntradaDev = RowMovimiento("CveMovimiento").ToString().ToEntero() Dim tCveAlmacen = RowMovimiento("CveAlmacen").ToString().ToEntero() CveSubProyecto = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {tCveAlmacen}").ToEntero() - CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $" CveTipoAlmacen = 24 AND CveSubProyecto={CveSubProyecto}").ToEntero() + CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() Else OcurrioError = True @@ -18366,20 +18370,20 @@ Partial Class Ventas If Con.GetEstimacionesPorFacturar(-1, CveCliente, DdlContrato.SelectedValue.ToEntero(), 0, UsuarioActual.CveEmpresa) Then - GvEst.DataSource = Con.DtResultados - If Con.DtResultados.Rows.Count > 0 Then - 'BtnEstimacion.Visible = True - DdlContrato.Items.Clear() - DdlContrato.Items.Add(New ListItem("Todos", "-1")) - DdlContrato.DataSource = Con.DtResultados.FiltraParametros("CveContrato > 0", "NumeroContrato", DistinctColumns:={"CveContrato", "NumeroContrato"}) - End If + GvEst.DataSource = Con.DtResultados + If Con.DtResultados.Rows.Count > 0 Then + 'BtnEstimacion.Visible = True + DdlContrato.Items.Clear() + DdlContrato.Items.Add(New ListItem("Todos", "-1")) + DdlContrato.DataSource = Con.DtResultados.FiltraParametros("CveContrato > 0", "NumeroContrato", DistinctColumns:={"CveContrato", "NumeroContrato"}) End If + End If - UPEstimaciones.Update() - Con.Dispose() - DdlContrato.DataBind() - GvEst.DataBind() + UPEstimaciones.Update() + Con.Dispose() + DdlContrato.DataBind() + GvEst.DataBind() @@ -20890,7 +20894,7 @@ Partial Class Ventas End If ObjVentas.Dispose() Else - CancelarDocumento() + CancelarDocumento() End If End Sub