Correciones de impresion de PDF en API SALI

This commit is contained in:
2020-07-20 20:57:18 -07:00
parent f621428e92
commit ecae4cf4bd
2 changed files with 3822 additions and 50 deletions

View File

@@ -17,6 +17,16 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
End Get End Get
End Property End Property
Public ReadOnly Property EsProduccion As Boolean
Get
If IsNothing(System.Configuration.ConfigurationManager.AppSettings("EsProduccion")) Then
Return False
Else
Return (System.Configuration.ConfigurationManager.AppSettings("EsProduccion").ToString() = "1")
End If
End Get
End Property
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim retorno As String = "no se encontro la variable" Dim retorno As String = "no se encontro la variable"
@@ -34,7 +44,7 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
Dim ListaDS = New List(Of ReportDataSource) Dim ListaDS = New List(Of ReportDataSource)
Dim Parametros As New List(Of ReportParameter) Dim Parametros As New List(Of ReportParameter)
Dim Formato = context.ModExtensiones.DirectorioBaseEmpresas + "Empresas/1/Report.rdlc" Dim Formato = ModExtensiones.DirectorioBaseEmpresas + "Empresas/Grales/ReporteAPI.rdlc"
Parametros.Add(New ReportParameter("Empresa", datos.Empresa.Empresa)) Parametros.Add(New ReportParameter("Empresa", datos.Empresa.Empresa))
Parametros.Add(New ReportParameter("RFC", datos.Empresa.RFC)) Parametros.Add(New ReportParameter("RFC", datos.Empresa.RFC))
@@ -49,20 +59,20 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
Parametros.Add(New ReportParameter("ImporteLetra", datos.Factura.Total.Texto2Letras())) Parametros.Add(New ReportParameter("ImporteLetra", datos.Factura.Total.Texto2Letras()))
Parametros.Add(New ReportParameter("FormaPago", datos.Factura.FormaPago)) Parametros.Add(New ReportParameter("FormaPago", datos.Factura.FormaPago))
Parametros.Add(New ReportParameter("MetodoPago", datos.Factura.MetodoPago)) Parametros.Add(New ReportParameter("MetodoPago", datos.Factura.MetodoPago))
Parametros.Add(New ReportParameter("SelloCFDI", "")) Parametros.Add(New ReportParameter("SelloCFDI", datos.Timbrado.SelloCFDI))
Parametros.Add(New ReportParameter("SelloSAT", "")) Parametros.Add(New ReportParameter("SelloSAT", datos.Timbrado.SelloSAT))
Parametros.Add(New ReportParameter("CadenaOriginal", "")) Parametros.Add(New ReportParameter("CadenaOriginal", datos.Timbrado.CadenaOriginal))
Parametros.Add(New ReportParameter("FolioFiscal", datos.Factura.UUID)) Parametros.Add(New ReportParameter("FolioFiscal", datos.Factura.UUID))
Parametros.Add(New ReportParameter("SerieCertificadoSAT", "")) Parametros.Add(New ReportParameter("SerieCertificadoSAT", datos.Timbrado.SerieCertificadoSAT))
Parametros.Add(New ReportParameter("FechaCertificado", "")) Parametros.Add(New ReportParameter("FechaCertificado", datos.Timbrado.FechaCertificado))
Parametros.Add(New ReportParameter("CertificadoContribuyente", "")) Parametros.Add(New ReportParameter("CertificadoContribuyente", datos.Timbrado.CertificadoContribuyente))
Parametros.Add(New ReportParameter("UsoCFDI", datos.Factura.UsoCFDI)) Parametros.Add(New ReportParameter("UsoCFDI", datos.Factura.UsoCFDI))
Parametros.Add(New ReportParameter("Vencimiento", Now.AddDays(30))) Parametros.Add(New ReportParameter("Vencimiento", datos.Factura.FechaVencimiento))
Parametros.Add(New ReportParameter("SubTotal", datos.Factura.SubTotal)) Parametros.Add(New ReportParameter("SubTotal", datos.Factura.SubTotal))
Parametros.Add(New ReportParameter("IVA", datos.Factura.IVA)) Parametros.Add(New ReportParameter("IVA", datos.Factura.IVA))
Parametros.Add(New ReportParameter("IEPS", datos.Factura.IEPS)) Parametros.Add(New ReportParameter("IEPS", datos.Factura.IEPS))
Parametros.Add(New ReportParameter("Total", datos.Factura.Total)) Parametros.Add(New ReportParameter("Total", datos.Factura.Total))
Parametros.Add(New ReportParameter("QR", "")) Parametros.Add(New ReportParameter("QR", datos.Timbrado.QR))
Dim DtDatos As New DataTable Dim DtDatos As New DataTable
DtDatos.Columns.Add(New DataColumn("Cantidad", GetType(Decimal))) DtDatos.Columns.Add(New DataColumn("Cantidad", GetType(Decimal)))
@@ -85,9 +95,10 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
DtDatos.Rows.Add(Row) DtDatos.Rows.Add(Row)
Next Next
ListaDS.Add(New ReportDataSource("DsProductos", DtDatos)) ListaDS.Add(New ReportDataSource("DsProductos", DtDatos))
ImprimirbytesPDF(context, StreamPDF(context, Formato, ListaDS, Parametros), "test") ImprimirbytesPDF(context, StreamPDF(context, Formato, ListaDS, Parametros), "Factura")
End If End If
Catch ex As Exception Catch ex As Exception
@@ -101,44 +112,83 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
'limpio ReportViwer 'limpio ReportViwer
Dim sw As New System.Diagnostics.Stopwatch() Dim sw As New System.Diagnostics.Stopwatch()
sw.Start() sw.Start()
If IsNothing(MR) Then MR = New ReportViewer
Dim Bytes As Byte() = Nothing Dim Bytes As Byte() = Nothing
Try
' MasterReporteador.LocalReport.DataSources.Clear() Dim bdir As String = If(RutaReporte.Contains("Empresas"), ModExtensiones.DirectorioBaseEmpresas, AppDomain.CurrentDomain.BaseDirectory)
For Each RDS As ReportDataSource In DataSource RutaReporte.Replace("/", "\")
MR.LocalReport.DataSources.Add(RDS) If Not RutaReporte.ToUpper().StartsWith(bdir.ToUpper()) Then
RutaReporte = String.Format("{0}{1}", bdir, RutaReporte)
End If
If EsProduccion Then
Dim CveUsuario As Integer = 0
Dim CveEmpresa As Integer = 0
Dim wsreport As New WSRDLC.WebServiceSoapClient
Dim params As New List(Of WSRDLC.ReportParameter)
Dim ds As New DataSet
For Each rpds As ReportDataSource In DataSource
Dim dt As DataTable = DirectCast(rpds.Value, Data.DataTable)
If dt Is Nothing Then
dt = New DataTable()
Else
dt = dt.Copy()
End If
dt.TableName = rpds.Name
ds.Tables.Add(dt)
Next Next
For Each rpds As ReportParameter In Parametros
Dim param As New WSRDLC.ReportParameter
param.Name = rpds.Name
param.Values = {rpds.Values(0)}
params.Add(param)
Next
Bytes = wsreport.StreamPDFBytes(RutaReporte, ds, params.ToArray(), NombreArchivo, Formato, CveEmpresa, CveUsuario)
wsreport = Nothing
params = Nothing
Else
If IsNothing(MR) Then MR = New ReportViewer
Try
' MasterReporteador.LocalReport.DataSources.Clear()
For Each RDS As ReportDataSource In DataSource
MR.LocalReport.DataSources.Add(RDS)
Next
MR.LocalReport.ReportPath = RutaReporte MR.LocalReport.ReportPath = RutaReporte
MR.ProcessingMode = ProcessingMode.Local MR.ProcessingMode = ProcessingMode.Local
MR.LocalReport.EnableExternalImages = True MR.LocalReport.EnableExternalImages = True
MR.LocalReport.SetParameters(Parametros) MR.LocalReport.SetParameters(Parametros)
MR.LocalReport.Refresh() MR.LocalReport.Refresh()
Dim Warnings As Warning() = Nothing Dim Warnings As Warning() = Nothing
Dim StreamIds As String() = Nothing Dim StreamIds As String() = Nothing
Dim MimeType As String = Nothing Dim MimeType As String = Nothing
Dim Encoding As String = Nothing Dim Encoding As String = Nothing
Dim Extension As String = Nothing Dim Extension As String = Nothing
Bytes = MR.LocalReport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds, Warnings) Bytes = MR.LocalReport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds, Warnings)
Catch ex As Microsoft.Reporting.WebForms.ScriptManagerNotFoundException Catch ex As Microsoft.Reporting.WebForms.ScriptManagerNotFoundException
GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}") GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}")
'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017
'GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") 'GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}")
Catch ex As Exception Catch ex As Exception
GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}") GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}")
'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017
'GuardaLog($"Error {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") 'GuardaLog($"Error {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}")
End Try End Try
MR.Dispose()
End If
sw.Stop() sw.Stop()
If sw.Elapsed.TotalSeconds > 10 Then
If sw.Elapsed.TotalSeconds > 5 Then
GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ") GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ")
End If End If
Return Bytes Return Bytes
End Function End Function
Public Sub ImprimirbytesPDF(ByVal context As HttpContext, bytes As Byte(), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional Descarga As Boolean = False) Public Sub ImprimirbytesPDF(ByVal context As HttpContext, bytes As Byte(), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional Descarga As Boolean = False)
'limpio ReportViwer 'limpio ReportViwer
Dim mimeType As String = Nothing Dim mimeType As String = Nothing
@@ -181,6 +231,7 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
Public Property CveCliente As Integer Public Property CveCliente As Integer
Public Property NombreCliente As String Public Property NombreCliente As String
Public Property Fecha As DateTime Public Property Fecha As DateTime
Public Property FechaVencimiento As DateTime
Public Property CveSubCentroCosto As Integer Public Property CveSubCentroCosto As Integer
Public Property CveTipoDocumento As Integer Public Property CveTipoDocumento As Integer
Public Property TipoDocumento As String Public Property TipoDocumento As String
@@ -271,10 +322,21 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
Public Property RegimenFiscal As String Public Property RegimenFiscal As String
End Class End Class
Public Class DatosSATWS
Public Property SelloCFDI As String
Public Property SelloSAT As String
Public Property CadenaOriginal As String
Public Property SerieCertificadoSAT As String
Public Property FechaCertificado As String
Public Property CertificadoContribuyente As String
Public Property QR As String
End Class
Public Class ParametroWS Public Class ParametroWS
Public Property Factura As FacturaWS Public Property Factura As FacturaWS
Public Property Cliente As ClienteWS Public Property Cliente As ClienteWS
Public Property Empresa As EmpresaWS Public Property Empresa As EmpresaWS
Public Property Timbrado As DatosSATWS
End Class End Class

File diff suppressed because it is too large Load Diff