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
@@ -97,48 +108,87 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
End Sub End Sub
Public Function StreamPDF(ByVal context As HttpContext, RutaReporte As String, DataSource As List(Of ReportDataSource), Parametros As List(Of ReportParameter), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional MR As ReportViewer = Nothing) As Byte() Public Function StreamPDF(ByVal context As HttpContext, RutaReporte As String, DataSource As List(Of ReportDataSource), Parametros As List(Of ReportParameter), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional MR As ReportViewer = Nothing) As Byte()
'limpio ReportViwer 'limpio ReportViwer
Dim sw As New System.Diagnostics.Stopwatch() Dim sw As New System.Diagnostics.Stopwatch()
sw.Start() sw.Start()
Dim Bytes As Byte() = Nothing
If IsNothing(MR) Then MR = New ReportViewer
Dim Bytes As Byte() = Nothing Dim bdir As String = If(RutaReporte.Contains("Empresas"), ModExtensiones.DirectorioBaseEmpresas, AppDomain.CurrentDomain.BaseDirectory)
Try RutaReporte.Replace("/", "\")
' MasterReporteador.LocalReport.DataSources.Clear() If Not RutaReporte.ToUpper().StartsWith(bdir.ToUpper()) Then
For Each RDS As ReportDataSource In DataSource RutaReporte = String.Format("{0}{1}", bdir, RutaReporte)
MR.LocalReport.DataSources.Add(RDS) End If
Next
If EsProduccion Then
MR.LocalReport.ReportPath = RutaReporte
MR.ProcessingMode = ProcessingMode.Local Dim CveUsuario As Integer = 0
MR.LocalReport.EnableExternalImages = True Dim CveEmpresa As Integer = 0
MR.LocalReport.SetParameters(Parametros)
MR.LocalReport.Refresh() Dim wsreport As New WSRDLC.WebServiceSoapClient
Dim Warnings As Warning() = Nothing Dim params As New List(Of WSRDLC.ReportParameter)
Dim StreamIds As String() = Nothing Dim ds As New DataSet
Dim MimeType As String = Nothing For Each rpds As ReportDataSource In DataSource
Dim Encoding As String = Nothing Dim dt As DataTable = DirectCast(rpds.Value, Data.DataTable)
Dim Extension As String = Nothing If dt Is Nothing Then
Bytes = MR.LocalReport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds, Warnings) dt = New DataTable()
Catch ex As Microsoft.Reporting.WebForms.ScriptManagerNotFoundException Else
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}") dt = dt.Copy()
'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 End If
'GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") dt.TableName = rpds.Name
Catch ex As Exception ds.Tables.Add(dt)
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}") Next
'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017 For Each rpds As ReportParameter In Parametros
'GuardaLog($"Error {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}") Dim param As New WSRDLC.ReportParameter
End Try param.Name = rpds.Name
param.Values = {rpds.Values(0)}
sw.Stop() params.Add(param)
If sw.Elapsed.TotalSeconds > 10 Then Next
GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ") Bytes = wsreport.StreamPDFBytes(RutaReporte, ds, params.ToArray(), NombreArchivo, Formato, CveEmpresa, CveUsuario)
End If wsreport = Nothing
params = Nothing
Return Bytes 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.ProcessingMode = ProcessingMode.Local
MR.LocalReport.EnableExternalImages = True
MR.LocalReport.SetParameters(Parametros)
MR.LocalReport.Refresh()
Dim Warnings As Warning() = Nothing
Dim StreamIds As String() = Nothing
Dim MimeType As String = Nothing
Dim Encoding As String = Nothing
Dim Extension As String = Nothing
Bytes = MR.LocalReport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds, Warnings)
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}")
'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}")
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}")
'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}")
End Try
MR.Dispose()
End If
sw.Stop()
If sw.Elapsed.TotalSeconds > 5 Then
GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ")
End If
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