diff --git a/Ashx/E119.ashx b/Ashx/E119.ashx index d3a68c8c6..0be1294cf 100644 --- a/Ashx/E119.ashx +++ b/Ashx/E119.ashx @@ -86,14 +86,16 @@ Public Class E119 : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim retorno As String = "" + Dim MsgLog As New StringBuilder + MsgLog.AppendLine("Inicia Petición.") Try Dim Metodo As String = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) - + MsgLog.AppendLine(Metodo) If Metodo = "BASF_POG40" Then context.Response.ContentType = "application/json" Dim Auth As AuthMessage = ValidarSolicitud(context) - If Auth.IsSucces Then + If Auth.IsSuccess Then retorno = ConsultaDatos(context) Else context.Response.StatusCode = Auth.StatusCode @@ -106,7 +108,7 @@ Public Class E119 : Implements IHttpHandler context.Response.ContentType = "application/json" Dim Auth As AuthMessage = ValidarSolicitud(context) - If Auth.IsSucces Then + If Auth.IsSuccess Then retorno = ConsultaProductos(context) Else context.Response.StatusCode = Auth.StatusCode @@ -118,7 +120,7 @@ Public Class E119 : Implements IHttpHandler context.Response.ContentType = "application/json" Dim Auth As AuthMessage = ValidarSolicitud(context) - If Auth.IsSucces Then + If Auth.IsSuccess Then retorno = ConsultaClasificaciones(context) Else context.Response.StatusCode = Auth.StatusCode @@ -130,7 +132,7 @@ Public Class E119 : Implements IHttpHandler context.Response.ContentType = "application/json" Dim Auth As AuthMessage = ValidarSolicitud(context) - If Auth.IsSucces Then + If Auth.IsSuccess Then retorno = RegistraRemision(context) Else context.Response.StatusCode = Auth.StatusCode @@ -142,14 +144,17 @@ Public Class E119 : Implements IHttpHandler Catch ex As Exception context.Response.ContentType = "text/html" + MsgLog.AppendLine("Error de procesamiento:" & ex.Message) Dim respuesta As New AuthMessage respuesta.ErrorMessage = New ResponseMsgError() With {.message = "La solicitud no se pudo procesar."} - respuesta.IsSucces = False + respuesta.IsSuccess = False respuesta.StatusCode = 200 retorno = JsonConvert.SerializeObject(respuesta.ErrorMessage) context.Response.Write(retorno) + End Try + MsgLog.ToString.GuardaLogAD("LogE119") End Sub Private Function ValidarSolicitud(ByVal context As HttpContext) As AuthMessage @@ -168,7 +173,7 @@ Public Class E119 : Implements IHttpHandler Else respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña son requeridos"} - respuesta.IsSucces = False + respuesta.IsSuccess = False respuesta.StatusCode = 200 Return respuesta @@ -176,13 +181,13 @@ Public Class E119 : Implements IHttpHandler If unauthorized Then respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña no son validos"} - respuesta.IsSucces = False + respuesta.IsSuccess = False respuesta.StatusCode = 200 Return respuesta Else respuesta.ErrorMessage = Nothing - respuesta.IsSucces = True + respuesta.IsSuccess = True respuesta.StatusCode = 200 Return respuesta @@ -337,112 +342,114 @@ Public Class E119 : Implements IHttpHandler Dim Respuesta As New ResponseMsg Dim RespuestaError As New ResponseMsgError Dim MsgLog As New StringBuilder + Try - MsgLog.Append("1.0 Registra") - If context.Request.InputStream IsNot Nothing Then - Using reader As New StreamReader(context.Request.InputStream) - Dim json As String = reader.ReadToEnd - - If Not String.IsNullOrEmpty(json) Then - JsonRequest = JObject.Parse(json) - If JsonRequest Is Nothing Then - TieneError = True - End If - Else - TieneError = True - End If - End Using - End If - - MsgLog.Append("1.1 accedido") - If TieneError Then - RespuestaError.message = "No se pudo procesar la solicitud - Formato mal formado" - context.Response.StatusCode = 200 - Return JsonConvert.SerializeObject(RespuestaError) - End If - - - If Not TieneError Then - Dim Usuario As Usuario = ValidaUsuarioSistema(100, CveEmpresa) - Dim ObjFactura As Modelos.Factura = Nothing - Dim Resp As New Modelos.Factura.MMensajeFactura - If Usuario IsNot Nothing Then - MsgLog.Append("1.1 Validado") - Dim ObjClientes As New ClsClientes() - Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL()) - Dim CveSubProyecto, CveCliente, CveMoneda, CvePS As Integer - Dim Cantidad, PU, Descuento As Decimal - Dim Obs As String = "" - CveSubProyecto = 12659 ' fijo Ecommerce - CveCliente = 0 - CveMoneda = 1 - Descuento = 0 - MsgLog.Append("1.3 billing") - Dim RFC As String = If(JsonRequest("billing") Is Nothing, "", JsonRequest("billing")("first_name").ToString()) - Dim NombreCliente As String = If(JsonRequest("billing") Is Nothing, "", JsonRequest("billing")("first_name").ToString() & " " & JsonRequest("billing")("last_name").ToString()) - 'BUSCAR SI ESTÁ REGISTRADO EL CLIENTE - If ObjClientes.GetClientes(-1, "-1", "-1", "-1", RFC, "-1", "-1", -1, CveEmpresa, 1, TipoCliente:=-1, TopSelect:=1) Then - If ObjClientes.DtResultados.Rows.Count > 0 Then - 'Resp.TieneError = False - CveCliente = ObjClientes.CveCliente - 'Resp.Mensajes.Add("El RFC ya existe en el sistema") - End If - End If - MsgLog.Append("1.4 verificar cliente") - - If CveCliente = 0 Then - ' 'DATOS DE BILLING - MsgLog.Append("1.5 crear cliente") - If JsonRequest("billing") IsNot Nothing Then - Dim CveEstado As Integer = -1 - Dim Direccion As String = If(JsonRequest("billing")("address_1") Is Nothing, "", JsonRequest("billing")("address_1").ToString()) - Dim NumExt As String = "" - Dim NumInt As String = "" - Dim Colonia As String = "" - Dim Ciudad As String = If(JsonRequest("billing")("city") Is Nothing, "", JsonRequest("billing")("city").ToString()) - Dim Localidad As String = If(JsonRequest("billing")("city") Is Nothing, "", JsonRequest("billing")("city").ToString()) - Dim CP As String = If(JsonRequest("billing")("postcode") Is Nothing, "", JsonRequest("billing")("postcode").ToString()) - Dim Telefono As String = If(JsonRequest("billing")("phone") Is Nothing, "", JsonRequest("billing")("phone").ToString()) - Dim Correo As String = If(JsonRequest("billing")("email") Is Nothing, "", JsonRequest("billing")("email").ToString()) - Dim Estado As String = If(JsonRequest("billing")("state") Is Nothing, "", JsonRequest("billing")("state").ToString()) - If Not String.IsNullOrEmpty(Estado) Then - CveEstado = ClsPaginas.GlobalDTGralEstados("MEX").FiltroPrimeroValor("CveEstado", $"NombreEstado = '{Estado.Trim}'").ToEntero() - If CveEstado <= 0 Then 'SI NO ENCUENTRA EL ESTADO INGRESA EL DE SONORA - CveEstado = 26 - End If - Else - CveEstado = 26 - End If - If ObjClientes.AgregarClienteNoFrecuente(NombreCliente, Direccion, NumExt, NumInt, Colonia, Localidad, Ciudad, CveEstado, RFC, CP, Telefono, Correo, CveSubProyecto, CveUsuario, CveEmpresa, "", -1, -1) Then - If ObjClientes.DtResultados.Rows.Count > 0 Then - CveCliente = ObjClientes.DtResultados(0)("CveCliente").ToString().ToEntero() - MsgLog.Append("1.5.5 cliente creado") - End If + MsgLog.AppendLine("1.0 Registra") + If context.Request.InputStream IsNot Nothing Then + Using reader As New StreamReader(context.Request.InputStream) + Dim json As String = reader.ReadToEnd + json = json.TrimStart("["c).TrimEnd("]"c) 'quito corchetes que están conteniendo el json, elimino al inicio y al final + If Not String.IsNullOrEmpty(json) Then + JsonRequest = JObject.Parse(json) + If JsonRequest Is Nothing Then + TieneError = True End If Else - MsgLog.Append("1.5.9 sin datos cliente") TieneError = True - Resp.Mensajes.Add("no existen datos del cliente") End If + End Using + End If - End If + MsgLog.AppendLine("1.1 accedido") + If TieneError Then + RespuestaError.message = "No se pudo procesar la solicitud - Formato mal formado" + context.Response.StatusCode = 200 + Return JsonConvert.SerializeObject(RespuestaError) + End If - Try - MsgLog.Append("1.6 inicio generar venta") + + If Not TieneError Then + Dim Usuario As Usuario = ValidaUsuarioSistema(100, CveEmpresa) + Dim ObjFactura As Modelos.Factura = Nothing + Dim Resp As New Modelos.Factura.MMensajeFactura + If Usuario IsNot Nothing Then + MsgLog.AppendLine("1.1 Validado") + Dim ObjClientes As New ClsClientes() + Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL()) + Dim CveSubProyecto, CveCliente, CveMoneda, CvePS As Integer + Dim Cantidad, PU, Descuento As Decimal + Dim Obs As String = "" + CveSubProyecto = 12659 ' fijo Ecommerce + CveCliente = 0 + CveMoneda = 1 + Descuento = 0 + MsgLog.AppendLine("1.3 billing") + Dim RFC As String = If(JsonRequest("billing") Is Nothing, "", JsonRequest("billing")("first_name").ToString()) + Dim NombreCliente As String = If(JsonRequest("billing") Is Nothing, "", JsonRequest("billing")("first_name").ToString() & " " & JsonRequest("billing")("last_name").ToString()) + 'BUSCAR SI ESTÁ REGISTRADO EL CLIENTE + If ObjClientes.GetClientes(-1, "-1", "-1", "-1", RFC, "-1", "-1", -1, CveEmpresa, 1, TipoCliente:=-1, TopSelect:=1) Then + If ObjClientes.DtResultados.Rows.Count > 0 Then + 'Resp.TieneError = False + CveCliente = ObjClientes.CveCliente + 'Resp.Mensajes.Add("El RFC ya existe en el sistema") + End If + End If + MsgLog.AppendLine("1.4 verificar cliente") + + If CveCliente = 0 Then + ' 'DATOS DE BILLING + MsgLog.AppendLine("1.5 crear cliente") + If JsonRequest("billing") IsNot Nothing Then + Dim CveEstado As Integer = -1 + Dim Direccion As String = If(JsonRequest("billing")("address_1") Is Nothing, "", JsonRequest("billing")("address_1").ToString()) + Dim NumExt As String = "" + Dim NumInt As String = "" + Dim Colonia As String = "" + Dim Ciudad As String = If(JsonRequest("billing")("city") Is Nothing, "", JsonRequest("billing")("city").ToString()) + Dim Localidad As String = If(JsonRequest("billing")("city") Is Nothing, "", JsonRequest("billing")("city").ToString()) + Dim CP As String = If(JsonRequest("billing")("postcode") Is Nothing, "", JsonRequest("billing")("postcode").ToString()) + Dim Telefono As String = If(JsonRequest("billing")("phone") Is Nothing, "", JsonRequest("billing")("phone").ToString()) + Dim Correo As String = If(JsonRequest("billing")("email") Is Nothing, "", JsonRequest("billing")("email").ToString()) + Dim Estado As String = If(JsonRequest("billing")("state") Is Nothing, "", JsonRequest("billing")("state").ToString()) + If Not String.IsNullOrEmpty(Estado) Then + CveEstado = ClsPaginas.GlobalDTGralEstados("MEX").FiltroPrimeroValor("CveEstado", $"NombreEstado = '{Estado.Trim}'").ToEntero() + If CveEstado <= 0 Then 'SI NO ENCUENTRA EL ESTADO INGRESA EL DE SONORA + CveEstado = 26 + End If + Else + CveEstado = 26 + End If + If ObjClientes.AgregarClienteNoFrecuente(NombreCliente, Direccion, NumExt, NumInt, Colonia, Localidad, Ciudad, CveEstado, RFC, CP, Telefono, Correo, CveSubProyecto, CveUsuario, CveEmpresa, "", -1, -1) Then + If ObjClientes.DtResultados.Rows.Count > 0 Then + CveCliente = ObjClientes.DtResultados(0)("CveCliente").ToString().ToEntero() + MsgLog.AppendLine("1.5.5 cliente creado") + End If + End If + Else + MsgLog.AppendLine("1.5.9 sin datos cliente") + TieneError = True + Resp.Mensajes.Add("no existen datos del cliente") + End If + + End If + ' shiping + 'shiping_lines/ method_id: free_shipping/local_pickup + + MsgLog.AppendLine("1.6 inicio generar venta") ObjFactura = Modelos.Factura.CrearVentaNueva(Usuario, CveSubProyecto, CveCliente, CveMoneda, "Rem") MsgLog.AppendFormat("1.6.0 objeto creado {0}", If(ObjFactura IsNot Nothing, "si", "no")) If JsonRequest("line_items") IsNot Nothing Then Dim ListaPS As JArray = JArray.Parse(JsonRequest("line_items").ToString()) Dim Consec As Integer = 1 - MsgLog.Append("1.6.1 recorrer ps") + MsgLog.AppendLine("1.6.1 recorrer ps") For Each JsonPS As JObject In ListaPS Cantidad = JsonPS("quantity").ToString.ToDecimal() PU = JsonPS("price").ToString.ToDecimal() CvePS = ClsPaginas.GlobalDTPSSimplificado(CveEmpresa, Codigo:=JsonPS("sku").ToString()).FiltroPrimeroValor("CvePS").ToEntero() ObjFactura.AgregarPS(CvePS, Cantidad, PU, Descuento, Obs, CveSubProyecto:=CveSubProyecto) - MsgLog.Append("1.6.1 agregar ps a venta") + MsgLog.AppendLine("1.6.1 agregar ps a venta") ''VALIDAR QUE SEA EL MISMO PRODUCTO If CvePS <= 0 Then TieneError = True @@ -459,11 +466,11 @@ Public Class E119 : Implements IHttpHandler End If If ObjFactura IsNot Nothing AndAlso Not TieneError Then - MsgLog.Append("1.7 agregar la remision") + MsgLog.AppendLine("1.7 agregar la remision") Resp = ObjFactura.EmitirFactura(False, Transac:=ObjClientes.IniciaTransacSQL()) If Resp.CveVenta > 0 Then - MsgLog.Append("2.0 remisión registrada") + MsgLog.AppendLine("2.0 remisión registrada") Dim data As New JArray Dim objSucursal As New JObject( New JProperty("Cve", Resp.CveVenta), @@ -473,7 +480,7 @@ Public Class E119 : Implements IHttpHandler Respuesta.status = "success" Respuesta.data = data Else - MsgLog.Append("1.8 error al agregar la remision") + MsgLog.AppendLine("1.8 error al agregar la remision") TieneError = True End If @@ -493,32 +500,30 @@ Public Class E119 : Implements IHttpHandler RespuestaError.message = sb.ToString() End If - Catch ex As Exception - TieneError = True - End Try + If TieneError Then + ObjClientes.RollBack() + ObjClientes.Dispose() + ObjInventario.Dispose() + Dim sb As New StringBuilder() + For Each msg As String In Resp.Mensajes + sb.AppendFormat("{0}. ", msg) + Next + RespuestaError.message = sb.ToString() - If TieneError Then - - ObjClientes.RollBack() - ObjClientes.Dispose() - ObjInventario.Dispose() - Dim sb As New StringBuilder() - For Each msg As String In Resp.Mensajes - sb.AppendFormat("{0}. ", msg) - Next - RespuestaError.message = sb.ToString() - - MsgLog.Append("99.0 ocurrió un error en el proceso") - Else - MsgLog.Append("4.0 proceso terminado") - ObjClientes.Commit() - ObjClientes.Dispose() - ObjInventario.Dispose() + MsgLog.Append("99.0 ocurrió un error en el proceso") + Else + MsgLog.Append("4.0 proceso terminado") + ObjClientes.Commit() + ObjClientes.Dispose() + ObjInventario.Dispose() + End If + If ObjFactura IsNot Nothing Then ObjFactura.Dispose() End If - If ObjFactura IsNot Nothing Then ObjFactura.Dispose() End If - End If + Catch ex As Exception + TieneError = True + End Try MsgLog.ToString.GuardaLogAD("LogE119") If TieneError Then @@ -548,7 +553,7 @@ Public Class E119 : Implements IHttpHandler End Class Private Class AuthMessage - Public Property IsSucces As Boolean + Public Property IsSuccess As Boolean Public Property ErrorMessage As ResponseMsgError Public Property StatusCode As Integer End Class