-- mejora del tema de registro de remisión

This commit is contained in:
2023-12-21 13:35:28 -07:00
parent e7e73b445f
commit 5349698f1a

View File

@@ -86,14 +86,16 @@ Public Class E119 : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim retorno As String = "" Dim retorno As String = ""
Dim MsgLog As New StringBuilder
MsgLog.AppendLine("Inicia Petición.")
Try Try
Dim Metodo As String = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) Dim Metodo As String = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString())
MsgLog.AppendLine(Metodo)
If Metodo = "BASF_POG40" Then If Metodo = "BASF_POG40" Then
context.Response.ContentType = "application/json" context.Response.ContentType = "application/json"
Dim Auth As AuthMessage = ValidarSolicitud(context) Dim Auth As AuthMessage = ValidarSolicitud(context)
If Auth.IsSucces Then If Auth.IsSuccess Then
retorno = ConsultaDatos(context) retorno = ConsultaDatos(context)
Else Else
context.Response.StatusCode = Auth.StatusCode context.Response.StatusCode = Auth.StatusCode
@@ -106,7 +108,7 @@ Public Class E119 : Implements IHttpHandler
context.Response.ContentType = "application/json" context.Response.ContentType = "application/json"
Dim Auth As AuthMessage = ValidarSolicitud(context) Dim Auth As AuthMessage = ValidarSolicitud(context)
If Auth.IsSucces Then If Auth.IsSuccess Then
retorno = ConsultaProductos(context) retorno = ConsultaProductos(context)
Else Else
context.Response.StatusCode = Auth.StatusCode context.Response.StatusCode = Auth.StatusCode
@@ -118,7 +120,7 @@ Public Class E119 : Implements IHttpHandler
context.Response.ContentType = "application/json" context.Response.ContentType = "application/json"
Dim Auth As AuthMessage = ValidarSolicitud(context) Dim Auth As AuthMessage = ValidarSolicitud(context)
If Auth.IsSucces Then If Auth.IsSuccess Then
retorno = ConsultaClasificaciones(context) retorno = ConsultaClasificaciones(context)
Else Else
context.Response.StatusCode = Auth.StatusCode context.Response.StatusCode = Auth.StatusCode
@@ -130,7 +132,7 @@ Public Class E119 : Implements IHttpHandler
context.Response.ContentType = "application/json" context.Response.ContentType = "application/json"
Dim Auth As AuthMessage = ValidarSolicitud(context) Dim Auth As AuthMessage = ValidarSolicitud(context)
If Auth.IsSucces Then If Auth.IsSuccess Then
retorno = RegistraRemision(context) retorno = RegistraRemision(context)
Else Else
context.Response.StatusCode = Auth.StatusCode context.Response.StatusCode = Auth.StatusCode
@@ -142,14 +144,17 @@ Public Class E119 : Implements IHttpHandler
Catch ex As Exception Catch ex As Exception
context.Response.ContentType = "text/html" context.Response.ContentType = "text/html"
MsgLog.AppendLine("Error de procesamiento:" & ex.Message)
Dim respuesta As New AuthMessage Dim respuesta As New AuthMessage
respuesta.ErrorMessage = New ResponseMsgError() With {.message = "La solicitud no se pudo procesar."} respuesta.ErrorMessage = New ResponseMsgError() With {.message = "La solicitud no se pudo procesar."}
respuesta.IsSucces = False respuesta.IsSuccess = False
respuesta.StatusCode = 200 respuesta.StatusCode = 200
retorno = JsonConvert.SerializeObject(respuesta.ErrorMessage) retorno = JsonConvert.SerializeObject(respuesta.ErrorMessage)
context.Response.Write(retorno) context.Response.Write(retorno)
End Try End Try
MsgLog.ToString.GuardaLogAD("LogE119")
End Sub End Sub
Private Function ValidarSolicitud(ByVal context As HttpContext) As AuthMessage Private Function ValidarSolicitud(ByVal context As HttpContext) As AuthMessage
@@ -168,7 +173,7 @@ Public Class E119 : Implements IHttpHandler
Else Else
respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña son requeridos"} respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña son requeridos"}
respuesta.IsSucces = False respuesta.IsSuccess = False
respuesta.StatusCode = 200 respuesta.StatusCode = 200
Return respuesta Return respuesta
@@ -176,13 +181,13 @@ Public Class E119 : Implements IHttpHandler
If unauthorized Then If unauthorized Then
respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña no son validos"} respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña no son validos"}
respuesta.IsSucces = False respuesta.IsSuccess = False
respuesta.StatusCode = 200 respuesta.StatusCode = 200
Return respuesta Return respuesta
Else Else
respuesta.ErrorMessage = Nothing respuesta.ErrorMessage = Nothing
respuesta.IsSucces = True respuesta.IsSuccess = True
respuesta.StatusCode = 200 respuesta.StatusCode = 200
Return respuesta Return respuesta
@@ -337,12 +342,13 @@ Public Class E119 : Implements IHttpHandler
Dim Respuesta As New ResponseMsg Dim Respuesta As New ResponseMsg
Dim RespuestaError As New ResponseMsgError Dim RespuestaError As New ResponseMsgError
Dim MsgLog As New StringBuilder Dim MsgLog As New StringBuilder
Try
MsgLog.Append("1.0 Registra") MsgLog.AppendLine("1.0 Registra")
If context.Request.InputStream IsNot Nothing Then If context.Request.InputStream IsNot Nothing Then
Using reader As New StreamReader(context.Request.InputStream) Using reader As New StreamReader(context.Request.InputStream)
Dim json As String = reader.ReadToEnd 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 If Not String.IsNullOrEmpty(json) Then
JsonRequest = JObject.Parse(json) JsonRequest = JObject.Parse(json)
If JsonRequest Is Nothing Then If JsonRequest Is Nothing Then
@@ -354,7 +360,7 @@ Public Class E119 : Implements IHttpHandler
End Using End Using
End If End If
MsgLog.Append("1.1 accedido") MsgLog.AppendLine("1.1 accedido")
If TieneError Then If TieneError Then
RespuestaError.message = "No se pudo procesar la solicitud - Formato mal formado" RespuestaError.message = "No se pudo procesar la solicitud - Formato mal formado"
context.Response.StatusCode = 200 context.Response.StatusCode = 200
@@ -367,7 +373,7 @@ Public Class E119 : Implements IHttpHandler
Dim ObjFactura As Modelos.Factura = Nothing Dim ObjFactura As Modelos.Factura = Nothing
Dim Resp As New Modelos.Factura.MMensajeFactura Dim Resp As New Modelos.Factura.MMensajeFactura
If Usuario IsNot Nothing Then If Usuario IsNot Nothing Then
MsgLog.Append("1.1 Validado") MsgLog.AppendLine("1.1 Validado")
Dim ObjClientes As New ClsClientes() Dim ObjClientes As New ClsClientes()
Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL()) Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL())
Dim CveSubProyecto, CveCliente, CveMoneda, CvePS As Integer Dim CveSubProyecto, CveCliente, CveMoneda, CvePS As Integer
@@ -377,7 +383,7 @@ Public Class E119 : Implements IHttpHandler
CveCliente = 0 CveCliente = 0
CveMoneda = 1 CveMoneda = 1
Descuento = 0 Descuento = 0
MsgLog.Append("1.3 billing") MsgLog.AppendLine("1.3 billing")
Dim RFC As String = If(JsonRequest("billing") Is Nothing, "", JsonRequest("billing")("first_name").ToString()) 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()) 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 'BUSCAR SI ESTÁ REGISTRADO EL CLIENTE
@@ -388,11 +394,11 @@ Public Class E119 : Implements IHttpHandler
'Resp.Mensajes.Add("El RFC ya existe en el sistema") 'Resp.Mensajes.Add("El RFC ya existe en el sistema")
End If End If
End If End If
MsgLog.Append("1.4 verificar cliente") MsgLog.AppendLine("1.4 verificar cliente")
If CveCliente = 0 Then If CveCliente = 0 Then
' 'DATOS DE BILLING ' 'DATOS DE BILLING
MsgLog.Append("1.5 crear cliente") MsgLog.AppendLine("1.5 crear cliente")
If JsonRequest("billing") IsNot Nothing Then If JsonRequest("billing") IsNot Nothing Then
Dim CveEstado As Integer = -1 Dim CveEstado As Integer = -1
Dim Direccion As String = If(JsonRequest("billing")("address_1") Is Nothing, "", JsonRequest("billing")("address_1").ToString()) Dim Direccion As String = If(JsonRequest("billing")("address_1") Is Nothing, "", JsonRequest("billing")("address_1").ToString())
@@ -416,33 +422,34 @@ Public Class E119 : Implements IHttpHandler
If ObjClientes.AgregarClienteNoFrecuente(NombreCliente, Direccion, NumExt, NumInt, Colonia, Localidad, Ciudad, CveEstado, RFC, CP, Telefono, Correo, CveSubProyecto, CveUsuario, CveEmpresa, "", -1, -1) Then 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 If ObjClientes.DtResultados.Rows.Count > 0 Then
CveCliente = ObjClientes.DtResultados(0)("CveCliente").ToString().ToEntero() CveCliente = ObjClientes.DtResultados(0)("CveCliente").ToString().ToEntero()
MsgLog.Append("1.5.5 cliente creado") MsgLog.AppendLine("1.5.5 cliente creado")
End If End If
End If End If
Else Else
MsgLog.Append("1.5.9 sin datos cliente") MsgLog.AppendLine("1.5.9 sin datos cliente")
TieneError = True TieneError = True
Resp.Mensajes.Add("no existen datos del cliente") Resp.Mensajes.Add("no existen datos del cliente")
End If End If
End If End If
' shiping
'shiping_lines/ method_id: free_shipping/local_pickup
Try MsgLog.AppendLine("1.6 inicio generar venta")
MsgLog.Append("1.6 inicio generar venta")
ObjFactura = Modelos.Factura.CrearVentaNueva(Usuario, CveSubProyecto, CveCliente, CveMoneda, "Rem") ObjFactura = Modelos.Factura.CrearVentaNueva(Usuario, CveSubProyecto, CveCliente, CveMoneda, "Rem")
MsgLog.AppendFormat("1.6.0 objeto creado {0}", If(ObjFactura IsNot Nothing, "si", "no")) MsgLog.AppendFormat("1.6.0 objeto creado {0}", If(ObjFactura IsNot Nothing, "si", "no"))
If JsonRequest("line_items") IsNot Nothing Then If JsonRequest("line_items") IsNot Nothing Then
Dim ListaPS As JArray = JArray.Parse(JsonRequest("line_items").ToString()) Dim ListaPS As JArray = JArray.Parse(JsonRequest("line_items").ToString())
Dim Consec As Integer = 1 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 For Each JsonPS As JObject In ListaPS
Cantidad = JsonPS("quantity").ToString.ToDecimal() Cantidad = JsonPS("quantity").ToString.ToDecimal()
PU = JsonPS("price").ToString.ToDecimal() PU = JsonPS("price").ToString.ToDecimal()
CvePS = ClsPaginas.GlobalDTPSSimplificado(CveEmpresa, Codigo:=JsonPS("sku").ToString()).FiltroPrimeroValor("CvePS").ToEntero() CvePS = ClsPaginas.GlobalDTPSSimplificado(CveEmpresa, Codigo:=JsonPS("sku").ToString()).FiltroPrimeroValor("CvePS").ToEntero()
ObjFactura.AgregarPS(CvePS, Cantidad, PU, Descuento, Obs, CveSubProyecto:=CveSubProyecto) 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 ''VALIDAR QUE SEA EL MISMO PRODUCTO
If CvePS <= 0 Then If CvePS <= 0 Then
TieneError = True TieneError = True
@@ -459,11 +466,11 @@ Public Class E119 : Implements IHttpHandler
End If End If
If ObjFactura IsNot Nothing AndAlso Not TieneError Then 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()) Resp = ObjFactura.EmitirFactura(False, Transac:=ObjClientes.IniciaTransacSQL())
If Resp.CveVenta > 0 Then 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 data As New JArray
Dim objSucursal As New JObject( Dim objSucursal As New JObject(
New JProperty("Cve", Resp.CveVenta), New JProperty("Cve", Resp.CveVenta),
@@ -473,7 +480,7 @@ Public Class E119 : Implements IHttpHandler
Respuesta.status = "success" Respuesta.status = "success"
Respuesta.data = data Respuesta.data = data
Else Else
MsgLog.Append("1.8 error al agregar la remision") MsgLog.AppendLine("1.8 error al agregar la remision")
TieneError = True TieneError = True
End If End If
@@ -493,12 +500,7 @@ Public Class E119 : Implements IHttpHandler
RespuestaError.message = sb.ToString() RespuestaError.message = sb.ToString()
End If End If
Catch ex As Exception
TieneError = True
End Try
If TieneError Then If TieneError Then
ObjClientes.RollBack() ObjClientes.RollBack()
ObjClientes.Dispose() ObjClientes.Dispose()
ObjInventario.Dispose() ObjInventario.Dispose()
@@ -519,6 +521,9 @@ Public Class E119 : Implements IHttpHandler
End If End If
End If End If
Catch ex As Exception
TieneError = True
End Try
MsgLog.ToString.GuardaLogAD("LogE119") MsgLog.ToString.GuardaLogAD("LogE119")
If TieneError Then If TieneError Then
@@ -548,7 +553,7 @@ Public Class E119 : Implements IHttpHandler
End Class End Class
Private Class AuthMessage Private Class AuthMessage
Public Property IsSucces As Boolean Public Property IsSuccess As Boolean
Public Property ErrorMessage As ResponseMsgError Public Property ErrorMessage As ResponseMsgError
Public Property StatusCode As Integer Public Property StatusCode As Integer
End Class End Class