Mejoras en reportes y cambios para generacion poliza

This commit is contained in:
HECTOR RODRIGUEZ
2021-04-30 11:12:25 -07:00
parent 6976377134
commit 2f75de7551
5 changed files with 257 additions and 23 deletions

View File

@@ -5,7 +5,10 @@ Imports Extensiones
Imports System.Linq
Imports System.Web.Services
Imports GemBox.Spreadsheet
Imports Microsoft.Reporting.WebForms
Imports System.IO
Imports iTextSharp.text.pdf
Partial Class ContabilidadC_RegPrePolizaS
Inherits ClsPaginas
@@ -159,6 +162,40 @@ Partial Class ContabilidadC_RegPrePolizaS
ViewState("IndiceGrid") = value
End Set
End Property
Public Property IdPoliza As Integer
Get
Return CType(ViewState("IdPoliza"), Integer)
End Get
Set(value As Integer)
ViewState("IdPoliza") = value
End Set
End Property
Public Property Tick As String
Get
Return CType(ViewState("Tick"), String)
End Get
Set(value As String)
ViewState("Tick") = value
End Set
End Property
Public Property CveIE As Integer
Get
Return CType(ViewState("CveIE"), Integer)
End Get
Set(value As Integer)
ViewState("CveIE") = value
End Set
End Property
Public Property TipoPoliza As String
Get
Return CType(ViewState("TipoPoliza"), String)
End Get
Set(value As String)
ViewState("TipoPoliza") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
@@ -175,6 +212,8 @@ Partial Class ContabilidadC_RegPrePolizaS
Observaciones = "-1"
Beneficiario = "-1"
Actualizar = False
IdPoliza = -1
If IfNull(Request("Tipo"), "").ToString = "NOMPROV" Then
DivTipoGasto.Visible = True
@@ -365,7 +404,9 @@ Partial Class ContabilidadC_RegPrePolizaS
DdlTipoPoliza.SelectedValue = dr("CveTipoPoliza")
TxtFechaDocumento.Text = dr("Fecha")
TxtConcepto.Text = dr("Concepto")
DivDatosPoliza.Visible = True
DivDatosPoliza.Visible = True
TipoPoliza = DdlTipoPoliza.SelectedItem.Text
Folio = dr("FolioPoliza").ToString
If UsuarioActual.CveRol = 1 OrElse UsuarioActual.TienePermisoProceso(221) Then
'DivAgregarConceptos.Visible = True
@@ -470,7 +511,13 @@ Partial Class ContabilidadC_RegPrePolizaS
If CveConceptoContable.Contiene(1, 2, 13, 38, 207, 203, 39, 61, 62, 63) Then e.Row.FCHyperLink("HlReferencia").NavigateUrl = String.Format("/Ventas/Ventas.aspx?CveVenta={0}", e.Row.DataKey("CveVenta"))
If CveConceptoContable.Contiene(5, 6, 17, 18, 14, 19, 25, 26, 60, 234, 235, 240) Then e.Row.FCHyperLink("HlReferencia").NavigateUrl = String.Format("/Compras/Compras.aspx?CveCompra={0}", e.Row.DataKey("CveCompra"))
If CveConceptoContable.Contiene(68) Then e.Row.FCHyperLink("HlReferencia").NavigateUrl = String.Format("/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}", e.Row.DBCampo("CveMovimientoAlmacen"))
If CveConceptoContable.Contiene(30, 204) Then e.Row.FCHyperLink("HlReferencia").NavigateUrl = String.Format("/Bancos/IE.aspx?CveIE={0}", e.Row.DBCampo("CveIE"))
If CveConceptoContable.Contiene(30, 204) Then e.Row.FCHyperLink("HlReferencia").NavigateUrl = String.Format("/Bancos/IE.aspx?CveIE={0}", e.Row.DBCampo("CveIE"))
If CveConceptoContable.Contiene(30) Then
LnkImprimirPDF.Visible = True
LnkComprobante.Visible = True
CveIE = e.Row.DBCampo("CveIE").ToString.ToEntero
End If
'e.Row.FCHyperLink("HlReferencia").NavigateUrl = CveConceptoContable
@@ -689,6 +736,8 @@ Partial Class ContabilidadC_RegPrePolizaS
dr("CvePersonal") = drt("CvePersonal")
dr("CveClasificacion") = -1
dr("MultipleSubProyecto") = drt("MultipleSubProyecto")
dr("FolioPoliza") = drt("FolioPoliza")
DtMovimientos.Rows.Add(dr)
Next
@@ -1951,5 +2000,150 @@ Partial Class ContabilidadC_RegPrePolizaS
End Sub
#End Region
#Region "Paquete Egresos"
Protected Sub LnkImprimirPDF_Click(sender As Object, e As EventArgs)
Dim Pathpdf As New List(Of String)
Dim Path As String
Try
Path = ImprimirPolizaPDF(IdPoliza)
If File.Exists(Path) Then
Pathpdf.Add(Path)
End If
MergePdfFiles(Pathpdf.ToArray)
If File.Exists(Path) Then
Directory.Delete(String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, Tick), True)
End If
Catch ex As Exception
Alert("Error al descargar la poliza", TipoMensaje.MsgError)
End Try
End Sub
Private Function ImprimirPolizaPDF(IdPoliza As Integer) As String
Dim ObjConta As New ClsContabilidad
'Dim ObjPoliza As New ClsContPAQi(UsuarioActual.Empresa)
Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/Polizas.rdlc", UsuarioActual.Empresa.Ruta))
Dim params As New List(Of ReportParameter)
Dim Bytes As Byte() = Nothing
'If ObjPoliza.GetPoliza(IdPoliza, -1, -1, -1, -1) AndAlso ObjPoliza.DtResultados.Rows.Count > 0 Then
If ObjConta.GetPrePolizasDetalle(CvePrePoliza) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
Dim dtVC As DataTable
Dim dr As DataRow
dtVC = ObjConta.DtResultados
dr = dtVC.Rows(0)
Dim ruta As String = ""
params.Add(New ReportParameter("Empresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("TipoPoliza", dr("TipoPoliza").ToString))
params.Add(New ReportParameter("Finicio", dr("Fecha").ToString.ToDate.ToShortDateString))
params.Add(New ReportParameter("FFin", dr("Fecha").ToString.ToDate.ToShortDateString))
params.Add(New ReportParameter("Fecha", dr("Fecha").ToString.ToDate.ToShortDateString))
'params.Add(New ReportParameter("Nombre", dr("Cuenta").ToString))
'params.Add(New ReportParameter("Cuenta", dr("Codigo").ToString))
params.Add(New ReportParameter("Numero", dr("FolioPoliza").ToString))
params.Add(New ReportParameter("Moneda", ""))
params.Add(New ReportParameter("CodigoPostal", ""))
If UsuarioActual.CveEmpresa = 119 Then
params.Add(New ReportParameter("UsuarioRegistro", GlobalDTUsuarios(dr("CveUsuario").ToString.ToEntero).FiltroPrimeroValor("Nombre")))
End If
If Archivo.Exists Then
ruta = UsuarioActual.Empresa.Ruta & "Formatos/Polizas.rdlc"
Else
ruta = "Empresas/Grales/Formatos/Polizas.rdlc"
End If
Bytes = StreamPDF(ruta, dtVC, params, "ppoliza")
If Not File.Exists(String.Format("{0}{1}\{2}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, IdPoliza.ToString)) Then
DirectoryExistsCreate(String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, Tick))
File.WriteAllBytes(String.Format("{0}\{1}\{2}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, IdPoliza.ToString), Bytes)
End If
End If
Return String.Format("{0}\{1}\{2}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, IdPoliza.ToString)
ObjConta.Dispose()
End Function
Private Sub MergePdfFiles(ByVal pdfFiles() As String)
Dim result As Boolean = False
Dim pdfCount As Integer = 0
Dim f As Integer = 0
Dim fileName As String
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
Dim pageCount As Integer = 0
Dim pdfDoc As iTextSharp.text.Document = Nothing
Dim writer As PdfWriter = Nothing
Dim cb As PdfContentByte = Nothing
Dim page As PdfImportedPage = Nothing
Dim rotation As Integer = 0
Try
pdfCount = pdfFiles.Length
If pdfCount > 0 Then
fileName = pdfFiles(f)
reader = New iTextSharp.text.pdf.PdfReader(fileName)
pageCount = reader.NumberOfPages
pdfDoc = New iTextSharp.text.Document(reader.GetPageSizeWithRotation(1), 18, 18, 18, 18)
writer = PdfWriter.GetInstance(pdfDoc, New FileStream(String.Format("{0}\{1}\{2}-{3}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, TipoPoliza, Folio), FileMode.Create))
With pdfDoc
.Open()
End With
cb = writer.DirectContent
While f < pdfCount
Dim i As Integer = 0
While i < pageCount
i += 1
pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i))
pdfDoc.NewPage()
page = writer.GetImportedPage(reader, i)
rotation = reader.GetPageRotation(i)
If rotation = 90 Then
cb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height)
ElseIf rotation = 270 Then
cb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30)
Else
cb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0)
End If
End While
f += 1
If f < pdfCount Then
fileName = pdfFiles(f)
reader = New iTextSharp.text.pdf.PdfReader(fileName)
pageCount = reader.NumberOfPages
End If
End While
pdfDoc.Close()
Dim Archivo As New System.IO.FileInfo(String.Format("{0}\{1}\{2}-{3}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, TipoPoliza, Folio))
If Archivo.Exists Then
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AppendHeader("Content-disposition", String.Format("attachment; filename={0}", Archivo.Name))
HttpContext.Current.Response.AddHeader("Content-Length", Archivo.Length.ToString())
HttpContext.Current.Response.TransmitFile(String.Format("{0}\{1}\{2}-{3}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, TipoPoliza, Folio))
Response.Flush() ' send it to the client to download
HttpContext.Current.Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
End If
result = True
End If
Catch ex As Exception
End Try
End Sub
#End Region
End Class