Correciones de impresion de PDF en API SALI
This commit is contained in:
@@ -17,6 +17,16 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
|
||||
End Get
|
||||
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
|
||||
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 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("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("FormaPago", datos.Factura.FormaPago))
|
||||
Parametros.Add(New ReportParameter("MetodoPago", datos.Factura.MetodoPago))
|
||||
Parametros.Add(New ReportParameter("SelloCFDI", ""))
|
||||
Parametros.Add(New ReportParameter("SelloSAT", ""))
|
||||
Parametros.Add(New ReportParameter("CadenaOriginal", ""))
|
||||
Parametros.Add(New ReportParameter("SelloCFDI", datos.Timbrado.SelloCFDI))
|
||||
Parametros.Add(New ReportParameter("SelloSAT", datos.Timbrado.SelloSAT))
|
||||
Parametros.Add(New ReportParameter("CadenaOriginal", datos.Timbrado.CadenaOriginal))
|
||||
Parametros.Add(New ReportParameter("FolioFiscal", datos.Factura.UUID))
|
||||
Parametros.Add(New ReportParameter("SerieCertificadoSAT", ""))
|
||||
Parametros.Add(New ReportParameter("FechaCertificado", ""))
|
||||
Parametros.Add(New ReportParameter("CertificadoContribuyente", ""))
|
||||
Parametros.Add(New ReportParameter("SerieCertificadoSAT", datos.Timbrado.SerieCertificadoSAT))
|
||||
Parametros.Add(New ReportParameter("FechaCertificado", datos.Timbrado.FechaCertificado))
|
||||
Parametros.Add(New ReportParameter("CertificadoContribuyente", datos.Timbrado.CertificadoContribuyente))
|
||||
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("IVA", datos.Factura.IVA))
|
||||
Parametros.Add(New ReportParameter("IEPS", datos.Factura.IEPS))
|
||||
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
|
||||
DtDatos.Columns.Add(New DataColumn("Cantidad", GetType(Decimal)))
|
||||
@@ -85,9 +95,10 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
|
||||
|
||||
DtDatos.Rows.Add(Row)
|
||||
Next
|
||||
|
||||
ListaDS.Add(New ReportDataSource("DsProductos", DtDatos))
|
||||
|
||||
ImprimirbytesPDF(context, StreamPDF(context, Formato, ListaDS, Parametros), "test")
|
||||
ImprimirbytesPDF(context, StreamPDF(context, Formato, ListaDS, Parametros), "Factura")
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
@@ -97,48 +108,87 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
|
||||
|
||||
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()
|
||||
'limpio ReportViwer
|
||||
Dim sw As New System.Diagnostics.Stopwatch()
|
||||
sw.Start()
|
||||
|
||||
If IsNothing(MR) Then MR = New ReportViewer
|
||||
Dim Bytes As Byte() = Nothing
|
||||
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
|
||||
|
||||
sw.Stop()
|
||||
If sw.Elapsed.TotalSeconds > 10 Then
|
||||
GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ")
|
||||
End If
|
||||
|
||||
Return Bytes
|
||||
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
|
||||
Dim sw As New System.Diagnostics.Stopwatch()
|
||||
sw.Start()
|
||||
Dim Bytes As Byte() = Nothing
|
||||
|
||||
Dim bdir As String = If(RutaReporte.Contains("Empresas"), ModExtensiones.DirectorioBaseEmpresas, AppDomain.CurrentDomain.BaseDirectory)
|
||||
RutaReporte.Replace("/", "\")
|
||||
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
|
||||
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.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
|
||||
|
||||
|
||||
|
||||
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
|
||||
Dim mimeType As String = Nothing
|
||||
@@ -181,6 +231,7 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
|
||||
Public Property CveCliente As Integer
|
||||
Public Property NombreCliente As String
|
||||
Public Property Fecha As DateTime
|
||||
Public Property FechaVencimiento As DateTime
|
||||
Public Property CveSubCentroCosto As Integer
|
||||
Public Property CveTipoDocumento As Integer
|
||||
Public Property TipoDocumento As String
|
||||
@@ -271,10 +322,21 @@ Public Class GenerarPDFFactura : Implements IHttpHandler
|
||||
Public Property RegimenFiscal As String
|
||||
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 Property Factura As FacturaWS
|
||||
Public Property Cliente As ClienteWS
|
||||
Public Property Empresa As EmpresaWS
|
||||
Public Property Timbrado As DatosSATWS
|
||||
End Class
|
||||
|
||||
|
||||
|
||||
3710
Empresas/Grales/ReporteAPI.rdlc
Normal file
3710
Empresas/Grales/ReporteAPI.rdlc
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user