-- 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
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,12 +342,13 @@ 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")
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
@@ -354,7 +360,7 @@ Public Class E119 : Implements IHttpHandler
End Using
End If
MsgLog.Append("1.1 accedido")
MsgLog.AppendLine("1.1 accedido")
If TieneError Then
RespuestaError.message = "No se pudo procesar la solicitud - Formato mal formado"
context.Response.StatusCode = 200
@@ -367,7 +373,7 @@ Public Class E119 : Implements IHttpHandler
Dim ObjFactura As Modelos.Factura = Nothing
Dim Resp As New Modelos.Factura.MMensajeFactura
If Usuario IsNot Nothing Then
MsgLog.Append("1.1 Validado")
MsgLog.AppendLine("1.1 Validado")
Dim ObjClientes As New ClsClientes()
Dim ObjInventario As New ClsInventarios(ObjClientes.IniciaTransacSQL())
Dim CveSubProyecto, CveCliente, CveMoneda, CvePS As Integer
@@ -377,7 +383,7 @@ Public Class E119 : Implements IHttpHandler
CveCliente = 0
CveMoneda = 1
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 NombreCliente As String = If(JsonRequest("billing") Is Nothing, "", JsonRequest("billing")("first_name").ToString() & " " & JsonRequest("billing")("last_name").ToString())
'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")
End If
End If
MsgLog.Append("1.4 verificar cliente")
MsgLog.AppendLine("1.4 verificar cliente")
If CveCliente = 0 Then
' 'DATOS DE BILLING
MsgLog.Append("1.5 crear cliente")
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())
@@ -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.DtResultados.Rows.Count > 0 Then
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
Else
MsgLog.Append("1.5.9 sin datos cliente")
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
Try
MsgLog.Append("1.6 inicio generar venta")
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,12 +500,7 @@ 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()
@@ -519,6 +521,9 @@ Public Class E119 : Implements IHttpHandler
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