Impresion de multiples pdf unificados

This commit is contained in:
HECTOR RODRIGUEZ
2021-04-27 14:33:09 -07:00
parent 2a5c0d853c
commit 300f9d677f
2 changed files with 245 additions and 8 deletions

View File

@@ -70,13 +70,21 @@
<asp:UpdatePanel runat="server">
<ContentTemplate>
<li>
<asp:LinkButton ID="LnkExcel" runat="server" Visible="true" data-target="#DivCargaExcel"><i class="far fa-file-excel" style="font-weight:bold;"></i> Cargar Excel</asp:LinkButton>
<asp:LinkButton ID="LnkExcel" runat="server" Visible="true" data-target="#DivCargaExcel"><i class="fa fa-ad-excel" style="font-weight:bold;"></i> Cargar Excel</asp:LinkButton>
</li>
<li>
<asp:LinkButton ID="LnkComplementoPago" runat="server" Visible="false" OnClick="LnkComplementoPago_Click" Style="color: #686868;"><i class="fa fa-money" style="color:#686868;"></i> Crear Complemento de Pago</asp:LinkButton>
</li>
<li>
<asp:LinkButton ID="LnkImprimirPDF" runat="server" Visible="false" OnClick="LnkImprimirPDF_Click" Style="color: #686868;"><i class="fa fa-ad-pdf" style="color:#686868;"></i> Imprmir PDF's</asp:LinkButton>
</li>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="LnkImprimirPDF" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="C" runat="Server">

View File

@@ -5,6 +5,9 @@ Imports Extensiones
Imports System.Linq
Imports System.Web.Services
Imports GemBox.Spreadsheet
Imports System.IO
Imports iTextSharp.text.pdf
Imports Microsoft.Reporting.WebForms
Partial Class ContabilidadC_RegPrePoliza
Inherits ClsPaginas
@@ -167,12 +170,23 @@ Partial Class ContabilidadC_RegPrePoliza
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
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Tick = DateTime.Now.Ticks.ToString
If UsuarioActual.Empresa.TipoContabilizacion = 1 OrElse UsuarioActual.Empresa.TipoContabilidad = 1 Then
Response.Redirect(Request.Url.PathAndQuery.Replace("RegPrePoliza", "RegPrePolizaS"))
@@ -265,8 +279,8 @@ Partial Class ContabilidadC_RegPrePoliza
ViewState("CveSubProyecto") = Request("CveSubProyecto").ToEntero
ViewState("CveTurno") = Request("CveTurno").ToEntero
DdlPlantilla.Items.Add(New ListItem("Pago Nomina", "61"))
DdlPlantilla.SelectedValue = "61"
'DdlPlantilla.Items.Add(New ListItem("Pago Nomina", "61"))
'DdlPlantilla.SelectedValue = "61"
DdlPlantilla.Enabled = False
DivAgregarConceptos.Visible = False
@@ -485,19 +499,19 @@ Partial Class ContabilidadC_RegPrePoliza
'Asignamos los Subproyectos
e.Row.FCDropDownList("DdlSubProyecto").DataSource = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa)
e.Row.FCDropDownList("DdlSubProyecto").DataBind()
e.Row.FCDropDownList("DdlSubProyecto").Items.Insert(0, New ListItem(" - ", "-1"))
'e.Row.FCDropDownList("DdlSubProyecto").Items.Insert(0, New ListItem(" - ", "-1"))
e.Row.FCDropDownList("DdlSubProyecto").SelectedValueExist(e.Row.DataKey("CveSubProyecto"))
'Asignamos los Tipos de Gasto
e.Row.FCDropDownList("DdlTipoGasto").DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa)
e.Row.FCDropDownList("DdlTipoGasto").DataBind()
e.Row.FCDropDownList("DdlTipoGasto").Items.Insert(0, New ListItem("Sin Asignar", "-1"))
'e.Row.FCDropDownList("DdlTipoGasto").Items.Insert(0, New ListItem("Sin Asignar", "-1"))
e.Row.FCDropDownList("DdlTipoGasto").SelectedValueExist(e.Row.DataKey("CveTipoGasto"))
'ASignamos las CuentasContables
e.Row.FCDropDownList("DdlCtaContable").DataSource = Session("DtCuentas")
e.Row.FCDropDownList("DdlCtaContable").DataBind()
e.Row.FCDropDownList("DdlCtaContable").Items.Insert(0, New ListItem("Sin Asignar", "0"))
'e.Row.FCDropDownList("DdlCtaContable").Items.Insert(0, New ListItem("Sin Asignar", "0"))
e.Row.FCDropDownList("DdlCtaContable").SelectedValueExist(e.Row.DataKey("IdCtaContable"))
TxtTotalCargos.Text = (TxtTotalCargos.Text.ToDouble + e.Row.FCTextBox("TxtCargo").Text.ToDouble).ToString.FormatoNumero
@@ -511,6 +525,7 @@ Partial Class ContabilidadC_RegPrePoliza
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) Then LnkImprimirPDF.Visible = True
'e.Row.FCHyperLink("HlReferencia").NavigateUrl = CveConceptoContable
@@ -1724,6 +1739,220 @@ Partial Class ContabilidadC_RegPrePoliza
Protected Sub LnkComplementoPago_Click(sender As Object, e As EventArgs)
GeneraTimbre(CvePrePoliza)
End Sub
Protected Sub LnkImprimirPDF_Click(sender As Object, e As EventArgs)
Dim pdf() As Byte
Dim filtro() As String = {"CveCompra", "CveIE", "CveConceptoContable"}
Dim filtroComplemento() As String = {"CveIE"}
Dim Pathpdf As New List(Of String)
Dim nombre As String = "recibo"
Dim pdfs = New List(Of Byte())
Dim Path As String
Dim Factura() As Byte
Dim dt As DataTable = DtMovimientos.FiltraParametros("", "", filtro)
Dim ObjCompra As New ClsCompras
Dim ObjIE As New ClsBancos()
Dim i As Integer = 0
Dim pathPoliza As String
Try
Path = ImprimirPolizaPDF(IdPoliza)
pathPoliza = Path
If File.Exists(Path) Then
Pathpdf.Add(Path)
End If
For Each Row As DataRow In dt.Rows
If Row("CveConceptoContable").ToString.ToEntero = 30 Then
If Row("CveIE").ToString.ToEntero > 0 Then
If ObjIE.GetBancosIE(Row("CveIE").ToString.ToEntero, UsuarioActual.CveEmpresa) Then
If ObjIE.DtResultados.Rows.Count > 0 Then
Path = String.Format("{0}IE\{1}", UsuarioActual.Empresa.Ruta, ObjIE.Comprobante.ToString)
If File.Exists(Path) Then
Pathpdf.Add(Path)
End If
End If
End If
End If
End If
If Row("CveConceptoContable").ToString.ToEntero.Contiene(17, 309, 312) Then
If ObjCompra.GetCompras(Row("CveCompra").ToString.ToEntero, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then
If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then
Dim dr As DataRow = ObjCompra.DtResultados.Rows(0)
Dim RFC As String = dr("RFC").ToString
Dim CveFactura As String = dr("CveFactura").ToString
Path = String.Format("{0}Compras\{1}\{2}.pdf", UsuarioActual.Empresa.Ruta, RFC, CveFactura)
If File.Exists(Path) Then
Pathpdf.Add(Path)
End If
End If
End If
End If
Next
dt = DtMovimientos.FiltraParametros("", "", filtroComplemento)
For Each Row As DataRow In dt.Rows
If ObjCompra.GetCompraComplementoPago(-1, UsuarioActual.CveEmpresa, Row("CveIE").ToString.ToEntero) Then
If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count > 0 Then
Dim dr As DataRow = ObjCompra.DtResultados.Rows(0)
Dim RFC As String = dr("RFCde").ToString
Dim CveFactura As String = dr("CveFactura").ToString
If CveFactura <> "" Then
Path = String.Format("{0}Compras\{1}\{2}.pdf", UsuarioActual.Empresa.Ruta, RFC, CveFactura)
If File.Exists(Path) Then
Pathpdf.Add(Path)
End If
End If
End If
End If
Next
MergePdfFiles(Pathpdf.ToArray)
If File.Exists(pathPoliza) Then
Directory.Delete(String.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, Tick), True)
End If
Catch ex As Exception
Alert("Error")
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
Try
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("CveTipoPoliza").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
Return String.Format("{0}\{1}\{2}.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick, IdPoliza.ToString)
Catch ex As Exception
Alert("ggg")
End Try
End If
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 > 1 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}\Salida.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick), 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}\Salida.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick))
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}\Salida.pdf", AppDomain.CurrentDomain.BaseDirectory, Tick))
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
@@ -1945,7 +2174,7 @@ Partial Class ContabilidadC_RegPrePoliza
Next
If Not TieneError Then
ObjConta.Commit()
Alert(String.Format("<br/><br/>Prepóliza: <b><a href = ""/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={0}"" class=""texto"" target=""_blank"" >{1}</a></b>", CvePrePoliza, ObjConta.ContaFolio))
Alert(String.Format("<br/><br/>Prepóliza: <b><a href=""/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={0}"" class=""texto"" target=""_blank"" >{1}</a></b>", CvePrePoliza, ObjConta.ContaFolio))
Alert($"Se agregó la póliza {ObjConta.ContaFolio}")