From 9204a091e4723dc29dfd7df499ff719ebf39736a Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Mon, 20 Jul 2020 20:58:13 -0700 Subject: [PATCH] Cambio de formato de respuesta en facturacion masiva del pescadito --- Ashx/SIGFacturacion.ashx | 98 ++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 34 deletions(-) diff --git a/Ashx/SIGFacturacion.ashx b/Ashx/SIGFacturacion.ashx index 5ab24ec65..eb3f2fa7d 100644 --- a/Ashx/SIGFacturacion.ashx +++ b/Ashx/SIGFacturacion.ashx @@ -11,40 +11,64 @@ Imports Extensiones Imports System.IO Imports Modelos -Public Class SIGFacturacion : Implements IHttpHandler, IRequiresSessionState +Public Class SIGFacturacion : Implements IHttpHandler, IRequiresSessionState + + Private Property CveEmpresaFacturar As Integer = 143 Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest - context.Response.ContentType = "application/json" - Try - If context.Request.InputStream IsNot Nothing Then - Using reader As New StreamReader(context.Request.InputStream) - Dim json = reader.ReadToEnd + context.Response.ContentType = "text/plain" + Dim Retorno As Boolean = False - If Not String.IsNullOrEmpty(json) Then - Dim JsonRequest As JObject = JObject.Parse(json) - If JsonRequest IsNot Nothing Then - Dim Metodo = JsonRequest("Metodo").ToString() - If Metodo = "FactMasivaRemisiones" Then - Dim pCveEmpresa = JsonRequest("CveEmpresa").ToString() - Dim pFechaI As String = "" - Dim pFechaF As String = "" - - If JsonRequest("FechaI") IsNot Nothing AndAlso JsonRequest("FechaF") IsNot Nothing Then - pFechaI = JsonRequest("FechaI") - pFechaF = JsonRequest("FechaF") - End If - - IniciaFacturacionMasiva(context, pCveEmpresa, pFechaI, pFechaF) - End If - End If - End If - - End Using + Try + 'If context.Request.InputStream IsNot Nothing Then + ' Using reader As New StreamReader(context.Request.InputStream) + ' Dim json = reader.ReadToEnd + + ' If Not String.IsNullOrEmpty(json) Then + ' Dim JsonRequest As JObject = JObject.Parse(json) + ' If JsonRequest IsNot Nothing Then + ' Dim Metodo = JsonRequest("Metodo").ToString() + ' If Metodo = "FactMasivaRemisiones" Then + ' Dim pCveEmpresa = JsonRequest("CveEmpresa").ToString() + ' Dim pFechaI As String = "" + ' Dim pFechaF As String = "" + + ' If JsonRequest("FechaI") IsNot Nothing AndAlso JsonRequest("FechaF") IsNot Nothing Then + ' pFechaI = JsonRequest("FechaI") + ' pFechaF = JsonRequest("FechaF") + ' End If + + ' IniciaFacturacionMasiva(context, CveEmpresaFacturar, pFechaI, pFechaF) + ' End If + ' End If + ' End If + + ' End Using + 'End If + + Dim Metodo = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) + If Metodo = "FactMasivaRemisiones" Then + Dim pFechaI As String = "" + Dim pFechaF As String = "" + + If context.Request("FechaI") IsNot Nothing AndAlso context.Request("FechaF") IsNot Nothing Then + pFechaI = context.Request("FechaI") + pFechaF = context.Request("FechaF") + End If + + Retorno = IniciaFacturacionMasiva(CveEmpresaFacturar, pFechaI, pFechaF) End If Catch ex As Exception ex.GuardaLog(ex.Message) - End Try + End Try + + If Retorno Then + context.Response.Write("True") + Else + context.Response.Write("False") + End If + End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable @@ -53,7 +77,8 @@ Public Class SIGFacturacion : Implements IHttpHandler, IRequiresSessionState End Get End Property - Private Sub IniciaFacturacionMasiva(ByVal context As HttpContext, pCveEmpresa As String, pFechaI As String, pFechaF As String) + Private Function IniciaFacturacionMasiva(pCveEmpresa As String, pFechaI As String, pFechaF As String) As Boolean + Dim Retorno As Boolean = True Dim JsonRetorno As New JObject() Dim CveEmpresa As Integer = pCveEmpresa.ToEntero() If CveEmpresa > 0 Then @@ -71,7 +96,10 @@ Public Class SIGFacturacion : Implements IHttpHandler, IRequiresSessionState FechaI = New DateTime(DomingoAnterior.Year, DomingoAnterior.Month, DomingoAnterior.Day, 0, 0, 0) FechaF = New DateTime(Sabado.Year, Sabado.Month, Sabado.Day, 23, 59, 59) - JsonRetorno = EjecutarFacturacionMasiva(Usuario, FechaI, FechaF, Usuario.Empresa.FacturaProduccion) + JsonRetorno = EjecutarFacturacionMasiva(Usuario, FechaI, FechaF, Usuario.Empresa.FacturaProduccion) + Else + Retorno = False + GuardaLogFacturacion("Ejecución no permitida, no es el dia permitido para ejecucion o no se espeficaron las fechas") End If Else FechaI = pFechaI.ToDateTime() @@ -79,11 +107,13 @@ Public Class SIGFacturacion : Implements IHttpHandler, IRequiresSessionState JsonRetorno = EjecutarFacturacionMasiva(Usuario, FechaI, FechaF, Usuario.Empresa.FacturaProduccion) End If - - - End If - context.Response.Write(JsonRetorno) - End Sub + End If + + GuardaLogFacturacion("Ejecución Exitosa, se generaron las siguientes facturas:") + GuardaLogFacturacion(JsonRetorno.ToString()) + + Return Retorno + End Function Public Shared Function GetNextWeekday(ByVal start As DateTime, ByVal day As DayOfWeek, hora As TimeSpan) As DateTime